Don't call map_win() in add_win()

Only case where you want to map window in add_win() is during compton
startup, when compton is registering existing windows. Otherwise,
add_win() is always called for newly created windows, so there will
always be a MapNotify coming up for that window. If we map newly created
windows in add_win(), we will try to map it a second time when the MapNotify
arrives.

So, just don't call map_win() from add_win(). For compton startup, we
explicitly call map_win() after calling add_win() in session_init.

Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
This commit is contained in:
Yuxuan Shui 2019-02-21 02:29:06 +00:00
parent ff37cf9756
commit 6c71146f1c
No known key found for this signature in database
GPG Key ID: 37C999F617EA1A47
4 changed files with 39 additions and 27 deletions

View File

@ -1240,7 +1240,7 @@ ev_destroy_notify(session_t *ps, xcb_destroy_notify_event_t *ev) {
inline static void inline static void
ev_map_notify(session_t *ps, xcb_map_notify_event_t *ev) { ev_map_notify(session_t *ps, xcb_map_notify_event_t *ev) {
map_win(ps, ev->window); map_win_by_id(ps, ev->window);
// FocusIn/Out may be ignored when the window is unmapped, so we must // FocusIn/Out may be ignored when the window is unmapped, so we must
// recheck focus here // recheck focus here
if (ps->o.track_focus) { if (ps->o.track_focus) {
@ -2771,6 +2771,12 @@ session_init(int argc, char **argv, Display *dpy, const char *config_file,
add_win(ps, children[i], i ? children[i-1] : XCB_NONE); add_win(ps, children[i], i ? children[i-1] : XCB_NONE);
} }
for (win *i = ps->list; i; i = i->next) {
if (i->a.map_state == XCB_MAP_STATE_VIEWABLE) {
map_win(ps, i);
}
}
free(reply); free(reply);
log_trace("Initial stack:"); log_trace("Initial stack:");
for (win *c = ps->list; c; c = c->next) { for (win *c = ps->list; c; c = c->next) {

View File

@ -41,8 +41,6 @@ find_client_win(session_t *ps, xcb_window_t w);
win *find_toplevel2(session_t *ps, xcb_window_t wid); win *find_toplevel2(session_t *ps, xcb_window_t wid);
void map_win(session_t *ps, xcb_window_t id);
/** /**
* Subtract two unsigned long values. * Subtract two unsigned long values.
* *

View File

@ -945,10 +945,6 @@ void add_win(session_t *ps, xcb_window_t id, xcb_window_t prev) {
cdbus_ev_win_added(ps, new); cdbus_ev_win_added(ps, new);
} }
#endif #endif
if (new->a.map_state == XCB_MAP_STATE_VIEWABLE) {
map_win(ps, id);
}
return; return;
} }
@ -1547,29 +1543,16 @@ void win_update_screen(session_t *ps, win *w) {
void configure_win(session_t *, xcb_configure_notify_event_t *); void configure_win(session_t *, xcb_configure_notify_event_t *);
/// Map an already registered window /// Map an already registered window
void void map_win(session_t *ps, win *w) {
map_win(session_t *ps, xcb_window_t id) { assert(w);
// Unmap overlay window if it got mapped but we are currently not
// in redirected state.
if (ps->overlay && id == ps->overlay && !ps->redirected) {
log_debug("Overlay is mapped while we are not redirected");
auto e = xcb_request_check(ps->c, xcb_unmap_window(ps->c, ps->overlay));
if (e) {
log_error("Failed to unmap the overlay window");
free(e);
}
// We don't track the overlay window, so we can return
return;
}
win *w = find_win(ps, id);
// Don't care about window mapping if it's an InputOnly window // Don't care about window mapping if it's an InputOnly window
// Also, try avoiding mapping a window twice // Also, try avoiding mapping a window twice
if (!w || w->a._class == XCB_WINDOW_CLASS_INPUT_ONLY) { if (w->a._class == XCB_WINDOW_CLASS_INPUT_ONLY) {
return; return;
} }
log_debug("Mapping (%#010x \"%s\")", id, w->name); log_debug("Mapping (%#010x \"%s\")", w->id, w->name);
if (w->state != WSTATE_UNMAPPED && w->state != WSTATE_UNMAPPING) { if (w->state != WSTATE_UNMAPPED && w->state != WSTATE_UNMAPPING) {
log_warn("Mapping an already mapped window"); log_warn("Mapping an already mapped window");
@ -1586,12 +1569,12 @@ map_win(session_t *ps, xcb_window_t id) {
// Set window event mask before reading properties so that no property // Set window event mask before reading properties so that no property
// changes are lost // changes are lost
xcb_change_window_attributes(ps->c, id, XCB_CW_EVENT_MASK, xcb_change_window_attributes(ps->c, w->id, XCB_CW_EVENT_MASK,
(const uint32_t[]) { determine_evmask(ps, id, WIN_EVMODE_FRAME) }); (const uint32_t[]) { determine_evmask(ps, w->id, WIN_EVMODE_FRAME) });
// Notify compton when the shape of a window changes // Notify compton when the shape of a window changes
if (ps->shape_exists) { if (ps->shape_exists) {
xcb_shape_select_input(ps->c, id, 1); xcb_shape_select_input(ps->c, w->id, 1);
} }
// Update window mode here to check for ARGB windows // Update window mode here to check for ARGB windows
@ -1659,5 +1642,27 @@ map_win(session_t *ps, xcb_window_t id) {
} }
} }
void map_win_by_id(session_t *ps, xcb_window_t id) {
// Unmap overlay window if it got mapped but we are currently not
// in redirected state.
if (ps->overlay && id == ps->overlay && !ps->redirected) {
log_debug("Overlay is mapped while we are not redirected");
auto e = xcb_request_check(ps->c, xcb_unmap_window(ps->c, ps->overlay));
if (e) {
log_error("Failed to unmap the overlay window");
free(e);
}
// We don't track the overlay window, so we can return
return;
}
win *w = find_win(ps, id);
if (!w) {
return;
}
map_win(ps, w);
}
// vim: set et sw=2 : // vim: set et sw=2 :

View File

@ -359,6 +359,9 @@ void add_win(session_t *ps, xcb_window_t id, xcb_window_t prev);
/// Unmap or destroy a window /// Unmap or destroy a window
void unmap_win(session_t *ps, win **, bool destroy); void unmap_win(session_t *ps, win **, bool destroy);
void map_win(session_t *ps, win *w);
void map_win_by_id(session_t *ps, xcb_window_t id);
/** /**
* Execute fade callback of a window if fading finished. * Execute fade callback of a window if fading finished.
*/ */