diff --git a/Changelog b/Changelog index ce546cfa..6967363a 100644 --- a/Changelog +++ b/Changelog @@ -5,6 +5,7 @@ unreleased - Allow user to specify background image. - Improved keybinding handling, allowing on-release and modifier only (#384). Bug fixes + - Grab mouse pointer with keyboard 1.0.1 Bug fixes diff --git a/include/x11-helper.h b/include/x11-helper.h index ef761bd9..f35e20a0 100644 --- a/include/x11-helper.h +++ b/include/x11-helper.h @@ -64,6 +64,7 @@ int monitor_get_smallest_size ( void ); * Release keyboard. */ void release_keyboard ( void ); +void release_pointer ( void ); /** * @param w xcb_window_t we want to grab keyboard on. @@ -73,6 +74,7 @@ void release_keyboard ( void ); * @return 1 when keyboard is grabbed, 0 not. */ int take_keyboard ( xcb_window_t w ); +int take_pointer ( xcb_window_t w ); /** * @param mask The mask to canonilize diff --git a/source/rofi.c b/source/rofi.c index b71dd4c0..be1abe10 100644 --- a/source/rofi.c +++ b/source/rofi.c @@ -151,6 +151,7 @@ static void teardown ( int pfd ) // Release the window. release_keyboard ( ); + release_pointer ( ); // Cleanup view rofi_view_cleanup (); diff --git a/source/view.c b/source/view.c index cd77bdf4..b4ba9877 100644 --- a/source/view.c +++ b/source/view.c @@ -1680,6 +1680,7 @@ RofiViewState *rofi_view_create ( Mode *sw, rofi_view_free ( state ); return NULL; } + take_pointer ( xcb_stuff_get_root_window ( xcb ) ); } TICK_N ( "Grab keyboard" ); // Get active monitor size. @@ -1836,6 +1837,7 @@ int rofi_view_error_dialog ( const char *msg, int markup ) fprintf ( stderr, "Failed to grab keyboard, even after %d uS.", 500 * 1000 ); return FALSE; } + take_pointer ( xcb_stuff_get_root_window ( xcb ) ); } rofi_view_calculate_window_and_element_width ( state ); diff --git a/source/x11-helper.c b/source/x11-helper.c index 1ed84c95..29c5e48c 100644 --- a/source/x11-helper.c +++ b/source/x11-helper.c @@ -360,7 +360,28 @@ void monitor_active ( workarea *mon ) monitor_dimensions ( 0, 0, mon ); } - +int take_pointer ( xcb_window_t w ) +{ + for ( int i = 0; i < 500; i++ ) { + if ( xcb_connection_has_error ( xcb->connection ) ) { + fprintf ( stderr, "Connection has error\n" ); + exit ( EXIT_FAILURE ); + } + xcb_grab_pointer_cookie_t cc = xcb_grab_pointer ( xcb->connection, 1, w, XCB_EVENT_MASK_BUTTON_RELEASE, + XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC, w, XCB_NONE, XCB_CURRENT_TIME ); + xcb_grab_pointer_reply_t *r = xcb_grab_pointer_reply ( xcb->connection, cc, NULL ); + if ( r ) { + if ( r->status == XCB_GRAB_STATUS_SUCCESS ) { + free ( r ); + return 1; + } + free ( r ); + } + usleep ( 1000 ); + } + fprintf ( stderr, "Failed to grab pointer.\n" ); + return 0; +} int take_keyboard ( xcb_window_t w ) { for ( int i = 0; i < 500; i++ ) { @@ -389,6 +410,10 @@ void release_keyboard ( void ) { xcb_ungrab_keyboard ( xcb->connection, XCB_CURRENT_TIME ); } +void release_pointer ( void ) +{ + xcb_ungrab_pointer ( xcb->connection, XCB_CURRENT_TIME ); +} static unsigned int x11_find_mod_mask ( xkb_stuff *xkb, ... ) {