Skip to content

Commit

Permalink
win: allow different dim level per window
Browse files Browse the repository at this point in the history
Instead of just a yes or no. Allow for more flexibility when universal
rules are implemented.

Signed-off-by: Yuxuan Shui <[email protected]>
  • Loading branch information
yshui committed Jul 29, 2024
1 parent 443c5a0 commit d85bd2b
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 44 deletions.
9 changes: 5 additions & 4 deletions src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,9 @@ struct window_maybe_options {
/// Window opacity, NaN means not set.
double opacity;

/// Window dim level, NaN means not set.
double dim;

/// Name of the custom fragment shader for this window. NULL means not set.
const struct shader_info *shader;

Expand All @@ -153,8 +156,6 @@ struct window_maybe_options {
enum tristate invert_color;
/// Whether to blur window background.
enum tristate blur_background;
/// Whether the window is to be dimmed.
enum tristate dim;
/// Whether this window should fade.
enum tristate fade;
/// Do not paint shadow over this window.
Expand All @@ -168,13 +169,13 @@ struct window_maybe_options {
/// Like `window_maybe_options`, but all fields are guaranteed to be set.
struct window_options {
double opacity;
double dim;
const struct shader_info *shader;
unsigned int corner_radius;
bool transparent_clipping;
bool shadow;
bool invert_color;
bool blur_background;
bool dim;
bool fade;
bool clip_shadow_above;
bool paint;
Expand All @@ -188,7 +189,7 @@ 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) == 29, "window_options has "
static_assert(offsetof(struct window_options, padding) == 36, "window_options has "
"implicit padding");

extern struct shader_info null_shader;
Expand Down
11 changes: 5 additions & 6 deletions src/picom.c
Original file line number Diff line number Diff line change
Expand Up @@ -1824,12 +1824,11 @@ static void draw_callback_impl(EV_P_ session_t *ps, int revents attr_unused) {
ps->layout_manager, ps->wm, ps->root_image_generation,
(ivec2){.width = ps->root_width, .height = ps->root_height});
bool succeeded = renderer_render(
ps->renderer, ps->backend_data, ps->root_image,
ps->layout_manager, ps->command_builder,
ps->backend_blur_context, render_start_us, ps->sync_fence,
ps->o.use_damage, ps->o.monitor_repaint, ps->o.force_win_blend,
ps->o.blur_background_frame, ps->o.inactive_dim_fixed,
ps->o.max_brightness, ps->o.inactive_dim,
ps->renderer, ps->backend_data, ps->root_image, ps->layout_manager,
ps->command_builder, ps->backend_blur_context, render_start_us,
ps->sync_fence, ps->o.use_damage, ps->o.monitor_repaint,
ps->o.force_win_blend, ps->o.blur_background_frame,
ps->o.inactive_dim_fixed, ps->o.max_brightness,
ps->o.crop_shadow_to_monitor ? &ps->monitors : NULL,
ps->o.wintype_option, &after_damage_us);
if (!succeeded) {
Expand Down
4 changes: 2 additions & 2 deletions src/render.c
Original file line number Diff line number Diff line change
Expand Up @@ -561,8 +561,8 @@ void paint_one(session_t *ps, struct win *w, const struct window_options *w_opts
}

// Dimming the window if needed
if (w_opts->dim) {
double dim_opacity = ps->o.inactive_dim;
if (w_opts->dim > 0) {
double dim_opacity = w_opts->dim;
if (!ps->o.inactive_dim_fixed) {
dim_opacity *= window_opacity;
}
Expand Down
21 changes: 9 additions & 12 deletions src/renderer/command_builder.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,14 @@
static inline unsigned
commands_for_window_body(struct layer *layer, struct backend_command *cmd,
const region_t *frame_region, bool inactive_dim_fixed,
double inactive_dim, double max_brightness) {
double max_brightness) {
auto w = layer->win;
scoped_region_t crop = region_from_box(layer->crop);
auto mode = win_calc_mode_raw(layer->win);
int border_width = w->g.border_width;
double dim = 0;
if (layer->options.dim) {
dim = inactive_dim;
if (!inactive_dim_fixed) {
dim *= layer->opacity;
}
double dim = layer->options.dim;
if (!inactive_dim_fixed) {
dim *= layer->opacity;
}
if (border_width == 0) {
// Some WM has borders implemented as WM frames
Expand Down Expand Up @@ -363,9 +360,9 @@ void command_builder_free(struct command_builder *cb) {

// TODO(yshui) reduce the number of parameters by storing the final effective parameter
// value in `struct managed_win`.
void command_builder_build(struct command_builder *cb, struct layout *layout, bool force_blend,
bool blur_frame, bool inactive_dim_fixed, double max_brightness,
double inactive_dim, const struct x_monitors *monitors,
void command_builder_build(struct command_builder *cb, struct layout *layout,
bool force_blend, bool blur_frame, bool inactive_dim_fixed,
double max_brightness, const struct x_monitors *monitors,
const struct win_option *wintype_options) {

unsigned ncmds = 1;
Expand Down Expand Up @@ -398,8 +395,8 @@ void command_builder_build(struct command_builder *cb, struct layout *layout, bo
layer->window.origin.y);

// Add window body
cmd -= commands_for_window_body(layer, cmd, &frame_region, inactive_dim_fixed,
inactive_dim, max_brightness);
cmd -= commands_for_window_body(layer, cmd, &frame_region,
inactive_dim_fixed, max_brightness);

// Add shadow
cmd -= command_for_shadow(layer, cmd, wintype_options, monitors, last + 1);
Expand Down
6 changes: 3 additions & 3 deletions src/renderer/command_builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ void command_builder_command_list_free(struct backend_command *cmds);
/// It is guaranteed that each of the command's region of operation (e.g. the mask.region
/// argument of blit), will be store in `struct backend_command::mask`. This might not
/// stay true after further passes.
void command_builder_build(struct command_builder *cb, struct layout *layout, bool force_blend,
bool blur_frame, bool inactive_dim_fixed, double max_brightness,
double inactive_dim, const struct x_monitors *monitors,
void command_builder_build(struct command_builder *cb, struct layout *layout,
bool force_blend, bool blur_frame, bool inactive_dim_fixed,
double max_brightness, const struct x_monitors *monitors,
const struct win_option *wintype_options);
11 changes: 5 additions & 6 deletions src/renderer/renderer.c
Original file line number Diff line number Diff line change
Expand Up @@ -486,11 +486,10 @@ void renderer_ensure_images_ready(struct renderer *r, struct backend_base *backe
/// @return true if a frame is rendered, false if this frame is skipped.
bool renderer_render(struct renderer *r, struct backend_base *backend,
image_handle root_image, struct layout_manager *lm,
struct command_builder *cb, void *blur_context,
uint64_t render_start_us, xcb_sync_fence_t xsync_fence,
bool use_damage, bool monitor_repaint, bool force_blend,
bool blur_frame, bool inactive_dim_fixed, double max_brightness,
double inactive_dim, const struct x_monitors *monitors,
struct command_builder *cb, void *blur_context, uint64_t render_start_us,
xcb_sync_fence_t xsync_fence, bool use_damage, bool monitor_repaint,
bool force_blend, bool blur_frame, bool inactive_dim_fixed,
double max_brightness, const struct x_monitors *monitors,
const struct win_option *wintype_options, uint64_t *after_damage_us) {
if (xsync_fence != XCB_NONE) {
// Trigger the fence but don't immediately wait on it. Let it run
Expand All @@ -512,7 +511,7 @@ bool renderer_render(struct renderer *r, struct backend_base *backend,
renderer_ensure_images_ready(r, backend, monitor_repaint);

command_builder_build(cb, layout, force_blend, blur_frame, inactive_dim_fixed,
max_brightness, inactive_dim, monitors, wintype_options);
max_brightness, monitors, wintype_options);
if (log_get_level_tls() <= LOG_LEVEL_TRACE) {
auto layer = layout->layers - 1;
auto layer_end = &layout->commands[layout->first_layer_start];
Expand Down
9 changes: 4 additions & 5 deletions src/renderer/renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@ struct renderer *renderer_new(struct backend_base *backend, double shadow_radius
struct color shadow_color, bool dithered_present);
bool renderer_render(struct renderer *r, struct backend_base *backend,
image_handle root_image, struct layout_manager *lm,
struct command_builder *cb, void *blur_context,
uint64_t render_start_us, xcb_sync_fence_t xsync_fence,
bool use_damage, bool monitor_repaint, bool force_blend,
bool blur_frame, bool inactive_dim_fixed, double max_brightness,
double inactive_dim, const struct x_monitors *monitors,
struct command_builder *cb, void *blur_context, uint64_t render_start_us,
xcb_sync_fence_t xsync_fence, bool use_damage, bool monitor_repaint,
bool force_blend, bool blur_frame, bool inactive_dim_fixed,
double max_brightness, const struct x_monitors *monitors,
const struct win_option *wintype_options, uint64_t *after_damage_us);
6 changes: 3 additions & 3 deletions src/wm/win.c
Original file line number Diff line number Diff line change
Expand Up @@ -875,9 +875,9 @@ static void win_update_dim(session_t *ps, struct win *w, bool focused) {
}

if (ps->o.inactive_dim > 0 && !focused) {
w->options.dim = TRI_TRUE;
w->options.dim = ps->o.inactive_dim;
} else {
w->options.dim = TRI_FALSE;
w->options.dim = 0;
}
}

Expand Down Expand Up @@ -1017,7 +1017,7 @@ static void win_determine_rounded_corners(session_t *ps, struct win *w) {

// Don't round full screen windows & excluded windows,
// unless we find a corner override in corner_radius_rules
if (!matched && w && w->is_fullscreen) {
if (!matched && w->is_fullscreen) {
w->options.corner_radius = 0;
log_debug("Not rounding corners for window %#010x", win_id(w));
} else {
Expand Down
6 changes: 3 additions & 3 deletions src/wm/win.h
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ static const struct window_maybe_options WIN_MAYBE_OPTIONS_DEFAULT = {
.fade = TRI_UNKNOWN,
.invert_color = TRI_UNKNOWN,
.paint = TRI_UNKNOWN,
.dim = TRI_UNKNOWN,
.dim = NAN,
.opacity = NAN,
.shader = NULL,
.corner_radius = -1,
Expand All @@ -320,11 +320,11 @@ win_maybe_options_fold(struct window_maybe_options upper, struct window_maybe_op
.blur_background = tri_or(upper.blur_background, lower.blur_background),
.clip_shadow_above = tri_or(upper.clip_shadow_above, lower.clip_shadow_above),
.shadow = tri_or(upper.shadow, lower.shadow),
.dim = tri_or(upper.dim, lower.dim),
.fade = tri_or(upper.fade, lower.fade),
.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,
.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 @@ -340,11 +340,11 @@ win_maybe_options_or(struct window_maybe_options maybe, struct window_options de
.shadow = tri_or_bool(maybe.shadow, def.shadow),
.corner_radius = maybe.corner_radius >= 0 ? (unsigned int)maybe.corner_radius
: def.corner_radius,
.dim = tri_or_bool(maybe.dim, def.dim),
.fade = tri_or_bool(maybe.fade, def.fade),
.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,
.dim = !safe_isnan(maybe.dim) ? maybe.dim : def.dim,
.shader = maybe.shader ? maybe.shader : def.shader,
};
}
Expand Down

0 comments on commit d85bd2b

Please sign in to comment.