| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
#pragma once |
| 7 |
|
| 8 |
|
| 9 |
|
| 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> |
| 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 |
|
| 56 |
VBLANK_SCHEDULER_PRESENT, |
| 57 |
|
| 58 |
VBLANK_SCHEDULER_SGI_VIDEO_SYNC, |
| 59 |
|
| 60 |
|
| 61 |
LAST_VBLANK_SCHEDULER, |
| 62 |
}; |
| 63 |
|
| 64 |
enum animation_trigger { |
| 65 |
|
| 66 |
ANIMATION_TRIGGER_SHOW = 0, |
| 67 |
|
| 68 |
ANIMATION_TRIGGER_HIDE, |
| 69 |
|
| 70 |
ANIMATION_TRIGGER_INCREASE_OPACITY, |
| 71 |
|
| 72 |
ANIMATION_TRIGGER_DECREASE_OPACITY, |
| 73 |
|
| 74 |
ANIMATION_TRIGGER_OPEN, |
| 75 |
|
| 76 |
ANIMATION_TRIGGER_CLOSE, |
| 77 |
|
| 78 |
ANIMATION_TRIGGER_SIZE, |
| 79 |
|
| 80 |
ANIMATION_TRIGGER_POSITION, |
| 81 |
|
| 82 |
|
| 83 |
ANIMATION_TRIGGER_COLOR, |
| 84 |
|
| 85 |
ANIMATION_TRIGGER_INVALID, |
| 86 |
ANIMATION_TRIGGER_COUNT = ANIMATION_TRIGGER_INVALID, |
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 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 |
|
| 160 |
|
| 161 |
uint64_t suppressions; |
| 162 |
struct script *script; |
| 163 |
|
| 164 |
int output_indices[NUM_OF_WIN_SCRIPT_OUTPUTS]; |
| 165 |
bool is_generated; |
| 166 |
}; |
| 167 |
|
| 168 |
extern const char *vblank_scheduler_str[]; |
| 169 |
|
| 170 |
|
| 171 |
struct debug_options { |
| 172 |
|
| 173 |
|
| 174 |
int smart_frame_pacing; |
| 175 |
|
| 176 |
int force_vblank_scheduler; |
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
int always_rebind_pixmap; |
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 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 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
WINDOW_UNREDIR_WHEN_POSSIBLE_ELSE_TERMINATE, |
| 206 |
|
| 207 |
|
| 208 |
WINDOW_UNREDIR_WHEN_POSSIBLE, |
| 209 |
|
| 210 |
|
| 211 |
WINDOW_UNREDIR_TERMINATE, |
| 212 |
|
| 213 |
WINDOW_UNREDIR_PASSIVE, |
| 214 |
|
| 215 |
WINDOW_UNREDIR_FORCED, |
| 216 |
|
| 217 |
|
| 218 |
WINDOW_UNREDIR_INVALID, |
| 219 |
}; |
| 220 |
|
| 221 |
struct shader_specification; |
| 222 |
|
| 223 |
struct window_maybe_options { |
| 224 |
|
| 225 |
struct color shadow_color; |
| 226 |
|
| 227 |
|
| 228 |
double opacity; |
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
double blur_opacity; |
| 233 |
|
| 234 |
|
| 235 |
double dim; |
| 236 |
|
| 237 |
|
| 238 |
const struct shader_specification *shader; |
| 239 |
|
| 240 |
|
| 241 |
int corner_radius; |
| 242 |
|
| 243 |
|
| 244 |
enum tristate transparent_clipping; |
| 245 |
|
| 246 |
enum tristate shadow; |
| 247 |
|
| 248 |
enum tristate invert_color; |
| 249 |
|
| 250 |
enum tristate blur_background; |
| 251 |
|
| 252 |
enum tristate fade; |
| 253 |
|
| 254 |
enum tristate clip_shadow_above; |
| 255 |
|
| 256 |
enum tristate paint; |
| 257 |
|
| 258 |
enum window_unredir_option unredir; |
| 259 |
|
| 260 |
enum tristate full_shadow; |
| 261 |
|
| 262 |
bool is_shadow_color_set; |
| 263 |
|
| 264 |
|
| 265 |
struct win_script animations[ANIMATION_TRIGGER_COUNT]; |
| 266 |
}; |
| 267 |
|
| 268 |
|
| 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 |
|
| 295 |
typedef struct options { |
| 296 |
|
| 297 |
struct option_name *problematic_options; |
| 298 |
|
| 299 |
|
| 300 |
|
| 301 |
char *config_file_path; |
| 302 |
|
| 303 |
struct list_node included_config_files; |
| 304 |
|
| 305 |
bool monitor_repaint; |
| 306 |
bool print_diagnostics; |
| 307 |
|
| 308 |
bool debug_mode; |
| 309 |
|
| 310 |
bool inspect_monitor; |
| 311 |
xcb_window_t inspect_win; |
| 312 |
|
| 313 |
|
| 314 |
bool use_legacy_backends; |
| 315 |
|
| 316 |
char *write_pid_path; |
| 317 |
|
| 318 |
struct backend_info *backend; |
| 319 |
|
| 320 |
int log_level; |
| 321 |
|
| 322 |
|
| 323 |
bool xrender_sync_fence; |
| 324 |
|
| 325 |
|
| 326 |
bool glx_no_stencil; |
| 327 |
|
| 328 |
bool glx_no_rebind_pixmap; |
| 329 |
|
| 330 |
bool detect_rounded_corners; |
| 331 |
|
| 332 |
bool force_win_blend; |
| 333 |
|
| 334 |
int resize_damage; |
| 335 |
|
| 336 |
|
| 337 |
bool unredir_if_possible; |
| 338 |
|
| 339 |
|
| 340 |
struct list_node unredir_if_possible_blacklist; |
| 341 |
|
| 342 |
int unredir_if_possible_delay; |
| 343 |
|
| 344 |
switch_t redirected_force; |
| 345 |
|
| 346 |
switch_t stoppaint_force; |
| 347 |
|
| 348 |
bool dbus; |
| 349 |
|
| 350 |
char *logpath; |
| 351 |
|
| 352 |
int benchmark; |
| 353 |
|
| 354 |
xcb_window_t benchmark_wid; |
| 355 |
|
| 356 |
struct list_node paint_blacklist; |
| 357 |
|
| 358 |
bool show_all_xerrors; |
| 359 |
|
| 360 |
bool no_x_selection; |
| 361 |
|
| 362 |
win_option_t wintype_option[NUM_WINTYPES]; |
| 363 |
struct win_option_mask wintype_option_mask[NUM_WINTYPES]; |
| 364 |
|
| 365 |
bool use_realtime_scheduling; |
| 366 |
|
| 367 |
|
| 368 |
|
| 369 |
bool vsync; |
| 370 |
|
| 371 |
|
| 372 |
bool vsync_use_glfinish; |
| 373 |
|
| 374 |
bool use_damage; |
| 375 |
|
| 376 |
bool frame_pacing; |
| 377 |
|
| 378 |
|
| 379 |
|
| 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 |
|
| 385 |
struct list_node shadow_blacklist; |
| 386 |
|
| 387 |
bool shadow_ignore_shaped; |
| 388 |
|
| 389 |
bool crop_shadow_to_monitor; |
| 390 |
|
| 391 |
struct list_node shadow_clip_list; |
| 392 |
bool shadow_enable; |
| 393 |
|
| 394 |
|
| 395 |
|
| 396 |
double fade_in_step; |
| 397 |
|
| 398 |
double fade_out_step; |
| 399 |
|
| 400 |
int fade_delta; |
| 401 |
|
| 402 |
bool no_fading_openclose; |
| 403 |
|
| 404 |
bool no_fading_destroyed_argb; |
| 405 |
|
| 406 |
struct list_node fade_blacklist; |
| 407 |
bool fading_enable; |
| 408 |
|
| 409 |
|
| 410 |
|
| 411 |
|
| 412 |
double inactive_opacity; |
| 413 |
|
| 414 |
double active_opacity; |
| 415 |
|
| 416 |
|
| 417 |
bool inactive_opacity_override; |
| 418 |
|
| 419 |
|
| 420 |
double frame_opacity; |
| 421 |
|
| 422 |
|
| 423 |
bool detect_client_opacity; |
| 424 |
|
| 425 |
|
| 426 |
|
| 427 |
enum blur_method blur_method; |
| 428 |
|
| 429 |
int blur_radius; |
| 430 |
|
| 431 |
double blur_deviation; |
| 432 |
|
| 433 |
int blur_strength; |
| 434 |
|
| 435 |
|
| 436 |
bool blur_background_frame; |
| 437 |
|
| 438 |
|
| 439 |
bool blur_background_fixed; |
| 440 |
|
| 441 |
struct list_node blur_background_blacklist; |
| 442 |
|
| 443 |
struct conv **blur_kerns; |
| 444 |
|
| 445 |
int blur_kernel_count; |
| 446 |
|
| 447 |
struct shader_specification *root_pixmap_shader; |
| 448 |
|
| 449 |
struct shader_specification *window_shader_fg; |
| 450 |
|
| 451 |
struct list_node window_shader_fg_rules; |
| 452 |
|
| 453 |
double inactive_dim; |
| 454 |
|
| 455 |
|
| 456 |
bool inactive_dim_fixed; |
| 457 |
|
| 458 |
struct list_node invert_color_list; |
| 459 |
|
| 460 |
struct list_node opacity_rules; |
| 461 |
|
| 462 |
double max_brightness; |
| 463 |
|
| 464 |
int corner_radius; |
| 465 |
|
| 466 |
struct list_node rounded_corners_blacklist; |
| 467 |
|
| 468 |
struct list_node corner_radius_rules; |
| 469 |
|
| 470 |
|
| 471 |
|
| 472 |
bool mark_wmwin_focused; |
| 473 |
|
| 474 |
bool mark_ovredir_focused; |
| 475 |
|
| 476 |
bool use_ewmh_active_win; |
| 477 |
|
| 478 |
struct list_node focus_blacklist; |
| 479 |
|
| 480 |
bool detect_transient; |
| 481 |
|
| 482 |
bool detect_client_leader; |
| 483 |
|
| 484 |
|
| 485 |
|
| 486 |
bool track_leader; |
| 487 |
|
| 488 |
|
| 489 |
bool no_ewmh_fullscreen; |
| 490 |
|
| 491 |
|
| 492 |
|
| 493 |
bool transparent_clipping; |
| 494 |
|
| 495 |
|
| 496 |
struct list_node transparent_clipping_blacklist; |
| 497 |
|
| 498 |
bool dithered_present; |
| 499 |
|
| 500 |
struct win_script animations[ANIMATION_TRIGGER_COUNT]; |
| 501 |
|
| 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 |
|
| 534 |
|
| 535 |
void *parse_window_shader_prefix(const char *src, const char **end, void *user_data); |
| 536 |
|
| 537 |
|
| 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 |
|
| 549 |
|
| 550 |
|
| 551 |
bool parse_config_libconfig(options_t *, const char *config_file); |
| 552 |
|
| 553 |
|
| 554 |
|
| 555 |
|
| 556 |
|
| 557 |
bool parse_config(options_t *, const char *config_file); |
| 558 |
|
| 559 |
|
| 560 |
|
| 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 |
|
| 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 |
|