diff --git a/src/event.c b/src/event.c index 065e75b76e..be9df40a48 100644 --- a/src/event.c +++ b/src/event.c @@ -352,7 +352,6 @@ static inline void ev_create_notify(session_t *ps, xcb_create_notify_event_t *ev /// Handle configure event of a regular window static void configure_win(session_t *ps, xcb_configure_notify_event_t *ce) { auto cursor = wm_find(ps->wm, ce->window); - auto below = wm_find(ps->wm, ce->above_sibling); if (!cursor) { if (wm_is_consistent(ps->wm)) { @@ -363,17 +362,7 @@ static void configure_win(session_t *ps, xcb_configure_notify_event_t *ce) { return; } - if (below == NULL && ce->above_sibling != XCB_NONE) { - log_error("Configure event received for window %#010x, but its sibling " - "window %#010x is not in our tree. Expect malfunction.", - ce->window, ce->above_sibling); - assert(false); - } else if (below != NULL) { - wm_stack_move_to_above(ps->wm, cursor, below); - } else { - // above_sibling being XCB_NONE means the window is put at the bottom. - wm_stack_move_to_end(ps->wm, cursor, true); - } + wm_stack_move_to_above(ps->wm, cursor, ce->above_sibling); auto w = wm_ref_deref(cursor); if (!w) { diff --git a/src/wm/wm.c b/src/wm/wm.c index f0b3536044..f38902043e 100644 --- a/src/wm/wm.c +++ b/src/wm/wm.c @@ -266,16 +266,31 @@ void wm_refresh_leaders(struct wm *wm) { } } -/// Move window `w` so it's right above `below`, if `below` is 0, `w` is moved +/// Move window `w` so it's right above `below`, if `below` is XCB_NONE, `w` is moved /// to the bottom of the stack -void wm_stack_move_to_above(struct wm *wm, struct wm_ref *cursor, struct wm_ref *below) { +void wm_stack_move_to_above(struct wm *wm, struct wm_ref *cursor, xcb_window_t below) { + BUG_ON_NULL(cursor); auto node = to_tree_node_mut(cursor); if (node->parent == &wm->orphan_root) { // If this window is orphaned, moving it around its siblings is // meaningless. Same below. + log_debug("Ignoring restack request for orphaned window %#010x", node->id.x); return; } - wm_tree_move_to_above(&wm->tree, node, to_tree_node_mut(below)); + if (below == XCB_NONE) { + // `below` being XCB_NONE means the window is put at the bottom. + wm_tree_move_to_end(&wm->tree, node, /*to_bottom=*/true); + return; + } + + auto below_node = wm_tree_find(&wm->tree, below); + if (below_node == NULL) { + log_error("Trying to restack window %#010x, but its sibling window " + "%#010x is not in our tree. Expect malfunction.", + node->id.x, below); + assert(false); + } + wm_tree_move_to_above(&wm->tree, node, below_node); } void wm_stack_move_to_end(struct wm *wm, struct wm_ref *cursor, bool to_bottom) { diff --git a/src/wm/wm.h b/src/wm/wm.h index 7bb0facc32..421cd7a7b9 100644 --- a/src/wm/wm.h +++ b/src/wm/wm.h @@ -137,7 +137,7 @@ struct wm_ref *attr_pure wm_ref_bottommost_child(const struct wm_ref *cursor); /// Move window `w` so it's right above `below`, if `below` is 0, `w` is moved /// to the bottom of the stack -void wm_stack_move_to_above(struct wm *wm, struct wm_ref *cursor, struct wm_ref *below); +void wm_stack_move_to_above(struct wm *wm, struct wm_ref *cursor, xcb_window_t below); /// Move window `w` to the top of the stack. void wm_stack_move_to_end(struct wm *wm, struct wm_ref *cursor, bool to_bottom);