1{ config, lib, pkgs, ... }:
2
3with lib;
4with builtins;
5
6let
7
8 cfg = config.services.compton;
9
10 configFile = pkgs.writeText "compton.conf"
11 (optionalString cfg.fade ''
12 # fading
13 fading = true;
14 fade-delta = ${toString cfg.fadeDelta};
15 fade-in-step = ${elemAt cfg.fadeSteps 0};
16 fade-out-step = ${elemAt cfg.fadeSteps 1};
17 fade-exclude = ${toJSON cfg.fadeExclude};
18 '' +
19 optionalString cfg.shadow ''
20
21 # shadows
22 shadow = true;
23 shadow-offset-x = ${toString (elemAt cfg.shadowOffsets 0)};
24 shadow-offset-y = ${toString (elemAt cfg.shadowOffsets 1)};
25 shadow-opacity = ${cfg.shadowOpacity};
26 shadow-exclude = ${toJSON cfg.shadowExclude};
27 '' + ''
28
29 # opacity
30 active-opacity = ${cfg.activeOpacity};
31 inactive-opacity = ${cfg.inactiveOpacity};
32 menu-opacity = ${cfg.menuOpacity};
33
34 # other options
35 backend = ${toJSON cfg.backend};
36 vsync = ${toJSON cfg.vSync};
37 refresh-rate = ${toString cfg.refreshRate};
38 '' + cfg.extraOptions);
39
40in {
41
42 options.services.compton = {
43 enable = mkOption {
44 type = types.bool;
45 default = false;
46 example = true;
47 description = ''
48 Whether of not to enable Compton as the X.org composite manager.
49 '';
50 };
51
52 fade = mkOption {
53 type = types.bool;
54 default = false;
55 example = true;
56 description = ''
57 Fade windows in and out.
58 '';
59 };
60
61 fadeDelta = mkOption {
62 type = types.int;
63 default = 10;
64 example = 5;
65 description = ''
66 Time between fade animation step (in ms).
67 '';
68 };
69
70 fadeSteps = mkOption {
71 type = types.listOf types.str;
72 default = [ "0.028" "0.03" ];
73 example = [ "0.04" "0.04" ];
74 description = ''
75 Opacity change between fade steps (in and out).
76 '';
77 };
78
79 fadeExclude = mkOption {
80 type = types.listOf types.str;
81 default = [];
82 example = [
83 "window_type *= 'menu'"
84 "name ~= 'Firefox$'"
85 "focused = 1"
86 ];
87 description = ''
88 List of condition of windows that should have no shadow.
89 See <literal>compton(1)</literal> man page for more examples.
90 '';
91 };
92
93 shadow = mkOption {
94 type = types.bool;
95 default = false;
96 example = true;
97 description = ''
98 Draw window shadows.
99 '';
100 };
101
102 shadowOffsets = mkOption {
103 type = types.listOf types.int;
104 default = [ (-15) (-15) ];
105 example = [ (-10) (-15) ];
106 description = ''
107 Left and right offset for shadows (in pixels).
108 '';
109 };
110
111 shadowOpacity = mkOption {
112 type = types.str;
113 default = "0.75";
114 example = "0.8";
115 description = ''
116 Window shadows opacity (number in range 0 - 1).
117 '';
118 };
119
120 shadowExclude = mkOption {
121 type = types.listOf types.str;
122 default = [];
123 example = [
124 "window_type *= 'menu'"
125 "name ~= 'Firefox$'"
126 "focused = 1"
127 ];
128 description = ''
129 List of condition of windows that should have no shadow.
130 See <literal>compton(1)</literal> man page for more examples.
131 '';
132 };
133
134 activeOpacity = mkOption {
135 type = types.str;
136 default = "1.0";
137 example = "0.8";
138 description = ''
139 Opacity of active windows.
140 '';
141 };
142
143 inactiveOpacity = mkOption {
144 type = types.str;
145 default = "1.0";
146 example = "0.8";
147 description = ''
148 Opacity of inactive windows.
149 '';
150 };
151
152 menuOpacity = mkOption {
153 type = types.str;
154 default = "1.0";
155 example = "0.8";
156 description = ''
157 Opacity of dropdown and popup menu.
158 '';
159 };
160
161 backend = mkOption {
162 type = types.str;
163 default = "glx";
164 description = ''
165 Backend to use: <literal>glx</literal> or <literal>xrender</literal>.
166 '';
167 };
168
169 vSync = mkOption {
170 type = types.str;
171 default = "none";
172 example = "opengl-swc";
173 description = ''
174 Enable vertical synchronization using the specified method.
175 See <literal>compton(1)</literal> man page available methods.
176 '';
177 };
178
179 refreshRate = mkOption {
180 type = types.int;
181 default = 0;
182 example = 60;
183 description = ''
184 Screen refresh rate (0 = automatically detect).
185 '';
186 };
187
188 package = mkOption {
189 type = types.package;
190 default = pkgs.compton;
191 example = literalExample "pkgs.compton";
192 description = ''
193 Compton derivation to use.
194 '';
195 };
196
197 extraOptions = mkOption {
198 type = types.str;
199 default = "";
200 example = ''
201 unredir-if-possible = true;
202 dbe = true;
203 '';
204 description = ''
205 Additional Compton configuration.
206 '';
207 };
208 };
209
210 config = mkIf cfg.enable {
211 systemd.user.services.compton = {
212 description = "Compton composite manager";
213 wantedBy = [ "default.target" ];
214 serviceConfig = {
215 ExecStart = "${cfg.package}/bin/compton --config ${configFile}";
216 RestartSec = 3;
217 Restart = "always";
218 };
219 environment.DISPLAY = ":0";
220 };
221
222 environment.systemPackages = [ cfg.package ];
223 };
224
225}