mirror of
https://github.com/nix-community/home-manager
synced 2024-11-05 10:49:44 +01:00
e2a85ac43f
If set to true, desktops configured in `monitors` will be reset every time the config is run. If set to false, desktops will only be configured the first time the config is run. This is useful if you want to dynamically add desktops and you don't want them to be destroyed if you re-run `bspwmrc`.
89 lines
2.5 KiB
Nix
89 lines
2.5 KiB
Nix
{ config, lib, pkgs, ... }:
|
|
|
|
with lib;
|
|
|
|
let
|
|
|
|
cfg = config.xsession.windowManager.bspwm;
|
|
|
|
camelToSnake =
|
|
builtins.replaceStrings upperChars (map (c: "_${c}") lowerChars);
|
|
|
|
formatMonitor = monitor: desktops:
|
|
let
|
|
resetDesktops =
|
|
"bspc monitor ${escapeShellArg monitor} -d ${escapeShellArgs desktops}";
|
|
defaultDesktopName =
|
|
"Desktop"; # https://github.com/baskerville/bspwm/blob/master/src/desktop.h
|
|
in if cfg.alwaysResetDesktops then
|
|
resetDesktops
|
|
else ''
|
|
if [[ $(bspc query --desktops --names --monitor ${
|
|
escapeShellArg monitor
|
|
}) == ${defaultDesktopName} ]]; then
|
|
${resetDesktops}
|
|
fi'';
|
|
|
|
formatValue = v:
|
|
if isList v then
|
|
concatMapStringsSep "," formatValue v
|
|
else if isBool v then
|
|
if v then "on" else "off"
|
|
else if isInt v || isFloat v then
|
|
toString v
|
|
else if isString v then
|
|
v
|
|
else
|
|
throw "unsupported type"; # should not happen
|
|
|
|
formatSetting = n: v: "bspc config ${escapeShellArgs [ n (formatValue v) ]}";
|
|
|
|
formatRule = target: directives:
|
|
let
|
|
formatDirective = n: v: "${camelToSnake n}=${formatValue v}";
|
|
|
|
directivesStr = escapeShellArgs (mapAttrsToList formatDirective
|
|
(filterAttrs (n: v: v != null) directives));
|
|
in "bspc rule -a ${escapeShellArg target} ${directivesStr}";
|
|
|
|
formatStartupProgram = s: "${s} &";
|
|
|
|
in {
|
|
meta.maintainers = [ maintainers.ncfavier ];
|
|
|
|
options = import ./options.nix { inherit pkgs lib; };
|
|
|
|
config = mkIf cfg.enable {
|
|
assertions = [
|
|
(hm.assertions.assertPlatform "xsession.windowManager.bspwm" pkgs
|
|
platforms.linux)
|
|
];
|
|
|
|
home.packages = [ cfg.package ];
|
|
|
|
xdg.configFile."bspwm/bspwmrc".source = pkgs.writeShellScript "bspwmrc" ''
|
|
${concatStringsSep "\n" (mapAttrsToList formatMonitor cfg.monitors)}
|
|
|
|
${concatStringsSep "\n" (mapAttrsToList formatSetting cfg.settings)}
|
|
|
|
bspc rule -r '*'
|
|
${concatStringsSep "\n" (mapAttrsToList formatRule cfg.rules)}
|
|
|
|
# java gui fixes
|
|
export _JAVA_AWT_WM_NONREPARENTING=1
|
|
bspc rule -a sun-awt-X11-XDialogPeer state=floating
|
|
|
|
${cfg.extraConfig}
|
|
${concatMapStringsSep "\n" formatStartupProgram cfg.startupPrograms}
|
|
'';
|
|
|
|
# for applications not started by bspwm, e.g. sxhkd
|
|
xsession.profileExtra = ''
|
|
# java gui fixes
|
|
export _JAVA_AWT_WM_NONREPARENTING=1
|
|
'';
|
|
|
|
xsession.windowManager.command =
|
|
"${cfg.package}/bin/bspwm -c ${config.xdg.configHome}/bspwm/bspwmrc";
|
|
};
|
|
}
|