| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
#include <limits.h> |
| 6 |
#include <stdio.h> |
| 7 |
#include <stdlib.h> |
| 8 |
#include <string.h> |
| 9 |
#include <unistd.h> |
| 10 |
|
| 11 |
#include <libconfig.h> |
| 12 |
#include <libgen.h> |
| 13 |
|
| 14 |
#include "backend/backend.h" |
| 15 |
#include "c2.h" |
| 16 |
#include "common.h" |
| 17 |
#include "config.h" |
| 18 |
#include "log.h" |
| 19 |
#include "transition/preset.h" |
| 20 |
#include "transition/script.h" |
| 21 |
#include "utils/dynarr.h" |
| 22 |
#include "utils/misc.h" |
| 23 |
#include "utils/str.h" |
| 24 |
#include "wm/win.h" |
| 25 |
|
| 26 |
#pragma GCC diagnostic error "-Wunused-parameter" |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
static inline int lcfg_lookup_bool(const config_t *config, const char *path, bool *value) { |
| 34 |
int ival; |
| 35 |
|
| 36 |
int ret = config_lookup_bool(config, path, &ival); |
| 37 |
if (ret) { |
| 38 |
*value = ival; |
| 39 |
} |
| 40 |
|
| 41 |
return ret; |
| 42 |
} |
| 43 |
|
| 44 |
|
| 45 |
FILE *open_config_file_at(const char *base, char **out_path) { |
| 46 |
static const char *config_paths[] = {"/picom.conf", "/picom/picom.conf", |
| 47 |
"/compton.conf", "/compton/compton.conf"}; |
| 48 |
for (size_t i = 0; i < ARR_SIZE(config_paths); i++) { |
| 49 |
char *path = mstrjoin(base, config_paths[i]); |
| 50 |
FILE *ret = fopen(path, "r"); |
| 51 |
if (ret && out_path) { |
| 52 |
*out_path = path; |
| 53 |
} else { |
| 54 |
free(path); |
| 55 |
} |
| 56 |
if (ret) { |
| 57 |
if (strstr(config_paths[i], "compton")) { |
| 58 |
log_warn("This compositor has been renamed to \"picom\", " |
| 59 |
"the old config file paths is deprecated. " |
| 60 |
"Please replace the \"compton\"s in the path " |
| 61 |
"with \"picom\""); |
| 62 |
} |
| 63 |
return ret; |
| 64 |
} |
| 65 |
} |
| 66 |
return NULL; |
| 67 |
} |
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
FILE *open_config_file(const char *cpath, char **ppath) { |
| 75 |
static const char config_filename_legacy[] = "/.compton.conf"; |
| 76 |
|
| 77 |
if (cpath) { |
| 78 |
FILE *ret = fopen(cpath, "r"); |
| 79 |
if (ret && ppath) { |
| 80 |
*ppath = strdup(cpath); |
| 81 |
} |
| 82 |
return ret; |
| 83 |
} |
| 84 |
|
| 85 |
|
| 86 |
auto config_home = xdg_config_home(); |
| 87 |
if (config_home) { |
| 88 |
auto ret = open_config_file_at(config_home, ppath); |
| 89 |
free((void *)config_home); |
| 90 |
if (ret) { |
| 91 |
return ret; |
| 92 |
} |
| 93 |
} |
| 94 |
|
| 95 |
|
| 96 |
const char *home = getenv("HOME"); |
| 97 |
if (home && strlen(home)) { |
| 98 |
auto path = mstrjoin(home, config_filename_legacy); |
| 99 |
auto ret = fopen(path, "r"); |
| 100 |
if (ret && ppath) { |
| 101 |
*ppath = path; |
| 102 |
} else { |
| 103 |
free(path); |
| 104 |
} |
| 105 |
if (ret) { |
| 106 |
return ret; |
| 107 |
} |
| 108 |
} |
| 109 |
|
| 110 |
|
| 111 |
auto config_dirs = xdg_config_dirs(); |
| 112 |
for (int i = 0; config_dirs[i]; i++) { |
| 113 |
auto ret = open_config_file_at(config_dirs[i], ppath); |
| 114 |
if (ret) { |
| 115 |
free(config_dirs); |
| 116 |
return ret; |
| 117 |
} |
| 118 |
} |
| 119 |
free(config_dirs); |
| 120 |
|
| 121 |
return NULL; |
| 122 |
} |
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
bool must_use parse_cfg_condlst(struct list_node *list, const config_t *pcfg, |
| 128 |
const char *name, bool *deprecated) { |
| 129 |
config_setting_t *setting = config_lookup(pcfg, name); |
| 130 |
if (setting == NULL) { |
| 131 |
return true; |
| 132 |
} |
| 133 |
|
| 134 |
if (config_setting_is_array(setting)) { |
| 135 |
int i = config_setting_length(setting); |
| 136 |
while (i--) { |
| 137 |
if (!c2_parse(list, config_setting_get_string_elem(setting, i), |
| 138 |
NULL, deprecated)) { |
| 139 |
return false; |
| 140 |
} |
| 141 |
} |
| 142 |
} |
| 143 |
|
| 144 |
else if (CONFIG_TYPE_STRING == config_setting_type(setting)) { |
| 145 |
if (!c2_parse(list, config_setting_get_string(setting), NULL, deprecated)) { |
| 146 |
return false; |
| 147 |
} |
| 148 |
} |
| 149 |
return true; |
| 150 |
} |
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
static inline bool |
| 156 |
parse_cfg_condlst_with_prefix(struct list_node *list, const config_t *pcfg, const char *name, |
| 157 |
void *(*parse_prefix)(const char *, const char **, void *), |
| 158 |
void (*free_value)(void *), void *user_data, bool *deprecated) { |
| 159 |
config_setting_t *setting = config_lookup(pcfg, name); |
| 160 |
if (setting == NULL) { |
| 161 |
return true; |
| 162 |
} |
| 163 |
|
| 164 |
if (config_setting_is_array(setting)) { |
| 165 |
int i = config_setting_length(setting); |
| 166 |
while (i--) { |
| 167 |
if (!c2_parse_with_prefix( |
| 168 |
list, config_setting_get_string_elem(setting, i), |
| 169 |
parse_prefix, free_value, user_data, deprecated)) { |
| 170 |
return false; |
| 171 |
} |
| 172 |
} |
| 173 |
} |
| 174 |
|
| 175 |
else if (config_setting_type(setting) == CONFIG_TYPE_STRING) { |
| 176 |
if (!c2_parse_with_prefix(list, config_setting_get_string(setting), |
| 177 |
parse_prefix, free_value, user_data, deprecated)) { |
| 178 |
return false; |
| 179 |
} |
| 180 |
} |
| 181 |
return true; |
| 182 |
} |
| 183 |
|
| 184 |
static inline void parse_wintype_config(const config_t *cfg, const char *member_name, |
| 185 |
win_option_t *o, win_option_mask_t *mask) { |
| 186 |
char *str = mstrjoin("wintypes.", member_name); |
| 187 |
const config_setting_t *setting = config_lookup(cfg, str); |
| 188 |
free(str); |
| 189 |
|
| 190 |
int ival = 0; |
| 191 |
if (setting) { |
| 192 |
if (config_setting_lookup_bool(setting, "shadow", &ival)) { |
| 193 |
o->shadow = ival; |
| 194 |
mask->shadow = true; |
| 195 |
} |
| 196 |
if (config_setting_lookup_bool(setting, "fade", &ival)) { |
| 197 |
o->fade = ival; |
| 198 |
mask->fade = true; |
| 199 |
} |
| 200 |
if (config_setting_lookup_bool(setting, "focus", &ival)) { |
| 201 |
o->focus = ival; |
| 202 |
mask->focus = true; |
| 203 |
} |
| 204 |
if (config_setting_lookup_bool(setting, "blur-background", &ival)) { |
| 205 |
o->blur_background = ival; |
| 206 |
mask->blur_background = true; |
| 207 |
} |
| 208 |
if (config_setting_lookup_bool(setting, "full-shadow", &ival)) { |
| 209 |
o->full_shadow = ival; |
| 210 |
mask->full_shadow = true; |
| 211 |
} |
| 212 |
if (config_setting_lookup_bool(setting, "redir-ignore", &ival)) { |
| 213 |
o->redir_ignore = ival; |
| 214 |
mask->redir_ignore = true; |
| 215 |
} |
| 216 |
if (config_setting_lookup_bool(setting, "clip-shadow-above", &ival)) { |
| 217 |
o->clip_shadow_above = ival; |
| 218 |
mask->clip_shadow_above = true; |
| 219 |
} |
| 220 |
|
| 221 |
double fval; |
| 222 |
if (config_setting_lookup_float(setting, "opacity", &fval)) { |
| 223 |
o->opacity = normalize_d(fval); |
| 224 |
mask->opacity = true; |
| 225 |
} |
| 226 |
} |
| 227 |
} |
| 228 |
|
| 229 |
enum animation_trigger parse_animation_trigger(const char *trigger) { |
| 230 |
for (unsigned i = 0; i < ARR_SIZE(animation_trigger_names); i++) { |
| 231 |
if (animation_trigger_names[i] != NULL && |
| 232 |
strcasecmp(trigger, animation_trigger_names[i]) == 0) { |
| 233 |
return i; |
| 234 |
} |
| 235 |
} |
| 236 |
return ANIMATION_TRIGGER_INVALID; |
| 237 |
} |
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
static bool |
| 242 |
compile_win_script(struct win_script *result, config_setting_t *setting, char **err) { |
| 243 |
if (config_setting_lookup(setting, "preset")) { |
| 244 |
return win_script_parse_preset(result, setting); |
| 245 |
} |
| 246 |
|
| 247 |
struct script_output_info outputs[ARR_SIZE(win_script_outputs)]; |
| 248 |
memcpy(outputs, win_script_outputs, sizeof(win_script_outputs)); |
| 249 |
|
| 250 |
struct script_parse_config parse_config = { |
| 251 |
.context_info = win_script_context_info, |
| 252 |
.output_info = outputs, |
| 253 |
}; |
| 254 |
result->script = script_compile(setting, parse_config, err); |
| 255 |
if (result->script == NULL) { |
| 256 |
return false; |
| 257 |
} |
| 258 |
for (int i = 0; i < NUM_OF_WIN_SCRIPT_OUTPUTS; i++) { |
| 259 |
result->output_indices[i] = outputs[i].slot; |
| 260 |
} |
| 261 |
return true; |
| 262 |
} |
| 263 |
|
| 264 |
|
| 265 |
static int next_bit(uint64_t *bitflags) { |
| 266 |
if (!*bitflags) { |
| 267 |
return -1; |
| 268 |
} |
| 269 |
auto lowbit = *bitflags & (~*bitflags + 1); |
| 270 |
#if defined(__has_builtin) && __has_builtin(__builtin_ctzll) |
| 271 |
int ret = __builtin_ctzll(lowbit); |
| 272 |
#else |
| 273 |
int ret = 63; |
| 274 |
if (lowbit & 0x00000000FFFFFFFF) { |
| 275 |
ret -= 32; |
| 276 |
} |
| 277 |
if (lowbit & 0x0000FFFF0000FFFF) { |
| 278 |
ret -= 16; |
| 279 |
} |
| 280 |
if (lowbit & 0x00FF00FF00FF00FF) { |
| 281 |
ret -= 8; |
| 282 |
} |
| 283 |
if (lowbit & 0x0F0F0F0F0F0F0F0F) { |
| 284 |
ret -= 4; |
| 285 |
} |
| 286 |
if (lowbit & 0x3333333333333333) { |
| 287 |
ret -= 2; |
| 288 |
} |
| 289 |
if (lowbit & 0x5555555555555555) { |
| 290 |
ret -= 1; |
| 291 |
} |
| 292 |
#endif |
| 293 |
*bitflags -= lowbit; |
| 294 |
return ret; |
| 295 |
} |
| 296 |
|
| 297 |
static bool set_animation(struct win_script *animations, uint64_t triggers, |
| 298 |
struct win_script animation, unsigned line) { |
| 299 |
bool needed = false; |
| 300 |
while (triggers != 0) { |
| 301 |
int trigger = next_bit(&triggers); |
| 302 |
if (trigger >= ANIMATION_TRIGGER_INVALID) { |
| 303 |
break; |
| 304 |
} |
| 305 |
if (animations[trigger].script != NULL) { |
| 306 |
log_error("Duplicate animation defined for trigger %s at line " |
| 307 |
"%d, it will be ignored.", |
| 308 |
animation_trigger_names[trigger], line); |
| 309 |
continue; |
| 310 |
} |
| 311 |
animations[trigger] = animation; |
| 312 |
needed = true; |
| 313 |
} |
| 314 |
return needed; |
| 315 |
} |
| 316 |
|
| 317 |
static bool parse_animation_one(struct win_script *animations, |
| 318 |
struct script ***all_scripts, config_setting_t *setting) { |
| 319 |
struct win_script result = {}; |
| 320 |
auto triggers = config_setting_lookup(setting, "triggers"); |
| 321 |
if (!triggers) { |
| 322 |
log_error("Missing triggers in animation script, at line %d", |
| 323 |
config_setting_source_line(setting)); |
| 324 |
return false; |
| 325 |
} |
| 326 |
if (!config_setting_is_list(triggers) && !config_setting_is_array(triggers) && |
| 327 |
config_setting_get_string(triggers) == NULL) { |
| 328 |
log_error("The \"triggers\" option must either be a string, a list, or " |
| 329 |
"an array, but is none of those at line %d", |
| 330 |
config_setting_source_line(triggers)); |
| 331 |
return false; |
| 332 |
} |
| 333 |
auto number_of_triggers = |
| 334 |
config_setting_get_string(triggers) == NULL ? config_setting_length(triggers) : 1; |
| 335 |
if (number_of_triggers > ANIMATION_TRIGGER_COUNT) { |
| 336 |
log_error("Too many triggers in animation defined at line %d", |
| 337 |
config_setting_source_line(triggers)); |
| 338 |
return false; |
| 339 |
} |
| 340 |
if (number_of_triggers == 0) { |
| 341 |
log_error("Trigger list is empty in animation defined at line %d", |
| 342 |
config_setting_source_line(triggers)); |
| 343 |
return false; |
| 344 |
} |
| 345 |
uint64_t trigger_types = 0; |
| 346 |
const char *trigger0 = config_setting_get_string(triggers); |
| 347 |
if (trigger0 == NULL) { |
| 348 |
for (int i = 0; i < number_of_triggers; i++) { |
| 349 |
auto trigger_i_str = config_setting_get_string_elem(triggers, i); |
| 350 |
auto trigger_i = trigger_i_str == NULL |
| 351 |
? ANIMATION_TRIGGER_INVALID |
| 352 |
: parse_animation_trigger(trigger_i_str); |
| 353 |
if (trigger_types & (1U << trigger_i)) { |
| 354 |
log_warn("Duplicate trigger \"%s\" set at line %d", |
| 355 |
trigger_i_str, config_setting_source_line(triggers)); |
| 356 |
} |
| 357 |
trigger_types |= 1U << trigger_i; |
| 358 |
} |
| 359 |
} else { |
| 360 |
trigger_types = 1 << parse_animation_trigger(trigger0); |
| 361 |
} |
| 362 |
if ((trigger_types & (1 << ANIMATION_TRIGGER_INVALID)) != 0) { |
| 363 |
log_error("Invalid trigger defined at line %d", |
| 364 |
config_setting_source_line(triggers)); |
| 365 |
} |
| 366 |
if ((trigger_types & (1 << ANIMATION_TRIGGER_ALIAS_GEOMETRY)) != 0) { |
| 367 |
const uint64_t to_set = |
| 368 |
(1 << ANIMATION_TRIGGER_SIZE) | (1 << ANIMATION_TRIGGER_POSITION); |
| 369 |
if ((trigger_types & to_set) != 0) { |
| 370 |
log_warn("Trigger \"geometry\" is an alias of \"size\" and " |
| 371 |
"\"position\", but one or both of them are also set at " |
| 372 |
"line %d", |
| 373 |
config_setting_source_line(triggers)); |
| 374 |
} |
| 375 |
trigger_types |= to_set; |
| 376 |
} |
| 377 |
|
| 378 |
|
| 379 |
config_setting_remove(setting, "triggers"); |
| 380 |
|
| 381 |
auto suppressions_setting = config_setting_lookup(setting, "suppressions"); |
| 382 |
if (suppressions_setting != NULL) { |
| 383 |
auto single_suppression = config_setting_get_string(suppressions_setting); |
| 384 |
if (!config_setting_is_list(suppressions_setting) && |
| 385 |
!config_setting_is_array(suppressions_setting) && |
| 386 |
single_suppression == NULL) { |
| 387 |
log_error("The \"suppressions\" option must either be a string, " |
| 388 |
"a list, or an array, but is none of those at line %d", |
| 389 |
config_setting_source_line(suppressions_setting)); |
| 390 |
return false; |
| 391 |
} |
| 392 |
if (single_suppression != NULL) { |
| 393 |
auto suppression = parse_animation_trigger(single_suppression); |
| 394 |
if (suppression == ANIMATION_TRIGGER_INVALID) { |
| 395 |
log_error("Invalid suppression defined at line %d", |
| 396 |
config_setting_source_line(suppressions_setting)); |
| 397 |
return false; |
| 398 |
} |
| 399 |
result.suppressions = 1 << suppression; |
| 400 |
} else { |
| 401 |
auto len = config_setting_length(suppressions_setting); |
| 402 |
for (int i = 0; i < len; i++) { |
| 403 |
auto suppression_str = |
| 404 |
config_setting_get_string_elem(suppressions_setting, i); |
| 405 |
if (suppression_str == NULL) { |
| 406 |
log_error( |
| 407 |
"The \"suppressions\" option must only " |
| 408 |
"contain strings, but one of them is not at " |
| 409 |
"line %d", |
| 410 |
config_setting_source_line(suppressions_setting)); |
| 411 |
return false; |
| 412 |
} |
| 413 |
auto suppression = parse_animation_trigger(suppression_str); |
| 414 |
if (suppression == ANIMATION_TRIGGER_INVALID) { |
| 415 |
log_error( |
| 416 |
"Invalid suppression defined at line %d", |
| 417 |
config_setting_source_line(suppressions_setting)); |
| 418 |
return false; |
| 419 |
} |
| 420 |
result.suppressions |= 1U << suppression; |
| 421 |
} |
| 422 |
} |
| 423 |
config_setting_remove(setting, "suppressions"); |
| 424 |
} |
| 425 |
|
| 426 |
if ((result.suppressions & (1 << ANIMATION_TRIGGER_ALIAS_GEOMETRY)) != 0) { |
| 427 |
const uint64_t to_set = |
| 428 |
(1 << ANIMATION_TRIGGER_SIZE) | (1 << ANIMATION_TRIGGER_POSITION); |
| 429 |
if ((result.suppressions & to_set) != 0) { |
| 430 |
log_warn("Trigger \"geometry\" is an alias of \"size\" and " |
| 431 |
"\"position\", but one or both of them are also set at " |
| 432 |
"line %d", |
| 433 |
config_setting_source_line(suppressions_setting)); |
| 434 |
} |
| 435 |
result.suppressions |= to_set; |
| 436 |
} |
| 437 |
result.suppressions &= (1 << ANIMATION_TRIGGER_COUNT) - 1; |
| 438 |
|
| 439 |
char *err; |
| 440 |
if (!compile_win_script(&result, setting, &err)) { |
| 441 |
log_error("Failed to parse animation script at line %d: %s", |
| 442 |
config_setting_source_line(setting), err); |
| 443 |
free(err); |
| 444 |
return false; |
| 445 |
} |
| 446 |
|
| 447 |
bool needed = set_animation(animations, trigger_types, result, |
| 448 |
config_setting_source_line(setting)); |
| 449 |
if (!needed) { |
| 450 |
script_free(result.script); |
| 451 |
} else { |
| 452 |
dynarr_push(*all_scripts, result.script); |
| 453 |
} |
| 454 |
return true; |
| 455 |
} |
| 456 |
|
| 457 |
|
| 458 |
static void parse_animations(struct win_script *animations, config_setting_t *setting, |
| 459 |
struct script ***out_scripts) { |
| 460 |
auto number_of_animations = (unsigned)config_setting_length(setting); |
| 461 |
for (unsigned i = 0; i < number_of_animations; i++) { |
| 462 |
auto sub = config_setting_get_elem(setting, i); |
| 463 |
parse_animation_one(animations, out_scripts, sub); |
| 464 |
} |
| 465 |
} |
| 466 |
|
| 467 |
#define FADING_TEMPLATE_1 \ |
| 468 |
"opacity = { " \ |
| 469 |
" duration = %s; " \ |
| 470 |
" start = \"window-raw-opacity-before\"; " \ |
| 471 |
" end = \"window-raw-opacity\"; " \ |
| 472 |
"};" \ |
| 473 |
"shadow-opacity = \"opacity\";" |
| 474 |
#define FADING_TEMPLATE_2 \ |
| 475 |
"blur-opacity = { " \ |
| 476 |
" duration = %s; " \ |
| 477 |
" start = %s; end = %s; " \ |
| 478 |
"};" |
| 479 |
|
| 480 |
static bool compile_win_script_from_string(struct win_script *result, const char *input) { |
| 481 |
config_t tmp_config; |
| 482 |
config_setting_t *setting; |
| 483 |
config_init(&tmp_config); |
| 484 |
config_set_auto_convert(&tmp_config, true); |
| 485 |
config_read_string(&tmp_config, input); |
| 486 |
setting = config_root_setting(&tmp_config); |
| 487 |
|
| 488 |
|
| 489 |
char *err = NULL; |
| 490 |
bool succeeded = compile_win_script(result, setting, &err); |
| 491 |
config_destroy(&tmp_config); |
| 492 |
BUG_ON(err != NULL); |
| 493 |
|
| 494 |
return succeeded; |
| 495 |
} |
| 496 |
|
| 497 |
void generate_fading_config(struct options *opt) { |
| 498 |
|
| 499 |
|
| 500 |
scoped_charp str = NULL; |
| 501 |
size_t len = 0; |
| 502 |
struct script *scripts[4]; |
| 503 |
unsigned number_of_scripts = 0; |
| 504 |
|
| 505 |
double duration = 1.0 / opt->fade_in_step * opt->fade_delta / 1000.0; |
| 506 |
if (!safe_isinf(duration) && !safe_isnan(duration) && duration > 0) { |
| 507 |
scoped_charp duration_str = NULL; |
| 508 |
uint64_t triggers = 0; |
| 509 |
dtostr(duration, &duration_str); |
| 510 |
|
| 511 |
|
| 512 |
|
| 513 |
|
| 514 |
auto start = opt->blur_background_fixed |
| 515 |
? "\"window-blur-opacity\"" |
| 516 |
: "\"window-blur-opacity-before\""; |
| 517 |
asnprintf(&str, &len, FADING_TEMPLATE_1 FADING_TEMPLATE_2, duration_str, |
| 518 |
duration_str, start, "\"window-blur-opacity\""); |
| 519 |
|
| 520 |
struct win_script fade_in1 = {.is_generated = true}; |
| 521 |
BUG_ON(!compile_win_script_from_string(&fade_in1, str)); |
| 522 |
if (opt->animations[ANIMATION_TRIGGER_OPEN].script == NULL && |
| 523 |
!opt->no_fading_openclose) { |
| 524 |
triggers |= 1 << ANIMATION_TRIGGER_OPEN; |
| 525 |
} |
| 526 |
if (opt->animations[ANIMATION_TRIGGER_SHOW].script == NULL) { |
| 527 |
triggers |= 1 << ANIMATION_TRIGGER_SHOW; |
| 528 |
} |
| 529 |
if (set_animation(opt->animations, triggers, fade_in1, 0)) { |
| 530 |
scripts[number_of_scripts++] = fade_in1.script; |
| 531 |
} else { |
| 532 |
script_free(fade_in1.script); |
| 533 |
} |
| 534 |
|
| 535 |
|
| 536 |
asnprintf(&str, &len, FADING_TEMPLATE_1 FADING_TEMPLATE_2, duration_str, |
| 537 |
duration_str, "\"window-blur-opacity-before\"", |
| 538 |
"\"window-blur-opacity\""); |
| 539 |
struct win_script fade_in2 = {.is_generated = true}; |
| 540 |
BUG_ON(!compile_win_script_from_string(&fade_in2, str)); |
| 541 |
triggers = 0; |
| 542 |
if (opt->animations[ANIMATION_TRIGGER_INCREASE_OPACITY].script == NULL) { |
| 543 |
triggers |= 1 << ANIMATION_TRIGGER_INCREASE_OPACITY; |
| 544 |
} |
| 545 |
if (set_animation(opt->animations, triggers, fade_in2, 0)) { |
| 546 |
scripts[number_of_scripts++] = fade_in2.script; |
| 547 |
} else { |
| 548 |
script_free(fade_in2.script); |
| 549 |
} |
| 550 |
} else { |
| 551 |
log_error("Invalid fade-in setting (step: %f, delta: %d), ignoring.", |
| 552 |
opt->fade_in_step, opt->fade_delta); |
| 553 |
} |
| 554 |
|
| 555 |
duration = 1.0 / opt->fade_out_step * opt->fade_delta / 1000.0; |
| 556 |
if (!safe_isinf(duration) && !safe_isnan(duration) && duration > 0) { |
| 557 |
scoped_charp duration_str = NULL; |
| 558 |
uint64_t triggers = 0; |
| 559 |
dtostr(duration, &duration_str); |
| 560 |
|
| 561 |
|
| 562 |
auto end = opt->blur_background_fixed ? "\"window-blur-opacity-before\"" |
| 563 |
: "\"window-blur-opacity\""; |
| 564 |
asnprintf(&str, &len, FADING_TEMPLATE_1 FADING_TEMPLATE_2, duration_str, |
| 565 |
duration_str, "\"window-blur-opacity-before\"", end); |
| 566 |
struct win_script fade_out1 = {.is_generated = true}; |
| 567 |
BUG_ON(!compile_win_script_from_string(&fade_out1, str)); |
| 568 |
if (opt->animations[ANIMATION_TRIGGER_CLOSE].script == NULL && |
| 569 |
!opt->no_fading_openclose) { |
| 570 |
triggers |= 1 << ANIMATION_TRIGGER_CLOSE; |
| 571 |
} |
| 572 |
if (opt->animations[ANIMATION_TRIGGER_HIDE].script == NULL) { |
| 573 |
triggers |= 1 << ANIMATION_TRIGGER_HIDE; |
| 574 |
} |
| 575 |
if (set_animation(opt->animations, triggers, fade_out1, 0)) { |
| 576 |
scripts[number_of_scripts++] = fade_out1.script; |
| 577 |
} else { |
| 578 |
script_free(fade_out1.script); |
| 579 |
} |
| 580 |
|
| 581 |
|
| 582 |
asnprintf(&str, &len, FADING_TEMPLATE_1 FADING_TEMPLATE_2, duration_str, |
| 583 |
duration_str, "\"window-blur-opacity-before\"", |
| 584 |
"\"window-blur-opacity\""); |
| 585 |
struct win_script fade_out2 = {.is_generated = true}; |
| 586 |
BUG_ON(!compile_win_script_from_string(&fade_out2, str)); |
| 587 |
triggers = 0; |
| 588 |
if (opt->animations[ANIMATION_TRIGGER_DECREASE_OPACITY].script == NULL) { |
| 589 |
triggers = 1 << ANIMATION_TRIGGER_DECREASE_OPACITY; |
| 590 |
} |
| 591 |
if (set_animation(opt->animations, triggers, fade_out2, 0)) { |
| 592 |
scripts[number_of_scripts++] = fade_out2.script; |
| 593 |
} else { |
| 594 |
script_free(fade_out2.script); |
| 595 |
} |
| 596 |
} else { |
| 597 |
log_error("Invalid fade-out setting (step: %f, delta: %d), ignoring.", |
| 598 |
opt->fade_out_step, opt->fade_delta); |
| 599 |
} |
| 600 |
|
| 601 |
log_debug("Generated %d scripts for fading.", number_of_scripts); |
| 602 |
dynarr_extend_from(opt->all_scripts, scripts, number_of_scripts); |
| 603 |
} |
| 604 |
|
| 605 |
static enum window_unredir_option parse_unredir_option(config_setting_t *setting) { |
| 606 |
if (config_setting_type(setting) == CONFIG_TYPE_BOOL) { |
| 607 |
auto bval = config_setting_get_bool(setting); |
| 608 |
return bval ? WINDOW_UNREDIR_WHEN_POSSIBLE_ELSE_TERMINATE |
| 609 |
: WINDOW_UNREDIR_TERMINATE; |
| 610 |
} |
| 611 |
const char *sval = config_setting_get_string(setting); |
| 612 |
if (!sval) { |
| 613 |
log_error("Invalid value for \"unredir\" at line %d. It must be a " |
| 614 |
"boolean or a string.", |
| 615 |
config_setting_source_line(setting)); |
| 616 |
return WINDOW_UNREDIR_INVALID; |
| 617 |
} |
| 618 |
if (strcmp(sval, "yes") == 0 || strcmp(sval, "true") == 0 || |
| 619 |
strcmp(sval, "default") == 0 || strcmp(sval, "when-possible-else-terminate") == 0) { |
| 620 |
return WINDOW_UNREDIR_WHEN_POSSIBLE_ELSE_TERMINATE; |
| 621 |
} |
| 622 |
if (strcmp(sval, "preferred") == 0 || strcmp(sval, "when-possible") == 0) { |
| 623 |
return WINDOW_UNREDIR_WHEN_POSSIBLE; |
| 624 |
} |
| 625 |
if (strcmp(sval, "no") == 0 || strcmp(sval, "false") == 0 || |
| 626 |
strcmp(sval, "terminate") == 0) { |
| 627 |
return WINDOW_UNREDIR_TERMINATE; |
| 628 |
} |
| 629 |
if (strcmp(sval, "passive") == 0) { |
| 630 |
return WINDOW_UNREDIR_PASSIVE; |
| 631 |
} |
| 632 |
if (strcmp(sval, "forced") == 0) { |
| 633 |
return WINDOW_UNREDIR_FORCED; |
| 634 |
} |
| 635 |
log_error("Invalid string value for \"unredir\" at line %d. It must be one of " |
| 636 |
"\"preferred\", \"passive\", or \"force\". Got \"%s\".", |
| 637 |
config_setting_source_line(setting), sval); |
| 638 |
return WINDOW_UNREDIR_INVALID; |
| 639 |
} |
| 640 |
|
| 641 |
static const struct { |
| 642 |
const char *name; |
| 643 |
ptrdiff_t offset; |
| 644 |
} all_window_options[] = { |
| 645 |
{"fade", offsetof(struct window_maybe_options, fade)}, |
| 646 |
{"paint", offsetof(struct window_maybe_options, paint)}, |
| 647 |
{"shadow", offsetof(struct window_maybe_options, shadow)}, |
| 648 |
{"full-shadow", offsetof(struct window_maybe_options, full_shadow)}, |
| 649 |
{"invert-color", offsetof(struct window_maybe_options, invert_color)}, |
| 650 |
{"blur-background", offsetof(struct window_maybe_options, blur_background)}, |
| 651 |
{"clip-shadow-above", offsetof(struct window_maybe_options, clip_shadow_above)}, |
| 652 |
{"transparent-clipping", offsetof(struct window_maybe_options, transparent_clipping)}, |
| 653 |
}; |
| 654 |
|
| 655 |
static struct shader_specification * |
| 656 |
parse_shader_specification(config_setting_t *setting, const char *include_dir) { |
| 657 |
const char *path = config_setting_get_string(setting); |
| 658 |
config_setting_t *defines = NULL; |
| 659 |
unsigned n = 0; |
| 660 |
if (!path) { |
| 661 |
if (!config_setting_is_group(setting)) { |
| 662 |
log_error("shader specification at line %d is neither a string " |
| 663 |
"nor a group.", |
| 664 |
config_setting_source_line(setting)); |
| 665 |
return NULL; |
| 666 |
} |
| 667 |
|
| 668 |
if (!config_setting_lookup_string(setting, "path", &path)) { |
| 669 |
log_error("shader specification at line %d does not have a path.", |
| 670 |
config_setting_source_line(setting)); |
| 671 |
return NULL; |
| 672 |
} |
| 673 |
|
| 674 |
defines = config_setting_lookup(setting, "defines"); |
| 675 |
n = defines ? (unsigned)config_setting_length(defines) : 0; |
| 676 |
} |
| 677 |
|
| 678 |
char *full_path = locate_auxiliary_file("shader", path, include_dir); |
| 679 |
if (!full_path) { |
| 680 |
log_error("Couldn't find custom shader file with name \"%s\"", path); |
| 681 |
return NULL; |
| 682 |
} |
| 683 |
|
| 684 |
auto len = strlen(full_path) + 1; |
| 685 |
for (unsigned i = 0; i < n; i++) { |
| 686 |
auto elem = config_setting_get_elem(defines, i); |
| 687 |
auto value = config_setting_get_string(elem); |
| 688 |
if (value == NULL) { |
| 689 |
log_error("shader define at line %d is not a string.", |
| 690 |
config_setting_source_line(elem)); |
| 691 |
return NULL; |
| 692 |
} |
| 693 |
len += strlen(config_setting_name(elem)) + 1; |
| 694 |
len += strlen(value) + 1; |
| 695 |
} |
| 696 |
|
| 697 |
struct shader_specification *ret = |
| 698 |
calloc(1, offsetof(struct shader_specification, data[len])); |
| 699 |
BUG_ON(ret == NULL); |
| 700 |
ret->size = len; |
| 701 |
strcpy(ret->data, full_path); |
| 702 |
|
| 703 |
auto pos = strlen(full_path) + 1; |
| 704 |
free(full_path); |
| 705 |
for (unsigned i = 0; i < n; i++) { |
| 706 |
auto elem = config_setting_get_elem(defines, i); |
| 707 |
auto value = config_setting_get_string(elem); |
| 708 |
|
| 709 |
strcpy(ret->data + pos, config_setting_name(elem)); |
| 710 |
pos += strlen(ret->data + pos) + 1; |
| 711 |
strcpy(ret->data + pos, value); |
| 712 |
pos += strlen(ret->data + pos) + 1; |
| 713 |
} |
| 714 |
|
| 715 |
return ret; |
| 716 |
} |
| 717 |
|
| 718 |
static bool |
| 719 |
parse_rule(struct list_node *rules, config_setting_t *setting, const char *include_dir, |
| 720 |
struct script ***out_scripts, bool *deprecated) { |
| 721 |
if (!config_setting_is_group(setting)) { |
| 722 |
log_error("Invalid rule at line %d. It must be a group.", |
| 723 |
config_setting_source_line(setting)); |
| 724 |
return false; |
| 725 |
} |
| 726 |
int ival; |
| 727 |
double fval; |
| 728 |
const char *sval; |
| 729 |
c2_condition *rule = NULL; |
| 730 |
if (config_setting_lookup_string(setting, "match", &sval)) { |
| 731 |
rule = c2_parse(rules, sval, NULL, deprecated); |
| 732 |
if (!rule) { |
| 733 |
log_error("Failed to parse rule at line %d.", |
| 734 |
config_setting_source_line(setting)); |
| 735 |
return false; |
| 736 |
} |
| 737 |
} else { |
| 738 |
|
| 739 |
rule = c2_new_true(rules); |
| 740 |
} |
| 741 |
|
| 742 |
auto wopts = cmalloc(struct window_maybe_options); |
| 743 |
*wopts = WIN_MAYBE_OPTIONS_DEFAULT; |
| 744 |
c2_condition_set_data(rule, wopts); |
| 745 |
|
| 746 |
for (size_t i = 0; i < ARR_SIZE(all_window_options); i++) { |
| 747 |
if (config_setting_lookup_bool(setting, all_window_options[i].name, &ival)) { |
| 748 |
void *ptr = (char *)wopts + all_window_options[i].offset; |
| 749 |
*(enum tristate *)ptr = tri_from_bool(ival); |
| 750 |
} |
| 751 |
} |
| 752 |
if (config_setting_lookup_float(setting, "opacity", &fval)) { |
| 753 |
wopts->opacity = normalize_d(fval); |
| 754 |
} |
| 755 |
if (config_setting_lookup_float(setting, "blur-opacity", &fval)) { |
| 756 |
wopts->blur_opacity = normalize_d(fval); |
| 757 |
} |
| 758 |
if (config_setting_lookup_float(setting, "dim", &fval)) { |
| 759 |
wopts->dim = normalize_d(fval); |
| 760 |
} |
| 761 |
if (config_setting_lookup_int(setting, "corner-radius", &ival)) { |
| 762 |
wopts->corner_radius = ival; |
| 763 |
} |
| 764 |
if (config_setting_lookup_string(setting, "shadow-color", &sval)) { |
| 765 |
wopts->is_shadow_color_set = true; |
| 766 |
wopts->shadow_color = hex_to_rgb(sval); |
| 767 |
wopts->shadow_color.alpha = 1.0; |
| 768 |
} |
| 769 |
|
| 770 |
auto unredir_setting = config_setting_lookup(setting, "unredir"); |
| 771 |
if (unredir_setting) { |
| 772 |
wopts->unredir = parse_unredir_option(unredir_setting); |
| 773 |
} |
| 774 |
|
| 775 |
auto animations = config_setting_lookup(setting, "animations"); |
| 776 |
if (animations) { |
| 777 |
parse_animations(wopts->animations, animations, out_scripts); |
| 778 |
} |
| 779 |
|
| 780 |
auto shader_setting = config_setting_lookup(setting, "shader"); |
| 781 |
if (shader_setting) { |
| 782 |
wopts->shader = parse_shader_specification(shader_setting, include_dir); |
| 783 |
if (!wopts->shader) { |
| 784 |
c2_condition_set_data(rule, NULL); |
| 785 |
free(wopts); |
| 786 |
return false; |
| 787 |
} |
| 788 |
} |
| 789 |
return true; |
| 790 |
} |
| 791 |
|
| 792 |
static bool |
| 793 |
parse_rules(struct list_node *rules, config_setting_t *setting, const char *include_dir, |
| 794 |
struct script ***out_scripts, bool *deprecated) { |
| 795 |
if (!config_setting_is_list(setting)) { |
| 796 |
log_error("Invalid value for \"rules\" at line %d. It must be a list.", |
| 797 |
config_setting_source_line(setting)); |
| 798 |
return false; |
| 799 |
} |
| 800 |
const auto length = (unsigned int)config_setting_length(setting); |
| 801 |
for (unsigned int i = 0; i < length; i++) { |
| 802 |
auto sub = config_setting_get_elem(setting, i); |
| 803 |
if (!parse_rule(rules, sub, include_dir, out_scripts, deprecated)) { |
| 804 |
return false; |
| 805 |
} |
| 806 |
} |
| 807 |
return true; |
| 808 |
} |
| 809 |
|
| 810 |
static const char ** |
| 811 |
resolve_include(config_t *cfg, const char *include_dir, const char *path, const char **err) { |
| 812 |
char *result = locate_auxiliary_file("include", path, include_dir); |
| 813 |
if (result == NULL) { |
| 814 |
*err = "Failed to locate included file"; |
| 815 |
return NULL; |
| 816 |
} |
| 817 |
|
| 818 |
struct options *opt = config_get_hook(cfg); |
| 819 |
auto included = ccalloc(1, struct included_config_file); |
| 820 |
included->path = strdup(result); |
| 821 |
list_insert_after(&opt->included_config_files, &included->siblings); |
| 822 |
|
| 823 |
log_debug("Resolved include file \"%s\" to \"%s\"", path, result); |
| 824 |
const char **ret = ccalloc(2, const char *); |
| 825 |
ret[0] = result; |
| 826 |
ret[1] = NULL; |
| 827 |
return ret; |
| 828 |
} |
| 829 |
|
| 830 |
bool parse_config_libconfig(options_t *opt, const char *config_file) { |
| 831 |
char *path = NULL; |
| 832 |
FILE *f; |
| 833 |
config_t cfg; |
| 834 |
int ival = 0; |
| 835 |
bool bval; |
| 836 |
double dval = 0.0; |
| 837 |
|
| 838 |
|
| 839 |
const char *sval = NULL; |
| 840 |
config_setting_t *subcfg; |
| 841 |
bool succeeded = false; |
| 842 |
|
| 843 |
f = open_config_file(config_file, &path); |
| 844 |
if (!f) { |
| 845 |
free(path); |
| 846 |
if (config_file) { |
| 847 |
log_fatal("Failed to read configuration file \"%s\".", config_file); |
| 848 |
return false; |
| 849 |
} |
| 850 |
|
| 851 |
return true; |
| 852 |
} |
| 853 |
|
| 854 |
config_init(&cfg); |
| 855 |
#ifdef CONFIG_OPTION_ALLOW_OVERRIDES |
| 856 |
config_set_options(&cfg, CONFIG_OPTION_ALLOW_OVERRIDES); |
| 857 |
#endif |
| 858 |
{ |
| 859 |
char *abspath = realpath(path, NULL); |
| 860 |
char *parent = dirname(abspath); |
| 861 |
|
| 862 |
if (parent) { |
| 863 |
config_set_include_dir(&cfg, parent); |
| 864 |
} |
| 865 |
config_set_include_func(&cfg, resolve_include); |
| 866 |
config_set_hook(&cfg, opt); |
| 867 |
|
| 868 |
free(abspath); |
| 869 |
} |
| 870 |
|
| 871 |
{ |
| 872 |
int read_result = config_read(&cfg, f); |
| 873 |
fclose(f); |
| 874 |
f = NULL; |
| 875 |
if (read_result == CONFIG_FALSE) { |
| 876 |
log_fatal("Error when reading configuration file \"%s\", line " |
| 877 |
"%d: %s", |
| 878 |
path, config_error_line(&cfg), config_error_text(&cfg)); |
| 879 |
goto out; |
| 880 |
} |
| 881 |
} |
| 882 |
config_set_auto_convert(&cfg, 1); |
| 883 |
|
| 884 |
|
| 885 |
if (config_lookup_string(&cfg, "log-level", &sval)) { |
| 886 |
opt->log_level = string_to_log_level(sval); |
| 887 |
if (opt->log_level == LOG_LEVEL_INVALID) { |
| 888 |
log_warn("Invalid log level, defaults to WARN"); |
| 889 |
record_problematic_option(opt, "log-level"); |
| 890 |
} else { |
| 891 |
log_set_level_tls(opt->log_level); |
| 892 |
} |
| 893 |
} |
| 894 |
|
| 895 |
|
| 896 |
|
| 897 |
|
| 898 |
|
| 899 |
|
| 900 |
auto plugins = config_lookup(&cfg, "plugins"); |
| 901 |
if (plugins != NULL) { |
| 902 |
sval = config_setting_get_string(plugins); |
| 903 |
if (sval) { |
| 904 |
if (!load_plugin(sval, NULL)) { |
| 905 |
log_fatal("Failed to load plugin \"%s\".", sval); |
| 906 |
goto out; |
| 907 |
} |
| 908 |
} else if (config_setting_is_array(plugins) || config_setting_is_list(plugins)) { |
| 909 |
for (int i = 0; i < config_setting_length(plugins); i++) { |
| 910 |
sval = config_setting_get_string_elem(plugins, i); |
| 911 |
if (!sval) { |
| 912 |
log_fatal("Invalid value for \"plugins\" at line " |
| 913 |
"%d.", |
| 914 |
config_setting_source_line(plugins)); |
| 915 |
goto out; |
| 916 |
} |
| 917 |
if (!load_plugin(sval, NULL)) { |
| 918 |
log_fatal("Failed to load plugin \"%s\".", sval); |
| 919 |
goto out; |
| 920 |
} |
| 921 |
} |
| 922 |
} else { |
| 923 |
log_fatal("Invalid value for \"plugins\" at line %d.", |
| 924 |
config_setting_source_line(plugins)); |
| 925 |
goto out; |
| 926 |
} |
| 927 |
} |
| 928 |
|
| 929 |
config_setting_t *rules = config_lookup(&cfg, "rules"); |
| 930 |
if (rules) { |
| 931 |
bool deprecated = false; |
| 932 |
if (!parse_rules(&opt->rules, rules, config_get_include_dir(&cfg), |
| 933 |
&opt->all_scripts, &deprecated)) { |
| 934 |
log_fatal("Couldn't parse window rules at line %d.", |
| 935 |
config_setting_source_line(rules)); |
| 936 |
goto out; |
| 937 |
} |
| 938 |
if (deprecated) { |
| 939 |
report_deprecated_option(opt, "rules", false); |
| 940 |
} |
| 941 |
} |
| 942 |
|
| 943 |
|
| 944 |
lcfg_lookup_bool(&cfg, "dbus", &opt->dbus); |
| 945 |
|
| 946 |
|
| 947 |
if (config_lookup_int(&cfg, "fade-delta", &ival)) { |
| 948 |
opt->fade_delta = ival; |
| 949 |
} |
| 950 |
|
| 951 |
if (config_lookup_float(&cfg, "fade-in-step", &dval)) { |
| 952 |
opt->fade_in_step = normalize_d(dval); |
| 953 |
} |
| 954 |
|
| 955 |
if (config_lookup_float(&cfg, "fade-out-step", &dval)) { |
| 956 |
opt->fade_out_step = normalize_d(dval); |
| 957 |
} |
| 958 |
|
| 959 |
config_lookup_int(&cfg, "shadow-radius", &opt->shadow_radius); |
| 960 |
|
| 961 |
config_lookup_float(&cfg, "shadow-opacity", &opt->shadow_opacity); |
| 962 |
|
| 963 |
config_lookup_int(&cfg, "shadow-offset-x", &opt->shadow_offset_x); |
| 964 |
|
| 965 |
config_lookup_int(&cfg, "shadow-offset-y", &opt->shadow_offset_y); |
| 966 |
|
| 967 |
if (config_lookup_float(&cfg, "inactive-opacity", &dval)) { |
| 968 |
opt->inactive_opacity = normalize_d(dval); |
| 969 |
if (!list_is_empty(&opt->rules)) { |
| 970 |
log_warn_both_style_of_rules(opt, "inactive-opacity"); |
| 971 |
} |
| 972 |
} |
| 973 |
|
| 974 |
if (config_lookup_float(&cfg, "active-opacity", &dval)) { |
| 975 |
opt->active_opacity = normalize_d(dval); |
| 976 |
if (!list_is_empty(&opt->rules)) { |
| 977 |
log_warn_both_style_of_rules(opt, "active-opacity"); |
| 978 |
} |
| 979 |
} |
| 980 |
|
| 981 |
config_lookup_int(&cfg, "corner-radius", &opt->corner_radius); |
| 982 |
|
| 983 |
if (lcfg_lookup_bool(&cfg, "no-frame-pacing", &bval)) { |
| 984 |
opt->frame_pacing = !bval; |
| 985 |
} |
| 986 |
|
| 987 |
|
| 988 |
config_lookup_float(&cfg, "frame-opacity", &opt->frame_opacity); |
| 989 |
|
| 990 |
lcfg_lookup_bool(&cfg, "shadow", &opt->shadow_enable); |
| 991 |
|
| 992 |
if (config_lookup_bool(&cfg, "fading", &ival)) { |
| 993 |
opt->fading_enable = ival; |
| 994 |
} |
| 995 |
|
| 996 |
lcfg_lookup_bool(&cfg, "no-fading-openclose", &opt->no_fading_openclose); |
| 997 |
|
| 998 |
lcfg_lookup_bool(&cfg, "no-fading-destroyed-argb", &opt->no_fading_destroyed_argb); |
| 999 |
|
| 1000 |
config_lookup_float(&cfg, "shadow-red", &opt->shadow_red); |
| 1001 |
|
| 1002 |
config_lookup_float(&cfg, "shadow-green", &opt->shadow_green); |
| 1003 |
|
| 1004 |
config_lookup_float(&cfg, "shadow-blue", &opt->shadow_blue); |
| 1005 |
|
| 1006 |
if (config_lookup_string(&cfg, "shadow-color", &sval)) { |
| 1007 |
struct color rgb; |
| 1008 |
rgb = hex_to_rgb(sval); |
| 1009 |
opt->shadow_red = rgb.red; |
| 1010 |
opt->shadow_green = rgb.green; |
| 1011 |
opt->shadow_blue = rgb.blue; |
| 1012 |
} |
| 1013 |
|
| 1014 |
if (config_lookup_string(&cfg, "shadow-exclude-reg", &sval)) { |
| 1015 |
log_error("shadow-exclude-reg is deprecated. Please use " |
| 1016 |
"clip-shadow-above for more flexible shadow exclusion."); |
| 1017 |
goto out; |
| 1018 |
} |
| 1019 |
|
| 1020 |
if (lcfg_lookup_bool(&cfg, "inactive-opacity-override", &opt->inactive_opacity_override) && |
| 1021 |
!list_is_empty(&opt->rules)) { |
| 1022 |
log_warn_both_style_of_rules(opt, "inactive-opacity-override"); |
| 1023 |
} |
| 1024 |
|
| 1025 |
if (config_lookup_float(&cfg, "inactive-dim", &opt->inactive_dim) && |
| 1026 |
!list_is_empty(&opt->rules)) { |
| 1027 |
log_warn_both_style_of_rules(opt, "inactive-dim"); |
| 1028 |
} |
| 1029 |
|
| 1030 |
if (lcfg_lookup_bool(&cfg, "mark-wmwin-focused", &opt->mark_wmwin_focused) && |
| 1031 |
!list_is_empty(&opt->rules)) { |
| 1032 |
log_warn_both_style_of_rules(opt, "mark-wmwin-focused"); |
| 1033 |
} |
| 1034 |
|
| 1035 |
if (lcfg_lookup_bool(&cfg, "mark-ovredir-focused", &opt->mark_ovredir_focused) && |
| 1036 |
!list_is_empty(&opt->rules)) { |
| 1037 |
log_warn_both_style_of_rules(opt, "mark-ovredir-focused"); |
| 1038 |
} |
| 1039 |
|
| 1040 |
if (lcfg_lookup_bool(&cfg, "shadow-ignore-shaped", &opt->shadow_ignore_shaped) && |
| 1041 |
!list_is_empty(&opt->rules)) { |
| 1042 |
log_warn_both_style_of_rules(opt, "shadow-ignore-shaped"); |
| 1043 |
} |
| 1044 |
|
| 1045 |
lcfg_lookup_bool(&cfg, "detect-rounded-corners", &opt->detect_rounded_corners); |
| 1046 |
|
| 1047 |
if (lcfg_lookup_bool(&cfg, "xinerama-shadow-crop", &opt->crop_shadow_to_monitor)) { |
| 1048 |
log_warn("xinerama-shadow-crop is deprecated. Use crop-shadow-to-monitor " |
| 1049 |
"instead."); |
| 1050 |
record_problematic_option(opt, "xinerama-shadow-crop"); |
| 1051 |
} |
| 1052 |
lcfg_lookup_bool(&cfg, "crop-shadow-to-monitor", &opt->crop_shadow_to_monitor); |
| 1053 |
|
| 1054 |
lcfg_lookup_bool(&cfg, "detect-client-opacity", &opt->detect_client_opacity); |
| 1055 |
|
| 1056 |
if (config_lookup_int(&cfg, "refresh-rate", &ival)) { |
| 1057 |
report_deprecated_option(opt, "refresh-rate", false); |
| 1058 |
} |
| 1059 |
|
| 1060 |
if (config_lookup_string(&cfg, "vsync", &sval)) { |
| 1061 |
bool parsed_vsync = parse_vsync(sval); |
| 1062 |
log_error("vsync option will take a boolean from now on. \"%s\" in " |
| 1063 |
"your configuration should be changed to \"%s\"", |
| 1064 |
sval, parsed_vsync ? "true" : "false"); |
| 1065 |
goto out; |
| 1066 |
} |
| 1067 |
lcfg_lookup_bool(&cfg, "vsync", &opt->vsync); |
| 1068 |
|
| 1069 |
if (config_lookup_string(&cfg, "backend", &sval)) { |
| 1070 |
opt->backend = backend_find(sval); |
| 1071 |
if (opt->backend == NULL) { |
| 1072 |
log_fatal("Invalid backend: %s", sval); |
| 1073 |
goto out; |
| 1074 |
} |
| 1075 |
} |
| 1076 |
|
| 1077 |
if (config_lookup_string(&cfg, "log-file", &sval)) { |
| 1078 |
if (*sval != '/') { |
| 1079 |
log_warn("The log-file in your configuration file is not an " |
| 1080 |
"absolute path"); |
| 1081 |
record_problematic_option(opt, "log-file"); |
| 1082 |
} |
| 1083 |
opt->logpath = strdup(sval); |
| 1084 |
} |
| 1085 |
|
| 1086 |
lcfg_lookup_bool(&cfg, "use-ewmh-active-win", &opt->use_ewmh_active_win); |
| 1087 |
|
| 1088 |
lcfg_lookup_bool(&cfg, "unredir-if-possible", &opt->unredir_if_possible); |
| 1089 |
|
| 1090 |
if (config_lookup_int(&cfg, "unredir-if-possible-delay", &ival)) { |
| 1091 |
if (ival < 0) { |
| 1092 |
log_warn("Invalid unredir-if-possible-delay %d", ival); |
| 1093 |
record_problematic_option(opt, "unredir-if-possible-delay"); |
| 1094 |
} else { |
| 1095 |
opt->unredir_if_possible_delay = ival; |
| 1096 |
} |
| 1097 |
} |
| 1098 |
|
| 1099 |
lcfg_lookup_bool(&cfg, "inactive-dim-fixed", &opt->inactive_dim_fixed); |
| 1100 |
|
| 1101 |
lcfg_lookup_bool(&cfg, "detect-transient", &opt->detect_transient); |
| 1102 |
|
| 1103 |
lcfg_lookup_bool(&cfg, "detect-client-leader", &opt->detect_client_leader); |
| 1104 |
|
| 1105 |
lcfg_lookup_bool(&cfg, "no-ewmh-fullscreen", &opt->no_ewmh_fullscreen); |
| 1106 |
|
| 1107 |
lcfg_lookup_bool(&cfg, "transparent-clipping", &opt->transparent_clipping); |
| 1108 |
|
| 1109 |
lcfg_lookup_bool(&cfg, "dithered-present", &opt->dithered_present); |
| 1110 |
const struct { |
| 1111 |
const char *name; |
| 1112 |
ptrdiff_t offset; |
| 1113 |
void *(*parse_prefix)(const char *, const char **, void *); |
| 1114 |
void (*free_value)(void *); |
| 1115 |
void *user_data; |
| 1116 |
} rule_list[] = { |
| 1117 |
{"transparent-clipping-exclude", |
| 1118 |
offsetof(struct options, transparent_clipping_blacklist)}, |
| 1119 |
{"shadow-exclude", offsetof(struct options, shadow_blacklist)}, |
| 1120 |
{"clip-shadow-above", offsetof(struct options, shadow_clip_list)}, |
| 1121 |
{"fade-exclude", offsetof(struct options, fade_blacklist)}, |
| 1122 |
{"focus-exclude", offsetof(struct options, focus_blacklist)}, |
| 1123 |
{"invert-color-include", offsetof(struct options, invert_color_list)}, |
| 1124 |
{"blur-background-exclude", offsetof(struct options, blur_background_blacklist)}, |
| 1125 |
{"unredir-if-possible-exclude", |
| 1126 |
offsetof(struct options, unredir_if_possible_blacklist)}, |
| 1127 |
{"rounded-corners-exclude", offsetof(struct options, rounded_corners_blacklist)}, |
| 1128 |
{"corner-radius-rules", offsetof(struct options, corner_radius_rules), |
| 1129 |
parse_numeric_prefix, NULL, (int[]){0, INT_MAX}}, |
| 1130 |
{"opacity-rule", offsetof(struct options, opacity_rules), |
| 1131 |
parse_numeric_prefix, NULL, (int[]){0, 100}}, |
| 1132 |
{"window-shader-fg-rule", offsetof(struct options, window_shader_fg_rules), |
| 1133 |
parse_window_shader_prefix, free, (void *)config_get_include_dir(&cfg)}, |
| 1134 |
}; |
| 1135 |
|
| 1136 |
if (!list_is_empty(&opt->rules)) { |
| 1137 |
for (size_t i = 0; i < ARR_SIZE(rule_list); i++) { |
| 1138 |
if (config_lookup(&cfg, rule_list[i].name)) { |
| 1139 |
log_warn_both_style_of_rules(opt, rule_list[i].name); |
| 1140 |
} |
| 1141 |
} |
| 1142 |
if (config_lookup(&cfg, "wintypes")) { |
| 1143 |
log_warn_both_style_of_rules(opt, "wintypes"); |
| 1144 |
} |
| 1145 |
} else { |
| 1146 |
for (size_t i = 0; i < ARR_SIZE(rule_list); i++) { |
| 1147 |
bool deprecated = false; |
| 1148 |
void *dst = (char *)opt + rule_list[i].offset; |
| 1149 |
if ((rule_list[i].parse_prefix != NULL && |
| 1150 |
!parse_cfg_condlst_with_prefix( |
| 1151 |
dst, &cfg, rule_list[i].name, rule_list[i].parse_prefix, |
| 1152 |
rule_list[i].free_value, rule_list[i].user_data, &deprecated)) || |
| 1153 |
(rule_list[i].parse_prefix == NULL && |
| 1154 |
!parse_cfg_condlst(dst, &cfg, rule_list[i].name, &deprecated))) { |
| 1155 |
goto out; |
| 1156 |
} |
| 1157 |
if (deprecated) { |
| 1158 |
log_warn("Rule option \"%s\" contains deprecated syntax " |
| 1159 |
"(see above).", |
| 1160 |
rule_list[i].name); |
| 1161 |
record_problematic_option(opt, rule_list[i].name); |
| 1162 |
} |
| 1163 |
} |
| 1164 |
} |
| 1165 |
|
| 1166 |
|
| 1167 |
if (config_lookup_string(&cfg, "blur-method", &sval)) { |
| 1168 |
int method = parse_blur_method(sval); |
| 1169 |
if (method >= BLUR_METHOD_INVALID) { |
| 1170 |
log_fatal("Invalid blur method %s", sval); |
| 1171 |
goto out; |
| 1172 |
} |
| 1173 |
opt->blur_method = (enum blur_method)method; |
| 1174 |
} |
| 1175 |
|
| 1176 |
config_lookup_int(&cfg, "blur-size", &opt->blur_radius); |
| 1177 |
|
| 1178 |
config_lookup_float(&cfg, "blur-deviation", &opt->blur_deviation); |
| 1179 |
|
| 1180 |
config_lookup_int(&cfg, "blur-strength", &opt->blur_strength); |
| 1181 |
|
| 1182 |
if (config_lookup_bool(&cfg, "blur-background", &ival) && ival) { |
| 1183 |
if (opt->blur_method == BLUR_METHOD_NONE) { |
| 1184 |
opt->blur_method = BLUR_METHOD_KERNEL; |
| 1185 |
} |
| 1186 |
} |
| 1187 |
|
| 1188 |
lcfg_lookup_bool(&cfg, "blur-background-frame", &opt->blur_background_frame); |
| 1189 |
|
| 1190 |
lcfg_lookup_bool(&cfg, "blur-background-fixed", &opt->blur_background_fixed); |
| 1191 |
|
| 1192 |
if (config_lookup_string(&cfg, "blur-kern", &sval)) { |
| 1193 |
opt->blur_kerns = parse_blur_kern_lst(sval, &opt->blur_kernel_count); |
| 1194 |
if (!opt->blur_kerns) { |
| 1195 |
log_fatal("Cannot parse \"blur-kern\""); |
| 1196 |
goto out; |
| 1197 |
} |
| 1198 |
} |
| 1199 |
|
| 1200 |
if (config_lookup_int(&cfg, "resize-damage", &opt->resize_damage)) { |
| 1201 |
report_deprecated_option(opt, "resize-damage", false); |
| 1202 |
} |
| 1203 |
|
| 1204 |
if (lcfg_lookup_bool(&cfg, "glx-no-stencil", &opt->glx_no_stencil)) { |
| 1205 |
report_deprecated_option(opt, "glx-no-stencil", false); |
| 1206 |
} |
| 1207 |
|
| 1208 |
if (lcfg_lookup_bool(&cfg, "glx-no-rebind-pixmap", &opt->glx_no_rebind_pixmap)) { |
| 1209 |
report_deprecated_option(opt, "glx-no-rebind-pixmap", false); |
| 1210 |
} |
| 1211 |
lcfg_lookup_bool(&cfg, "force-win-blend", &opt->force_win_blend); |
| 1212 |
|
| 1213 |
lcfg_lookup_bool(&cfg, "use-damage", &opt->use_damage); |
| 1214 |
|
| 1215 |
|
| 1216 |
if (config_lookup_float(&cfg, "max-brightness", &opt->max_brightness) && |
| 1217 |
opt->use_damage && opt->max_brightness < 1) { |
| 1218 |
log_warn("max-brightness requires use-damage = false. Falling back to " |
| 1219 |
"1.0"); |
| 1220 |
record_problematic_option(opt, "max-brightness"); |
| 1221 |
opt->max_brightness = 1.0; |
| 1222 |
} |
| 1223 |
|
| 1224 |
|
| 1225 |
subcfg = config_lookup(&cfg, "window-shader-fg"); |
| 1226 |
if (subcfg) { |
| 1227 |
opt->window_shader_fg = |
| 1228 |
parse_shader_specification(subcfg, config_get_include_dir(&cfg)); |
| 1229 |
if (!opt->window_shader_fg) { |
| 1230 |
goto out; |
| 1231 |
} |
| 1232 |
} |
| 1233 |
|
| 1234 |
subcfg = config_lookup(&cfg, "root-pixmap-shader"); |
| 1235 |
if (subcfg) { |
| 1236 |
opt->root_pixmap_shader = |
| 1237 |
parse_shader_specification(subcfg, config_get_include_dir(&cfg)); |
| 1238 |
if (!opt->root_pixmap_shader) { |
| 1239 |
goto out; |
| 1240 |
} |
| 1241 |
} |
| 1242 |
|
| 1243 |
|
| 1244 |
lcfg_lookup_bool(&cfg, "xrender-sync-fence", &opt->xrender_sync_fence); |
| 1245 |
|
| 1246 |
config_setting_t *blur_cfg = config_lookup(&cfg, "blur"); |
| 1247 |
if (blur_cfg) { |
| 1248 |
if (config_setting_lookup_string(blur_cfg, "method", &sval)) { |
| 1249 |
int method = parse_blur_method(sval); |
| 1250 |
if (method >= BLUR_METHOD_INVALID) { |
| 1251 |
log_warn("Invalid blur method %s, ignoring.", sval); |
| 1252 |
record_problematic_option(opt, "blur method"); |
| 1253 |
} else { |
| 1254 |
opt->blur_method = (enum blur_method)method; |
| 1255 |
} |
| 1256 |
} |
| 1257 |
|
| 1258 |
config_setting_lookup_int(blur_cfg, "size", &opt->blur_radius); |
| 1259 |
|
| 1260 |
if (config_setting_lookup_string(blur_cfg, "kernel", &sval)) { |
| 1261 |
opt->blur_kerns = parse_blur_kern_lst(sval, &opt->blur_kernel_count); |
| 1262 |
if (!opt->blur_kerns) { |
| 1263 |
log_warn("Failed to parse blur kernel: %s", sval); |
| 1264 |
record_problematic_option(opt, "blur kernel"); |
| 1265 |
} |
| 1266 |
} |
| 1267 |
|
| 1268 |
config_setting_lookup_float(blur_cfg, "deviation", &opt->blur_deviation); |
| 1269 |
config_setting_lookup_int(blur_cfg, "strength", &opt->blur_strength); |
| 1270 |
} |
| 1271 |
|
| 1272 |
|
| 1273 |
if (config_lookup_string(&cfg, "write-pid-path", &sval)) { |
| 1274 |
if (*sval != '/') { |
| 1275 |
log_warn("The write-pid-path in your configuration file is not" |
| 1276 |
" an absolute path"); |
| 1277 |
record_problematic_option(opt, "write-pid-path"); |
| 1278 |
} |
| 1279 |
opt->write_pid_path = strdup(sval); |
| 1280 |
} |
| 1281 |
|
| 1282 |
|
| 1283 |
|
| 1284 |
|
| 1285 |
if (list_is_empty(&opt->rules)) { |
| 1286 |
for (wintype_t i = 0; i < NUM_WINTYPES; ++i) { |
| 1287 |
parse_wintype_config(&cfg, WINTYPES[i].name, &opt->wintype_option[i], |
| 1288 |
&opt->wintype_option_mask[i]); |
| 1289 |
} |
| 1290 |
|
| 1291 |
parse_wintype_config(&cfg, "notify", |
| 1292 |
&opt->wintype_option[WINTYPE_NOTIFICATION], |
| 1293 |
&opt->wintype_option_mask[WINTYPE_NOTIFICATION]); |
| 1294 |
} |
| 1295 |
|
| 1296 |
config_setting_t *animations = config_lookup(&cfg, "animations"); |
| 1297 |
if (animations) { |
| 1298 |
parse_animations(opt->animations, animations, &opt->all_scripts); |
| 1299 |
} |
| 1300 |
|
| 1301 |
opt->config_file_path = path; |
| 1302 |
path = NULL; |
| 1303 |
succeeded = true; |
| 1304 |
|
| 1305 |
out: |
| 1306 |
config_destroy(&cfg); |
| 1307 |
free(path); |
| 1308 |
return succeeded; |
| 1309 |
} |