mirror of
https://github.com/davatorium/rofi.git
synced 2024-11-25 13:55:34 -05:00
Change keyboard grabbing behaviour, if you fail, continue running and try in background to get them.
This commit is contained in:
parent
129d96928a
commit
051be0cfe6
4 changed files with 52 additions and 15 deletions
|
@ -123,21 +123,23 @@ 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.
|
||||||
|
* @param iters Number of retries.
|
||||||
*
|
*
|
||||||
* Grab keyboard.
|
* Grab keyboard.
|
||||||
*
|
*
|
||||||
* @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 iters );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param w xcb_window_t we want to grab mouse on.
|
* @param w xcb_window_t we want to grab mouse on.
|
||||||
|
* @param iters Number of retries.
|
||||||
*
|
*
|
||||||
* Grab mouse.
|
* Grab mouse.
|
||||||
*
|
*
|
||||||
* @return 1 when mouse is grabbed, 0 not.
|
* @return 1 when mouse is grabbed, 0 not.
|
||||||
*/
|
*/
|
||||||
int take_pointer ( xcb_window_t w );
|
int take_pointer ( xcb_window_t w, int iters );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param mask The mask to canonilize
|
* @param mask The mask to canonilize
|
||||||
|
|
|
@ -576,6 +576,36 @@ static void error_trap_pop ( G_GNUC_UNUSED SnDisplay *display, xcb_connection_t
|
||||||
--error_trap_depth;
|
--error_trap_depth;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsigned int lazy_grab_retry_count_kb = 0;
|
||||||
|
unsigned int lazy_grab_retry_count_pt = 0;
|
||||||
|
static gboolean lazy_grab_pointer ( G_GNUC_UNUSED gpointer data )
|
||||||
|
{
|
||||||
|
// After 5 sec.
|
||||||
|
if ( lazy_grab_retry_count_kb > (5*1000)) {
|
||||||
|
fprintf(stderr, "Failed to grab keyboard after %u times. Giving up.\n", lazy_grab_retry_count_kb);
|
||||||
|
g_main_loop_quit ( main_loop );
|
||||||
|
return G_SOURCE_REMOVE;
|
||||||
|
}
|
||||||
|
if ( take_pointer ( xcb_stuff_get_root_window ( xcb ), 0 ) ){
|
||||||
|
return G_SOURCE_REMOVE;
|
||||||
|
}
|
||||||
|
lazy_grab_retry_count_kb++;
|
||||||
|
return G_SOURCE_CONTINUE;
|
||||||
|
}
|
||||||
|
static gboolean lazy_grab_keyboard ( G_GNUC_UNUSED gpointer data )
|
||||||
|
{
|
||||||
|
// After 5 sec.
|
||||||
|
if ( lazy_grab_retry_count_pt > (5*1000)) {
|
||||||
|
fprintf(stderr, "Failed to grab pointer after %u times. Giving up.\n", lazy_grab_retry_count_pt);
|
||||||
|
return G_SOURCE_REMOVE;
|
||||||
|
}
|
||||||
|
if ( take_keyboard ( xcb_stuff_get_root_window ( xcb), 0 ) ){
|
||||||
|
return G_SOURCE_REMOVE;
|
||||||
|
}
|
||||||
|
lazy_grab_retry_count_pt++;
|
||||||
|
return G_SOURCE_CONTINUE;
|
||||||
|
}
|
||||||
|
|
||||||
static gboolean startup ( G_GNUC_UNUSED gpointer data )
|
static gboolean startup ( G_GNUC_UNUSED gpointer data )
|
||||||
{
|
{
|
||||||
TICK_N ( "Startup" );
|
TICK_N ( "Startup" );
|
||||||
|
@ -595,13 +625,12 @@ static gboolean startup ( G_GNUC_UNUSED gpointer data )
|
||||||
// We grab this using the rootwindow (as dmenu does it).
|
// We grab this using the rootwindow (as dmenu does it).
|
||||||
// this seems to result in the smallest delay for most people.
|
// this seems to result in the smallest delay for most people.
|
||||||
if ( ( window_flags & MENU_NORMAL_WINDOW ) == 0 ) {
|
if ( ( window_flags & MENU_NORMAL_WINDOW ) == 0 ) {
|
||||||
int has_keyboard = take_keyboard ( xcb_stuff_get_root_window ( xcb ) );
|
if ( !take_keyboard ( xcb_stuff_get_root_window ( xcb), 0) ){
|
||||||
if ( !has_keyboard ) {
|
g_timeout_add ( 1,lazy_grab_keyboard, NULL);
|
||||||
fprintf ( stderr, "Failed to grab keyboard, even after %d uS.", 500 * 1000 );
|
}
|
||||||
g_main_loop_quit ( main_loop );
|
if ( !take_pointer ( xcb_stuff_get_root_window ( xcb ), 0 )) {
|
||||||
return G_SOURCE_REMOVE;
|
g_timeout_add ( 1,lazy_grab_pointer, NULL);
|
||||||
}
|
}
|
||||||
take_pointer ( xcb_stuff_get_root_window ( xcb ) );
|
|
||||||
}
|
}
|
||||||
TICK_N ( "Grab keyboard" );
|
TICK_N ( "Grab keyboard" );
|
||||||
__create_window ( window_flags );
|
__create_window ( window_flags );
|
||||||
|
|
|
@ -1266,7 +1266,7 @@ void rofi_view_itterrate ( RofiViewState *state, xcb_generic_event_t *ev, xkb_st
|
||||||
}
|
}
|
||||||
case XCB_FOCUS_IN:
|
case XCB_FOCUS_IN:
|
||||||
if ( ( CacheState.flags & MENU_NORMAL_WINDOW ) == 0 ) {
|
if ( ( CacheState.flags & MENU_NORMAL_WINDOW ) == 0 ) {
|
||||||
take_keyboard ( CacheState.main_window );
|
take_keyboard ( CacheState.main_window, 1);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case XCB_FOCUS_OUT:
|
case XCB_FOCUS_OUT:
|
||||||
|
|
|
@ -515,9 +515,10 @@ int monitor_active ( workarea *mon )
|
||||||
monitor_dimensions ( 0, 0, mon );
|
monitor_dimensions ( 0, 0, mon );
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
int take_pointer ( xcb_window_t w )
|
int take_pointer ( xcb_window_t w, int iters )
|
||||||
{
|
{
|
||||||
for ( int i = 0; i < 500; i++ ) {
|
int i = 0;
|
||||||
|
while ( TRUE ) {
|
||||||
if ( xcb_connection_has_error ( xcb->connection ) ) {
|
if ( xcb_connection_has_error ( xcb->connection ) ) {
|
||||||
fprintf ( stderr, "Connection has error\n" );
|
fprintf ( stderr, "Connection has error\n" );
|
||||||
exit ( EXIT_FAILURE );
|
exit ( EXIT_FAILURE );
|
||||||
|
@ -532,14 +533,17 @@ int take_pointer ( xcb_window_t w )
|
||||||
}
|
}
|
||||||
free ( r );
|
free ( r );
|
||||||
}
|
}
|
||||||
|
if ( (++i) > iters ){
|
||||||
|
break;
|
||||||
|
}
|
||||||
usleep ( 1000 );
|
usleep ( 1000 );
|
||||||
}
|
}
|
||||||
fprintf ( stderr, "Failed to grab pointer.\n" );
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
int take_keyboard ( xcb_window_t w )
|
int take_keyboard ( xcb_window_t w, int iters )
|
||||||
{
|
{
|
||||||
for ( int i = 0; i < 500; i++ ) {
|
int i = 0;
|
||||||
|
while ( TRUE ) {
|
||||||
if ( xcb_connection_has_error ( xcb->connection ) ) {
|
if ( xcb_connection_has_error ( xcb->connection ) ) {
|
||||||
fprintf ( stderr, "Connection has error\n" );
|
fprintf ( stderr, "Connection has error\n" );
|
||||||
exit ( EXIT_FAILURE );
|
exit ( EXIT_FAILURE );
|
||||||
|
@ -555,9 +559,11 @@ int take_keyboard ( xcb_window_t w )
|
||||||
}
|
}
|
||||||
free ( r );
|
free ( r );
|
||||||
}
|
}
|
||||||
|
if ( (++i) > iters ){
|
||||||
|
break;
|
||||||
|
}
|
||||||
usleep ( 1000 );
|
usleep ( 1000 );
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue