From f613df48d23e3f934129c79726d438ee19f2400c Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Mon, 18 Apr 2011 19:28:03 +0200 Subject: [PATCH] =?utf8?q?Bugfix:=20Check=20if=20a=20floating=20window?= =?utf8?q?=E2=80=99s=20coordinates=20are=20within=20a=20different=20worksp?= =?utf8?q?ace=20when=20managing=20(Thanks=20Merovius)?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Fixes: #297 --- include/floating.h | 7 +++++++ src/floating.c | 41 +++++++++++++++++++++++++++-------------- 2 files changed, 34 insertions(+), 14 deletions(-) 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(); } -- 2.39.5