2018-08-28 15:46:24 +02:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.xsession.windowManager.bspwm;
|
|
|
|
|
2021-06-20 00:40:17 +02:00
|
|
|
camelToSnake =
|
|
|
|
builtins.replaceStrings upperChars (map (c: "_${c}") lowerChars);
|
2018-08-28 15:46:24 +02:00
|
|
|
|
2021-06-20 00:40:17 +02:00
|
|
|
formatMonitor = monitor: desktops:
|
2022-03-18 03:56:56 +01:00
|
|
|
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'';
|
2021-06-20 06:57:40 +02:00
|
|
|
|
|
|
|
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) ]}";
|
2021-06-20 00:40:17 +02:00
|
|
|
|
|
|
|
formatRule = target: directives:
|
2018-08-28 15:46:24 +02:00
|
|
|
let
|
2021-06-20 06:57:40 +02:00
|
|
|
formatDirective = n: v: "${camelToSnake n}=${formatValue v}";
|
|
|
|
|
|
|
|
directivesStr = escapeShellArgs (mapAttrsToList formatDirective
|
2021-06-20 00:40:17 +02:00
|
|
|
(filterAttrs (n: v: v != null) directives));
|
2021-06-20 06:57:40 +02:00
|
|
|
in "bspc rule -a ${escapeShellArg target} ${directivesStr}";
|
2021-06-20 00:40:17 +02:00
|
|
|
|
|
|
|
formatStartupProgram = s: "${s} &";
|
2018-08-28 15:46:24 +02:00
|
|
|
|
2020-02-02 00:39:17 +01:00
|
|
|
in {
|
2021-06-20 00:40:17 +02:00
|
|
|
meta.maintainers = [ maintainers.ncfavier ];
|
|
|
|
|
|
|
|
options = import ./options.nix { inherit pkgs lib; };
|
2018-08-28 15:46:24 +02:00
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
2021-07-07 23:24:27 +02:00
|
|
|
assertions = [
|
|
|
|
(hm.assertions.assertPlatform "xsession.windowManager.bspwm" pkgs
|
|
|
|
platforms.linux)
|
|
|
|
];
|
|
|
|
|
2021-06-20 00:40:17 +02:00
|
|
|
home.packages = [ cfg.package ];
|
|
|
|
|
2022-08-27 06:09:46 +02:00
|
|
|
xdg.configFile."bspwm/bspwmrc".source = pkgs.writeShellScript "bspwmrc"
|
|
|
|
((optionalString (cfg.extraConfigEarly != "")
|
|
|
|
(cfg.extraConfigEarly + "\n")) + ''
|
|
|
|
${concatStringsSep "\n" (mapAttrsToList formatMonitor cfg.monitors)}
|
2021-06-20 00:40:17 +02:00
|
|
|
|
2022-08-27 06:09:46 +02:00
|
|
|
${concatStringsSep "\n" (mapAttrsToList formatSetting cfg.settings)}
|
2021-06-20 00:40:17 +02:00
|
|
|
|
2022-08-27 06:09:46 +02:00
|
|
|
bspc rule -r '*'
|
|
|
|
${concatStringsSep "\n" (mapAttrsToList formatRule cfg.rules)}
|
2021-06-20 00:40:17 +02:00
|
|
|
|
2022-08-27 06:09:46 +02:00
|
|
|
# java gui fixes
|
|
|
|
export _JAVA_AWT_WM_NONREPARENTING=1
|
|
|
|
bspc rule -a sun-awt-X11-XDialogPeer state=floating
|
2021-06-20 00:40:17 +02:00
|
|
|
|
2022-08-27 06:09:46 +02:00
|
|
|
${cfg.extraConfig}
|
|
|
|
${concatMapStringsSep "\n" formatStartupProgram cfg.startupPrograms}
|
|
|
|
'');
|
2021-06-20 00:40:17 +02:00
|
|
|
|
2022-01-18 00:44:20 +01:00
|
|
|
# for applications not started by bspwm, e.g. sxhkd
|
|
|
|
xsession.profileExtra = ''
|
|
|
|
# java gui fixes
|
|
|
|
export _JAVA_AWT_WM_NONREPARENTING=1
|
|
|
|
'';
|
|
|
|
|
2021-06-20 00:40:17 +02:00
|
|
|
xsession.windowManager.command =
|
|
|
|
"${cfg.package}/bin/bspwm -c ${config.xdg.configHome}/bspwm/bspwmrc";
|
2018-08-28 15:46:24 +02:00
|
|
|
};
|
|
|
|
}
|