Map newly created window in handle_new_window

A window might be mapped before we had the chance to start managing it.
So check to see if we should map a window after we call fill_win on it.

Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
This commit is contained in:
Yuxuan Shui 2019-04-19 21:10:38 +01:00
parent 58944f36ce
commit 0753eaacf8
No known key found for this signature in database
GPG Key ID: 37C999F617EA1A47
3 changed files with 19 additions and 11 deletions

View File

@ -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) { static void handle_new_windows(session_t *ps) {
list_foreach_safe(struct win, w, &ps->window_stack, stack_neighbour) { list_foreach_safe(struct win, w, &ps->window_stack, stack_neighbour) {
if (w->is_new) { 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);
}
} }
} }
} }

View File

@ -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` /// Query the Xorg for information about window `win`
/// `win` pointer might become invalid after this function returns /// `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 = { static const struct managed_win win_def = {
// No need to initialize. (or, you can think that // No need to initialize. (or, you can think that
// they are initialized right here). // they are initialized right here).
@ -1070,16 +1071,18 @@ void fill_win(session_t *ps, struct win *w) {
assert(!w->destroyed); assert(!w->destroyed);
assert(w->is_new); assert(w->is_new);
w->is_new = false;
// Reject overlay window and already added windows // Reject overlay window and already added windows
if (w->id == ps->overlay) { if (w->id == ps->overlay) {
return; return w;
} }
auto duplicated_win = find_managed_win(ps, w->id); auto duplicated_win = find_managed_win(ps, w->id);
if (duplicated_win) { if (duplicated_win) {
log_debug("Window %#010x (recorded name: %s) added multiple times", w->id, log_debug("Window %#010x (recorded name: %s) added multiple times", w->id,
duplicated_win->name); duplicated_win->name);
return; return &duplicated_win->base;
} }
log_debug("Adding window %#010x", w->id); 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 // BTW, we don't care about Input Only windows, except for stacking
// proposes, so we need to keep track of them still. // proposes, so we need to keep track of them still.
free(a); free(a);
return; return w;
} }
if (a->_class == XCB_WINDOW_CLASS_INPUT_ONLY) { if (a->_class == XCB_WINDOW_CLASS_INPUT_ONLY) {
// No need to manage this window, but we still keep it on the window stack // No need to manage this window, but we still keep it on the window stack
w->managed = false; w->managed = false;
w->is_new = false; return w;
return;
} }
// Allocate and initialize the new win structure // Allocate and initialize the new win structure
@ -1111,7 +1113,6 @@ void fill_win(session_t *ps, struct win *w) {
// by map_win // by map_win
*new = win_def; *new = win_def;
new->base = *w; new->base = *w;
new->base.is_new = false;
new->base.managed = true; new->base.managed = true;
new->a = *a; new->a = *a;
pixman_region32_init(&new->bounding_shape); pixman_region32_init(&new->bounding_shape);
@ -1126,7 +1127,7 @@ void fill_win(session_t *ps, struct win *w) {
if (e) { if (e) {
free(e); free(e);
free(new); free(new);
return; return w;
} }
new->pictfmt = x_get_pictform_for_visual(ps->c, new->a.visual); 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); cdbus_ev_win_added(ps, &new->base);
} }
#endif #endif
return; return &new->base;
} }
/** /**

View File

@ -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); struct win *add_win_top(session_t *ps, xcb_window_t id);
/// Query the Xorg for information about window `win` /// Query the Xorg for information about window `win`
/// `win` pointer might become invalid after this function returns /// `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 /// Unmap or destroy a window
void unmap_win(session_t *ps, struct managed_win **, bool destroy); void unmap_win(session_t *ps, struct managed_win **, bool destroy);
/// Destroy an unmanaged window /// Destroy an unmanaged window