diff options
author | Dave Davenport <qball@gmpclient.org> | 2016-05-09 08:47:28 +0200 |
---|---|---|
committer | Dave Davenport <qball@gmpclient.org> | 2016-05-09 08:47:28 +0200 |
commit | bd412b9975b06c03a7d2e44b0ac1240ec713e9d3 (patch) | |
tree | ec2383cbdd410f9d1124f10fc6148ad7fdcdae10 /source/x11-helper.c | |
parent | 171d132b9bd36aa142bb52f58f9c68bebe5e42b2 (diff) |
Grab mouse pointer with keyboard.
Diffstat (limited to 'source/x11-helper.c')
-rw-r--r-- | source/x11-helper.c | 27 |
1 files changed, 26 insertions, 1 deletions
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, ... ) { |