1
0
Fork 0
mirror of https://github.com/yshui/picom.git synced 2025-02-24 16:06:42 -05:00

win: store focused state in struct managed_win

So we don't need the whole session_t just to check if a window is
focused.

Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
This commit is contained in:
Yuxuan Shui 2024-02-15 00:07:31 +00:00
parent f509008cb9
commit 7e7c2b0cef
No known key found for this signature in database
GPG key ID: D3A4405BE6CC17F4
4 changed files with 21 additions and 18 deletions

View file

@ -1383,9 +1383,7 @@ static inline void c2_match_once_leaf(session_t *ps, const struct managed_win *w
case C2_L_PFULLSCREEN: predef_target = w->is_fullscreen; 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_POVREDIR: predef_target = w->a.override_redirect; break;
case C2_L_PARGB: predef_target = win_has_alpha(w); break; case C2_L_PARGB: predef_target = win_has_alpha(w); break;
case C2_L_PFOCUSED: case C2_L_PFOCUSED: predef_target = win_is_focused_raw(w); break;
predef_target = win_is_focused_raw(ps, w);
break;
case C2_L_PWMWIN: predef_target = w->wmwin; break; case C2_L_PWMWIN: predef_target = w->wmwin; break;
case C2_L_PBSHAPED: predef_target = w->bounding_shaped; break; case C2_L_PBSHAPED: predef_target = w->bounding_shaped; break;
case C2_L_PROUNDED: predef_target = w->rounded_corners; break; case C2_L_PROUNDED: predef_target = w->rounded_corners; break;

View file

@ -906,7 +906,7 @@ cdbus_process_window_property_get(session_t *ps, DBusMessage *msg, cdbus_window_
} }
if (!strcmp("RawFocused", target)) { if (!strcmp("RawFocused", target)) {
cdbus_reply(ps, msg, cdbus_append_bool_variant, cdbus_reply(ps, msg, cdbus_append_bool_variant,
(bool[]){win_is_focused_raw(ps, w)}); (bool[]){win_is_focused_raw(w)});
return true; return true;
} }
@ -976,7 +976,7 @@ static bool cdbus_process_win_get(session_t *ps, DBusMessage *msg) {
cdbus_m_win_get_do(wmwin, cdbus_reply_bool); cdbus_m_win_get_do(wmwin, cdbus_reply_bool);
cdbus_m_win_get_do(leader, cdbus_reply_wid); cdbus_m_win_get_do(leader, cdbus_reply_wid);
if (!strcmp("focused_raw", target)) { if (!strcmp("focused_raw", target)) {
cdbus_reply_bool(ps, msg, win_is_focused_raw(ps, w)); cdbus_reply_bool(ps, msg, win_is_focused_raw(w));
return true; return true;
} }
cdbus_m_win_get_do(fade_force, cdbus_reply_enum); cdbus_m_win_get_do(fade_force, cdbus_reply_enum);

View file

@ -139,10 +139,10 @@ static inline bool attr_pure win_is_real_visible(const struct managed_win *w) {
* Update focused state of a window. * Update focused state of a window.
*/ */
static void win_update_focused(session_t *ps, struct managed_win *w) { static void win_update_focused(session_t *ps, struct managed_win *w) {
if (UNSET != w->focused_force) { if (w->focused_force != UNSET) {
w->focused = w->focused_force; w->focused = w->focused_force;
} else { } else {
w->focused = win_is_focused_raw(ps, w); w->focused = win_is_focused_raw(w);
// Use wintype_focus, and treat WM windows and override-redirected // Use wintype_focus, and treat WM windows and override-redirected
// windows specially // windows specially
@ -210,7 +210,7 @@ static inline bool group_is_focused(session_t *ps, xcb_window_t leader) {
continue; continue;
} }
auto mw = (struct managed_win *)w; auto mw = (struct managed_win *)w;
if (win_get_leader(ps, mw) == leader && win_is_focused_raw(ps, mw)) { if (win_get_leader(ps, mw) == leader && win_is_focused_raw(mw)) {
return true; return true;
} }
} }
@ -843,7 +843,7 @@ double win_calc_opacity_target(session_t *ps, const struct managed_win *w) {
} else { } else {
// Respect active_opacity only when the window is physically // Respect active_opacity only when the window is physically
// focused // focused
if (win_is_focused_raw(ps, w)) { if (win_is_focused_raw(w)) {
opacity = ps->o.active_opacity; opacity = ps->o.active_opacity;
} else if (!w->focused) { } else if (!w->focused) {
// Respect inactive_opacity in some cases // Respect inactive_opacity in some cases
@ -1792,7 +1792,7 @@ static inline void win_set_leader(session_t *ps, struct managed_win *w, xcb_wind
// Update the old and new window group and active_leader if the // Update the old and new window group and active_leader if the
// window could affect their state. // window could affect their state.
xcb_window_t cache_leader = win_get_leader(ps, w); xcb_window_t cache_leader = win_get_leader(ps, w);
if (win_is_focused_raw(ps, w) && cache_leader_old != cache_leader) { if (win_is_focused_raw(w) && cache_leader_old != cache_leader) {
ps->active_leader = cache_leader; ps->active_leader = cache_leader;
group_on_factor_change(ps, cache_leader_old); group_on_factor_change(ps, cache_leader_old);
@ -1905,7 +1905,7 @@ static void win_on_focus_change(session_t *ps, struct managed_win *w) {
xcb_window_t leader = win_get_leader(ps, w); xcb_window_t leader = win_get_leader(ps, w);
// If the window gets focused, replace the old active_leader // If the window gets focused, replace the old active_leader
if (win_is_focused_raw(ps, w) && leader != ps->active_leader) { if (win_is_focused_raw(w) && leader != ps->active_leader) {
xcb_window_t active_leader_old = ps->active_leader; xcb_window_t active_leader_old = ps->active_leader;
ps->active_leader = leader; ps->active_leader = leader;
@ -1914,7 +1914,7 @@ static void win_on_focus_change(session_t *ps, struct managed_win *w) {
group_on_factor_change(ps, leader); group_on_factor_change(ps, leader);
} }
// If the group get unfocused, remove it from active_leader // If the group get unfocused, remove it from active_leader
else if (!win_is_focused_raw(ps, w) && leader && else if (!win_is_focused_raw(w) && leader &&
leader == ps->active_leader && !group_is_focused(ps, leader)) { leader == ps->active_leader && !group_is_focused(ps, leader)) {
ps->active_leader = XCB_NONE; ps->active_leader = XCB_NONE;
group_on_factor_change(ps, leader); group_on_factor_change(ps, leader);
@ -1927,7 +1927,7 @@ static void win_on_focus_change(session_t *ps, struct managed_win *w) {
#ifdef CONFIG_DBUS #ifdef CONFIG_DBUS
// Send D-Bus signal // Send D-Bus signal
if (ps->o.dbus) { if (ps->o.dbus) {
if (win_is_focused_raw(ps, w)) { if (win_is_focused_raw(w)) {
cdbus_ev_win_focusin(ps, &w->base); cdbus_ev_win_focusin(ps, &w->base);
} else { } else {
cdbus_ev_win_focusout(ps, &w->base); cdbus_ev_win_focusout(ps, &w->base);
@ -1945,15 +1945,18 @@ void win_set_focused(session_t *ps, struct managed_win *w) {
return; return;
} }
if (win_is_focused_raw(ps, w)) { if (w->is_ewmh_focused) {
assert(ps->active_win == w);
return; return;
} }
auto old_active_win = ps->active_win; auto old_active_win = ps->active_win;
ps->active_win = w; ps->active_win = w;
assert(win_is_focused_raw(ps, w)); w->is_ewmh_focused = true;
if (old_active_win) { if (old_active_win) {
assert(old_active_win->is_ewmh_focused);
old_active_win->is_ewmh_focused = false;
win_on_focus_change(ps, old_active_win); win_on_focus_change(ps, old_active_win);
} }
win_on_focus_change(ps, w); win_on_focus_change(ps, w);
@ -2866,8 +2869,8 @@ bool win_is_bypassing_compositor(const session_t *ps, const struct managed_win *
* Check if a window is focused, without using any focus rules or forced focus * Check if a window is focused, without using any focus rules or forced focus
* settings * settings
*/ */
bool win_is_focused_raw(const session_t *ps, const struct managed_win *w) { bool win_is_focused_raw(const struct managed_win *w) {
return w->a.map_state == XCB_MAP_STATE_VIEWABLE && ps->active_win == w; return w->a.map_state == XCB_MAP_STATE_VIEWABLE && w->is_ewmh_focused;
} }
// Find the managed window immediately below `i` in the window stack // Find the managed window immediately below `i` in the window stack

View file

@ -205,6 +205,8 @@ struct managed_win {
/// `is_ewmh_fullscreen`, or the windows spatial relation with the /// `is_ewmh_fullscreen`, or the windows spatial relation with the
/// root window. Which one is used is determined by user configuration. /// root window. Which one is used is determined by user configuration.
bool is_fullscreen; bool is_fullscreen;
/// Whether the window is the EWMH active window.
bool is_ewmh_focused;
// Opacity-related members // Opacity-related members
/// Current window opacity. /// Current window opacity.
@ -435,7 +437,7 @@ struct managed_win *find_managed_window_or_parent(session_t *ps, xcb_window_t wi
/** /**
* Check if a window is focused, without using any focus rules or forced focus settings * Check if a window is focused, without using any focus rules or forced focus settings
*/ */
bool attr_pure win_is_focused_raw(const session_t *ps, const struct managed_win *w); bool attr_pure win_is_focused_raw(const struct managed_win *w);
/// check if window has ARGB visual /// check if window has ARGB visual
bool attr_pure win_has_alpha(const struct managed_win *w); bool attr_pure win_has_alpha(const struct managed_win *w);