From 82b9822fd09f20ed25826c7cdb5cc25c7ef2e95d Mon Sep 17 00:00:00 2001 From: Yuxuan Shui Date: Sat, 1 Jun 2019 00:39:00 +0100 Subject: [PATCH] config: introduce new syntax for blur options. Parsing only, not used yet. Signed-off-by: Yuxuan Shui --- src/config.c | 15 ++++++++++++++- src/config.h | 17 +++++++++++++++-- src/config_libconfig.c | 33 ++++++++++++++++++++++++++++++++- src/dbus.c | 2 +- src/options.c | 12 ++++++++---- src/render.c | 2 +- src/win.c | 2 +- 7 files changed, 72 insertions(+), 11 deletions(-) diff --git a/src/config.c b/src/config.c index 128c726..f22fd56 100644 --- a/src/config.c +++ b/src/config.c @@ -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, diff --git a/src/config.h b/src/config.h index 2e8ff45..256df77 100644 --- a/src/config.h +++ b/src/config.h @@ -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. diff --git a/src/config_libconfig.c b/src/config_libconfig.c index ed83635..95eb08c 100644 --- a/src/config_libconfig.c +++ b/src/config_libconfig.c @@ -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 diff --git a/src/dbus.c b/src/dbus.c index d06c596..05c84c1 100644 --- a/src/dbus.c +++ b/src/dbus.c @@ -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); diff --git a/src/options.c b/src/options.c index 80f4540..d2237ad 100644 --- a/src/options.c +++ b/src/options.c @@ -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)); } diff --git a/src/render.c b/src/render.c index e524d0b..9c0f4cc 100644 --- a/src/render.c +++ b/src/render.c @@ -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 diff --git a/src/win.c b/src/win.c index 15baa57..deff35e 100644 --- a/src/win.c +++ b/src/win.c @@ -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);