From 3592174c6af889c48445bc7c791d84c300e78ad2 Mon Sep 17 00:00:00 2001 From: Yuxuan Shui Date: Tue, 30 Jul 2024 20:36:19 +0100 Subject: [PATCH] rules: add opacity-override option to replace inactive-opacity-override Signed-off-by: Yuxuan Shui --- src/config.h | 11 +++++++++-- src/config_libconfig.c | 1 + src/picom.c | 1 + src/wm/win.c | 6 ++++-- src/wm/win.h | 2 ++ 5 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/config.h b/src/config.h index 7a96676310..f60774e3f5 100644 --- a/src/config.h +++ b/src/config.h @@ -8,6 +8,7 @@ /// Common functions and definitions for configuration parsing /// Used for command line arguments and config files +#include #include #include #include @@ -164,6 +165,9 @@ struct window_maybe_options { enum tristate paint; /// Whether this window should be considered for unredirect-if-possible. enum tristate unredir_ignore; + /// Whether opacity value from rules should override the opacity property set + /// on the window. + enum tristate opacity_override; }; /// Like `window_maybe_options`, but all fields are guaranteed to be set. @@ -180,8 +184,9 @@ struct window_options { bool clip_shadow_above; bool paint; bool unredir_ignore; + bool opacity_override; - char padding[2]; + char padding[3]; }; static inline bool @@ -189,8 +194,10 @@ win_options_eq(const struct window_options *a, const struct window_options *b) { return memcmp(a, b, offsetof(struct window_options, padding)) == 0; } -static_assert(offsetof(struct window_options, padding) == 36, "window_options has " +static_assert(offsetof(struct window_options, padding) == 37, "window_options has " "implicit padding"); +static_assert(sizeof(struct window_options) % alignof(struct window_options) == 0, + "window_options is not aligned"); extern struct shader_info null_shader; diff --git a/src/config_libconfig.c b/src/config_libconfig.c index 146dd3a479..a6c94448a6 100644 --- a/src/config_libconfig.c +++ b/src/config_libconfig.c @@ -537,6 +537,7 @@ static const struct { {"shadow", offsetof(struct window_maybe_options, shadow)}, {"invert-color", offsetof(struct window_maybe_options, invert_color)}, {"blur-background", offsetof(struct window_maybe_options, blur_background)}, + {"opacity-override", offsetof(struct window_maybe_options, opacity_override)}, {"clip-shadow-above", offsetof(struct window_maybe_options, clip_shadow_above)}, {"transparent-clipping", offsetof(struct window_maybe_options, transparent_clipping)}, }; diff --git a/src/picom.c b/src/picom.c index f596f1684d..ff5f48eff4 100644 --- a/src/picom.c +++ b/src/picom.c @@ -1996,6 +1996,7 @@ static struct window_options win_options_from_config(const struct options *opts) .clip_shadow_above = false, .unredir_ignore = false, .opacity = 1, + .opacity_override = false, }; } diff --git a/src/wm/win.c b/src/wm/win.c index cbd1823ec1..559f21d848 100644 --- a/src/wm/win.c +++ b/src/wm/win.c @@ -1073,10 +1073,12 @@ void win_on_factor_change(session_t *ps, struct win *w) { c2_list_foreach(ps->o.rules, win_update_rule, ¶ms); w->options = params.options; assert(w->state == WSTATE_MAPPED); - if (w->has_opacity_prop) { + + auto final_options = win_options(w); + if (w->has_opacity_prop && !final_options.opacity_override) { w->opacity = ((double)w->opacity_prop) / OPAQUE; } else { - w->opacity = win_options(w).opacity; + w->opacity = final_options.opacity; } } diff --git a/src/wm/win.h b/src/wm/win.h index 731d9ea581..5044cd8e3d 100644 --- a/src/wm/win.h +++ b/src/wm/win.h @@ -322,6 +322,7 @@ win_maybe_options_fold(struct window_maybe_options upper, struct window_maybe_op .invert_color = tri_or(upper.invert_color, lower.invert_color), .paint = tri_or(upper.paint, lower.paint), .opacity = !safe_isnan(upper.opacity) ? upper.opacity : lower.opacity, + .opacity_override = tri_or(upper.opacity_override, lower.opacity_override), .dim = !safe_isnan(upper.dim) ? upper.dim : lower.dim, .shader = upper.shader ? upper.shader : lower.shader, .corner_radius = upper.corner_radius >= 0 ? upper.corner_radius : lower.corner_radius, @@ -342,6 +343,7 @@ win_maybe_options_or(struct window_maybe_options maybe, struct window_options de .invert_color = tri_or_bool(maybe.invert_color, def.invert_color), .paint = tri_or_bool(maybe.paint, def.paint), .opacity = !safe_isnan(maybe.opacity) ? maybe.opacity : def.opacity, + .opacity_override = tri_or_bool(maybe.opacity_override, def.opacity_override), .dim = !safe_isnan(maybe.dim) ? maybe.dim : def.dim, .shader = maybe.shader ? maybe.shader : def.shader, };