fork/home-manager

git clone https://git.julia.blue/fork/home-manager

Matthew Tooheysway, bspwm: add extraConfigEarly (#2847)d89bdff4

master
2.6 KiB91 linesraw
1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
6
7  cfg = config.xsession.windowManager.bspwm;
8
9  camelToSnake =
10    builtins.replaceStrings upperChars (map (c: "_${c}") lowerChars);
11
12  formatMonitor = monitor: desktops:
13    let
14      resetDesktops =
15        "bspc monitor ${escapeShellArg monitor} -d ${escapeShellArgs desktops}";
16      defaultDesktopName =
17        "Desktop"; # https://github.com/baskerville/bspwm/blob/master/src/desktop.h
18    in if cfg.alwaysResetDesktops then
19      resetDesktops
20    else ''
21      if [[ $(bspc query --desktops --names --monitor ${
22        escapeShellArg monitor
23      }) == ${defaultDesktopName} ]]; then
24        ${resetDesktops}
25      fi'';
26
27  formatValue = v:
28    if isList v then
29      concatMapStringsSep "," formatValue v
30    else if isBool v then
31      if v then "on" else "off"
32    else if isInt v || isFloat v then
33      toString v
34    else if isString v then
35      v
36    else
37      throw "unsupported type"; # should not happen
38
39  formatSetting = n: v: "bspc config ${escapeShellArgs [ n (formatValue v) ]}";
40
41  formatRule = target: directives:
42    let
43      formatDirective = n: v: "${camelToSnake n}=${formatValue v}";
44
45      directivesStr = escapeShellArgs (mapAttrsToList formatDirective
46        (filterAttrs (n: v: v != null) directives));
47    in "bspc rule -a ${escapeShellArg target} ${directivesStr}";
48
49  formatStartupProgram = s: "${s} &";
50
51in {
52  meta.maintainers = [ maintainers.ncfavier ];
53
54  options = import ./options.nix { inherit pkgs lib; };
55
56  config = mkIf cfg.enable {
57    assertions = [
58      (hm.assertions.assertPlatform "xsession.windowManager.bspwm" pkgs
59        platforms.linux)
60    ];
61
62    home.packages = [ cfg.package ];
63
64    xdg.configFile."bspwm/bspwmrc".source = pkgs.writeShellScript "bspwmrc"
65      ((optionalString (cfg.extraConfigEarly != "")
66        (cfg.extraConfigEarly + "\n")) + ''
67          ${concatStringsSep "\n" (mapAttrsToList formatMonitor cfg.monitors)}
68
69          ${concatStringsSep "\n" (mapAttrsToList formatSetting cfg.settings)}
70
71          bspc rule -r '*'
72          ${concatStringsSep "\n" (mapAttrsToList formatRule cfg.rules)}
73
74          # java gui fixes
75          export _JAVA_AWT_WM_NONREPARENTING=1
76          bspc rule -a sun-awt-X11-XDialogPeer state=floating
77
78          ${cfg.extraConfig}
79          ${concatMapStringsSep "\n" formatStartupProgram cfg.startupPrograms}
80        '');
81
82    # for applications not started by bspwm, e.g. sxhkd
83    xsession.profileExtra = ''
84      # java gui fixes
85      export _JAVA_AWT_WM_NONREPARENTING=1
86    '';
87
88    xsession.windowManager.command =
89      "${cfg.package}/bin/bspwm -c ${config.xdg.configHome}/bspwm/bspwmrc";
90  };
91}