sway, bspwm: add extraConfigEarly (#2847)

This commit is contained in:
Matthew Toohey 2022-08-27 00:09:46 -04:00 committed by GitHub
parent 8e4220e6c6
commit d89bdff445
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 99 additions and 67 deletions

View file

@ -61,21 +61,23 @@ in {
home.packages = [ cfg.package ]; home.packages = [ cfg.package ];
xdg.configFile."bspwm/bspwmrc".source = pkgs.writeShellScript "bspwmrc" '' xdg.configFile."bspwm/bspwmrc".source = pkgs.writeShellScript "bspwmrc"
${concatStringsSep "\n" (mapAttrsToList formatMonitor cfg.monitors)} ((optionalString (cfg.extraConfigEarly != "")
(cfg.extraConfigEarly + "\n")) + ''
${concatStringsSep "\n" (mapAttrsToList formatMonitor cfg.monitors)}
${concatStringsSep "\n" (mapAttrsToList formatSetting cfg.settings)} ${concatStringsSep "\n" (mapAttrsToList formatSetting cfg.settings)}
bspc rule -r '*' bspc rule -r '*'
${concatStringsSep "\n" (mapAttrsToList formatRule cfg.rules)} ${concatStringsSep "\n" (mapAttrsToList formatRule cfg.rules)}
# java gui fixes # java gui fixes
export _JAVA_AWT_WM_NONREPARENTING=1 export _JAVA_AWT_WM_NONREPARENTING=1
bspc rule -a sun-awt-X11-XDialogPeer state=floating bspc rule -a sun-awt-X11-XDialogPeer state=floating
${cfg.extraConfig} ${cfg.extraConfig}
${concatMapStringsSep "\n" formatStartupProgram cfg.startupPrograms} ${concatMapStringsSep "\n" formatStartupProgram cfg.startupPrograms}
''; '');
# for applications not started by bspwm, e.g. sxhkd # for applications not started by bspwm, e.g. sxhkd
xsession.profileExtra = '' xsession.profileExtra = ''

View file

@ -187,6 +187,13 @@ in {
''; '';
}; };
extraConfigEarly = mkOption {
type = types.lines;
default = "";
description =
"Like extraConfig, except commands are run at the start of the config file.";
};
monitors = mkOption { monitors = mkOption {
type = types.attrsOf (types.listOf types.str); type = types.attrsOf (types.listOf types.str);
default = { }; default = { };

View file

@ -263,60 +263,61 @@ let
seatStr = moduleStr "seat"; seatStr = moduleStr "seat";
configFile = pkgs.writeText "sway.conf" (concatStringsSep "\n" configFile = pkgs.writeText "sway.conf" (concatStringsSep "\n"
((if cfg.config != null then ((optional (cfg.extraConfigEarly != "") cfg.extraConfigEarly)
with cfg.config; ++ (if cfg.config != null then
([ with cfg.config;
(fontConfigStr fonts) ([
"floating_modifier ${floating.modifier}" (fontConfigStr fonts)
(windowBorderString window floating) "floating_modifier ${floating.modifier}"
"hide_edge_borders ${window.hideEdgeBorders}" (windowBorderString window floating)
"focus_wrapping ${lib.hm.booleans.yesNo focus.forceWrapping}" "hide_edge_borders ${window.hideEdgeBorders}"
"focus_follows_mouse ${focus.followMouse}" "focus_wrapping ${lib.hm.booleans.yesNo focus.forceWrapping}"
"focus_on_window_activation ${focus.newWindow}" "focus_follows_mouse ${focus.followMouse}"
"mouse_warping ${ "focus_on_window_activation ${focus.newWindow}"
if builtins.isString (focus.mouseWarping) then "mouse_warping ${
focus.mouseWarping if builtins.isString (focus.mouseWarping) then
else if focus.mouseWarping then focus.mouseWarping
"output" else if focus.mouseWarping then
else "output"
"none" else
}" "none"
"workspace_layout ${workspaceLayout}" }"
"workspace_auto_back_and_forth ${ "workspace_layout ${workspaceLayout}"
lib.hm.booleans.yesNo workspaceAutoBackAndForth "workspace_auto_back_and_forth ${
}" lib.hm.booleans.yesNo workspaceAutoBackAndForth
"client.focused ${colorSetStr colors.focused}" }"
"client.focused_inactive ${colorSetStr colors.focusedInactive}" "client.focused ${colorSetStr colors.focused}"
"client.unfocused ${colorSetStr colors.unfocused}" "client.focused_inactive ${colorSetStr colors.focusedInactive}"
"client.urgent ${colorSetStr colors.urgent}" "client.unfocused ${colorSetStr colors.unfocused}"
"client.placeholder ${colorSetStr colors.placeholder}" "client.urgent ${colorSetStr colors.urgent}"
"client.background ${colors.background}" "client.placeholder ${colorSetStr colors.placeholder}"
(keybindingsStr { "client.background ${colors.background}"
keybindings = keybindingDefaultWorkspace; (keybindingsStr {
bindsymArgs = keybindings = keybindingDefaultWorkspace;
lib.optionalString (cfg.config.bindkeysToCode) "--to-code"; bindsymArgs =
}) lib.optionalString (cfg.config.bindkeysToCode) "--to-code";
(keybindingsStr { })
keybindings = keybindingsRest; (keybindingsStr {
bindsymArgs = keybindings = keybindingsRest;
lib.optionalString (cfg.config.bindkeysToCode) "--to-code"; bindsymArgs =
}) lib.optionalString (cfg.config.bindkeysToCode) "--to-code";
(keycodebindingsStr keycodebindings) })
] ++ mapAttrsToList inputStr input (keycodebindingsStr keycodebindings)
++ mapAttrsToList outputStr output # outputs ] ++ mapAttrsToList inputStr input
++ mapAttrsToList seatStr seat # seats ++ mapAttrsToList outputStr output # outputs
++ mapAttrsToList (modeStr cfg.config.bindkeysToCode) modes # modes ++ mapAttrsToList seatStr seat # seats
++ mapAttrsToList assignStr assigns # assigns ++ mapAttrsToList (modeStr cfg.config.bindkeysToCode) modes # modes
++ map barStr bars # bars ++ mapAttrsToList assignStr assigns # assigns
++ optional (gaps != null) gapsStr # gaps ++ map barStr bars # bars
++ map floatingCriteriaStr floating.criteria # floating ++ optional (gaps != null) gapsStr # gaps
++ map windowCommandsStr window.commands # window commands ++ map floatingCriteriaStr floating.criteria # floating
++ map startupEntryStr startup # startup ++ map windowCommandsStr window.commands # window commands
++ map workspaceOutputStr workspaceOutputAssign # custom mapping ++ map startupEntryStr startup # startup
) ++ map workspaceOutputStr workspaceOutputAssign # custom mapping
else )
[ ]) ++ (optional cfg.systemdIntegration '' else
exec "${pkgs.dbus}/bin/dbus-update-activation-environment --systemd DISPLAY WAYLAND_DISPLAY SWAYSOCK XDG_CURRENT_DESKTOP; systemctl --user start sway-session.target"'') [ ]) ++ (optional cfg.systemdIntegration ''
exec "${pkgs.dbus}/bin/dbus-update-activation-environment --systemd DISPLAY WAYLAND_DISPLAY SWAYSOCK XDG_CURRENT_DESKTOP; systemctl --user start sway-session.target"'')
++ (optional (!cfg.xwayland) "xwayland disable") ++ [ cfg.extraConfig ])); ++ (optional (!cfg.xwayland) "xwayland disable") ++ [ cfg.extraConfig ]));
defaultSwayPackage = pkgs.sway.override { defaultSwayPackage = pkgs.sway.override {
@ -425,6 +426,13 @@ in {
description = description =
"Extra configuration lines to add to ~/.config/sway/config."; "Extra configuration lines to add to ~/.config/sway/config.";
}; };
extraConfigEarly = mkOption {
type = types.lines;
default = "";
description =
"Like extraConfig, except lines are added to ~/.config/sway/config before all other configuration.";
};
}; };
config = mkIf cfg.enable (mkMerge [ config = mkIf cfg.enable (mkMerge [

View file

@ -1,3 +1,5 @@
extra config early
if [[ $(bspc query --desktops --names --monitor 'focused') == Desktop ]]; then if [[ $(bspc query --desktops --names --monitor 'focused') == Desktop ]]; then
bspc monitor 'focused' -d 'desktop 1' 'd'\''esk top' bspc monitor 'focused' -d 'desktop 1' 'd'\''esk top'
fi fi

View file

@ -24,6 +24,9 @@ with lib;
border = null; border = null;
unknownRule = 42; unknownRule = 42;
}; };
extraConfigEarly = ''
extra config early
'';
extraConfig = '' extraConfig = ''
extra config extra config
''; '';

View file

@ -1,6 +1,7 @@
{ {
sway-bar-focused-colors = ./sway-bar-focused-colors.nix; sway-bar-focused-colors = ./sway-bar-focused-colors.nix;
sway-bindkeys-to-code = ./sway-bindkeys-to-code.nix; sway-bindkeys-to-code-and-extra-config =
./sway-bindkeys-to-code-and-extra-config.nix;
sway-default = ./sway-default.nix; sway-default = ./sway-default.nix;
sway-followmouse = ./sway-followmouse.nix; sway-followmouse = ./sway-followmouse.nix;
sway-followmouse-legacy = ./sway-followmouse-legacy.nix; sway-followmouse-legacy = ./sway-followmouse-legacy.nix;

View file

@ -1,3 +1,5 @@
import $HOME/.cache/wal/colors-sway
font pango:monospace 8.000000 font pango:monospace 8.000000
floating_modifier Mod1 floating_modifier Mod1
default_border pixel 2 default_border pixel 2
@ -104,3 +106,4 @@ bar {
} }
exec "/nix/store/00000000000000000000000000000000-dbus/bin/dbus-update-activation-environment --systemd DISPLAY WAYLAND_DISPLAY SWAYSOCK XDG_CURRENT_DESKTOP; systemctl --user start sway-session.target" exec "/nix/store/00000000000000000000000000000000-dbus/bin/dbus-update-activation-environment --systemd DISPLAY WAYLAND_DISPLAY SWAYSOCK XDG_CURRENT_DESKTOP; systemctl --user start sway-session.target"
exec_always pkill flashfocus; flasfocus &

View file

@ -9,11 +9,17 @@
# overriding findutils causes issues # overriding findutils causes issues
config.menu = "${pkgs.dmenu}/bin/dmenu_run"; config.menu = "${pkgs.dmenu}/bin/dmenu_run";
config.bindkeysToCode = true; config.bindkeysToCode = true;
extraConfigEarly = ''
import $HOME/.cache/wal/colors-sway
'';
extraConfig = ''
exec_always pkill flashfocus; flasfocus &
'';
}; };
nmt.script = '' nmt.script = ''
assertFileExists home-files/.config/sway/config assertFileExists home-files/.config/sway/config
assertFileContent $(normalizeStorePaths home-files/.config/sway/config) \ assertFileContent $(normalizeStorePaths home-files/.config/sway/config) \
${./sway-bindkeys-to-code.conf} ${./sway-bindkeys-to-code-and-extra-config.conf}
''; '';
} }