~sumner/home-manager-config

home-manager-config/modules/window-manager/wayland.nix -rw-r--r-- 6.6 KiB
468d12f0Sumner Evans multimedia: fix obs-studio-plugins.wlrobs a day 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
175
176
177
178
179
180
181
182
183
184
{ config, lib, options, pkgs, ... }: with lib; let
  cfg = config.wayland;
  common = import ./common.nix { inherit config lib pkgs; };
  clipmanHistpath = ''--histpath="${config.xdg.cacheHome}/clipman.json"'';
  clipmanCmd = "${pkgs.clipman}/bin/clipman";
  swaylockCmd = concatStringsSep " " [
    "${pkgs.swaylock-effects}/bin/swaylock"
    "--daemonize"
    "--screenshots"
    "--clock"
    "--indicator"
    "--indicator-radius 100"
    "--indicator-thickness 7"
    "--effect-blur 7x5"
    "--effect-vignette 0.7:0.7"
    "--fade-in 0.5"
  ];
in
{
  options = {
    wayland.enable = mkEnableOption "the Wayland stack";
    wayland.extraSwayConfig = mkOption {
      type = types.attrsOf types.anything;
      description = "Extra config for Sway";
      default = {};
    };
  };

  config = mkIf cfg.enable {
    wayland.windowManager.sway = mkMerge [
      common.i3SwayConfig
      {
        wrapperFeatures.gtk = true;
        config.focus.forceWrapping = true;
        config.startup =
          let
            wlpaste = "${pkgs.wl-clipboard}/bin/wl-paste";
            gsettings = "${pkgs.glib}/bin/gsettings";
            gnomeSchema = "org.gnome.desktop.interface";
            inactive-windows-transparency = pkgs.writeScriptBin "inactive-windows-transparency"
              (builtins.readFile ./bin/inactive-windows-transparency.py);
          in
            [
              # Clipboard Manager
              { command = "${wlpaste} -t text --watch ${clipmanCmd} store --max-items=10000 ${clipmanHistpath}"; }
              { command = "${wlpaste} -p -t text --watch ${clipmanCmd} store -P --max-items=10000 ${clipmanHistpath}"; }

              # Window transparency
              { command = "${inactive-windows-transparency}/bin/inactive-windows-transparency"; }

              # Lock screen & DPMS
              {
                # TODO add keyboard on kohaku
                command = ''
                  swayidle -w \
                      timeout 300 '${swaylockCmd}' \
                      timeout 360 '${pkgs.sway}/bin/swaymsg "output * dpms off"' \
                           resume '${pkgs.sway}/bin/swaymsg "output * dpms on"' \
                     before-sleep '${pkgs.playerctl}/bin/playerctl pause' \
                     before-sleep '${swaylockCmd}'
                '';
              }

              # Make all the pinentry stuff work
              # See: https://github.com/NixOS/nixpkgs/issues/119445#issuecomment-820507505
              # and: https://github.com/NixOS/nixpkgs/issues/57602#issuecomment-820512097
              { command = "dbus-update-activation-environment WAYLAND_DISPLAY"; }

              # GTK
              { command = "${gsettings} set ${gnomeSchema} gtk-theme 'Arc-Dark'"; always = true; }
              { command = "${gsettings} set ${gnomeSchema} icon-theme 'Arc'"; always = true; }
              { command = "${gsettings} set ${gnomeSchema} cursor-theme 'capitaine-cursors'"; always = true; }
              { command = "${gsettings} set ${gnomeSchema} cursor-size 24"; always = true; }
            ];

        config.keybindings =
          let
            modifier = config.windowManager.modKey;
            grim = "${pkgs.grim}/bin/grim";
            slurp = "${pkgs.slurp}/bin/slurp";
            screenshotOutfile = "${config.home.homeDirectory}/tmp/$(${pkgs.coreutils}/bin/date +%Y-%m-%d-%T).png";
            screenshotSlurpScript = pkgs.writeShellScriptBin "screenshot" ''
              ${grim} -g "$(${slurp})" ${screenshotOutfile}
              ${pkgs.wl-clipboard}/bin/wl-copy <${screenshotOutfile}
            '';
            screenshotFullscreenScript = pkgs.writeShellScriptBin "screenshot" ''
              ${grim} ${screenshotOutfile}
              ${pkgs.wl-clipboard}/bin/wl-copy <${screenshotOutfile}
            '';
          in
            {
              # Popup Clipboard Manager
              "${modifier}+c" = "exec ${clipmanCmd} pick -t rofi ${clipmanHistpath}";

              # Lock screen
              "${modifier}+Shift+x" = "exec ${swaylockCmd}";

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

              # Screenshots
              "${modifier}+shift+c" = "exec ${screenshotSlurpScript}/bin/screenshot";
              Print = "exec ${screenshotFullscreenScript}/bin/screenshot";
            };

        config.seat."*" = {
          hide_cursor = "when-typing enable";
          xcursor_theme = "capitaine-cursors 24";
        };
      }
      cfg.extraSwayConfig
    ];

    home.sessionVariables = {
      GTK_THEME = "Arc-Dark";
      MOZ_ENABLE_WAYLAND = "1";
      XDG_CURRENT_DESKTOP = "sway";
      XDG_SESSION_TYPE = "wayland";
    };

    home.packages = with pkgs; [
      clipman
      glib
      grim
      slurp
      v4l-utils
      wf-recorder
      wl-clipboard # clipboard management
      capitaine-cursors
      # TODO use wofi?
    ];

    programs.mpv.config = {
      gpu-context = "wayland";
    };

    # Gammastep
    services.gammastep = common.redshiftGammastepCfg;

    programs.mako = {
      enable = true;

      borderRadius = 5;
      borderSize = 2;
      defaultTimeout = 8000;
      font = "Iosevka 12";
      groupBy = "app-name,summary";
      sort = "-priority";
      width = 400;
      backgroundColor = common.notificationColorConfig.urgency_normal.background + "CC";
      borderColor = common.notificationColorConfig.urgency_normal.frame_color;
      textColor = common.notificationColorConfig.urgency_normal.foreground;

      extraConfig = generators.toINI {} (
        mapAttrs'
          (
            name: val: nameValuePair
              (builtins.replaceStrings [ "_" "critical" ] [ "=" "high" ] name)
              (
                mapAttrs'
                  (
                    k: v:
                      nameValuePair
                        (
                          if k == "timeout" then "default-timeout"
                          else if k == "frame_color" then "border-color"
                          else if k == "foreground" then "text-color"
                          else if k == "background" then "background-color"
                          else k
                        )
                        (
                          if k == "timeout" then v * 1000
                          else if k == "background" then v + "CC"
                          else v
                        )
                  )
                  val
              )
          )
          common.notificationColorConfig
      );
    };
  };
}