From f613df48d23e3f934129c79726d438ee19f2400c Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Mon, 18 Apr 2011 19:28:03 +0200 Subject: [PATCH] =?UTF-8?q?Bugfix:=20Check=20if=20a=20floating=20window?= =?UTF-8?q?=E2=80=99s=20coordinates=20are=20within=20a=20different=20works?= =?UTF-8?q?pace=20when=20managing=20(Thanks=20Merovius)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes: #297 --- include/floating.h | 7 ++++++ src/floating.c | 53 +++++++++++++++++++++++++++++----------------- 2 files changed, 40 insertions(+), 20 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,6 +227,36 @@ void floating_raise_con(Con *con) { TAILQ_INSERT_TAIL(&(con->parent->floating_head), con, floating_windows); } +/* + * 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 false; + } + + if (con_get_output(con) == output->con) { + DLOG("still the same ws\n"); + return false; + } + + DLOG("Need to re-assign!\n"); + + Con *content = output_get_content(output->con); + Con *ws = TAILQ_FIRST(&(content->nodes_head)); + 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; @@ -237,27 +269,8 @@ DRAGGING_CB(drag_window_callback) { xcb_flush(conn); /* Check if we cross workspace boundaries while moving */ - 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"); + if (!floating_maybe_reassign_ws(con)) return; - } - - if (con_get_output(con) == output->con) { - DLOG("still the same ws\n"); - return; - } - - DLOG("Need to re-assign!\n"); - - Con *content = output_get_content(output->con); - Con *ws = TAILQ_FIRST(&(content->nodes_head)); - 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)); tree_render(); }