-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add COSMIC desktop shortcuts configuration
Add support for configuring COSMIC desktop keyboard shortcuts using home-manager. The changes include: - New capitalizeWord utility function for string manipulation - New shortcuts module with comprehensive keyboard shortcut configuration options - Integration of shortcuts module into default modules
- Loading branch information
1 parent
6da040e
commit daf6783
Showing
3 changed files
with
240 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
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 |
---|---|---|
|
@@ -18,6 +18,7 @@ | |
[ | ||
./files.nix | ||
./panels.nix | ||
./shortcuts.nix | ||
] | ||
++ lib.foldlAttrs ( | ||
prev: name: type: | ||
|
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,232 @@ | ||
{ config, lib, ... }: | ||
let | ||
cfg = config.wayland.desktopManager.cosmic; | ||
|
||
inherit (lib.cosmic.options) mkNullOrOption; | ||
inherit (lib.cosmic.utils) capitalizeWord; | ||
in | ||
{ | ||
options.wayland.desktopManager.cosmic.shortcuts = | ||
let | ||
shortcutSubmodule = | ||
let | ||
# NOTE: Last updated: 26/12/2024 at 4:15 UTC-3 with the following commit: | ||
# https://github.com/pop-os/cosmic-settings-daemon/commit/747e482ca197497ee3bc5f6e9dcd23c73e592e47 | ||
direction = [ | ||
"Down" | ||
"Left" | ||
"Right" | ||
"Up" | ||
]; | ||
|
||
enumVariants = [ | ||
"Close" | ||
"Debug" | ||
"Disable" | ||
"LastWorkspace" | ||
"Maximize" | ||
"MigrateWorkspaceToNextOutput" | ||
"MigrateWorkspaceToPreviousOutput" | ||
"Minimize" | ||
"MoveToLastWorkspace" | ||
"MoveToNextOutput" | ||
"MoveToNextWorkspace" | ||
"MoveToPreviousOutput" | ||
"MoveToPreviousWorkspace" | ||
"NextOutput" | ||
"NextWorkspace" | ||
"PreviousOutput" | ||
"PreviousWorkspace" | ||
"SendToLastWorkspace" | ||
"SendToNextOutput" | ||
"SendToNextWorkspace" | ||
"SendToPreviousOutput" | ||
"SendToPreviousWorkspace" | ||
"SwapWindow" | ||
"ToggleOrientation" | ||
"ToggleStacking" | ||
"ToggleSticky" | ||
"ToggleTiling" | ||
"ToggleWindowFloating" | ||
]; | ||
|
||
focusDirection = [ | ||
"Down" | ||
"In" | ||
"Left" | ||
"Right" | ||
"Out" | ||
"Up" | ||
]; | ||
|
||
orientation = [ | ||
"Horizontal" | ||
"Vertical" | ||
]; | ||
|
||
resizeDirection = [ | ||
"Inwards" | ||
"Outwards" | ||
]; | ||
|
||
# NOTE: Unused but kept since it might be useful in the future | ||
# deadnix: skip | ||
resizeEdge = [ | ||
"Bottom" | ||
"BottomLeft" | ||
"BottomRight" | ||
"Left" | ||
"Right" | ||
"Top" | ||
"TopLeft" | ||
"TopRight" | ||
]; | ||
|
||
system = [ | ||
"AppLibrary" | ||
"BrightnessDown" | ||
"BrightnessUp" | ||
"HomeFolder" | ||
"KeyboardBrightnessDown" | ||
"KeyboardBrightnessUp" | ||
"Launcher" | ||
"LockScreen" | ||
"Mute" | ||
"MuteMic" | ||
"PlayPause" | ||
"PlayNext" | ||
"PlayPrev" | ||
"Screenshot" | ||
"Terminal" | ||
"VolumeLower" | ||
"VolumeRaise" | ||
"WebBrowser" | ||
"WindowSwitcher" | ||
"WindowSwitcherPrevious" | ||
"WorkspaceOverview" | ||
]; | ||
in | ||
lib.types.submodule { | ||
options = { | ||
description = mkNullOrOption { | ||
type = with lib.types; ronOptionalOf str; | ||
example = { | ||
__type = "optional"; | ||
value = "Open Terminal"; | ||
}; | ||
description = "Description of the shortcut"; | ||
}; | ||
key = lib.mkOption { | ||
type = lib.types.str; | ||
example = "Super+Q"; | ||
description = "The key combination for the shortcut"; | ||
}; | ||
value = lib.mkOption { | ||
type = | ||
with lib.types; | ||
oneOf [ | ||
(ronEnum enumVariants) | ||
(ronTupleEnumOf (ronEnum direction) [ | ||
"MigrateWorkspaceToNextOutput" | ||
"Move" | ||
"MoveToOutput" | ||
"SendToOutput" | ||
"SwitchOutput" | ||
]) | ||
(ronTupleEnumOf ints.u8 [ | ||
"MoveToWorkspace" | ||
"SendToWorkspace" | ||
"Workspace" | ||
]) | ||
(ronTupleEnumOf (ronEnum focusDirection) [ "Focus" ]) | ||
(ronTupleEnumOf (ronEnum orientation) [ "Orientation" ]) | ||
(ronTupleEnumOf (ronEnum resizeDirection) [ "Resizing" ]) | ||
(ronTupleEnumOf (ronEnum system) [ "System" ]) | ||
(ronTupleEnumOf str [ "Spawn" ]) | ||
]; | ||
example = { | ||
__type = "enum"; | ||
variant = "Close"; | ||
}; | ||
description = "The action to be performed by the shortcut"; | ||
}; | ||
}; | ||
}; | ||
in | ||
mkNullOrOption { | ||
type = lib.types.listOf shortcutSubmodule; | ||
example = [ | ||
{ | ||
description = "Open Firefox"; | ||
key = "Super+Alt+B"; | ||
value = { | ||
__type = "enum"; | ||
variant = "Spawn"; | ||
value = "firefox"; | ||
}; | ||
} | ||
{ | ||
key = "Super+Q"; | ||
value = { | ||
__type = "enum"; | ||
variant = "Close"; | ||
}; | ||
} | ||
]; | ||
description = '' | ||
List of shortcuts to be configured for COSMIC. | ||
''; | ||
}; | ||
|
||
config = | ||
let | ||
parseShortcuts = | ||
key: | ||
let | ||
parts = builtins.filter (x: x != "") (lib.splitString "+" key); | ||
|
||
validModifiers = [ | ||
"Alt" | ||
"Ctrl" | ||
"Shift" | ||
"Super" | ||
]; | ||
in | ||
{ | ||
key = | ||
let | ||
last = lib.last parts; | ||
in | ||
if builtins.stringLength last == 1 then | ||
lib.toLower last | ||
else if builtins.elem (capitalizeWord last) validModifiers then | ||
throw "Last part of the key cannot be a modifier" | ||
else | ||
last; | ||
modifiers = map ( | ||
modifier: | ||
if builtins.elem modifier validModifiers then | ||
modifier | ||
else | ||
throw "Invalid modifier: ${modifier}. Valid modifiers are: ${builtins.concatStringsSep ", " validModifiers}" | ||
) (lib.init parts); | ||
}; | ||
in | ||
lib.mkIf (cfg.enable && cfg.shortcuts != null) { | ||
wayland.desktopManager.cosmic.configFile."com.system76.CosmicSettings.Shortcuts" = { | ||
entries.custom = { | ||
__type = "map"; | ||
value = map (shortcut: { | ||
key = lib.cosmic.utils.cleanNullsExceptOptional ( | ||
parseShortcuts shortcut.key | ||
// { | ||
inherit (shortcut) description; | ||
} | ||
); | ||
inherit (shortcut) value; | ||
}) cfg.shortcuts; | ||
}; | ||
version = 1; | ||
}; | ||
}; | ||
} |