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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
|
// SPDX-License-Identifier: MIT
// Copyright (c) 2011-2013, Christopher Jeffrey
// Copyright (c) 2013 Richard Grenville <[email protected]>
// Copyright (c) 2018 Yuxuan Shui <[email protected]>
#pragma once
/// Common functions and definitions for configuration parsing
/// Used for command line arguments and config files
#include <ctype.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <xcb/render.h> // for xcb_render_fixed_t, XXX
#include <xcb/xcb.h>
#include <xcb/xfixes.h>
#include "uthash_extra.h"
#ifdef CONFIG_LIBCONFIG
#include <libconfig.h>
#endif
#include "compiler.h"
#include "kernel.h"
#include "log.h"
#include "region.h"
#include "types.h"
#include "win_defs.h"
typedef struct session session_t;
/// @brief Possible backends
enum backend {
BKEND_XRENDER,
BKEND_GLX,
BKEND_XR_GLX_HYBRID,
BKEND_DUMMY,
BKEND_EGL,
NUM_BKEND,
};
enum open_window_animation {
OPEN_WINDOW_ANIMATION_NONE = 0,
OPEN_WINDOW_ANIMATION_AUTO,
OPEN_WINDOW_ANIMATION_FLYIN,
OPEN_WINDOW_ANIMATION_ZOOM,
OPEN_WINDOW_ANIMATION_SLIDE_UP,
OPEN_WINDOW_ANIMATION_SLIDE_DOWN,
OPEN_WINDOW_ANIMATION_SLIDE_LEFT,
OPEN_WINDOW_ANIMATION_SLIDE_RIGHT,
// OPEN_WINDOW_ANIMATION_SLIDE_IN,
// OPEN_WINDOW_ANIMATION_SLIDE_OUT,
OPEN_WINDOW_ANIMATION_INVALID,
};
enum wm_support {
WM_SUPPORT_NONE = 0,
WM_SUPPORT_AWESOME,
WM_SUPPORT_HERB,
WM_SUPPORT_DWM,
WM_SUPPORT_INVALID,
};
typedef struct win_option_mask {
bool shadow : 1;
bool fade : 1;
bool focus : 1;
bool blur_background : 1;
bool full_shadow : 1;
bool redir_ignore : 1;
bool opacity : 1;
bool clip_shadow_above : 1;
enum open_window_animation animation;
enum open_window_animation animation_unmap;
// enum open_window_animation animation_workspace_in;
// enum open_window_animation animation_workspace_out;
} win_option_mask_t;
typedef struct win_option {
bool shadow;
bool fade;
bool focus;
bool blur_background;
bool full_shadow;
bool redir_ignore;
double opacity;
bool clip_shadow_above;
enum open_window_animation animation;
enum open_window_animation animation_unmap;
// enum open_window_animation animation_workspace_in;
// enum open_window_animation animation_workspace_out;
} win_option_t;
enum blur_method {
BLUR_METHOD_NONE = 0,
BLUR_METHOD_KERNEL,
BLUR_METHOD_BOX,
BLUR_METHOD_GAUSSIAN,
BLUR_METHOD_DUAL_KAWASE,
BLUR_METHOD_INVALID,
};
typedef struct _c2_lptr c2_lptr_t;
/// Structure representing all options.
typedef struct options {
// === Debugging ===
bool monitor_repaint;
bool print_diagnostics;
/// Render to a separate window instead of taking over the screen
bool debug_mode;
// === General ===
/// Use the legacy backends?
bool legacy_backends;
/// Path to write PID to.
char *write_pid_path;
/// The backend in use.
enum backend backend;
/// Whether to sync X drawing with X Sync fence to avoid certain delay
/// issues with GLX backend.
bool xrender_sync_fence;
/// Whether to avoid using stencil buffer under GLX backend. Might be
/// unsafe.
bool glx_no_stencil;
/// Whether to avoid rebinding pixmap on window damage.
bool glx_no_rebind_pixmap;
/// Custom fragment shader for painting windows, as a string.
char *glx_fshader_win_str;
/// Whether to detect rounded corners.
bool detect_rounded_corners;
/// Force painting of window content with blending.
bool force_win_blend;
/// Resize damage for a specific number of pixels.
int resize_damage;
/// Whether to unredirect all windows if a full-screen opaque window
/// is detected.
bool unredir_if_possible;
/// List of conditions of windows to ignore as a full-screen window
/// when determining if a window could be unredirected.
c2_lptr_t *unredir_if_possible_blacklist;
/// Delay before unredirecting screen, in milliseconds.
long unredir_if_possible_delay;
/// Forced redirection setting through D-Bus.
switch_t redirected_force;
/// Whether to stop painting. Controlled through D-Bus.
switch_t stoppaint_force;
/// Whether to enable D-Bus support.
bool dbus;
/// Path to log file.
char *logpath;
/// Number of cycles to paint in benchmark mode. 0 for disabled.
int benchmark;
/// Window to constantly repaint in benchmark mode. 0 for full-screen.
xcb_window_t benchmark_wid;
/// A list of conditions of windows not to paint.
c2_lptr_t *paint_blacklist;
/// Whether to show all X errors.
bool show_all_xerrors;
/// Whether to avoid acquiring X Selection.
bool no_x_selection;
/// Window type option override.
win_option_t wintype_option[NUM_WINTYPES];
// === VSync & software optimization ===
/// VSync method to use;
bool vsync;
/// Whether to use glFinish() instead of glFlush() for (possibly) better
/// VSync yet probably higher CPU usage.
bool vsync_use_glfinish;
/// Whether use damage information to help limit the area to paint
bool use_damage;
// === Shadow ===
/// Red, green and blue tone of the shadow.
double shadow_red, shadow_green, shadow_blue;
int shadow_radius;
int shadow_offset_x, shadow_offset_y;
double shadow_opacity;
/// argument string to shadow-exclude-reg option
char *shadow_exclude_reg_str;
/// Shadow blacklist. A linked list of conditions.
c2_lptr_t *shadow_blacklist;
/// Whether bounding-shaped window should be ignored.
bool shadow_ignore_shaped;
/// Whether to crop shadow to the very Xinerama screen.
bool xinerama_shadow_crop;
/// Don't draw shadow over these windows. A linked list of conditions.
c2_lptr_t *shadow_clip_list;
// === Fading ===
/// How much to fade in in a single fading step.
double fade_in_step;
/// How much to fade out in a single fading step.
double fade_out_step;
/// Fading time delta. In milliseconds.
int fade_delta;
/// Whether to disable fading on window open/close.
bool no_fading_openclose;
/// Whether to disable fading on ARGB managed destroyed windows.
bool no_fading_destroyed_argb;
/// Fading blacklist. A linked list of conditions.
c2_lptr_t *fade_blacklist;
// === Animations ===
/// Whether to do window animations
bool animations;
/// Which animation to run when opening a window
enum open_window_animation animation_for_open_window;
/// Which animation to run when opening a transient window
// enum open_window_animation animation_for_transient_window;
/// Which animation to run when unmapping (e.g. minimizing) a window
enum open_window_animation animation_for_unmap_window;
/// Which animation to run when switching workspace
/// IMPORTANT: will only work if window manager updates
/// _NET_CURRENT_DESKTOP before doing the hide/show of windows
// enum open_window_animation animation_for_workspace_switch_in;
// enum open_window_animation animation_for_workspace_switch_out;
/// Spring stiffness for animation
double animation_stiffness;
/// Window mass for animation
double animation_window_mass;
/// Animation dampening
double animation_dampening;
/// Animation delta. In milliseconds.
double animation_delta;
/// Whether to force animations to not miss a beat
bool animation_force_steps;
/// Whether to clamp animations
bool animation_clamping;
// Wm Support
enum wm_support support_for_wm;
bool blur_whitelist;
// === Opacity ===
/// Default opacity for inactive windows.
/// 32-bit integer with the format of _NET_WM_WINDOW_OPACITY.
double inactive_opacity;
/// Default opacity for inactive windows.
double active_opacity;
/// Whether inactive_opacity overrides the opacity set by window
/// attributes.
bool inactive_opacity_override;
/// Frame opacity. Relative to window opacity, also affects shadow
/// opacity.
double frame_opacity;
/// Whether to detect _NET_WM_WINDOW_OPACITY on client windows. Used on window
/// managers that don't pass _NET_WM_WINDOW_OPACITY to frame windows.
bool detect_client_opacity;
// === Other window processing ===
/// Blur method for background of semi-transparent windows
enum blur_method blur_method;
// Size of the blur kernel
int blur_radius;
// Standard deviation for the gaussian blur
double blur_deviation;
// Strength of the dual_kawase blur
int blur_strength;
/// Whether to blur background when the window frame is not opaque.
/// Implies blur_background.
bool blur_background_frame;
/// Whether to use fixed blur strength instead of adjusting according
/// to window opacity.
bool blur_background_fixed;
/// Background blur blacklist. A linked list of conditions.
c2_lptr_t *blur_background_blacklist;
/// Blur convolution kernel.
struct conv **blur_kerns;
/// Number of convolution kernels
int blur_kernel_count;
/// Custom fragment shader for painting windows
char *window_shader_fg;
/// Rules to change custom fragment shader for painting windows.
c2_lptr_t *window_shader_fg_rules;
/// How much to dim an inactive window. 0.0 - 1.0, 0 to disable.
double inactive_dim;
/// Whether to use fixed inactive dim opacity, instead of deciding
/// based on window opacity.
bool inactive_dim_fixed;
/// Conditions of windows to have inverted colors.
c2_lptr_t *invert_color_list;
/// Rules to change window opacity.
c2_lptr_t *opacity_rules;
// Rules for setting corner radius
c2_lptr_t *corner_rules;
// Rules to make windows use blur
c2_lptr_t *blur_rules;
// Rules to exclude windows from having a open animation
c2_lptr_t *animation_open_blacklist;
// Rules to exclude windows from having a unmap animation
c2_lptr_t *animation_unmap_blacklist;
// Rules to exclude windows from having being affected by active-opacity
c2_lptr_t *active_opacity_blacklist;
// Rules to exclude windows from having being affected by inactive-opacity
c2_lptr_t *inactive_opacity_blacklist;
/// Limit window brightness
double max_brightness;
// Radius of rounded window corners
int corner_radius;
/// Rounded corners blacklist. A linked list of conditions.
c2_lptr_t *rounded_corners_blacklist;
// === Focus related ===
/// Whether to try to detect WM windows and mark them as focused.
bool mark_wmwin_focused;
/// Whether to mark override-redirect windows as focused.
bool mark_ovredir_focused;
/// Whether to use EWMH _NET_ACTIVE_WINDOW to find active window.
bool use_ewmh_active_win;
/// A list of windows always to be considered focused.
c2_lptr_t *focus_blacklist;
/// Whether to do window grouping with <code>WM_TRANSIENT_FOR</code>.
bool detect_transient;
/// Whether to do window grouping with <code>WM_CLIENT_LEADER</code>.
bool detect_client_leader;
// === Calculated ===
/// Whether we need to track window leaders.
bool track_leader;
// Don't use EWMH to detect fullscreen applications
bool no_ewmh_fullscreen;
// Make transparent windows clip other windows, instead of blending on top of
// them
bool transparent_clipping;
/// A list of conditions of windows to which transparent clipping
/// should not apply
c2_lptr_t *transparent_clipping_blacklist;
} options_t;
extern const char *const BACKEND_STRS[NUM_BKEND + 1];
bool must_use parse_long(const char *, long *);
bool must_use parse_int(const char *, int *);
struct conv **must_use parse_blur_kern_lst(const char *, bool *hasneg, int *count);
bool must_use parse_geometry(session_t *, const char *, region_t *);
bool must_use parse_rule_opacity(c2_lptr_t **, const char *);
bool must_use parse_rule_corners(c2_lptr_t **, const char *);
bool must_use parse_rule_window_shader(c2_lptr_t **, const char *, const char *);
char *must_use locate_auxiliary_file(const char *scope, const char *path,
const char *include_dir);
enum blur_method must_use parse_blur_method(const char *src);
enum open_window_animation must_use parse_open_window_animation(const char *src);
enum wm_support must_use parse_wm_support(const char *src);
/**
* Add a pattern to a condition linked list.
*/
bool condlst_add(c2_lptr_t **, const char *);
#ifdef CONFIG_LIBCONFIG
const char *xdg_config_home(void);
char **xdg_config_dirs(void);
/// Parse a configuration file
/// Returns the actually config_file name used, allocated on heap
/// Outputs:
/// shadow_enable = whether shaodw is enabled globally
/// fading_enable = whether fading is enabled globally
/// win_option_mask = whether option overrides for specific window type is set for given
/// options
/// hasneg = whether the convolution kernel has negative values
char *
parse_config_libconfig(options_t *, const char *config_file, bool *shadow_enable,
bool *fading_enable, bool *hasneg, win_option_mask_t *winopt_mask);
#endif
void set_default_winopts(options_t *, win_option_mask_t *, bool shadow_enable,
bool fading_enable, bool blur_enable);
/// Parse a configuration file is that is enabled, also initialize the winopt_mask with
/// default values
/// Outputs and returns:
/// same as parse_config_libconfig
char *parse_config(options_t *, const char *config_file, bool *shadow_enable,
bool *fading_enable, bool *hasneg, win_option_mask_t *winopt_mask);
/**
* Parse a backend option argument.
*/
static inline attr_pure enum backend parse_backend(const char *str) {
for (enum backend i = 0; BACKEND_STRS[i]; ++i) {
if (!strcasecmp(str, BACKEND_STRS[i])) {
return i;
}
}
// Keep compatibility with an old revision containing a spelling mistake...
if (!strcasecmp(str, "xr_glx_hybird")) {
log_warn("backend xr_glx_hybird should be xr_glx_hybrid, the misspelt "
"version will be removed soon.");
return BKEND_XR_GLX_HYBRID;
}
// cju wants to use dashes
if (!strcasecmp(str, "xr-glx-hybrid")) {
log_warn("backend xr-glx-hybrid should be xr_glx_hybrid, the alternative "
"version will be removed soon.");
return BKEND_XR_GLX_HYBRID;
}
log_error("Invalid backend argument: %s", str);
return NUM_BKEND;
}
/**
* Parse a VSync option argument.
*/
static inline bool parse_vsync(const char *str) {
if (strcmp(str, "no") == 0 || strcmp(str, "none") == 0 ||
strcmp(str, "false") == 0 || strcmp(str, "nah") == 0) {
return false;
}
return true;
}
// vim: set noet sw=8 ts=8 :
|