-
-
Notifications
You must be signed in to change notification settings - Fork 185
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
qt: add flexible theming with sensible defaults (#780)
This extends the Qt theming improvements for KDE from PR [1] ("kde: replace kdeglobals with Kvantum theme") to provide generic Qt theming support in KDE and non-KDE environments. [1]: #142 Link: #780 Co-authored-by: Blusk <[email protected]> Co-authored-by: Jackaed <[email protected]> Co-authored-by: Kilian Mio <[email protected]> Reviewed-by: NAHO <[email protected]> Tested-by: https://github.com/Mistrustfully Tested-by: https://github.com/eblechschmidt Tested-by: NAHO <[email protected]>
- Loading branch information
1 parent
b00c9f4
commit b7f50a5
Showing
5 changed files
with
2,587 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
{ | ||
pkgs, | ||
config, | ||
lib, | ||
... | ||
}: | ||
{ | ||
options.stylix.targets.qt = { | ||
enable = config.lib.stylix.mkEnableTarget "QT" pkgs.stdenv.hostPlatform.isLinux; | ||
platform = lib.mkOption { | ||
description = '' | ||
Selects the platform theme to use for Qt applications. | ||
Defaults to the standard platform theme used in the configured DE in NixOS when | ||
`stylix.homeManagerIntegration.followSystem = true`. | ||
''; | ||
type = lib.types.str; | ||
default = "qtct"; | ||
}; | ||
}; | ||
|
||
config = lib.mkIf config.stylix.targets.qt.enable ( | ||
let | ||
iconTheme = | ||
if (config.stylix.polarity == "dark") then | ||
config.stylix.iconTheme.dark | ||
else | ||
config.stylix.iconTheme.light; | ||
|
||
recommendedStyles = { | ||
gnome = if config.stylix.polarity == "dark" then "adwaita-dark" else "adwaita"; | ||
kde = "breeze"; | ||
qtct = "kvantum"; | ||
}; | ||
|
||
recommendedStyle = recommendedStyles."${config.qt.platformTheme.name}" or null; | ||
|
||
kvantumPackage = | ||
let | ||
kvconfig = config.lib.stylix.colors { | ||
template = ./kvconfig.mustache; | ||
extension = ".kvconfig"; | ||
}; | ||
svg = config.lib.stylix.colors { | ||
template = ./kvantum-svg.mustache; | ||
extension = "svg"; | ||
}; | ||
in | ||
pkgs.runCommandLocal "base16-kvantum" { } '' | ||
directory="$out/share/Kvantum/Base16Kvantum" | ||
mkdir --parents "$directory" | ||
cp ${kvconfig} "$directory/Base16Kvantum.kvconfig" | ||
cp ${svg} "$directory/Base16Kvantum.svg" | ||
''; | ||
in | ||
{ | ||
warnings = | ||
(lib.optional (config.stylix.targets.qt.platform != "qtct") | ||
"stylix: qt: `config.stylix.targets.qt.platform` other than 'qtct' are currently unsupported: ${config.stylix.targets.qt.platform}. Support may be added in the future." | ||
) | ||
++ (lib.optional (config.qt.style.name != recommendedStyle) | ||
"stylix: qt: Changing `config.qt.style` is unsupported and may result in breakage! Use with caution!" | ||
); | ||
|
||
home.packages = lib.optional (config.qt.style.name == "kvantum") kvantumPackage; | ||
|
||
qt = { | ||
enable = true; | ||
style.name = recommendedStyle; | ||
platformTheme.name = config.stylix.targets.qt.platform; | ||
}; | ||
|
||
xdg.configFile = | ||
let | ||
qtctConf = | ||
'' | ||
[Appearance] | ||
'' | ||
+ lib.optionalString (config.qt.style ? name) '' | ||
style=${config.qt.style.name} | ||
'' | ||
+ lib.optionalString (iconTheme != null) '' | ||
icon_theme=${iconTheme} | ||
''; | ||
|
||
in | ||
lib.mkMerge [ | ||
(lib.mkIf (config.qt.style.name == "kvantum") { | ||
"Kvantum/kvantum.kvconfig".source = | ||
(pkgs.formats.ini { }).generate "kvantum.kvconfig" | ||
{ General.theme = "Base16Kvantum"; }; | ||
|
||
"Kvantum/Base16Kvantum".source = | ||
"${kvantumPackage}/share/Kvantum/Base16Kvantum"; | ||
}) | ||
|
||
(lib.mkIf (config.qt.platformTheme.name == "qtct") { | ||
"qt5ct/qt5ct.conf".text = qtctConf; | ||
"qt5ct/qt6ct.conf".text = qtctConf; | ||
}) | ||
]; | ||
} | ||
); | ||
} |
Oops, something went wrong.