config: introduce new syntax for blur options.

Parsing only, not used yet.

Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
This commit is contained in:
Yuxuan Shui 2019-06-01 00:39:00 +01:00
parent 4a74b4f199
commit 82b9822fd0
No known key found for this signature in database
GPG Key ID: 37C999F617EA1A47
7 changed files with 72 additions and 11 deletions

View File

@ -81,6 +81,19 @@ const char *parse_readnum(const char *src, double *dest) {
return pc;
}
enum blur_method parse_blur_method(const char *src) {
if (strcmp(src, "kernel") == 0) {
return BLUR_METHOD_KERNEL;
} else if (strcmp(src, "box") == 0) {
return BLUR_METHOD_BOX;
} else if (strcmp(src, "gaussian") == 0) {
return BLUR_METHOD_GAUSSIAN;
} else if (strcmp(src, "none") == 0) {
return BLUR_METHOD_NONE;
}
return BLUR_METHOD_INVALID;
}
/**
* Parse a matrix.
*
@ -524,7 +537,7 @@ char *parse_config(options_t *opt, const char *config_file, bool *shadow_enable,
.frame_opacity = 1.0,
.detect_client_opacity = false,
.blur_background = false,
.blur_method = BLUR_METHOD_NONE,
.blur_background_frame = false,
.blur_background_fixed = false,
.blur_background_blacklist = NULL,

View File

@ -36,6 +36,14 @@ enum backend {
NUM_BKEND,
};
enum blur_method {
BLUR_METHOD_NONE = 0,
BLUR_METHOD_KERNEL,
BLUR_METHOD_BOX,
BLUR_METHOD_GAUSSIAN,
BLUR_METHOD_INVALID,
};
typedef struct win_option_mask {
bool shadow : 1;
bool fade : 1;
@ -180,8 +188,12 @@ typedef struct options {
bool detect_client_opacity;
// === Other window processing ===
/// Whether to blur background of semi-transparent / ARGB windows.
bool blur_background;
/// 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;
/// Whether to blur background when the window frame is not opaque.
/// Implies blur_background.
bool blur_background_frame;
@ -230,6 +242,7 @@ bool must_use parse_int(const char *, int *);
bool must_use parse_blur_kern_lst(const char *, conv **, int, bool *hasneg);
bool must_use parse_geometry(session_t *, const char *, region_t *);
bool must_use parse_rule_opacity(c2_lptr_t **, const char *);
enum blur_method must_use parse_blur_method(const char *src);
/**
* Add a pattern to a condition linked list.

View File

@ -371,7 +371,9 @@ char *parse_config_libconfig(options_t *opt, const char *config_file, bool *shad
parse_cfg_condlst(&cfg, &opt->unredir_if_possible_blacklist,
"unredir-if-possible-exclude");
// --blur-background
lcfg_lookup_bool(&cfg, "blur-background", &opt->blur_background);
if (config_lookup_bool(&cfg, "blur-background", &ival) && ival) {
opt->blur_method = BLUR_METHOD_KERNEL;
}
// --blur-background-frame
lcfg_lookup_bool(&cfg, "blur-background-frame", &opt->blur_background_frame);
// --blur-background-fixed
@ -445,6 +447,35 @@ char *parse_config_libconfig(options_t *opt, const char *config_file, bool *shad
return ERR_PTR(-1);
}
config_setting_t *blur_cfg = config_lookup(&cfg, "blur");
// This is not a loop
if (blur_cfg) {
if (config_setting_lookup_string(blur_cfg, "method", &sval)) {
enum blur_method method = parse_blur_method(sval);
if (method >= BLUR_METHOD_INVALID) {
log_warn("Invalid blur method %s, ignoring.", sval);
} else {
opt->blur_method = method;
}
}
opt->blur_radius = -1;
config_setting_lookup_int(blur_cfg, "size", &opt->blur_radius);
if (config_setting_lookup_string(blur_cfg, "kernel", &sval)) {
struct conv *kerns[5];
if (!parse_blur_kern_lst(sval, kerns, MAX_BLUR_PASS,
conv_kern_hasneg)) {
log_warn("Failed to parse blur kernel: %s", sval);
} else {
memcpy(opt->blur_kerns, kerns, sizeof kerns);
}
}
opt->blur_deviation = 0.84089642;
config_setting_lookup_float(blur_cfg, "deviation", &opt->blur_deviation);
}
// Wintype settings
// XXX ! Refactor all the wintype_* arrays into a struct

View File

@ -1025,7 +1025,7 @@ static bool cdbus_process_opts_get(session_t *ps, DBusMessage *msg) {
cdbus_m_opts_get_do(fade_out_step, cdbus_reply_double);
cdbus_m_opts_get_do(no_fading_openclose, cdbus_reply_bool);
cdbus_m_opts_get_do(blur_background, cdbus_reply_bool);
cdbus_m_opts_get_do(blur_method, cdbus_reply_bool);
cdbus_m_opts_get_do(blur_background_frame, cdbus_reply_bool);
cdbus_m_opts_get_do(blur_background_fixed, cdbus_reply_bool);

View File

@ -630,7 +630,10 @@ void get_cfg(options_t *opt, int argc, char *const *argv, bool shadow_enable,
P_CASEBOOL(280, inactive_dim_fixed);
P_CASEBOOL(281, detect_transient);
P_CASEBOOL(282, detect_client_leader);
P_CASEBOOL(283, blur_background);
case 283:
// --blur_background
opt->blur_method = BLUR_METHOD_KERNEL;
break;
P_CASEBOOL(284, blur_background_frame);
P_CASEBOOL(285, blur_background_fixed);
P_CASEBOOL(286, dbus);
@ -801,8 +804,9 @@ void get_cfg(options_t *opt, int argc, char *const *argv, bool shadow_enable,
set_default_winopts(opt, winopt_mask, shadow_enable, fading_enable);
// --blur-background-frame implies --blur-background
if (opt->blur_background_frame)
opt->blur_background = true;
if (opt->blur_background_frame && !opt->blur_method) {
opt->blur_method = BLUR_METHOD_KERNEL;
}
// Other variables determined by options
@ -812,7 +816,7 @@ void get_cfg(options_t *opt, int argc, char *const *argv, bool shadow_enable,
}
// Fill default blur kernel
if (opt->blur_background && !opt->blur_kerns[0]) {
if (opt->blur_method == BLUR_METHOD_KERNEL && !opt->blur_kerns[0]) {
CHECK(parse_blur_kern_lst("3x3box", opt->blur_kerns, MAX_BLUR_PASS,
&conv_kern_hasneg));
}

View File

@ -1143,7 +1143,7 @@ bool init_render(session_t *ps) {
}
// Blur filter
if (ps->o.blur_background || ps->o.blur_background_frame) {
if (ps->o.blur_method || ps->o.blur_background_frame) {
bool ret = false;
if (ps->o.backend == BKEND_GLX) {
#ifdef CONFIG_OPENGL

View File

@ -709,7 +709,7 @@ void win_determine_blur_background(session_t *ps, struct managed_win *w) {
if (w->a.map_state != XCB_MAP_STATE_VIEWABLE)
return;
bool blur_background_new = ps->o.blur_background &&
bool blur_background_new = ps->o.blur_method &&
!c2_match(ps, w, ps->o.blur_background_blacklist, NULL);
win_set_blur_background(ps, w, blur_background_new);