Move the initialization of wintype options into common function

Make sure the wintype options are properly initialized even when there
is no config file specified/supported.

Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
This commit is contained in:
Yuxuan Shui 2018-12-04 16:28:19 +00:00
parent 94d500bd53
commit 8f05b03411
No known key found for this signature in database
GPG Key ID: 37C999F617EA1A47
3 changed files with 49 additions and 47 deletions

View File

@ -340,3 +340,47 @@ condlst_add(session_t *ps, c2_lptr_t **pcondlst, const char *pattern) {
return true;
}
void parse_config(session_t *ps, bool *shadow_enable, bool *fading_enable,
win_option_mask_t *winopt_mask) {
#ifdef CONFIG_LIBCONFIG
parse_config_libconfig(ps, shadow_enable, fading_enable, 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;
ps->o.wintype_option[WINTYPE_DESKTOP].shadow = false;
}
// Focused/unfocused state only apply to a few window types, all other windows
// are always considered focused.
const wintype_t nofocus_type[] =
{ WINTYPE_UNKNOWN, WINTYPE_NORMAL, WINTYPE_UTILITY };
for (unsigned long i = 0; i < ARR_SIZE(nofocus_type); i++) {
if (!winopt_mask[nofocus_type[i]].focus) {
winopt_mask[nofocus_type[i]].focus = true;
ps->o.wintype_option[nofocus_type[i]].focus = false;
}
}
for (unsigned long i = 0; i < NUM_WINTYPES; i++) {
if (!winopt_mask[i].focus) {
winopt_mask[i].focus = true;
ps->o.wintype_option[i].focus = true;
}
if (!winopt_mask[i].full_shadow) {
winopt_mask[i].full_shadow = true;
ps->o.wintype_option[i].full_shadow = false;
}
if (!winopt_mask[i].opacity) {
winopt_mask[i].opacity = true;
// Opacity is not set to a concrete number here because the opacity logic
// is complicated, and needs an "unset" state
ps->o.wintype_option[i].opacity = NAN;
}
}
}

View File

@ -25,16 +25,11 @@ bool parse_rule_opacity(session_t *, const char *);
bool condlst_add(session_t *, c2_lptr_t **, const char *);
#ifdef CONFIG_LIBCONFIG
FILE *
open_config_file(char *cpath, char **path);
void
parse_cfg_condlst(session_t *ps, const config_t *pcfg, c2_lptr_t **pcondlst,
const char *name);
parse_config_libconfig(session_t *ps, bool *shadow_enable,
bool *fading_enable, win_option_mask_t *winopt_mask);
#endif
void
parse_config(session_t *ps, bool *shadow_enable,
bool *fading_enable, win_option_mask_t *winopt_mask);
#else
static inline void parse_config() {}
#endif

View File

@ -156,8 +156,8 @@ parse_cfg_condlst_opct(session_t *ps, const config_t *pcfg, const char *name) {
/**
* Parse a configuration file from default location.
*/
void parse_config(session_t *ps, bool *shadow_enable, bool *fading_enable,
win_option_mask_t *winopt_mask)
void parse_config_libconfig(session_t *ps, bool *shadow_enable,
bool *fading_enable, win_option_mask_t *winopt_mask)
{
char *path = NULL;
FILE *f;
@ -429,42 +429,5 @@ void parse_config(session_t *ps, bool *shadow_enable, bool *fading_enable,
}
}
// 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;
ps->o.wintype_option[WINTYPE_DESKTOP].shadow = false;
}
// Focused/unfocused state only apply to a few window types, all other windows
// are always considered focused.
const wintype_t nofocus_type[] =
{ WINTYPE_UNKNOWN, WINTYPE_NORMAL, WINTYPE_UTILITY };
for (unsigned long i = 0; i < ARR_SIZE(nofocus_type); i++) {
if (!winopt_mask[nofocus_type[i]].focus) {
winopt_mask[nofocus_type[i]].focus = true;
ps->o.wintype_option[nofocus_type[i]].focus = false;
}
}
for (unsigned long i = 0; i < NUM_WINTYPES; i++) {
if (!winopt_mask[i].focus) {
winopt_mask[i].focus = true;
ps->o.wintype_option[i].focus = true;
}
if (!winopt_mask[i].full_shadow) {
winopt_mask[i].full_shadow = true;
ps->o.wintype_option[i].full_shadow = false;
}
if (!winopt_mask[i].opacity) {
winopt_mask[i].opacity = true;
// Opacity is not set to a concrete number here because the opacity logic
// is complicated, and needs an "unset" state
ps->o.wintype_option[i].opacity = NAN;
}
}
config_destroy(&cfg);
}