From: Michael Stapelberg Date: Mon, 18 Apr 2011 17:28:03 +0000 (+0200) Subject: Bugfix: Check if a floating window’s coordinates are within a different workspace... X-Git-Tag: tree-pr3~75 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=f613df48d23e3f934129c79726d438ee19f2400c;p=i3%2Fi3 Bugfix: Check if a floating window’s coordinates are within a different workspace when managing (Thanks Merovius) Fixes: #297 --- diff --git a/include/floating.h b/include/floating.h index c3935252..6ab4cf2e 100644 --- a/include/floating.h +++ b/include/floating.h @@ -59,6 +59,13 @@ void toggle_floating_mode(Con *con, bool automatic); */ void floating_raise_con(Con *con); +/** + * Checks if con’s coordinates are within its workspace and re-assigns it to + * the actual workspace if not. + * + */ +bool floating_maybe_reassign_ws(Con *con); + #if 0 /** * Removes the floating client from its workspace and attaches it to the new diff --git a/src/floating.c b/src/floating.c index 0f653430..78804c8e 100644 --- a/src/floating.c +++ b/src/floating.c @@ -156,6 +156,8 @@ void floating_enable(Con *con, bool automatic) { // TODO: don’t influence focus handling when Con was not focused before. if (set_focus) con_focus(con); + + floating_maybe_reassign_ws(nc); } void floating_disable(Con *con, bool automatic) { @@ -225,30 +227,24 @@ void floating_raise_con(Con *con) { TAILQ_INSERT_TAIL(&(con->parent->floating_head), con, floating_windows); } -DRAGGING_CB(drag_window_callback) { - struct xcb_button_press_event_t *event = extra; - - /* Reposition the client correctly while moving */ - con->rect.x = old_rect->x + (new_x - event->root_x); - con->rect.y = old_rect->y + (new_y - event->root_y); - - render_con(con, false); - x_push_node(con, true); - xcb_flush(conn); - - /* Check if we cross workspace boundaries while moving */ +/* + * Checks if con’s coordinates are within its workspace and re-assigns it to + * the actual workspace if not. + * + */ +bool floating_maybe_reassign_ws(Con *con) { Output *output = get_output_containing( con->rect.x + (con->rect.width / 2), con->rect.y + (con->rect.height / 2)); if (!output) { ELOG("No output found at destination coordinates?\n"); - return; + return false; } if (con_get_output(con) == output->con) { DLOG("still the same ws\n"); - return; + return false; } DLOG("Need to re-assign!\n"); @@ -258,6 +254,23 @@ DRAGGING_CB(drag_window_callback) { DLOG("Moving con %p / %s to workspace %p / %s\n", con, con->name, ws, ws->name); con_move_to_workspace(con, ws); con_focus(con_descend_focused(con)); + return true; +} + +DRAGGING_CB(drag_window_callback) { + struct xcb_button_press_event_t *event = extra; + + /* Reposition the client correctly while moving */ + con->rect.x = old_rect->x + (new_x - event->root_x); + con->rect.y = old_rect->y + (new_y - event->root_y); + + render_con(con, false); + x_push_node(con, true); + xcb_flush(conn); + + /* Check if we cross workspace boundaries while moving */ + if (!floating_maybe_reassign_ws(con)) + return; tree_render(); }