Skip to content

Commit

Permalink
i3,sway: add option for default workspace (nix-community#2002)
Browse files Browse the repository at this point in the history
  • Loading branch information
SebTM authored and chisui committed May 31, 2021
1 parent caa593d commit 64c499f
Show file tree
Hide file tree
Showing 18 changed files with 305 additions and 6 deletions.
7 changes: 4 additions & 3 deletions modules/services/window-managers/i3-sway/i3.nix
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ let
inherit (commonOptions)
fonts window floating focus assigns modifier workspaceLayout
workspaceAutoBackAndForth keycodebindings colors bars startup gaps menu
terminal;
terminal defaultWorkspace;

keybindings = mkOption {
type = types.attrsOf (types.nullOr types.str);
Expand Down Expand Up @@ -141,7 +141,7 @@ let
inherit (commonFunctions)
keybindingsStr keycodebindingsStr modeStr assignStr barStr gapsStr
floatingCriteriaStr windowCommandsStr colorSetStr windowBorderString
fontConfigStr;
fontConfigStr keybindingDefaultWorkspace keybindingsRest;

startupEntryStr = { command, always, notification, workspace, ... }: ''
${if always then "exec_always" else "exec"} ${
Expand Down Expand Up @@ -176,7 +176,8 @@ let
client.placeholder ${colorSetStr colors.placeholder}
client.background ${colors.background}
${keybindingsStr { inherit keybindings; }}
${keybindingsStr { keybindings = keybindingDefaultWorkspace; }}
${keybindingsStr { keybindings = keybindingsRest; }}
${keycodebindingsStr keycodebindings}
${concatStringsSep "\n" (mapAttrsToList modeStr modes)}
${concatStringsSep "\n" (mapAttrsToList assignStr assigns)}
Expand Down
8 changes: 8 additions & 0 deletions modules/services/window-managers/i3-sway/lib/functions.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ rec {
concatStringsSep " " (mapAttrsToList (k: v: ''${k}="${v}"'') criteria)
}]";

keybindingDefaultWorkspace = filterAttrs (n: v:
cfg.config.defaultWorkspace != null && v == cfg.config.defaultWorkspace)
cfg.config.keybindings;

keybindingsRest = filterAttrs (n: v:
cfg.config.defaultWorkspace == null || v != cfg.config.defaultWorkspace)
cfg.config.keybindings;

keybindingsStr = { keybindings, bindsymArgs ? "" }:
concatStringsSep "\n" (mapAttrsToList (keycomb: action:
optionalString (action != null) "bindsym ${
Expand Down
12 changes: 12 additions & 0 deletions modules/services/window-managers/i3-sway/lib/options.nix
Original file line number Diff line number Diff line change
Expand Up @@ -819,4 +819,16 @@ in {
description = "Default launcher to use.";
example = "bemenu-run";
};

defaultWorkspace = mkOption {
type = types.nullOr types.str;
default = null;
description = ''
The default workspace to show when ${
if isSway then "sway" else "i3"
} is launched.
This must to correspond to the value of the keybinding of the default workspace.
'';
example = "workspace number 9";
};
}
11 changes: 8 additions & 3 deletions modules/services/window-managers/i3-sway/sway.nix
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ let
inherit (commonOptions)
fonts window floating focus assigns workspaceLayout
workspaceAutoBackAndForth modifier keycodebindings colors bars startup
gaps menu terminal;
gaps menu terminal defaultWorkspace;

left = mkOption {
type = types.str;
Expand Down Expand Up @@ -246,7 +246,7 @@ let
inherit (commonFunctions)
keybindingsStr keycodebindingsStr modeStr assignStr barStr gapsStr
floatingCriteriaStr windowCommandsStr colorSetStr windowBorderString
fontConfigStr;
fontConfigStr keybindingDefaultWorkspace keybindingsRest;

startupEntryStr = { command, always, ... }: ''
${if always then "exec_always" else "exec"} ${command}
Expand Down Expand Up @@ -285,7 +285,12 @@ let
client.background ${colors.background}
${keybindingsStr {
inherit keybindings;
keybindings = keybindingDefaultWorkspace;
bindsymArgs =
lib.optionalString (cfg.config.bindkeysToCode) "--to-code";
}}
${keybindingsStr {
keybindings = keybindingsRest;
bindsymArgs =
lib.optionalString (cfg.config.bindkeysToCode) "--to-code";
}}
Expand Down
1 change: 1 addition & 0 deletions tests/modules/services/window-managers/i3/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
i3-fonts-deprecated = ./i3-fonts-deprecated.nix;
i3-keybindings = ./i3-keybindings.nix;
i3-null-config = ./i3-null-config.nix;
i3-workspace-default = ./i3-workspace-default.nix;
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ client.urgent #2f343a #900000 #ffffff #900000 #900000
client.placeholder #000000 #0c0c0c #ffffff #000000 #0c0c0c
client.background #ffffff


bindsym Mod1+0 workspace number 10
bindsym Mod1+1 workspace number 1
bindsym Mod1+2 workspace number 2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ client.urgent #2f343a #900000 #ffffff #900000 #900000
client.placeholder #000000 #0c0c0c #ffffff #000000 #0c0c0c
client.background #ffffff


bindsym Mod1+0 workspace number 10
bindsym Mod1+1 workspace number 1
bindsym Mod1+2 workspace number 2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ client.urgent #2f343a #900000 #ffffff #900000 #900000
client.placeholder #000000 #0c0c0c #ffffff #000000 #0c0c0c
client.background #ffffff


bindsym Mod1+0 workspace number 10
bindsym Mod1+1 workspace number 1
bindsym Mod1+2 workspace number 2
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
font pango:monospace 8.000000
floating_modifier Mod1
default_border normal 2
default_floating_border normal 2
hide_edge_borders none
force_focus_wrapping no
focus_follows_mouse yes
focus_on_window_activation smart
mouse_warping output
workspace_layout default
workspace_auto_back_and_forth no

client.focused #4c7899 #285577 #ffffff #2e9ef4 #285577
client.focused_inactive #333333 #5f676a #ffffff #484e50 #5f676a
client.unfocused #333333 #222222 #888888 #292d2e #222222
client.urgent #2f343a #900000 #ffffff #900000 #900000
client.placeholder #000000 #0c0c0c #ffffff #000000 #0c0c0c
client.background #ffffff

bindsym Mod1+1 workspace number 1
bindsym Mod1+0 workspace number 10
bindsym Mod1+2 workspace number 2
bindsym Mod1+3 workspace number 3
bindsym Mod1+4 workspace number 4
bindsym Mod1+5 workspace number 5
bindsym Mod1+6 workspace number 6
bindsym Mod1+7 workspace number 7
bindsym Mod1+8 workspace number 8
bindsym Mod1+9 workspace number 9
bindsym Mod1+Down focus down
bindsym Mod1+Left focus left
bindsym Mod1+Return exec i3-sensible-terminal
bindsym Mod1+Right focus right
bindsym Mod1+Shift+0 move container to workspace number 10
bindsym Mod1+Shift+1 move container to workspace number 1
bindsym Mod1+Shift+2 move container to workspace number 2
bindsym Mod1+Shift+3 move container to workspace number 3
bindsym Mod1+Shift+4 move container to workspace number 4
bindsym Mod1+Shift+5 move container to workspace number 5
bindsym Mod1+Shift+6 move container to workspace number 6
bindsym Mod1+Shift+7 move container to workspace number 7
bindsym Mod1+Shift+8 move container to workspace number 8
bindsym Mod1+Shift+9 move container to workspace number 9
bindsym Mod1+Shift+Down move down
bindsym Mod1+Shift+Left move left
bindsym Mod1+Shift+Right move right
bindsym Mod1+Shift+Up move up
bindsym Mod1+Shift+c reload
bindsym Mod1+Shift+e exec i3-nagbar -t warning -m 'Do you want to exit i3?' -b 'Yes' 'i3-msg exit'
bindsym Mod1+Shift+minus move scratchpad
bindsym Mod1+Shift+q kill
bindsym Mod1+Shift+r restart
bindsym Mod1+Shift+space floating toggle
bindsym Mod1+Up focus up
bindsym Mod1+a focus parent
bindsym Mod1+d exec @dmenu@/bin/dmenu_run
bindsym Mod1+e layout toggle split
bindsym Mod1+f fullscreen toggle
bindsym Mod1+h split h
bindsym Mod1+minus scratchpad show
bindsym Mod1+r mode resize
bindsym Mod1+s layout stacking
bindsym Mod1+space focus mode_toggle
bindsym Mod1+v split v
bindsym Mod1+w layout tabbed

mode "resize" {
bindsym Down resize grow height 10 px or 10 ppt
bindsym Escape mode default
bindsym Left resize shrink width 10 px or 10 ppt
bindsym Return mode default
bindsym Right resize grow width 10 px or 10 ppt
bindsym Up resize shrink height 10 px or 10 ppt
}


bar {

font pango:monospace 8.000000
mode dock
hidden_state hide
position bottom
status_command @i3status@/bin/i3status
i3bar_command @i3@/bin/i3bar
workspace_buttons yes
strip_workspace_numbers no
tray_output primary
colors {
background #000000
statusline #ffffff
separator #666666
focused_workspace #4c7899 #285577 #ffffff
active_workspace #333333 #5f676a #ffffff
inactive_workspace #333333 #222222 #888888
urgent_workspace #2f343a #900000 #ffffff
binding_mode #2f343a #900000 #ffffff
}

}






21 changes: 21 additions & 0 deletions tests/modules/services/window-managers/i3/i3-workspace-default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{ config, lib, ... }:

with lib;

{
config = {
xsession.windowManager.i3 = {
enable = true;

config.defaultWorkspace = "workspace number 1";
};

nixpkgs.overlays = [ (import ./i3-overlay.nix) ];

nmt.script = ''
assertFileExists home-files/.config/i3/config
assertFileContent home-files/.config/i3/config \
${./i3-workspace-default-expected.conf}
'';
};
}
1 change: 1 addition & 0 deletions tests/modules/services/window-managers/sway/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
sway-null-config = ./sway-null-config.nix;
sway-null-package = ./sway-null-package.nix;
sway-modules = ./sway-modules.nix;
sway-workspace-default = ./sway-workspace-default.nix;
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ client.urgent #2f343a #900000 #ffffff #900000 #900000
client.placeholder #000000 #0c0c0c #ffffff #000000 #0c0c0c
client.background #ffffff


bindsym Mod1+1 workspace number 1
bindsym Mod1+2 workspace number 2
bindsym Mod1+3 workspace number 3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ client.urgent #2f343a #900000 #ffffff #900000 #900000
client.placeholder #000000 #0c0c0c #ffffff #000000 #0c0c0c
client.background #ffffff


bindsym Mod1+1 workspace number 1
bindsym Mod1+2 workspace number 2
bindsym Mod1+3 workspace number 3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ client.urgent #2f343a #900000 #ffffff #900000 #900000
client.placeholder #000000 #0c0c0c #ffffff #000000 #0c0c0c
client.background #ffffff


bindsym Mod1+1 workspace number 1
bindsym Mod1+2 workspace number 2
bindsym Mod1+3 workspace number 3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ client.urgent #2f343a #900000 #ffffff #900000 #900000
client.placeholder #000000 #0c0c0c #ffffff #000000 #0c0c0c
client.background #ffffff


bindsym Mod1+1 workspace number 1
bindsym Mod1+2 workspace number 2
bindsym Mod1+3 workspace number 3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ client.urgent #2f343a #900000 #ffffff #900000 #900000
client.placeholder #000000 #0c0c0c #ffffff #000000 #0c0c0c
client.background #ffffff


bindsym Mod1+1 workspace number 1
bindsym Mod1+2 workspace number 2
bindsym Mod1+3 workspace number 3
Expand Down
Loading

0 comments on commit 64c499f

Please sign in to comment.