@@ -535,6 +535,11 @@ void floating_drag_window(Con *con, const xcb_button_press_event_t *event) {
535
535
/* Drag the window */
536
536
drag_result_t drag_result = drag_pointer (con , event , XCB_NONE , BORDER_TOP /* irrelevant */ , XCURSOR_CURSOR_MOVE , drag_window_callback , event );
537
537
538
+ if (!con_exists (con )) {
539
+ DLOG ("The container has been closed in the meantime.\n" );
540
+ return ;
541
+ }
542
+
538
543
/* If the user cancelled, undo the changes. */
539
544
if (drag_result == DRAG_REVERT )
540
545
floating_reposition (con , initial_rect );
@@ -646,6 +651,11 @@ void floating_resize_window(Con *con, const bool proportional,
646
651
647
652
drag_result_t drag_result = drag_pointer (con , event , XCB_NONE , BORDER_TOP /* irrelevant */ , cursor , resize_window_callback , & params );
648
653
654
+ if (!con_exists (con )) {
655
+ DLOG ("The container has been closed in the meantime.\n" );
656
+ return ;
657
+ }
658
+
649
659
/* If the user cancels, undo the resize */
650
660
if (drag_result == DRAG_REVERT )
651
661
floating_reposition (con , initial_rect );
@@ -743,12 +753,17 @@ static void xcb_drag_check_cb(EV_P_ ev_check *w, int revents) {
743
753
if (last_motion_notify == NULL )
744
754
return ;
745
755
746
- dragloop -> callback (
747
- dragloop -> con ,
748
- & (dragloop -> old_rect ),
749
- last_motion_notify -> root_x ,
750
- last_motion_notify -> root_y ,
751
- dragloop -> extra );
756
+ /* Ensure that we are either dragging the resize handle (con is NULL) or that the
757
+ * container still exists. The latter might not be true, e.g., if the window closed
758
+ * for any reason while the user was dragging it. */
759
+ if (!dragloop -> con || con_exists (dragloop -> con )) {
760
+ dragloop -> callback (
761
+ dragloop -> con ,
762
+ & (dragloop -> old_rect ),
763
+ last_motion_notify -> root_x ,
764
+ last_motion_notify -> root_y ,
765
+ dragloop -> extra );
766
+ }
752
767
free (last_motion_notify );
753
768
}
754
769
0 commit comments