Skip to content

Commit

Permalink
win: remember calculated fullscreen state for window
Browse files Browse the repository at this point in the history
Signed-off-by: Yuxuan Shui <[email protected]>
  • Loading branch information
yshui committed Feb 14, 2024
1 parent 613d179 commit 05b1fbf
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 25 deletions.
4 changes: 1 addition & 3 deletions src/c2.c
Original file line number Diff line number Diff line change
Expand Up @@ -1380,9 +1380,7 @@ static inline void c2_match_once_leaf(session_t *ps, const struct managed_win *w
case C2_L_PWIDTHB: predef_target = w->widthb; break;
case C2_L_PHEIGHTB: predef_target = w->heightb; break;
case C2_L_PBDW: predef_target = w->g.border_width; break;
case C2_L_PFULLSCREEN:
predef_target = win_is_fullscreen(ps, w);
break;
case C2_L_PFULLSCREEN: predef_target = w->is_fullscreen; break;
case C2_L_POVREDIR: predef_target = w->a.override_redirect; break;
case C2_L_PARGB: predef_target = win_has_alpha(w); break;
case C2_L_PFOCUSED:
Expand Down
11 changes: 10 additions & 1 deletion src/picom.c
Original file line number Diff line number Diff line change
Expand Up @@ -791,6 +791,8 @@ static bool initialize_backend(session_t *ps) {

/// Handle configure event of the root window
static void configure_root(session_t *ps) {
// TODO(yshui) re-initializing backend should be done outside of the
// critical section. Probably set a flag and do it in draw_callback_impl.
auto r = XCB_AWAIT(xcb_get_geometry, ps->c.c, ps->c.screen_info->root);
if (!r) {
log_fatal("Failed to fetch root geometry");
Expand Down Expand Up @@ -830,6 +832,13 @@ static void configure_root(session_t *ps) {
top_w->reg_ignore_valid = false;
}

// Whether a window is fullscreen depends on the new screen
// size. So we need to refresh the fullscreen state of all
// windows.
win_stack_foreach_managed(w, &ps->window_stack) {
win_update_is_fullscreen(ps, w);
}

if (ps->redirected) {
for (int i = 0; i < ps->ndamage; i++) {
pixman_region32_clear(&ps->damage_ring[i]);
Expand Down Expand Up @@ -1072,7 +1081,7 @@ static bool paint_preprocess(session_t *ps, bool *fade_running, bool *animation,
// is not correctly set.
if (ps->o.unredir_if_possible && is_highest) {
if (w->mode == WMODE_SOLID && !ps->o.force_win_blend &&
win_is_fullscreen(ps, w) && !w->unredir_if_possible_excluded) {
w->is_fullscreen && !w->unredir_if_possible_excluded) {
unredir_possible = true;
}
}
Expand Down
28 changes: 14 additions & 14 deletions src/win.c
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,9 @@ void win_process_update_flags(session_t *ps, struct managed_win *w) {
// Update window geometry
w->g = w->pending_g;

// Whether a window is fullscreen changes based on its geometry
win_update_is_fullscreen(ps, w);

if (win_check_flags_all(w, WIN_FLAGS_SIZE_STALE)) {
win_on_win_size_change(ps, w);
win_update_bounding_shape(ps, w);
Expand Down Expand Up @@ -1187,7 +1190,7 @@ static void win_determine_rounded_corners(session_t *ps, struct managed_win *w)

// Don't round full screen windows & excluded windows,
// unless we find a corner override in corner_radius_rules
if (!radius_override && ((w && win_is_fullscreen(ps, w)) ||
if (!radius_override && ((w && w->is_fullscreen) ||
c2_match(ps, w, ps->o.rounded_corners_blacklist, NULL))) {
w->corner_radius = 0;
log_debug("Not rounding corners for window %#010x", w->base.id);
Expand Down Expand Up @@ -1254,9 +1257,10 @@ void win_update_opacity_rule(session_t *ps, struct managed_win *w) {
*/
void win_on_factor_change(session_t *ps, struct managed_win *w) {
log_debug("Window %#010x (%s) factor change", w->base.id, w->name);
// Focus needs to be updated first, as other rules might depend on the
// focused state of the window
// Focus and is_fullscreen needs to be updated first, as other rules might depend
// on the focused state of the window
win_update_focused(ps, w);
win_update_is_fullscreen(ps, w);

win_determine_shadow(ps, w);
win_determine_clip_shadow_above(ps, w);
Expand Down Expand Up @@ -2746,13 +2750,6 @@ struct managed_win *find_managed_window_or_parent(session_t *ps, xcb_window_t wi
return (struct managed_win *)w;
}

/**
* Check if a rectangle includes the whole screen.
*/
static inline bool rect_is_fullscreen(const session_t *ps, int x, int y, int wid, int hei) {
return (x <= 0 && y <= 0 && (x + wid) >= ps->root_width && (y + hei) >= ps->root_height);
}

/// Set flags on a window. Some sanity checks are performed
void win_set_flags(struct managed_win *w, uint64_t flags) {
log_debug("Set flags %" PRIu64 " to window %#010x (%s)", flags, w->base.id, w->name);
Expand Down Expand Up @@ -2837,12 +2834,15 @@ bool win_check_flags_all(struct managed_win *w, uint64_t flags) {
*
* It's not using w->border_size for performance measures.
*/
bool win_is_fullscreen(const session_t *ps, const struct managed_win *w) {
void win_update_is_fullscreen(const session_t *ps, struct managed_win *w) {
if (!ps->o.no_ewmh_fullscreen && w->is_ewmh_fullscreen) {
return true;
w->is_fullscreen = true;
return;
}
return rect_is_fullscreen(ps, w->g.x, w->g.y, w->widthb, w->heightb) &&
(!w->bounding_shaped || w->rounded_corners);
w->is_fullscreen = w->g.x <= 0 && w->g.y <= 0 &&
(w->g.x + w->widthb) >= ps->root_width &&
(w->g.y + w->heightb) >= ps->root_height &&
(!w->bounding_shaped || w->rounded_corners);
}

/**
Expand Down
13 changes: 6 additions & 7 deletions src/win.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,10 @@ struct managed_win {
char *role;
/// Whether the window sets the EWMH fullscreen property.
bool is_ewmh_fullscreen;
/// Whether the window should be considered fullscreen. Based on
/// `is_ewmh_fullscreen`, or the windows spatial relation with the
/// root window. Which one is used is determined by user configuration.
bool is_fullscreen;

// Opacity-related members
/// Current window opacity.
Expand Down Expand Up @@ -351,6 +355,8 @@ void win_update_monitor(struct x_monitors *monitors, struct managed_win *mw);
*/
// XXX was win_border_size
void win_update_bounding_shape(session_t *ps, struct managed_win *w);
/// Recheck if a window is fullscreen
void win_update_is_fullscreen(const session_t *ps, struct managed_win *w);
/**
* Check if a window has BYPASS_COMPOSITOR property set
*/
Expand Down Expand Up @@ -426,13 +432,6 @@ struct managed_win *find_toplevel(session_t *ps, xcb_window_t id);
*/
struct managed_win *find_managed_window_or_parent(session_t *ps, xcb_window_t wid);

/**
* Check if a window is a fullscreen window.
*
* It's not using w->border_size for performance measures.
*/
bool attr_pure win_is_fullscreen(const session_t *ps, const struct managed_win *w);

/**
* Check if a window is focused, without using any focus rules or forced focus settings
*/
Expand Down

0 comments on commit 05b1fbf

Please sign in to comment.