diff --git a/src/event.c b/src/event.c index 77b20cadaf..67cdaaaffa 100644 --- a/src/event.c +++ b/src/event.c @@ -277,9 +277,6 @@ static void configure_win(session_t *ps, xcb_configure_notify_event_t *ce) { w->pending_g.border_width = ce->border_width; win_set_flags(w, WIN_FLAGS_SIZE_STALE); } - - // Recalculate which monitor this window is on - win_update_monitor(&ps->monitors, w); } // override_redirect flag cannot be changed after window creation, as far diff --git a/src/render.c b/src/render.c index 1e80623ae6..a20651954a 100644 --- a/src/render.c +++ b/src/render.c @@ -1121,18 +1121,20 @@ void paint_all(session_t *ps, struct win *t) { pixman_region32_subtract(®_tmp, ®_tmp, &bshape_no_corners); } - if (ps->o.crop_shadow_to_monitor && w->randr_monitor >= 0 && - w->randr_monitor < ps->monitors.count) { - // There can be a window where number of monitors is - // updated, but the monitor number attached to the window - // have not. - // - // Window monitor number will be updated eventually, so - // here we just check to make sure we don't access out of - // bounds. - pixman_region32_intersect( - ®_tmp, ®_tmp, - &ps->monitors.regions[w->randr_monitor]); + if (ps->o.crop_shadow_to_monitor) { + auto monitor_index = win_find_monitor(&ps->monitors, w); + if (monitor_index >= 0) { + // There can be a window where number of monitors + // is updated, but the monitor number attached to + // the window have not. + // + // Window monitor number will be updated + // eventually, so here we just check to make sure + // we don't access out of bounds. + pixman_region32_intersect( + ®_tmp, ®_tmp, + &ps->monitors.regions[monitor_index]); + } } // Detect if the region is empty before painting diff --git a/src/renderer/command_builder.c b/src/renderer/command_builder.c index b4228cd435..a2aa1b9614 100644 --- a/src/renderer/command_builder.c +++ b/src/renderer/command_builder.c @@ -135,9 +135,12 @@ command_for_shadow(struct layer *layer, struct backend_command *cmd, } } log_region(TRACE, &cmd->target_mask); - if (monitors && w->randr_monitor >= 0 && w->randr_monitor < monitors->count) { - pixman_region32_intersect(&cmd->target_mask, &cmd->target_mask, - &monitors->regions[w->randr_monitor]); + if (monitors) { + auto monitor_index = win_find_monitor(monitors, w); + if (monitor_index >= 0) { + pixman_region32_intersect(&cmd->target_mask, &cmd->target_mask, + &monitors->regions[monitor_index]); + } } log_region(TRACE, &cmd->target_mask); if (w->corner_radius > 0) { diff --git a/src/wm/win.c b/src/wm/win.c index af3bde3055..eef92171dc 100644 --- a/src/wm/win.c +++ b/src/wm/win.c @@ -538,8 +538,6 @@ void win_process_update_flags(session_t *ps, struct win *w) { damaged = true; win_clear_flags(w, WIN_FLAGS_POSITION_STALE); } - - win_update_monitor(&ps->monitors, w); } if (win_check_flags_all(w, WIN_FLAGS_PROPERTY_STALE)) { @@ -1401,7 +1399,6 @@ struct win *win_maybe_allocate(session_t *ps, struct wm_ref *cursor) { .focused_force = UNSET, .invert_color_force = UNSET, - .randr_monitor = -1, .mode = WMODE_TRANS, .leader = XCB_NONE, .cache_leader = XCB_NONE, @@ -1983,9 +1980,10 @@ void unmap_win_start(struct win *w) { } struct win_script_context win_script_context_prepare(struct session *ps, struct win *w) { + auto monitor_index = win_find_monitor(&ps->monitors, w); auto monitor = - (w->randr_monitor >= 0 && w->randr_monitor < ps->monitors.count) - ? *pixman_region32_extents(&ps->monitors.regions[w->randr_monitor]) + monitor_index >= 0 + ? *pixman_region32_extents(&ps->monitors.regions[monitor_index]) : (pixman_box32_t){ .x1 = 0, .y1 = 0, .x2 = ps->root_width, .y2 = ps->root_height}; struct win_script_context ret = { @@ -2158,24 +2156,23 @@ bool win_process_animation_and_state_change(struct session *ps, struct win *w, d #undef WSTATE_PAIR -// TODO(absolutelynothelix): rename to x_update_win_(randr_?)monitor and move to -// the x.c. -void win_update_monitor(struct x_monitors *monitors, struct win *mw) { - mw->randr_monitor = -1; +/// Find which monitor a window is on. +int win_find_monitor(const struct x_monitors *monitors, const struct win *mw) { + int ret = -1; for (int i = 0; i < monitors->count; i++) { auto e = pixman_region32_extents(&monitors->regions[i]); if (e->x1 <= mw->g.x && e->y1 <= mw->g.y && e->x2 >= mw->g.x + mw->widthb && e->y2 >= mw->g.y + mw->heightb) { - mw->randr_monitor = i; log_debug("Window %#010x (%s), %dx%d+%dx%d, is entirely on the " "monitor %d (%dx%d+%dx%d)", win_id(mw), mw->name, mw->g.x, mw->g.y, mw->widthb, mw->heightb, i, e->x1, e->y1, e->x2 - e->x1, e->y2 - e->y1); - return; + return i; } } log_debug("Window %#010x (%s), %dx%d+%dx%d, is not entirely on any monitor", win_id(mw), mw->name, mw->g.x, mw->g.y, mw->widthb, mw->heightb); + return ret; } /// Start the mapping of a window. We cannot map immediately since we might need to fade diff --git a/src/wm/win.h b/src/wm/win.h index d82a0fb90b..9e498e3591 100644 --- a/src/wm/win.h +++ b/src/wm/win.h @@ -114,8 +114,6 @@ struct win { struct win_geometry g; /// Updated geometry received in events struct win_geometry pending_g; - /// X RandR monitor this window is on. - int randr_monitor; /// Window visual pict format const xcb_render_pictforminfo_t *pictfmt; /// Client window visual pict format @@ -372,7 +370,7 @@ void win_on_client_update(session_t *ps, struct win *w); bool attr_pure win_should_dim(session_t *ps, const struct win *w); -void win_update_monitor(struct x_monitors *monitors, struct win *mw); +int attr_pure win_find_monitor(const struct x_monitors *monitors, const struct win *mw); /// Recheck if a window is fullscreen void win_update_is_fullscreen(const session_t *ps, struct win *w);