Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -407,13 +407,13 @@
/modules/services/window-managers/herbstluftwm @olmokramer
/tests/modules/services/window-managers/herbstluftwm @olmokramer

/modules/services/window-managers/i3-sway/i3.nix @sumnerevans
/tests/modules/services/window-managers/i3 @sumnerevans
/modules/services/window-managers/i3-sway/i3.nix @sumnerevans @sebtm
/tests/modules/services/window-managers/i3 @sumnerevans @sebtm

/modules/services/window-managers/i3-sway/lib @sumnerevans
/modules/services/window-managers/i3-sway/lib @sumnerevans @sebtm

/modules/services/window-managers/i3-sway/sway.nix @alexarice @sumnerevans
/tests/modules/services/window-managers/sway @sumnerevans
/modules/services/window-managers/i3-sway/sway.nix @alexarice @sumnerevans @sebtm
/tests/modules/services/window-managers/sway @sumnerevans @sebtm

/modules/services/window-managers/i3-sway/swaynag.nix @polykernel

Expand Down
6 changes: 6 additions & 0 deletions modules/lib/maintainers.nix
Original file line number Diff line number Diff line change
Expand Up @@ -241,4 +241,10 @@
github = "kmaasrud";
githubId = 54394333;
};
sebtm = {
name = "Sebastian Sellmeier";
email = "sebtm@users.noreply.github.com";
github = "sebtm";
githubId = 17243347;
};
}
90 changes: 43 additions & 47 deletions modules/services/window-managers/i3-sway/i3.nix
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ let
};

commonFunctions = import ./lib/functions.nix {
inherit cfg lib;
inherit config cfg lib;
moduleName = "i3";
};

Expand All @@ -143,53 +143,49 @@ let
floatingCriteriaStr windowCommandsStr colorSetStr windowBorderString
fontConfigStr keybindingDefaultWorkspace keybindingsRest workspaceOutputStr;

startupEntryStr = { command, always, notification, workspace, ... }: ''
${if always then "exec_always" else "exec"} ${
if (notification && workspace == null) then "" else "--no-startup-id"
} ${
if (workspace == null) then
startupEntryStr = { command, always, notification, workspace, ... }:
concatStringsSep " " [
(if always then "exec_always" else "exec")
(if (notification && workspace == null) then "" else "--no-startup-id")
(if (workspace == null) then
command
else
"i3-msg 'workspace ${workspace}; exec ${command}'"
}
'';

configFile = pkgs.writeText "i3.conf" ((if cfg.config != null then
with cfg.config; ''
${fontConfigStr fonts}
floating_modifier ${floating.modifier}
${windowBorderString window floating}
hide_edge_borders ${window.hideEdgeBorders}
force_focus_wrapping ${if focus.forceWrapping then "yes" else "no"}
focus_follows_mouse ${if focus.followMouse then "yes" else "no"}
focus_on_window_activation ${focus.newWindow}
mouse_warping ${if focus.mouseWarping then "output" else "none"}
workspace_layout ${workspaceLayout}
workspace_auto_back_and_forth ${
if workspaceAutoBackAndForth then "yes" else "no"
}

client.focused ${colorSetStr colors.focused}
client.focused_inactive ${colorSetStr colors.focusedInactive}
client.unfocused ${colorSetStr colors.unfocused}
client.urgent ${colorSetStr colors.urgent}
client.placeholder ${colorSetStr colors.placeholder}
client.background ${colors.background}

${keybindingsStr { keybindings = keybindingDefaultWorkspace; }}
${keybindingsStr { keybindings = keybindingsRest; }}
${keycodebindingsStr keycodebindings}
${concatStringsSep "\n" (mapAttrsToList (modeStr false) modes)}
${concatStringsSep "\n" (mapAttrsToList assignStr assigns)}
${concatStringsSep "\n" (map barStr bars)}
${optionalString (gaps != null) gapsStr}
${concatStringsSep "\n" (map floatingCriteriaStr floating.criteria)}
${concatStringsSep "\n" (map windowCommandsStr window.commands)}
${concatStringsSep "\n" (map startupEntryStr startup)}
${concatStringsSep "\n" (map workspaceOutputStr workspaceOutputAssign)}
''
else
"") + "\n" + cfg.extraConfig);
"i3-msg 'workspace ${workspace}; exec ${command}'")
];

