diff --git a/src/compton.c b/src/compton.c index fb7bb8c..9c56a70 100644 --- a/src/compton.c +++ b/src/compton.c @@ -1373,7 +1373,14 @@ static void handle_queued_x_events(EV_P_ ev_prepare *w, int revents) { static void handle_new_windows(session_t *ps) { list_foreach_safe(struct win, w, &ps->window_stack, stack_neighbour) { if (w->is_new) { - fill_win(ps, w); + auto new_w = fill_win(ps, w); + if (!new_w->managed) { + continue; + } + auto mw = (struct managed_win *)new_w; + if (mw->a.map_state == XCB_MAP_STATE_VIEWABLE) { + map_win(ps, mw); + } } } } diff --git a/src/win.c b/src/win.c index 6a7f541..a6fa0a5 100644 --- a/src/win.c +++ b/src/win.c @@ -989,7 +989,8 @@ struct win *add_win_above(session_t *ps, xcb_window_t id, xcb_window_t below) { /// Query the Xorg for information about window `win` /// `win` pointer might become invalid after this function returns -void fill_win(session_t *ps, struct win *w) { +/// Returns the pointer to the window, might be different from `w` +struct win *fill_win(session_t *ps, struct win *w) { static const struct managed_win win_def = { // No need to initialize. (or, you can think that // they are initialized right here). @@ -1070,16 +1071,18 @@ void fill_win(session_t *ps, struct win *w) { assert(!w->destroyed); assert(w->is_new); + w->is_new = false; + // Reject overlay window and already added windows if (w->id == ps->overlay) { - return; + return w; } auto duplicated_win = find_managed_win(ps, w->id); if (duplicated_win) { log_debug("Window %#010x (recorded name: %s) added multiple times", w->id, duplicated_win->name); - return; + return &duplicated_win->base; } log_debug("Adding window %#010x", w->id); @@ -1093,14 +1096,13 @@ void fill_win(session_t *ps, struct win *w) { // BTW, we don't care about Input Only windows, except for stacking // proposes, so we need to keep track of them still. free(a); - return; + return w; } if (a->_class == XCB_WINDOW_CLASS_INPUT_ONLY) { // No need to manage this window, but we still keep it on the window stack w->managed = false; - w->is_new = false; - return; + return w; } // Allocate and initialize the new win structure @@ -1111,7 +1113,6 @@ void fill_win(session_t *ps, struct win *w) { // by map_win *new = win_def; new->base = *w; - new->base.is_new = false; new->base.managed = true; new->a = *a; pixman_region32_init(&new->bounding_shape); @@ -1126,7 +1127,7 @@ void fill_win(session_t *ps, struct win *w) { if (e) { free(e); free(new); - return; + return w; } new->pictfmt = x_get_pictform_for_visual(ps->c, new->a.visual); @@ -1143,7 +1144,7 @@ void fill_win(session_t *ps, struct win *w) { cdbus_ev_win_added(ps, &new->base); } #endif - return; + return &new->base; } /** diff --git a/src/win.h b/src/win.h index e6876b2..ca96ae0 100644 --- a/src/win.h +++ b/src/win.h @@ -418,7 +418,7 @@ struct win *add_win_above(session_t *ps, xcb_window_t id, xcb_window_t below); struct win *add_win_top(session_t *ps, xcb_window_t id); /// Query the Xorg for information about window `win` /// `win` pointer might become invalid after this function returns -void fill_win(session_t *ps, struct win *win); +struct win *fill_win(session_t *ps, struct win *win); /// Unmap or destroy a window void unmap_win(session_t *ps, struct managed_win **, bool destroy); /// Destroy an unmanaged window