plasma-manager/modules/kwin.nix

91 lines
2.2 KiB
Nix
Raw Normal View History

{ config, lib, ... }:
with lib;
let
cfg = config.programs.plasma;
2023-12-20 14:24:32 +03:00
validTitlebarButtons = {
longNames = [
"more-window-actions"
"application-menu"
"on-all-desktops"
"minimize"
"maximize"
"close"
"help"
"shade"
"keep-below-windows"
"keep-above-windows"
];
shortNames = [
"M"
"N"
"S"
"I"
"A"
"X"
"H"
"L"
"B"
"F"
];
};
# Gets a list with long names and turns it into short names
getShortNames = wantedButtons:
lists.forEach
(
lists.flatten (
lists.forEach wantedButtons (currentButton:
lists.remove null (
lists.imap0
(index: value:
if value == currentButton then "${toString index}" else null
)
validTitlebarButtons.longNames
)
2023-12-20 14:24:32 +03:00
)
)
)
getShortNameFromIndex;
2023-12-20 14:24:32 +03:00
# Gets the index and returns the short name in that position
getShortNameFromIndex = position: builtins.elemAt validTitlebarButtons.shortNames (strings.toInt position);
in
{
options.programs.plasma.kwin = {
titlebarButtons.right = mkOption {
2023-12-20 14:24:32 +03:00
type = with types; nullOr (listOf (enum validTitlebarButtons.longNames));
default = null;
2023-12-20 15:56:12 +03:00
example = [ "help" "minimize" "maximize" "close" ];
description = ''
Title bar buttons to be placed on the right.
'';
};
titlebarButtons.left = mkOption {
2023-12-20 14:24:32 +03:00
type = with types; nullOr (listOf (enum validTitlebarButtons.longNames));
default = null;
2023-12-20 15:56:12 +03:00
example = [ "on-all-desktops" "keep-above-windows" ];
description = ''
Title bar buttons to be placed on the left.
'';
};
};
config = mkIf cfg.enable {
# Titlebar buttons
programs.plasma.configFile."kwinrc"."org.kde.kdecoration2" = mkMerge [
(
mkIf (cfg.kwin.titlebarButtons.left != null) {
"ButtonsOnLeft".value = strings.concatStrings (getShortNames cfg.kwin.titlebarButtons.left);
}
)
(
mkIf (cfg.kwin.titlebarButtons.right != null) {
"ButtonsOnRight".value = strings.concatStrings (getShortNames cfg.kwin.titlebarButtons.right);
}
)
];
};
}