Debian Codegraph @

src/config.h

raw symbols SCIP
1 // SPDX-License-Identifier: MIT
2 // Copyright (c) 2011-2013, Christopher Jeffrey
3 // Copyright (c) 2013 Richard Grenville <[email protected]>
4 // Copyright (c) 2018 Yuxuan Shui <[email protected]>
5
6 #pragma once
7
8 /// Common functions and definitions for configuration parsing
9 /// Used for command line arguments and config files
10
11 #include <stdalign.h>
12 #include <stdbool.h>
13 #include <stddef.h>
14 #include <string.h>
15 #include <uthash.h>
16 #include <xcb/render.h> // for xcb_render_fixed_t, XXX
17 #include <xcb/xcb.h>
18 #include <xcb/xfixes.h>
19
20 #include <libconfig.h>
21 #include <picom/types.h>
22
23 #include "compiler.h"
24 #include "log.h"
25 #include "utils/kernel.h"
26 #include "utils/list.h"
27 #include "utils/misc.h"
28 #include "wm/defs.h"
29
30 typedef struct session session_t;
31
32 typedef struct win_option_mask {
33 bool shadow : 1;
34 bool fade : 1;
35 bool focus : 1;
36 bool blur_background : 1;
37 bool full_shadow : 1;
38 bool redir_ignore : 1;
39 bool opacity : 1;
40 bool clip_shadow_above : 1;
41 } win_option_mask_t;
42
43 typedef struct win_option {
44 bool shadow;
45 bool fade;
46 bool focus;
47 bool blur_background;
48 bool full_shadow;
49 bool redir_ignore;
50 double opacity;
51 bool clip_shadow_above;
52 } win_option_t;
53
54 enum vblank_scheduler_type {
55 /// X Present extension based vblank events
56 VBLANK_SCHEDULER_PRESENT,
57 /// GLX_SGI_video_sync based vblank events
58 VBLANK_SCHEDULER_SGI_VIDEO_SYNC,
59 /// An invalid scheduler, served as a scheduler count, and
60 /// as a sentinel value.
61 LAST_VBLANK_SCHEDULER,
62 };
63
64 enum animation_trigger {
65 /// When a hidden window is shown
66 ANIMATION_TRIGGER_SHOW = 0,
67 /// When a window is hidden
68 ANIMATION_TRIGGER_HIDE,
69 /// When window opacity is increased
70 ANIMATION_TRIGGER_INCREASE_OPACITY,
71 /// When window opacity is decreased
72 ANIMATION_TRIGGER_DECREASE_OPACITY,
73 /// When a new window opens
74 ANIMATION_TRIGGER_OPEN,
75 /// When a window is closed
76 ANIMATION_TRIGGER_CLOSE,
77 /// When a window's size changes
78 ANIMATION_TRIGGER_SIZE,
79 /// When a window's position changes
80 ANIMATION_TRIGGER_POSITION,
81 /// When one of a window's color properties changes,
82 /// This includes: shadow-color
83 ANIMATION_TRIGGER_COLOR,
84
85 ANIMATION_TRIGGER_INVALID,
86 ANIMATION_TRIGGER_COUNT = ANIMATION_TRIGGER_INVALID,
87
88 // Aliases are not included in the count
89
90 /// Alias of size + position
91 ANIMATION_TRIGGER_ALIAS_GEOMETRY,
92 };
93
94 static const char *animation_trigger_names[] attr_unused = {
95 [ANIMATION_TRIGGER_SHOW] = "show",
96 [ANIMATION_TRIGGER_HIDE] = "hide",
97 [ANIMATION_TRIGGER_INCREASE_OPACITY] = "increase-opacity",
98 [ANIMATION_TRIGGER_DECREASE_OPACITY] = "decrease-opacity",
99 [ANIMATION_TRIGGER_OPEN] = "open",
100 [ANIMATION_TRIGGER_CLOSE] = "close",
101 [ANIMATION_TRIGGER_SIZE] = "size",
102 [ANIMATION_TRIGGER_POSITION] = "position",
103 [ANIMATION_TRIGGER_COLOR] = "color",
104 [ANIMATION_TRIGGER_ALIAS_GEOMETRY] = "geometry",
105 };
106
107 struct shader_specification {
108 size_t size;
109 char data[];
110 };
111
112 struct shader_defines_iter {
113 const char *name;
114 const char *value;
115 };
116
117 static inline struct shader_specification *shader_spec_from_path(const char *path) {
118 auto len = strlen(path) + 1;
119 struct shader_specification *ret =
120 calloc(1, offsetof(struct shader_specification, data[len]));
121 BUG_ON(ret == NULL);
122 ret->size = len;
123 strcpy(ret->data, path);
124 return ret;
125 }
126
127 static inline const char *shader_spec_get_path(const struct shader_specification *spec) {
128 return spec->data;
129 }
130
131 static inline bool shader_spec_get_defines(const struct shader_specification *spec,
132 struct shader_defines_iter *iter) {
133 const char *end = &spec->data[spec->size];
134 const char *first = spec->data + strlen(spec->data) + 1;
135 if (first >= end) {
136 return false;
137 }
138 iter->name = first;
139 iter->value = first + strlen(first) + 1;
140 assert(iter->value < end);
141 return true;
142 }
143
144 static inline bool shader_spec_defines_iter_next(const struct shader_specification *spec,
145 struct shader_defines_iter *iter) {
146 const char *end = &spec->data[spec->size];
147 const char *next = iter->value + strlen(iter->value) + 1;
148 if (next >= end) {
149 return false;
150 }
151 iter->name = next;
152 iter->value = next + strlen(next) + 1;
153 assert(iter->value < end);
154 return true;
155 }
156
157 struct script;
158 struct win_script {
159 /// A running animation can be configured to prevent other animations from
160 /// starting.
161 uint64_t suppressions;
162 struct script *script;
163 /// true if this script is generated by us, false if this is a user choice.
164 int output_indices[NUM_OF_WIN_SCRIPT_OUTPUTS];
165 bool is_generated;
166 };
167
168 extern const char *vblank_scheduler_str[];
169
170 /// Internal, private options for debugging and development use.
171 struct debug_options {
172 /// Try to reduce frame latency by using vblank interval and render time
173 /// estimates. Right now it's not working well across drivers.
174 int smart_frame_pacing;
175 /// Override the vblank scheduler chosen by the compositor.
176 int force_vblank_scheduler;
177 /// Release then immediately rebind every window pixmap each frame.
178 /// Useful when being traced under apitrace, to force it to pick up
179 /// updated contents. WARNING, extremely slow.
180 int always_rebind_pixmap;
181 /// When using damage, replaying an apitrace becomes non-deterministic, because
182 /// the buffer age we got when we rendered will be different from the buffer age
183 /// apitrace gets when it replays. When this option is enabled, we saves the
184 /// contents of each rendered frame, and at the beginning of each render, we
185 /// restore the content of the back buffer based on the buffer age we get,
186 /// ensuring no matter what buffer age apitrace gets during replay, the result
187 /// will be the same.
188 int consistent_buffer_age;
189 };
190
191 extern struct debug_options global_debug_options;
192
193 struct included_config_file {
194 char *path;
195 struct list_node siblings;
196 };
197
198 enum window_unredir_option {
199 /// This window should trigger unredirection if it meets certain conditions, and
200 /// it should terminate unredirection otherwise. Termination of unredir is always
201 /// suppressed if there is another window triggering unredirection, this is the
202 /// same for `WINDOW_UNREDIR_TERMINATE` as well.
203 ///
204 /// This is the default choice for windows.
205 WINDOW_UNREDIR_WHEN_POSSIBLE_ELSE_TERMINATE,
206 /// This window should trigger unredirection if it meets certain conditions.
207 /// Otherwise it should have no effect on the compositor's redirection status.
208 WINDOW_UNREDIR_WHEN_POSSIBLE,
209 /// This window should always take the compositor out of unredirection, and never
210 /// trigger unredirection.
211 WINDOW_UNREDIR_TERMINATE,
212 /// This window should not cause either redirection or unredirection.
213 WINDOW_UNREDIR_PASSIVE,
214 /// This window always trigger unredirection
215 WINDOW_UNREDIR_FORCED,
216
217 /// Sentinel value
218 WINDOW_UNREDIR_INVALID,
219 };
220
221 struct shader_specification;
222
223 struct window_maybe_options {
224 /// Shadow color
225 struct color shadow_color;
226
227 /// Window opacity, NaN means not set.
228 double opacity;
229
230 /// Opacity of the blurred background, NaN means not set, ignored if
231 /// blur_background is disabled.
232 double blur_opacity;
233
234 /// Window dim level, NaN means not set.
235 double dim;
236
237 /// The name of the custom fragment shader for this window. NULL means not set.
238 const struct shader_specification *shader;
239
240 /// Radius of rounded window corners, -1 means not set.
241 int corner_radius;
242
243 /// Whether transparent clipping is excluded by the rules.
244 enum tristate transparent_clipping;
245 /// Whether a window has shadow.
246 enum tristate shadow;
247 /// Whether to invert window color.
248 enum tristate invert_color;
249 /// Whether to blur window background.
250 enum tristate blur_background;
251 /// Whether this window should fade.
252 enum tristate fade;
253 /// Do not paint shadow over this window.
254 enum tristate clip_shadow_above;
255 /// Whether the window is painted.
256 enum tristate paint;
257 /// Whether this window should be considered for unredirect-if-possible.
258 enum window_unredir_option unredir;
259 /// Whether shadow should be rendered beneath this window.
260 enum tristate full_shadow;
261 /// Whether shadow color is set
262 bool is_shadow_color_set;
263
264 /// Window specific animations
265 struct win_script animations[ANIMATION_TRIGGER_COUNT];
266 };
267
268 /// Like `window_maybe_options`, but all fields are guaranteed to be set.
269 struct window_options {
270 struct color shadow_color;
271 double opacity;
272 double blur_opacity;
273 double dim;
274 const struct shader_specification *shader;
275 unsigned int corner_radius;
276 enum window_unredir_option unredir;
277 bool transparent_clipping;
278 bool shadow;
279 bool invert_color;
280 bool blur_background;
281 bool fade;
282 bool clip_shadow_above;
283 bool paint;
284 bool full_shadow;
285
286 struct win_script animations[ANIMATION_TRIGGER_COUNT];
287 };
288
289 struct option_name {
290 UT_hash_handle hh;
291 const char *name;
292 };
293
294 /// Structure representing all options.
295 typedef struct options {
296 // === Deprecation ===
297 struct option_name *problematic_options;
298
299 // === Config ===
300 /// Path to the config file
301 char *config_file_path;
302 /// List of config files included by the main config file
303 struct list_node included_config_files;
304 // === Debugging ===
305 bool monitor_repaint;
306 bool print_diagnostics;
307 /// Render to a separate window instead of taking over the screen
308 bool debug_mode;
309 /// For picom-inspect only, dump windows in a loop
310 bool inspect_monitor;
311 xcb_window_t inspect_win;
312 // === General ===
313 /// Use the legacy backends?
314 bool use_legacy_backends;
315 /// Path to write PID to.
316 char *write_pid_path;
317 /// Name of the backend
318 struct backend_info *backend;
319 /// Log level.
320 int log_level;
321 /// Whether to sync X drawing with X Sync fence to avoid certain delay
322 /// issues with GLX backend.
323 bool xrender_sync_fence;
324 /// Whether to avoid using stencil buffer under GLX backend. Might be
325 /// unsafe.
326 bool glx_no_stencil;
327 /// Whether to avoid rebinding pixmap on window damage.
328 bool glx_no_rebind_pixmap;
329 /// Whether to detect rounded corners.
330 bool detect_rounded_corners;
331 /// Force painting of window content with blending.
332 bool force_win_blend;
333 /// Resize damage for a specific number of pixels.
334 int resize_damage;
335 /// Whether to unredirect all windows if a full-screen opaque window
336 /// is detected.
337 bool unredir_if_possible;
338 /// List of conditions of windows to ignore as a full-screen window
339 /// when determining if a window could be unredirected.
340 struct list_node unredir_if_possible_blacklist;
341 /// Delay before unredirecting screen, in milliseconds.
342 int unredir_if_possible_delay;
343 /// Forced redirection setting through D-Bus.
344 switch_t redirected_force;
345 /// Whether to stop painting. Controlled through D-Bus.
346 switch_t stoppaint_force;
347 /// Whether to enable D-Bus support.
348 bool dbus;
349 /// Path to log file.
350 char *logpath;
351 /// Number of cycles to paint in benchmark mode. 0 for disabled.
352 int benchmark;
353 /// Window to constantly repaint in benchmark mode. 0 for full-screen.
354 xcb_window_t benchmark_wid;
355 /// A list of conditions of windows not to paint.
356 struct list_node paint_blacklist;
357 /// Whether to show all X errors.
358 bool show_all_xerrors;
359 /// Whether to avoid acquiring X Selection.
360 bool no_x_selection;
361 /// Window type option override.
362 win_option_t wintype_option[NUM_WINTYPES];
363 struct win_option_mask wintype_option_mask[NUM_WINTYPES];
364 /// Whether to set realtime scheduling policy for the compositor process.
365 bool use_realtime_scheduling;
366
367 // === VSync & software optimization ===
368 /// VSync method to use;
369 bool vsync;
370 /// Whether to use glFinish() instead of glFlush() for (possibly) better
371 /// VSync yet probably higher CPU usage.
372 bool vsync_use_glfinish;
373 /// Whether use damage information to help limit the area to paint
374 bool use_damage;
375 /// Disable frame pacing
376 bool frame_pacing;
377
378 // === Shadow ===
379 /// Red, green and blue tone of the shadow.
380 double shadow_red, shadow_green, shadow_blue;
381 int shadow_radius;
382 int shadow_offset_x, shadow_offset_y;
383 double shadow_opacity;
384 /// Shadow blacklist. A linked list of conditions.
385 struct list_node shadow_blacklist;
386 /// Whether bounding-shaped window should be ignored.
387 bool shadow_ignore_shaped;
388 /// Whether to crop shadow to the very X RandR monitor.
389 bool crop_shadow_to_monitor;
390 /// Don't draw shadow over these windows. A linked list of conditions.
391 struct list_node shadow_clip_list;
392 bool shadow_enable;
393
394 // === Fading ===
395 /// How much to fade in in a single fading step.
396 double fade_in_step;
397 /// How much to fade out in a single fading step.
398 double fade_out_step;
399 /// Fading time delta. In milliseconds.
400 int fade_delta;
401 /// Whether to disable fading on window open/close.
402 bool no_fading_openclose;
403 /// Whether to disable fading on ARGB managed destroyed windows.
404 bool no_fading_destroyed_argb;
405 /// Fading blacklist. A linked list of conditions.
406 struct list_node fade_blacklist;
407 bool fading_enable;
408
409 // === Opacity ===
410 /// Default opacity for inactive windows.
411 /// 32-bit integer with the format of _NET_WM_WINDOW_OPACITY.
412 double inactive_opacity;
413 /// Default opacity for inactive windows.
414 double active_opacity;
415 /// Whether inactive_opacity overrides the opacity set by window
416 /// attributes.
417 bool inactive_opacity_override;
418 /// Frame opacity. Relative to window opacity, also affects shadow
419 /// opacity.
420 double frame_opacity;
421 /// Whether to detect _NET_WM_WINDOW_OPACITY on client windows. Used on window
422 /// managers that don't pass _NET_WM_WINDOW_OPACITY to frame windows.
423 bool detect_client_opacity;
424
425 // === Other window processing ===
426 /// Blur method for background of semi-transparent windows
427 enum blur_method blur_method;
428 // Size of the blur kernel
429 int blur_radius;
430 // Standard deviation for the gaussian blur
431 double blur_deviation;
432 // Strength of the dual_kawase blur
433 int blur_strength;
434 /// Whether to blur background when the window frame is not opaque.
435 /// Implies blur_background.
436 bool blur_background_frame;
437 /// Whether to use fixed blur strength instead of adjusting according
438 /// to window opacity.
439 bool blur_background_fixed;
440 /// Background blur blacklist. A linked list of conditions.
441 struct list_node blur_background_blacklist;
442 /// Blur convolution kernel.
443 struct conv **blur_kerns;
444 /// Number of convolution kernels
445 int blur_kernel_count;
446 /// Custom fragment shader for painting the root window pixmap
447 struct shader_specification *root_pixmap_shader;
448 /// Custom fragment shader for painting windows
449 struct shader_specification *window_shader_fg;
450 /// Rules to change custom fragment shader for painting windows.
451 struct list_node window_shader_fg_rules;
452 /// How much to dim an inactive window. 0.0 - 1.0, 0 to disable.
453 double inactive_dim;
454 /// Whether to use fixed inactive dim opacity, instead of deciding
455 /// based on window opacity.
456 bool inactive_dim_fixed;
457 /// Conditions of windows to have inverted colors.
458 struct list_node invert_color_list;
459 /// Rules to change window opacity.
460 struct list_node opacity_rules;
461 /// Limit window brightness
462 double max_brightness;
463 // Radius of rounded window corners
464 int corner_radius;
465 /// Rounded corners blacklist. A linked list of conditions.
466 struct list_node rounded_corners_blacklist;
467 /// Rounded corner rules. A linked list of conditions.
468 struct list_node corner_radius_rules;
469
470 // === Focus related ===
471 /// Whether to try to detect WM windows and mark them as focused.
472 bool mark_wmwin_focused;
473 /// Whether to mark override-redirect windows as focused.
474 bool mark_ovredir_focused;
475 /// Whether to use EWMH _NET_ACTIVE_WINDOW to find active window.
476 bool use_ewmh_active_win;
477 /// A list of windows always to be considered focused.
478 struct list_node focus_blacklist;
479 /// Whether to do window grouping with <code>WM_TRANSIENT_FOR</code>.
480 bool detect_transient;
481 /// Whether to do window grouping with <code>WM_CLIENT_LEADER</code>.
482 bool detect_client_leader;
483
484 // === Calculated ===
485 /// Whether we need to track window leaders.
486 bool track_leader;
487
488 // Don't use EWMH to detect fullscreen applications
489 bool no_ewmh_fullscreen;
490
491 // Make transparent windows clip other windows, instead of blending on top of
492 // them
493 bool transparent_clipping;
494 /// A list of conditions of windows to which transparent clipping
495 /// should not apply
496 struct list_node transparent_clipping_blacklist;
497
498 bool dithered_present;
499 // === Animation ===
500 struct win_script animations[ANIMATION_TRIGGER_COUNT];
501 /// Array of all the scripts used in `animations`. This is a dynarr.
502 struct script **all_scripts;
503
504 struct list_node rules;
505 bool has_both_style_of_rules;
506 } options_t;
507
508 bool load_plugin(const char *name, const char *include_dir);
509 static inline void record_problematic_option(struct options *opt, const char *name) {
510 struct option_name *record = calloc(1, sizeof(*record));
511 record->name = name;
512 HASH_ADD_STR(opt->problematic_options, name, record);
513 }
514
515 static inline void
516 report_deprecated_option(struct options *opt, const char *name, bool error) {
517 struct option_name *record = NULL;
518 HASH_FIND_STR(opt->problematic_options, name, record);
519 if (record != NULL) {
520 return;
521 }
522 enum log_level level = error ? LOG_LEVEL_ERROR : LOG_LEVEL_WARN;
523 LOG_(level,
524 "Option \"%s\" is deprecated, please remove it from your config file and/or "
525 "command line options.",
526 name);
527 record_problematic_option(opt, name);
528 }
529
530 bool must_use parse_long(const char *, long *);
531 bool must_use parse_int(const char *, int *);
532 struct conv **must_use parse_blur_kern_lst(const char *, int *count);
533 /// Parse the path prefix of a c2 rule. Then look for the specified file in the
534 /// given include directories. The include directories are passed via `user_data`.
535 void *parse_window_shader_prefix(const char *src, const char **end, void *user_data);
536 /// Same as `parse_window_shader_prefix`, but the path is relative to the current
537 /// working directory. `user_data` is ignored.
538 void *parse_window_shader_prefix_with_cwd(const char *src, const char **end, void *);
539 void *parse_numeric_prefix(const char *src, const char **end, void *user_data);
540 char *must_use locate_auxiliary_file(const char *scope, const char *path,
541 const char *include_dir);
542 int must_use parse_blur_method(const char *src);
543 void parse_debug_options(struct debug_options *);
544
545 const char *xdg_config_home(void);
546 char **xdg_config_dirs(void);
547
548 /// Parse a configuration file from default location.
549 ///
550 /// @return if config is successfully parsed.
551 bool parse_config_libconfig(options_t *, const char *config_file);
552
553 /// Parse a configuration file is that is enabled, also initialize the winopt_mask with
554 /// default values
555 /// Outputs and returns:
556 /// same as parse_config_libconfig
557 bool parse_config(options_t *, const char *config_file);
558
559 /**
560 * Parse a VSync option argument.
561 */
562 static inline bool parse_vsync(const char *str) {
563 if (strcmp(str, "no") == 0 || strcmp(str, "none") == 0 ||
564 strcmp(str, "false") == 0 || strcmp(str, "nah") == 0) {
565 return false;
566 }
567 return true;
568 }
569
570 /// Generate animation script for legacy fading options
571 void generate_fading_config(struct options *opt);
572
573 static inline void log_warn_both_style_of_rules(struct options *opt, const char *option_name) {
574 log_warn("Option \"%s\" is set along with \"rules\". \"rules\" will take "
575 "precedence, and \"%s\" will have no effect.",
576 option_name, option_name);
577 opt->has_both_style_of_rules = true;
578 record_problematic_option(opt, option_name);
579 }
580 enum animation_trigger parse_animation_trigger(const char *trigger);
581
582 // vim: set noet sw=8 ts=8 :