win: break win_set_focused into 2 functions

Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
This commit is contained in:
Yuxuan Shui 2019-05-24 23:13:24 +01:00
parent 51476cafa4
commit 98d351ecf6
No known key found for this signature in database
GPG Key ID: 37C999F617EA1A47
3 changed files with 18 additions and 19 deletions

View File

@ -344,7 +344,7 @@ void recheck_focus(session_t *ps) {
// And we set the focus state here
if (w) {
win_set_focused(ps, w, true);
win_set_focused(ps, w);
return;
}
}
@ -864,7 +864,7 @@ void update_ewmh_active_win(session_t *ps) {
// Mark the window focused. No need to unfocus the previous one.
if (w) {
win_set_focused(ps, w, true);
win_set_focused(ps, w);
}
}

View File

@ -1356,25 +1356,27 @@ static void win_on_focus_change(session_t *ps, struct managed_win *w) {
#endif
}
static void win_unset_focused(session_t *ps, struct managed_win *w) {
if (w == ps->active_win) {
ps->active_win = NULL;
}
}
/**
* Set real focused state of a window.
*/
void win_set_focused(session_t *ps, struct managed_win *w, bool focused) {
void win_set_focused(session_t *ps, struct managed_win *w) {
// Unmapped windows will have their focused state reset on map
if (w->a.map_state == XCB_MAP_STATE_UNMAPPED)
if (w->a.map_state != XCB_MAP_STATE_VIEWABLE) {
return;
}
if (win_is_focused_real(ps, w) == focused)
if (win_is_focused_real(ps, w)) {
return;
}
if (focused) {
if (ps->active_win)
win_set_focused(ps, ps->active_win, false);
ps->active_win = w;
} else if (w == ps->active_win)
ps->active_win = NULL;
assert(win_is_focused_real(ps, w) == focused);
ps->active_win = w;
assert(win_is_focused_real(ps, w));
win_on_focus_change(ps, w);
}
@ -1598,10 +1600,7 @@ static void finish_destroy_win(session_t *ps, struct managed_win **_w) {
log_trace("Trying to destroy (%#010x)", w->base.id);
list_remove(&w->base.stack_neighbour);
if (w == ps->active_win) {
ps->active_win = NULL;
}
win_unset_focused(ps, w);
free_win_res(ps, w);
// Drop w from all prev_trans to avoid accessing freed memory in
@ -1770,7 +1769,7 @@ void unmap_win(session_t *ps, struct managed_win **_w, bool destroy) {
}
// Set focus out
win_set_focused(ps, w, false);
win_unset_focused(ps, w);
w->a.map_state = XCB_MAP_STATE_UNMAPPED;
w->state = target_state;

View File

@ -335,7 +335,7 @@ void win_set_invert_color_force(session_t *ps, struct managed_win *w, switch_t v
/**
* Set real focused state of a window.
*/
void win_set_focused(session_t *ps, struct managed_win *w, bool focused);
void win_set_focused(session_t *ps, struct managed_win *w);
bool attr_pure win_should_fade(session_t *ps, const struct managed_win *w);
void win_update_prop_shadow_raw(session_t *ps, struct managed_win *w);
void win_update_prop_shadow(session_t *ps, struct managed_win *w);