|
1 | 1 | { config, lib, ... }:
|
| 2 | +let |
| 3 | + inherit (builtins) |
| 4 | + all |
| 5 | + elem |
| 6 | + filter |
| 7 | + getAttr |
| 8 | + groupBy |
| 9 | + hasAttr |
| 10 | + mapAttrs |
| 11 | + stringLength |
| 12 | + ; |
| 13 | + |
| 14 | + inherit (lib) |
| 15 | + importJSON |
| 16 | + init |
| 17 | + last |
| 18 | + mapAttrsToList |
| 19 | + mkIf |
| 20 | + mkOption |
| 21 | + pipe |
| 22 | + splitString |
| 23 | + toLower |
| 24 | + types |
| 25 | + unique |
| 26 | + ; |
| 27 | + |
| 28 | + inherit (lib.cosmic) |
| 29 | + cleanNullsExceptOptional |
| 30 | + defaultNullOpts |
| 31 | + mkRonExpression |
| 32 | + rustToNixType |
| 33 | + ; |
| 34 | +in |
2 | 35 | {
|
3 | 36 | options.wayland.desktopManager.cosmic.shortcuts =
|
4 | 37 | let
|
5 |
| - inherit (lib.cosmic) defaultNullOpts; |
6 |
| - |
7 | 38 | shortcutSubmodule =
|
8 | 39 | let
|
9 |
| - generatedActions = lib.importJSON ../generated/actions-for-shortcuts.json; |
| 40 | + generatedActions = importJSON ../generated/actions-for-shortcuts.json; |
10 | 41 | in
|
11 |
| - lib.types.submodule { |
| 42 | + types.submodule { |
12 | 43 | options = {
|
13 | 44 | description =
|
14 |
| - defaultNullOpts.mkRonOptionalOf lib.types.str |
| 45 | + defaultNullOpts.mkRonOptionalOf types.str |
15 | 46 | {
|
16 | 47 | __type = "optional";
|
17 | 48 | value = "Open Terminal";
|
|
21 | 52 | Used by COSMIC Settings to display the name of a custom shortcut.
|
22 | 53 | This field is optional, and should only be used when defining custom shortcuts.
|
23 | 54 | '';
|
24 |
| - key = lib.mkOption { |
25 |
| - type = lib.types.str; |
| 55 | + key = mkOption { |
| 56 | + type = types.str; |
26 | 57 | example = "Super+Q";
|
27 | 58 | description = ''
|
28 | 59 | The key combination that triggers the action.
|
29 | 60 | For example, "Super+Q" would trigger the action when the Super and Q keys are pressed together.
|
30 | 61 | '';
|
31 | 62 | };
|
32 |
| - action = lib.mkOption { |
| 63 | + action = mkOption { |
33 | 64 | type =
|
34 |
| - with lib.types; |
| 65 | + with types; |
35 | 66 | maybeRonRaw (
|
36 | 67 | oneOf (
|
37 | 68 | [
|
38 | 69 | (ronEnum (
|
39 |
| - lib.pipe generatedActions [ |
40 |
| - (builtins.getAttr "Actions") |
41 |
| - (builtins.filter (action: !(builtins.hasAttr "type" action))) |
| 70 | + pipe generatedActions [ |
| 71 | + (getAttr "Actions") |
| 72 | + (filter (action: !(hasAttr "type" action))) |
42 | 73 | (map (action: action.name))
|
| 74 | + # Remove deprecated actions from the list |
| 75 | + # TODO: Remove it when it gets removed from actions |
| 76 | + (filter ( |
| 77 | + action: |
| 78 | + !(elem action [ |
| 79 | + "MigrateWorkspaceToNextOutput" |
| 80 | + "MigrateWorkspaceToPreviousOutput" |
| 81 | + "MoveToNextOutput" |
| 82 | + "MoveToPreviousOutput" |
| 83 | + "NextOutput" |
| 84 | + "PreviousOutput" |
| 85 | + "SendToNextOutput" |
| 86 | + "SendToPreviousOutput" |
| 87 | + ]) |
| 88 | + )) |
43 | 89 | ]
|
44 | 90 | ))
|
45 | 91 | ]
|
46 | 92 | ++
|
47 |
| - lib.mapAttrsToList |
| 93 | + mapAttrsToList |
48 | 94 | (
|
49 | 95 | type: names:
|
50 | 96 | let
|
51 | 97 | actionDependencies = generatedActions.Dependencies;
|
52 | 98 |
|
53 | 99 | elemType =
|
54 |
| - let |
55 |
| - inherit (lib.cosmic) rustToNixType; |
56 |
| - in |
57 |
| - if builtins.hasAttr type actionDependencies then |
| 100 | + if hasAttr type actionDependencies then |
58 | 101 | ronEnum (map (action: action.name) actionDependencies.${type})
|
59 | 102 | else
|
60 | 103 | rustToNixType type;
|
61 | 104 | in
|
62 | 105 | ronTupleEnumOf elemType names 1
|
63 | 106 | )
|
64 | 107 | (
|
65 |
| - lib.pipe generatedActions [ |
66 |
| - (builtins.getAttr "Actions") |
67 |
| - (builtins.filter (action: builtins.hasAttr "type" action)) |
68 |
| - (builtins.groupBy (action: action.type)) |
69 |
| - (builtins.mapAttrs (_: actions: map (action: action.name) actions)) |
| 108 | + pipe generatedActions [ |
| 109 | + (getAttr "Actions") |
| 110 | + (filter (action: hasAttr "type" action)) |
| 111 | + (groupBy (action: action.type)) |
| 112 | + (mapAttrs (_: actions: map (action: action.name) actions)) |
70 | 113 | ]
|
71 | 114 | )
|
72 | 115 | )
|
73 | 116 | );
|
74 |
| - example = |
75 |
| - let |
76 |
| - inherit (lib.cosmic) mkRonExpression; |
77 |
| - in |
78 |
| - mkRonExpression 0 { |
79 |
| - __type = "enum"; |
80 |
| - variant = "Spawn"; |
81 |
| - value = [ "firefox" ]; |
82 |
| - } null; |
| 117 | + example = mkRonExpression 0 { |
| 118 | + __type = "enum"; |
| 119 | + variant = "Spawn"; |
| 120 | + value = [ "firefox" ]; |
| 121 | + } null; |
83 | 122 | description = ''
|
84 | 123 | The action triggered by the shortcut.
|
85 | 124 | Actions can include running a command, moving windows, system actions, and more.
|
|
88 | 127 | };
|
89 | 128 | };
|
90 | 129 | in
|
91 |
| - defaultNullOpts.mkNullable (lib.types.listOf shortcutSubmodule) |
| 130 | + defaultNullOpts.mkNullable (types.listOf shortcutSubmodule) |
92 | 131 | [
|
93 | 132 | {
|
94 | 133 | description = {
|
|
162 | 201 | "Super"
|
163 | 202 | ];
|
164 | 203 |
|
165 |
| - isModifier = part: builtins.elem part validModifiers; |
| 204 | + isModifier = part: elem part validModifiers; |
166 | 205 |
|
167 |
| - parts = lib.pipe key [ |
168 |
| - (lib.splitString "+") |
169 |
| - (builtins.filter (x: x != "")) |
| 206 | + parts = pipe key [ |
| 207 | + (splitString "+") |
| 208 | + (filter (x: x != "")) |
170 | 209 | ];
|
171 |
| - |
172 |
| - init = lib.init parts; |
173 |
| - last = lib.last parts; |
174 | 210 | in
|
175 | 211 | {
|
176 | 212 | key =
|
177 |
| - if builtins.all isModifier parts then |
| 213 | + if all isModifier parts then |
178 | 214 | null
|
179 |
| - else if builtins.stringLength last == 1 then |
180 |
| - lib.toLower last |
| 215 | + else if stringLength last == 1 then |
| 216 | + toLower (last parts) |
181 | 217 | else
|
182 | 218 | last;
|
183 | 219 |
|
184 | 220 | modifiers = map (modifier: {
|
185 | 221 | __type = "enum";
|
186 | 222 | variant = modifier;
|
187 |
| - }) (lib.unique (if builtins.all isModifier parts then parts else init)); |
| 223 | + }) (unique (if all isModifier parts then parts else init parts)); |
188 | 224 | };
|
189 | 225 | in
|
190 |
| - lib.mkIf (cfg.shortcuts != null) { |
| 226 | + mkIf (cfg.shortcuts != null) { |
191 | 227 | wayland.desktopManager.cosmic.configFile."com.system76.CosmicSettings.Shortcuts" = {
|
192 | 228 | entries.custom = {
|
193 | 229 | __type = "map";
|
194 |
| - value = lib.pipe cfg.shortcuts [ |
195 |
| - (map (shortcut: { |
196 |
| - key = |
197 |
| - let |
198 |
| - inherit (lib.cosmic) cleanNullsExceptOptional; |
199 |
| - in |
200 |
| - lib.pipe shortcut.key [ |
201 |
| - parseShortcuts |
202 |
| - (parsed: parsed // { inherit (shortcut) description; }) |
203 |
| - cleanNullsExceptOptional |
204 |
| - ]; |
205 |
| - value = shortcut.action; |
206 |
| - })) |
207 |
| - ]; |
| 230 | + value = map (shortcut: { |
| 231 | + key = pipe shortcut.key [ |
| 232 | + parseShortcuts |
| 233 | + (parsed: parsed // { inherit (shortcut) description; }) |
| 234 | + cleanNullsExceptOptional |
| 235 | + ]; |
| 236 | + value = shortcut.action; |
| 237 | + }) cfg.shortcuts; |
208 | 238 | };
|
209 | 239 | version = 1;
|
210 | 240 | };
|
|
0 commit comments