1
0
Fork 0
mirror of https://github.com/davatorium/rofi.git synced 2024-11-18 13:54:36 -05:00

Grab mouse pointer with keyboard.

This commit is contained in:
Dave Davenport 2016-05-09 08:47:28 +02:00
parent 171d132b9b
commit bd412b9975
5 changed files with 32 additions and 1 deletions

View file

@ -5,6 +5,7 @@ unreleased
- Allow user to specify background image. - Allow user to specify background image.
- Improved keybinding handling, allowing on-release and modifier only (#384). - Improved keybinding handling, allowing on-release and modifier only (#384).
Bug fixes Bug fixes
- Grab mouse pointer with keyboard
1.0.1 1.0.1
Bug fixes Bug fixes

View file

@ -64,6 +64,7 @@ int monitor_get_smallest_size ( void );
* Release keyboard. * Release keyboard.
*/ */
void release_keyboard ( void ); void release_keyboard ( void );
void release_pointer ( void );
/** /**
* @param w xcb_window_t we want to grab keyboard on. * @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. * @return 1 when keyboard is grabbed, 0 not.
*/ */
int take_keyboard ( xcb_window_t w ); int take_keyboard ( xcb_window_t w );
int take_pointer ( xcb_window_t w );
/** /**
* @param mask The mask to canonilize * @param mask The mask to canonilize

View file

@ -151,6 +151,7 @@ static void teardown ( int pfd )
// Release the window. // Release the window.
release_keyboard ( ); release_keyboard ( );
release_pointer ( );
// Cleanup view // Cleanup view
rofi_view_cleanup (); rofi_view_cleanup ();

View file

@ -1680,6 +1680,7 @@ RofiViewState *rofi_view_create ( Mode *sw,
rofi_view_free ( state ); rofi_view_free ( state );
return NULL; return NULL;
} }
take_pointer ( xcb_stuff_get_root_window ( xcb ) );
} }
TICK_N ( "Grab keyboard" ); TICK_N ( "Grab keyboard" );
// Get active monitor size. // 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 ); fprintf ( stderr, "Failed to grab keyboard, even after %d uS.", 500 * 1000 );
return FALSE; return FALSE;
} }
take_pointer ( xcb_stuff_get_root_window ( xcb ) );
} }
rofi_view_calculate_window_and_element_width ( state ); rofi_view_calculate_window_and_element_width ( state );

View file

@ -360,7 +360,28 @@ void monitor_active ( workarea *mon )
monitor_dimensions ( 0, 0, 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 ) int take_keyboard ( xcb_window_t w )
{ {
for ( int i = 0; i < 500; i++ ) { for ( int i = 0; i < 500; i++ ) {
@ -389,6 +410,10 @@ void release_keyboard ( void )
{ {
xcb_ungrab_keyboard ( xcb->connection, XCB_CURRENT_TIME ); 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, ... ) static unsigned int x11_find_mod_mask ( xkb_stuff *xkb, ... )
{ {