From c815fc798d530aaaac1ab3402ccd47defb7bcc0f Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Tue, 10 Feb 2015 17:46:02 -0500 Subject: [PATCH] Handle button release events This enables the --release switch on mouse button bindings. --- docs/userguide | 7 ++++--- src/click.c | 14 ++++++++++---- src/handlers.c | 1 + 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/docs/userguide b/docs/userguide index d6afa334..4b4dacc8 100644 --- a/docs/userguide +++ b/docs/userguide @@ -404,17 +404,18 @@ can configure mouse bindings in a similar way to key bindings. *Syntax*: ---------------------------------- -bindsym [--whole-window] [Modifiers+]button[n] command +bindsym [--release] [--whole-window] [Modifiers+]button[n] command ---------------------------------- By default, the binding will only run when you click on the titlebar of the window. If the +--whole-window+ flag is given, it will run when any part of the -window is clicked. +window is clicked. If the +--release+ flag is given, it will run when the mouse +button is released. *Examples*: -------------------------------- # The middle button over a titlebar kills the window -bindsym button2 kill +bindsym --release button2 kill # The middle button and a modifer over any part of the window kills the window bindsym --whole-window $mod+button2 kill diff --git a/src/click.c b/src/click.c index 86a63ea6..51ffcf3a 100644 --- a/src/click.c +++ b/src/click.c @@ -200,6 +200,11 @@ static int route_click(Con *con, xcb_button_press_event_t *event, const bool mod } } + /* There is no default behavior for button release events so we are done. */ + if (event->response_type == XCB_BUTTON_RELEASE) { + goto done; + } + /* Any click in a workspace should focus that workspace. If the * workspace is on another output we need to do a workspace_show in * order for i3bar (and others) to notice the change in workspace. */ @@ -336,9 +341,10 @@ done: */ int handle_button_press(xcb_button_press_event_t *event) { Con *con; - DLOG("Button %d pressed on window 0x%08x (child 0x%08x) at (%d, %d) (root %d, %d)\n", - event->state, event->event, event->child, event->event_x, event->event_y, - event->root_x, event->root_y); + DLOG("Button %d %s on window 0x%08x (child 0x%08x) at (%d, %d) (root %d, %d)\n", + event->state, (event->response_type == XCB_BUTTON_PRESS ? "press" : "release"), + event->event, event->child, event->event_x, event->event_y, event->root_x, + event->root_y); last_timestamp = event->time; @@ -351,7 +357,7 @@ int handle_button_press(xcb_button_press_event_t *event) { if (!(con = con_by_frame_id(event->event))) { /* If the root window is clicked, find the relevant output from the * click coordinates and focus the output's active workspace. */ - if (event->event == root) { + if (event->event == root && event->response_type == XCB_BUTTON_PRESS) { Con *output, *ws; TAILQ_FOREACH(output, &(croot->nodes_head), nodes) { if (con_is_internal(output) || diff --git a/src/handlers.c b/src/handlers.c index 569a8ec3..7ebb2ccb 100644 --- a/src/handlers.c +++ b/src/handlers.c @@ -1257,6 +1257,7 @@ void handle_event(int type, xcb_generic_event_t *event) { break; case XCB_BUTTON_PRESS: + case XCB_BUTTON_RELEASE: handle_button_press((xcb_button_press_event_t *)event); break; -- 2.39.2