configFile = pkgs.writeText "i3.conf" (concatStringsSep "\n"
((if cfg.config != null then
with cfg.config;
([
(fontConfigStr fonts)
"floating_modifier ${floating.modifier}"
(windowBorderString window floating)
"hide_edge_borders ${window.hideEdgeBorders}"
"force_focus_wrapping ${if focus.forceWrapping then "yes" else "no"}"
"focus_follows_mouse ${if focus.followMouse then "yes" else "no"}"
"focus_on_window_activation ${focus.newWindow}"
"mouse_warping ${if focus.mouseWarping then "output" else "none"}"
"workspace_layout ${workspaceLayout}"
"workspace_auto_back_and_forth ${
if workspaceAutoBackAndForth then "yes" else "no"
}"
"client.focused ${colorSetStr colors.focused}"
"client.focused_inactive ${colorSetStr colors.focusedInactive}"
"client.unfocused ${colorSetStr colors.unfocused}"
"client.urgent ${colorSetStr colors.urgent}"
"client.placeholder ${colorSetStr colors.placeholder}"
"client.background ${colors.background}"
(keybindingsStr { keybindings = keybindingDefaultWorkspace; })
(keybindingsStr { keybindings = keybindingsRest; })
(keycodebindingsStr keycodebindings)
] ++ mapAttrsToList (modeStr false) modes
++ mapAttrsToList assignStr assigns ++ map barStr bars
Comment thread
SebTM marked this conversation as resolved.
++ optional (gaps != null) gapsStr
++ map floatingCriteriaStr floating.criteria
++ map windowCommandsStr window.commands ++ map startupEntryStr startup
Comment thread
SebTM marked this conversation as resolved.
++ map workspaceOutputStr workspaceOutputAssign)
else
[ ]) ++ [ cfg.extraConfig ]));

# Validates the i3 configuration
checkI3Config =
Expand All @@ -207,7 +203,7 @@ let
'';

