Skip to content

Commit

Permalink
event: don't complain if an orphaned window's sibling isn't found
Browse files Browse the repository at this point in the history
Orphaned windows aren't expected to have all of their siblings in the
tree, so this is normal. And we aren't going to move orphaned windows in
the stack anyway, so this is harmless.

Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
  • Loading branch information
yshui committed Sep 13, 2024
1 parent 3820c33 commit 3899d2c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 16 deletions.
13 changes: 1 addition & 12 deletions src/event.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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) {
Expand Down
22 changes: 19 additions & 3 deletions src/wm/wm.c
Original file line number Diff line number Diff line change
Expand Up @@ -266,16 +266,32 @@ 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);
return;
}
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) {
Expand Down
2 changes: 1 addition & 1 deletion src/wm/wm.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 3899d2c

Please sign in to comment.