~sumner/home-manager-config

home-manager-config/modules/window-manager/xorg.nix -rw-r--r-- 4.7 KiB
e986663dSumner Evans display: add coruscant Dell monitor configs 5 hours ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
{ config, lib, pkgs, ... }: with lib; let
  cfg = config.xorg;
  common = import ./common.nix { inherit config lib pkgs; };
  fuzzy-lock = import ./fuzzy-lock.nix { inherit config lib pkgs; };

  modifier = config.windowManager.modKey;
  tmpdir = "${config.home.homeDirectory}/tmp";
  mvTmp = "${pkgs.coreutils}/bin/mv $f ${tmpdir}";
  scrotCmd = "${pkgs.scrot}/bin/scrot '%Y-%m-%d-%T.png'";
  i3lockcmd = "${pkgs.i3lock-fancy}/bin/i3lock-fancy --font Iosevka -- ${scrotCmd} -z";
in
{
  options.xorg = {
    enable = mkEnableOption "the Xorg stack";
    extrai3wmConfig = mkOption {
      type = types.attrsOf types.anything;
      description = "Extra config for i3wm";
      default = {};
    };
    remapEscToCaps = mkOption {
      type = types.bool;
      description = "Remap the physical escape key to Caps Lock.";
      default = true;
    };
  };

  config = mkIf cfg.enable {
    dconf.enable = false;
    xsession = {
      enable = true;

      windowManager.i3 = mkMerge [
        common.i3SwayConfig
        {
          config.startup = [
            { command = "${pkgs.autorandr}/bin/autorandr --change"; always = true; }
          ];

          config.keybindings = {
            # Popup Clipboard Manager
            "${modifier}+c" = "exec ${pkgs.clipmenu}/bin/clipmenu";

            # Lock screen
            "${modifier}+Shift+x" = "exec ${fuzzy-lock}/bin/fuzzy-lock";

            # exit i3wm (logs you out of your session)
            "${modifier}+Shift+e" = ''exec "${pkgs.i3-gaps}/bin/i3-nagbar -t warning -m 'You pressed the exit shortcut. Do you really want to exit i3? This will end your X session.' -b 'Yes, exit i3' 'i3-msg exit'"'';

            # Screenshots
            "${modifier}+shift+ctrl+c" = ''exec "${scrotCmd} -e '${mvTmp}'"'';
            "${modifier}+shift+c" = ''exec "${pkgs.flameshot}/bin/flameshot gui -p ${tmpdir}"'';
            "${modifier}+shift+f" = ''exec "${pkgs.flameshot}/bin/flameshot gui -p ${tmpdir}"'';
            Print = ''exec "${scrotCmd} -e '${mvTmp}'"'';
          };
        }
        cfg.extrai3wmConfig
      ];

      pointerCursor = {
        package = pkgs.capitaine-cursors;
        name = "Capitaine";
        size = 16;
      };

      profileExtra = ''
        systemctl --user import-environment
      '';
    };

    xresources.extraConfig = ''
      Xft.dpi: 100
    '';

    services.clipmenu.enable = true;
    home.sessionVariables = {
      CM_HISTLENGTH = "20";
      CM_LAUNCHER = "rofi";
    };

    home.packages = with pkgs; [
      flameshot
      i3lock
      lxappearance
      scrot
      xclip
      xorg.xbacklight
      xorg.xdpyinfo
      xorg.xprop
    ];

    services.redshift = common.redshiftGammastepCfg;

    services.dunst = {
      enable = true;
      iconTheme = {
        name = "hicolor";
        package = pkgs.paper-icon-theme;
        size = "32x32";
      };
      settings = {
        global = {
          corner_radius = 5;
          frame_color = "#8EC07C";
          geometry = "350x50-15+45";
          horizontal_padding = 6;
          idle_threshold = 30;
          markup = true;
          padding = 6;
          show_age_threshold = 20;
          show_indicators = false;
          transparency = 10;
          word_wrap = true;

          # Text
          font = "Iosevka 10";
          format = "<b>%s</b>\\n%b\\n%p";
          line_height = 3;
        };
      } // common.notificationColorConfig;
    };

    services.picom = {
      enable = true;
      vSync = true;

      fade = true;
      fadeDelta = 5;

      inactiveOpacity = "0.8";
      opacityRule = [
        "100:class_g *= 'obs'"
        "100:class_g *= 'i3lock'"
        "100:class_g ?= 'rofi'"
      ];

      shadow = true;
      shadowExclude = [
        "name = 'Notification'"
        "class_g = 'Conky'"
        "class_g ?= 'Notify-osd'"
        "class_g = 'Cairo-clock'"
        "class_g = 'i3-frame'"
        "_GTK_FRAME_EXTENTS@:c"
      ];
    };

    systemd.user.services =
      let
        xmodmapConfig = pkgs.writeText "Xmodmap.conf" ''
          ! Reverse scrolling
          ! pointer = 1 2 3 5 4 6 7 8 9 10 11 12
          keycode 9 = Caps_Lock Caps_Lock Caps_Lock
        '';
        startupServices = {
          xbanish = "${pkgs.xbanish}/bin/xbanish";
        } // (
          optionalAttrs cfg.remapEscToCaps {
            xmodmap = "${pkgs.xorg.xmodmap}/bin/xmodmap ${xmodmapConfig}";
          }
        );
      in
        mapAttrs (
          name: value: {
            Unit = {
              Description = "Run ${name} on startup.";
              PartOf = [ "graphical-session.target" ];
            };
            Service.ExecStart = value;
            Service.Restart = "always";
            Install.WantedBy = [ "graphical-session.target" ];
          }
        ) startupServices;
  };
}