in {
meta.maintainers = with maintainers; [ sumnerevans ];
meta.maintainers = with maintainers; [ sumnerevans sebtm ];

options = {
xsession.windowManager.i3 = {
Expand Down
160 changes: 79 additions & 81 deletions modules/services/window-managers/i3-sway/lib/functions.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ cfg, lib, moduleName }:
{ cfg, config, lib, moduleName }:

with lib;

Expand All @@ -20,9 +20,9 @@ rec {
cfg.config.defaultWorkspace == null || v != cfg.config.defaultWorkspace)
cfg.config.keybindings;

keybindingsStr = { keybindings, bindsymArgs ? "" }:
keybindingsStr = { keybindings, bindsymArgs ? "", indent ? "" }:
concatStringsSep "\n" (mapAttrsToList (keycomb: action:
optionalString (action != null) "bindsym ${
optionalString (action != null) "${indent}bindsym ${
lib.optionalString (bindsymArgs != "") "${bindsymArgs} "
}${keycomb} ${action}") keybindings);

Expand All @@ -46,6 +46,7 @@ rec {
${keybindingsStr {
inherit keybindings;
bindsymArgs = lib.optionalString bindkeysToCode "--to-code";
indent = " ";
}}
}
'';
Expand Down Expand Up @@ -73,89 +74,76 @@ rec {
let colorsNotNull = lib.filterAttrs (n: v: v != null) colors != { };
in ''
bar {
${optionalString (id != null) "id ${id}"}
${fontConfigStr fonts}
${optionalString (mode != null) "mode ${mode}"}
${optionalString (hiddenState != null) "hidden_state ${hiddenState}"}
${optionalString (position != null) "position ${position}"}
${
optionalString (statusCommand != null)
"status_command ${statusCommand}"
concatStringsSep "\n" (indent (lists.subtractLists [ "" null ]
(flatten [
(optionalString (id != null) "id ${id}")
(fontConfigStr fonts)
(optionalString (mode != null) "mode ${mode}")
(optionalString (hiddenState != null)
"hidden_state ${hiddenState}")
(optionalString (position != null) "position ${position}")
(optionalString (statusCommand != null)
"status_command ${statusCommand}")
"${moduleName}bar_command ${command}"
(optionalString (workspaceButtons != null)
"workspace_buttons ${if workspaceButtons then "yes" else "no"}")
(optionalString (workspaceNumbers != null)
"strip_workspace_numbers ${
if !workspaceNumbers then "yes" else "no"
}")
(optionalString (trayOutput != null) "tray_output ${trayOutput}")
(optionals colorsNotNull (indent
(lists.subtractLists [ "" null ] [
"colors {"
(optionalString (colors.background != null)
"background ${colors.background}")
(optionalString (colors.statusline != null)
"statusline ${colors.statusline}")
(optionalString (colors.separator != null)
"separator ${colors.separator}")
(optionalString (colors.focusedBackground != null)
"focused_background ${colors.focusedBackground}")
(optionalString (colors.focusedStatusline != null)
"focused_statusline ${colors.focusedStatusline}")
(optionalString (colors.focusedSeparator != null)
"focused_separator ${colors.focusedSeparator}")
(optionalString (colors.focusedWorkspace != null)
"focused_workspace ${
barColorSetStr colors.focusedWorkspace
}")
(optionalString (colors.activeWorkspace != null)
"active_workspace ${barColorSetStr colors.activeWorkspace}")
(optionalString (colors.inactiveWorkspace != null)
"inactive_workspace ${
barColorSetStr colors.inactiveWorkspace
}")
(optionalString (colors.urgentWorkspace != null)
"urgent_workspace ${barColorSetStr colors.urgentWorkspace}")
(optionalString (colors.bindingMode != null)
"binding_mode ${barColorSetStr colors.bindingMode}")
"}"
])) { })
extraConfig
])) { })
}
${moduleName}bar_command ${command}
${
optionalString (workspaceButtons != null)
"workspace_buttons ${if workspaceButtons then "yes" else "no"}"
}
${
optionalString (workspaceNumbers != null)
"strip_workspace_numbers ${if !workspaceNumbers then "yes" else "no"}"
}
${optionalString (trayOutput != null) "tray_output ${trayOutput}"}
${optionalString colorsNotNull "colors {"}
${
optionalString (colors.background != null)
"background ${colors.background}"
}
${
optionalString (colors.statusline != null)
"statusline ${colors.statusline}"
}
${
optionalString (colors.separator != null)
"separator ${colors.separator}"
}
${
optionalString (colors.focusedBackground != null)
"focused_background ${colors.focusedBackground}"
}
${
optionalString (colors.focusedStatusline != null)
"focused_statusline ${colors.focusedStatusline}"
}
${
optionalString (colors.focusedSeparator != null)
"focused_separator ${colors.focusedSeparator}"
}
${
optionalString (colors.focusedWorkspace != null)
"focused_workspace ${barColorSetStr colors.focusedWorkspace}"
}
${
optionalString (colors.activeWorkspace != null)
"active_workspace ${barColorSetStr colors.activeWorkspace}"
}
${
optionalString (colors.inactiveWorkspace != null)
"inactive_workspace ${barColorSetStr colors.inactiveWorkspace}"
}
${
optionalString (colors.urgentWorkspace != null)
"urgent_workspace ${barColorSetStr colors.urgentWorkspace}"
}
${
optionalString (colors.bindingMode != null)
"binding_mode ${barColorSetStr colors.bindingMode}"
}
${optionalString colorsNotNull "}"}
${extraConfig}
}
'';

gapsStr = with cfg.config.gaps; ''
${optionalString (inner != null) "gaps inner ${toString inner}"}
${optionalString (outer != null) "gaps outer ${toString outer}"}
${optionalString (horizontal != null)
"gaps horizontal ${toString horizontal}"}
${optionalString (vertical != null) "gaps vertical ${toString vertical}"}
${optionalString (top != null) "gaps top ${toString top}"}
${optionalString (bottom != null) "gaps bottom ${toString bottom}"}
${optionalString (left != null) "gaps left ${toString left}"}
${optionalString (right != null) "gaps right ${toString right}"}

${optionalString smartGaps "smart_gaps on"}
${optionalString (smartBorders != "off") "smart_borders ${smartBorders}"}
'';
gapsStr = with cfg.config.gaps;
concatStringsSep "\n" (lists.subtractLists [ "" null ] [
(optionalString (inner != null) "gaps inner ${toString inner}")
(optionalString (outer != null) "gaps outer ${toString outer}")
(optionalString (horizontal != null)
"gaps horizontal ${toString horizontal}")
(optionalString (vertical != null) "gaps vertical ${toString vertical}")
(optionalString (top != null) "gaps top ${toString top}")
(optionalString (bottom != null) "gaps bottom ${toString bottom}")
(optionalString (left != null) "gaps left ${toString left}")
(optionalString (right != null) "gaps right ${toString right}")
(optionalString smartGaps "smart_gaps on")
(optionalString (smartBorders != "off") "smart_borders ${smartBorders}")
]);

windowBorderString = window: floating:
let
Expand All @@ -172,4 +160,14 @@ rec {
"for_window ${criteriaStr criteria} ${command}";
workspaceOutputStr = item:
''workspace "${item.workspace}" output ${item.output}'';

indent = list:
{ includesWrapper ? true, level ? 1 }:
let prefix = concatStringsSep "" (lib.genList (x: " ") (level * 2));

in (lib.imap1 (i: v:
"${if includesWrapper && (i == 1 || i == (lib.length list)) then
v
else
"${prefix}${v}"}") list);
}
Loading