Refactor setting the default winopts

Move filling winopts with default values to after command line options have
been parsed, not after parsing the config file. This is more intuitive.

Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
This commit is contained in:
Yuxuan Shui 2018-12-24 18:28:00 +00:00
parent b434451abb
commit f41765fca5
No known key found for this signature in database
GPG Key ID: 37C999F617EA1A47
3 changed files with 35 additions and 38 deletions

View File

@ -350,22 +350,11 @@ condlst_add(c2_lptr_t **pcondlst, const char *pattern) {
return true; return true;
} }
char *parse_config(options_t *opt, const char *config_file, void set_default_winopts(options_t *opt, win_option_mask_t *mask, bool shadow_enable, bool fading_enable) {
bool *shadow_enable, bool *fading_enable, bool *hasneg, // Apply default wintype options.
win_option_mask_t *winopt_mask) { if (!mask[WINTYPE_DESKTOP].shadow) {
char *ret = NULL; // Desktop windows are always drawn without shadow by default.
#ifdef CONFIG_LIBCONFIG mask[WINTYPE_DESKTOP].shadow = true;
ret = parse_config_libconfig(opt, config_file, shadow_enable, fading_enable,
hasneg, winopt_mask);
#endif
// Apply default wintype options that does not depends on global options.
// For example, wintype shadow option will depend on the global shadow
// option, so it is not set here.
//
// Except desktop windows are always drawn without shadow.
if (!winopt_mask[WINTYPE_DESKTOP].shadow) {
winopt_mask[WINTYPE_DESKTOP].shadow = true;
opt->wintype_option[WINTYPE_DESKTOP].shadow = false; opt->wintype_option[WINTYPE_DESKTOP].shadow = false;
} }
@ -374,30 +363,48 @@ char *parse_config(options_t *opt, const char *config_file,
const wintype_t nofocus_type[] = const wintype_t nofocus_type[] =
{ WINTYPE_UNKNOWN, WINTYPE_NORMAL, WINTYPE_UTILITY }; { WINTYPE_UNKNOWN, WINTYPE_NORMAL, WINTYPE_UTILITY };
for (unsigned long i = 0; i < ARR_SIZE(nofocus_type); i++) { for (unsigned long i = 0; i < ARR_SIZE(nofocus_type); i++) {
if (!winopt_mask[nofocus_type[i]].focus) { if (!mask[nofocus_type[i]].focus) {
winopt_mask[nofocus_type[i]].focus = true; mask[nofocus_type[i]].focus = true;
opt->wintype_option[nofocus_type[i]].focus = false; opt->wintype_option[nofocus_type[i]].focus = false;
} }
} }
for (unsigned long i = 0; i < NUM_WINTYPES; i++) { for (unsigned long i = 0; i < NUM_WINTYPES; i++) {
if (!winopt_mask[i].focus) { if (!mask[i].shadow) {
winopt_mask[i].focus = true; mask[i].shadow = true;
opt->wintype_option[i].shadow = shadow_enable;
}
if (!mask[i].fade) {
mask[i].fade = true;
opt->wintype_option[i].fade = fading_enable;
}
if (!mask[i].focus) {
mask[i].focus = true;
opt->wintype_option[i].focus = true; opt->wintype_option[i].focus = true;
} }
if (!winopt_mask[i].full_shadow) { if (!mask[i].full_shadow) {
winopt_mask[i].full_shadow = true; mask[i].full_shadow = true;
opt->wintype_option[i].full_shadow = false; opt->wintype_option[i].full_shadow = false;
} }
if (!winopt_mask[i].redir_ignore) { if (!mask[i].redir_ignore) {
winopt_mask[i].redir_ignore = true; mask[i].redir_ignore = true;
opt->wintype_option[i].redir_ignore = false; opt->wintype_option[i].redir_ignore = false;
} }
if (!winopt_mask[i].opacity) { if (!mask[i].opacity) {
winopt_mask[i].opacity = true; mask[i].opacity = true;
// Opacity is not set to a concrete number here because the opacity logic // Opacity is not set to a concrete number here because the opacity logic
// is complicated, and needs an "unset" state // is complicated, and needs an "unset" state
opt->wintype_option[i].opacity = NAN; opt->wintype_option[i].opacity = NAN;
} }
} }
}
char *parse_config(options_t *opt, const char *config_file,
bool *shadow_enable, bool *fading_enable, bool *hasneg,
win_option_mask_t *winopt_mask) {
char *ret = NULL;
#ifdef CONFIG_LIBCONFIG
ret = parse_config_libconfig(opt, config_file, shadow_enable, fading_enable,
hasneg, winopt_mask);
#endif
return ret; return ret;
} }

View File

@ -269,6 +269,7 @@ parse_config_libconfig(options_t *, const char *config_file, bool *shadow_enable
bool *fading_enable, bool *hasneg, win_option_mask_t *winopt_mask); bool *fading_enable, bool *hasneg, win_option_mask_t *winopt_mask);
#endif #endif
void set_default_winopts(options_t *, win_option_mask_t *, bool shadow_enable, bool fading_enable);
/// Parse a configuration file is that is enabled, also initialize the winopt_mask with /// Parse a configuration file is that is enabled, also initialize the winopt_mask with
/// default values /// default values
/// Outputs and returns: /// Outputs and returns:

View File

@ -793,18 +793,7 @@ void get_cfg(options_t *opt, int argc, char *const *argv, bool shadow_enable,
opt->refresh_rate = normalize_i_range(opt->refresh_rate, 0, 300); opt->refresh_rate = normalize_i_range(opt->refresh_rate, 0, 300);
// Apply default wintype options that are dependent on global options // Apply default wintype options that are dependent on global options
for (int i = 0; i < NUM_WINTYPES; i++) { set_default_winopts(opt, winopt_mask, shadow_enable, fading_enable);
auto wo = &opt->wintype_option[i];
auto mask = &winopt_mask[i];
if (!mask->shadow) {
wo->shadow = shadow_enable;
mask->shadow = true;
}
if (!mask->fade) {
wo->fade = fading_enable;
mask->fade = true;
}
}
// --blur-background-frame implies --blur-background // --blur-background-frame implies --blur-background
if (opt->blur_background_frame) if (opt->blur_background_frame)