From 07c73842727c6a5fd3094dddda5e0b016b123edd Mon Sep 17 00:00:00 2001 From: Orestis Floros Date: Fri, 10 Apr 2020 12:22:24 +0200 Subject: [PATCH 1/8] route_click: Add some const bools for readability --- src/click.c | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/src/click.c b/src/click.c index 811f74d50..ee23c9d59 100644 --- a/src/click.c +++ b/src/click.c @@ -160,9 +160,6 @@ static void route_click(Con *con, xcb_button_press_event_t *event, const bool mo if (con->parent->type == CT_DOCKAREA) goto done; - const bool is_left_or_right_click = (event->detail == XCB_BUTTON_CLICK_LEFT || - event->detail == XCB_BUTTON_CLICK_RIGHT); - /* if the user has bound an action to this click, it should override the * default behavior. */ if (dest == CLICK_DECORATION || dest == CLICK_INSIDE || dest == CLICK_BORDER) { @@ -207,14 +204,16 @@ static void route_click(Con *con, xcb_button_press_event_t *event, const bool mo const bool proportional = (event->state & XCB_KEY_BUT_MASK_SHIFT) == XCB_KEY_BUT_MASK_SHIFT; const bool in_stacked = (con->parent->layout == L_STACKED || con->parent->layout == L_TABBED); const bool was_focused = focused == con; + const bool is_left_click = (event->detail == XCB_BUTTON_CLICK_LEFT); + const bool is_right_click = (event->detail == XCB_BUTTON_CLICK_RIGHT); + const bool is_left_or_right_click = (is_left_click || is_right_click); + const bool is_scroll = (event->detail == XCB_BUTTON_SCROLL_UP || + event->detail == XCB_BUTTON_SCROLL_DOWN || + event->detail == XCB_BUTTON_SCROLL_LEFT || + event->detail == XCB_BUTTON_SCROLL_RIGHT); /* 1: see if the user scrolled on the decoration of a stacked/tabbed con */ - if (in_stacked && - dest == CLICK_DECORATION && - (event->detail == XCB_BUTTON_SCROLL_UP || - event->detail == XCB_BUTTON_SCROLL_DOWN || - event->detail == XCB_BUTTON_SCROLL_LEFT || - event->detail == XCB_BUTTON_SCROLL_RIGHT)) { + if (in_stacked && dest == CLICK_DECORATION && is_scroll) { DLOG("Scrolling on a window decoration\n"); /* Use the focused child of the tabbed / stacked container, not the * container the user scrolled on. */ @@ -235,7 +234,7 @@ static void route_click(Con *con, xcb_button_press_event_t *event, const bool mo Con *fs = con_get_fullscreen_covering_ws(ws); if (floatingcon != NULL && fs != con) { /* 4: floating_modifier plus left mouse button drags */ - if (mod_pressed && event->detail == XCB_BUTTON_CLICK_LEFT) { + if (mod_pressed && is_left_click) { floating_drag_window(floatingcon, event, false); return; } @@ -243,7 +242,7 @@ static void route_click(Con *con, xcb_button_press_event_t *event, const bool mo /* 5: resize (floating) if this was a (left or right) click on the * left/right/bottom border, or a right click on the decoration. * also try resizing (tiling) if possible */ - if (mod_pressed && event->detail == XCB_BUTTON_CLICK_RIGHT) { + if (mod_pressed && is_right_click) { DLOG("floating resize due to floatingmodifier\n"); floating_resize_window(floatingcon, proportional, event); return; @@ -257,7 +256,7 @@ static void route_click(Con *con, xcb_button_press_event_t *event, const bool mo goto done; } - if (dest == CLICK_DECORATION && event->detail == XCB_BUTTON_CLICK_RIGHT) { + if (dest == CLICK_DECORATION && is_right_click) { DLOG("floating resize due to decoration right click\n"); floating_resize_window(floatingcon, proportional, event); return; @@ -271,7 +270,7 @@ static void route_click(Con *con, xcb_button_press_event_t *event, const bool mo /* 6: dragging, if this was a click on a decoration (which did not lead * to a resize) */ - if (dest == CLICK_DECORATION && event->detail == XCB_BUTTON_CLICK_LEFT) { + if (dest == CLICK_DECORATION && is_left_click) { floating_drag_window(floatingcon, event, !was_focused); return; } @@ -280,7 +279,7 @@ static void route_click(Con *con, xcb_button_press_event_t *event, const bool mo } /* 7: floating modifier pressed, initiate a resize */ - if (dest == CLICK_INSIDE && mod_pressed && event->detail == XCB_BUTTON_CLICK_RIGHT) { + if (dest == CLICK_INSIDE && mod_pressed && is_right_click) { floating_mod_on_tiled_client(con, event); /* Avoid propagating events to clients, since the user expects * $mod + click to be handled by i3. */ From 58d383b1a07a083911343201cb7f9f38a61355a0 Mon Sep 17 00:00:00 2001 From: Orestis Floros Date: Fri, 10 Apr 2020 12:24:18 +0200 Subject: [PATCH 2/8] route_click: Remove condition that is always true For reference: typedef enum { CLICK_BORDER = 0, CLICK_DECORATION = 1, CLICK_INSIDE = 2 } click_destination_t; --- src/click.c | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/src/click.c b/src/click.c index ee23c9d59..12e391b53 100644 --- a/src/click.c +++ b/src/click.c @@ -162,21 +162,18 @@ static void route_click(Con *con, xcb_button_press_event_t *event, const bool mo /* if the user has bound an action to this click, it should override the * default behavior. */ - if (dest == CLICK_DECORATION || dest == CLICK_INSIDE || dest == CLICK_BORDER) { - Binding *bind = get_binding_from_xcb_event((xcb_generic_event_t *)event); - - if (bind != NULL && ((dest == CLICK_DECORATION && !bind->exclude_titlebar) || - (dest == CLICK_INSIDE && bind->whole_window) || - (dest == CLICK_BORDER && bind->border))) { - CommandResult *result = run_binding(bind, con); - - /* ASYNC_POINTER eats the event */ - xcb_allow_events(conn, XCB_ALLOW_ASYNC_POINTER, event->time); - xcb_flush(conn); + Binding *bind = get_binding_from_xcb_event((xcb_generic_event_t *)event); + if (bind && ((dest == CLICK_DECORATION && !bind->exclude_titlebar) || + (dest == CLICK_INSIDE && bind->whole_window) || + (dest == CLICK_BORDER && bind->border))) { + CommandResult *result = run_binding(bind, con); + + /* ASYNC_POINTER eats the event */ + xcb_allow_events(conn, XCB_ALLOW_ASYNC_POINTER, event->time); + xcb_flush(conn); - command_result_free(result); - return; - } + command_result_free(result); + return; } /* There is no default behavior for button release events so we are done. */ From 57a37f8af46b54a018a2007b3afceadcf2bf2020 Mon Sep 17 00:00:00 2001 From: Orestis Floros Date: Fri, 10 Apr 2020 16:41:36 +0200 Subject: [PATCH 3/8] run_command: Update outdated docstring --- src/ipc.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/ipc.c b/src/ipc.c index 100e1f70c..368bea52e 100644 --- a/src/ipc.c +++ b/src/ipc.c @@ -217,8 +217,7 @@ void ipc_shutdown(shutdown_reason_t reason, int exempt_fd) { } /* - * Executes the command and returns whether it could be successfully parsed - * or not (at the moment, always returns true). + * Executes the given command. * */ IPC_HANDLER(run_command) { From 964456b628523c9e8d5cb182d11837ad51b0dae9 Mon Sep 17 00:00:00 2001 From: Orestis Floros Date: Fri, 10 Apr 2020 16:41:51 +0200 Subject: [PATCH 4/8] Limit log length with IPC commands Fixes #3525 --- src/commands.c | 2 +- src/commands_parser.c | 2 +- src/ipc.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/commands.c b/src/commands.c index 14bd877dc..ddc659ebc 100644 --- a/src/commands.c +++ b/src/commands.c @@ -766,7 +766,7 @@ void cmd_border(I3_CMD, const char *border_style_str, long border_width) { */ void cmd_nop(I3_CMD, const char *comment) { LOG("-------------------------------------------------\n"); - LOG(" NOP: %s\n", comment); + LOG(" NOP: %.4000s\n", comment); LOG("-------------------------------------------------\n"); ysuccess(true); } diff --git a/src/commands_parser.c b/src/commands_parser.c index f734a7aa3..2fd763095 100644 --- a/src/commands_parser.c +++ b/src/commands_parser.c @@ -263,7 +263,7 @@ char *parse_string(const char **walk, bool as_word) { * Free the returned CommandResult with command_result_free(). */ CommandResult *parse_command(const char *input, yajl_gen gen, ipc_client *client) { - DLOG("COMMAND: *%s*\n", input); + DLOG("COMMAND: *%.4000s*\n", input); state = INITIAL; CommandResult *result = scalloc(1, sizeof(CommandResult)); diff --git a/src/ipc.c b/src/ipc.c index 368bea52e..75fa8ee74 100644 --- a/src/ipc.c +++ b/src/ipc.c @@ -224,7 +224,7 @@ IPC_HANDLER(run_command) { /* To get a properly terminated buffer, we copy * message_size bytes out of the buffer */ char *command = sstrndup((const char *)message, message_size); - LOG("IPC: received: *%s*\n", command); + LOG("IPC: received: *%.4000s*\n", command); yajl_gen gen = yajl_gen_alloc(NULL); CommandResult *result = parse_command(command, gen, client); From e4cfb80a056cfbab86b74b68ce9ac90fca94e074 Mon Sep 17 00:00:00 2001 From: Orestis Floros Date: Sat, 11 Apr 2020 10:10:44 +0200 Subject: [PATCH 5/8] Fix trailing whitespace in a DLOG --- src/window.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/window.c b/src/window.c index 369aaa96b..d84f8869a 100644 --- a/src/window.c +++ b/src/window.c @@ -288,7 +288,7 @@ bool window_update_normal_hints(i3Window *win, xcb_get_property_reply_t *reply, ASSIGN_IF_CHANGED(win->max_width, max_width); ASSIGN_IF_CHANGED(win->max_height, max_height); } else { - DLOG("Clearing maximum size \n"); + DLOG("Clearing maximum size\n"); ASSIGN_IF_CHANGED(win->max_width, 0); ASSIGN_IF_CHANGED(win->max_height, 0); From bb8f2927aec8801040086bd4cb828b6eeb39763d Mon Sep 17 00:00:00 2001 From: Orestis Floros Date: Sat, 11 Apr 2020 10:52:35 +0200 Subject: [PATCH 6/8] Call tree_render if floating move changes workspace This fixes a bug where moving a floating container with cmd_move_direction displays a "broken" state if the container crosses workspace boundaries. --- src/commands.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/commands.c b/src/commands.c index 14bd877dc..ae3e09a92 100644 --- a/src/commands.c +++ b/src/commands.c @@ -1526,7 +1526,7 @@ void cmd_move_direction(I3_CMD, const char *direction_str, long move_px) { break; } - floating_reposition(current->con->parent, newrect); + cmd_output->needs_tree_render = floating_reposition(current->con->parent, newrect); } else { tree_move(current->con, direction); cmd_output->needs_tree_render = true; From 755d306df3aab4f1117b852c183bbc49b9ef1be2 Mon Sep 17 00:00:00 2001 From: Orestis Floros Date: Sat, 11 Apr 2020 11:08:55 +0200 Subject: [PATCH 7/8] Revert "floating_reposition: avoid extra tree_render" This reverts commit 204eefc67975f0ed1afb3b513f8fc4eb2020d2f6. workspace_show does not call tree_render --- src/floating.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/floating.c b/src/floating.c index 2bf9ae944..6fd9d9c9e 100644 --- a/src/floating.c +++ b/src/floating.c @@ -745,16 +745,13 @@ bool floating_reposition(Con *con, Rect newrect) { con->rect = newrect; - bool reassigned = floating_maybe_reassign_ws(con); + floating_maybe_reassign_ws(con); /* If this is a scratchpad window, don't auto center it from now on. */ if (con->scratchpad_state == SCRATCHPAD_FRESH) con->scratchpad_state = SCRATCHPAD_CHANGED; - /* Workspace change will already result in a tree_render. */ - if (!reassigned) { - tree_render(); - } + tree_render(); return true; } From 5eab604a105f10f2ae275f2c05989ccd19b3373a Mon Sep 17 00:00:00 2001 From: Orestis Floros Date: Sat, 11 Apr 2020 11:10:51 +0200 Subject: [PATCH 8/8] floating_maybe_reassign_ws: only re-focus if previously focused Fixes #3979 --- src/floating.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/floating.c b/src/floating.c index 2bf9ae944..d12aabc49 100644 --- a/src/floating.c +++ b/src/floating.c @@ -514,9 +514,15 @@ bool floating_maybe_reassign_ws(Con *con) { Con *content = output_get_content(output->con); Con *ws = TAILQ_FIRST(&(content->focus_head)); DLOG("Moving con %p / %s to workspace %p / %s\n", con, con->name, ws, ws->name); + Con *needs_focus = con_descend_focused(con); + if (!con_inside_focused(needs_focus)) { + needs_focus = NULL; + } con_move_to_workspace(con, ws, false, true, false); - workspace_show(ws); - con_activate(con_descend_focused(con)); + if (needs_focus) { + workspace_show(ws); + con_activate(needs_focus); + } return true; }