/* Drag the window */
drag_result_t drag_result = drag_pointer(con, event, XCB_NONE, BORDER_TOP /* irrelevant */, XCURSOR_CURSOR_MOVE, drag_window_callback, event);
+ if (!con_exists(con)) {
+ DLOG("The container has been closed in the meantime.\n");
+ return;
+ }
+
/* If the user cancelled, undo the changes. */
if (drag_result == DRAG_REVERT)
floating_reposition(con, initial_rect);
drag_result_t drag_result = drag_pointer(con, event, XCB_NONE, BORDER_TOP /* irrelevant */, cursor, resize_window_callback, ¶ms);
+ if (!con_exists(con)) {
+ DLOG("The container has been closed in the meantime.\n");
+ return;
+ }
+
/* If the user cancels, undo the resize */
if (drag_result == DRAG_REVERT)
floating_reposition(con, initial_rect);
if (last_motion_notify == NULL)
return;
- dragloop->callback(
- dragloop->con,
- &(dragloop->old_rect),
- last_motion_notify->root_x,
- last_motion_notify->root_y,
- dragloop->extra);
+ /* Ensure that we are either dragging the resize handle (con is NULL) or that the
+ * container still exists. The latter might not be true, e.g., if the window closed
+ * for any reason while the user was dragging it. */
+ if (!dragloop->con || con_exists(dragloop->con)) {
+ dragloop->callback(
+ dragloop->con,
+ &(dragloop->old_rect),
+ last_motion_notify->root_x,
+ last_motion_notify->root_y,
+ dragloop->extra);
+ }
free(last_motion_notify);
}