Skip to content

Commit

Permalink
rules: add opacity-override option to replace inactive-opacity-override
Browse files Browse the repository at this point in the history
Signed-off-by: Yuxuan Shui <[email protected]>
  • Loading branch information
yshui committed Jul 30, 2024
1 parent bd8860f commit 3592174
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 4 deletions.
11 changes: 9 additions & 2 deletions src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
/// Common functions and definitions for configuration parsing
/// Used for command line arguments and config files

#include <stdalign.h>
#include <stdbool.h>
#include <stddef.h>
#include <string.h>
Expand Down Expand Up @@ -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.
Expand All @@ -180,17 +184,20 @@ struct window_options {
bool clip_shadow_above;
bool paint;
bool unredir_ignore;
bool opacity_override;

char padding[2];
char padding[3];
};

static inline bool
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;

Expand Down
1 change: 1 addition & 0 deletions src/config_libconfig.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)},
};
Expand Down
1 change: 1 addition & 0 deletions src/picom.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
}

Expand Down
6 changes: 4 additions & 2 deletions src/wm/win.c
Original file line number Diff line number Diff line change
Expand Up @@ -1073,10 +1073,12 @@ void win_on_factor_change(session_t *ps, struct win *w) {
c2_list_foreach(ps->o.rules, win_update_rule, &params);
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;
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/wm/win.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
};
Expand Down

0 comments on commit 3592174

Please sign in to comment.