summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorQuentin Glidic <sardemff7+git@sardemff7.net>2017-06-01 11:57:57 +0200
committerQuentin Glidic <sardemff7+git@sardemff7.net>2017-06-01 11:57:57 +0200
commit000dce1083c2599467e108d6e571955a5a0a1ae5 (patch)
treed2a92a23ed35654f7b0adf9d51c4b897a57b0de9
parentf042851add70c9af0adc2b3017dedbb563c9ca3a (diff)
xcb: Hide grab details
Signed-off-by: Quentin Glidic <sardemff7+git@sardemff7.net>
-rw-r--r--include/xcb.h2
-rw-r--r--source/rofi.c65
-rw-r--r--source/xcb.c62
3 files changed, 67 insertions, 62 deletions
diff --git a/include/xcb.h b/include/xcb.h
index 0c89bb30..26163ca6 100644
--- a/include/xcb.h
+++ b/include/xcb.h
@@ -210,7 +210,7 @@ extern xcb_visualtype_t *visual;
*/
extern xcb_colormap_t map;
-void x11_late_setup ( void );
+gboolean x11_late_setup ( void );
/**
* Gets a surface containing the background image of the desktop.
diff --git a/source/rofi.c b/source/rofi.c
index b22e3e25..f06657d1 100644
--- a/source/rofi.c
+++ b/source/rofi.c
@@ -600,38 +600,6 @@ static gboolean main_loop_signal_handler_int ( G_GNUC_UNUSED gpointer data )
return G_SOURCE_CONTINUE;
}
-/** Retry count of grabbing keyboard. */
-unsigned int lazy_grab_retry_count_kb = 0;
-/** Retry count of grabbing pointer. */
-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_pt > ( 5 * 1000 ) ) {
- g_warning ( "Failed to grab pointer after %u times. Giving up.", lazy_grab_retry_count_pt );
- return G_SOURCE_REMOVE;
- }
- if ( take_pointer ( xcb_stuff_get_root_window (), 0 ) ) {
- return G_SOURCE_REMOVE;
- }
- lazy_grab_retry_count_pt++;
- return G_SOURCE_CONTINUE;
-}
-static gboolean lazy_grab_keyboard ( G_GNUC_UNUSED gpointer data )
-{
- // After 5 sec.
- if ( lazy_grab_retry_count_kb > ( 5 * 1000 ) ) {
- g_warning ( "Failed to grab keyboard after %u times. Giving up.", lazy_grab_retry_count_kb );
- g_main_loop_quit ( main_loop );
- return G_SOURCE_REMOVE;
- }
- if ( take_keyboard ( xcb_stuff_get_root_window (), 0 ) ) {
- return G_SOURCE_REMOVE;
- }
- lazy_grab_retry_count_kb++;
- return G_SOURCE_CONTINUE;
-}
-
static gboolean startup ( G_GNUC_UNUSED gpointer data )
{
TICK_N ( "Startup" );
@@ -643,33 +611,6 @@ static gboolean startup ( G_GNUC_UNUSED gpointer data )
if ( find_arg ( "-normal-window" ) >= 0 ) {
window_flags |= MENU_NORMAL_WINDOW;
}
-
- /**
- * Create window (without showing)
- */
- // Try to grab the keyboard as early as possible.
- // We grab this using the rootwindow (as dmenu does it).
- // this seems to result in the smallest delay for most people.
- if ( ( window_flags & MENU_NORMAL_WINDOW ) == 0 ) {
- if ( find_arg ( "-no-lazy-grab" ) >= 0 ) {
- if ( !take_keyboard ( xcb_stuff_get_root_window (), 500 ) ) {
- g_warning ( "Failed to grab keyboard, even after %d uS.", 500 * 1000 );
- g_main_loop_quit ( main_loop );
- return G_SOURCE_REMOVE;
- }
- if ( !take_pointer ( xcb_stuff_get_root_window (), 100 ) ) {
- g_warning ( "Failed to grab mouse pointer, even after %d uS.", 100 * 1000 );
- }
- }
- else {
- if ( !take_keyboard ( xcb_stuff_get_root_window (), 0 ) ) {
- g_timeout_add ( 1, lazy_grab_keyboard, NULL );
- }
- if ( !take_pointer ( xcb_stuff_get_root_window (), 0 ) ) {
- g_timeout_add ( 1, lazy_grab_pointer, NULL );
- }
- }
- }
TICK_N ( "Grab keyboard" );
__create_window ( window_flags );
TICK_N ( "Create Window" );
@@ -949,7 +890,11 @@ int main ( int argc, char *argv[] )
}
textbox_setup ();
- x11_late_setup ();
+ if ( !x11_late_setup () ) {
+ g_warning ( "Failed to properly finish display setup" );
+ cleanup ();
+ return EXIT_FAILURE;
+ }
// Setup signal handling sources.
// SIGINT
diff --git a/source/xcb.c b/source/xcb.c
index 5284be6c..9e2236a2 100644
--- a/source/xcb.c
+++ b/source/xcb.c
@@ -890,9 +890,69 @@ static void x11_create_visual_and_colormap ( void )
}
}
-void x11_late_setup ( void )
+/** Retry count of grabbing keyboard. */
+unsigned int lazy_grab_retry_count_kb = 0;
+/** Retry count of grabbing pointer. */
+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_pt > ( 5 * 1000 ) ) {
+ g_warning ( "Failed to grab pointer after %u times. Giving up.", lazy_grab_retry_count_pt );
+ return G_SOURCE_REMOVE;
+ }
+ if ( take_pointer ( xcb_stuff_get_root_window (), 0 ) ) {
+ return G_SOURCE_REMOVE;
+ }
+ lazy_grab_retry_count_pt++;
+ return G_SOURCE_CONTINUE;
+}
+static gboolean lazy_grab_keyboard ( G_GNUC_UNUSED gpointer data )
+{
+ // After 5 sec.
+ if ( lazy_grab_retry_count_kb > ( 5 * 1000 ) ) {
+ g_warning ( "Failed to grab keyboard after %u times. Giving up.", lazy_grab_retry_count_kb );
+ g_main_loop_quit ( xcb->main_loop );
+ return G_SOURCE_REMOVE;
+ }
+ if ( take_keyboard ( xcb_stuff_get_root_window (), 0 ) ) {
+ return G_SOURCE_REMOVE;
+ }
+ lazy_grab_retry_count_kb++;
+ return G_SOURCE_CONTINUE;
+}
+
+gboolean x11_late_setup ( void )
{
x11_create_visual_and_colormap ();
+
+ /**
+ * Create window (without showing)
+ */
+ // Try to grab the keyboard as early as possible.
+ // We grab this using the rootwindow (as dmenu does it).
+ // this seems to result in the smallest delay for most people.
+ if ( find_arg ( "-normal-window" ) >= 0 ) {
+ return;
+ }
+ if ( find_arg ( "-no-lazy-grab" ) >= 0 ) {
+ if ( !take_keyboard ( xcb_stuff_get_root_window (), 500 ) ) {
+ g_warning ( "Failed to grab keyboard, even after %d uS.", 500 * 1000 );
+ return FALSE;
+ }
+ if ( !take_pointer ( xcb_stuff_get_root_window (), 100 ) ) {
+ g_warning ( "Failed to grab mouse pointer, even after %d uS.", 100 * 1000 );
+ }
+ }
+ else {
+ if ( !take_keyboard ( xcb_stuff_get_root_window (), 0 ) ) {
+ g_timeout_add ( 1, lazy_grab_keyboard, NULL );
+ }
+ if ( !take_pointer ( xcb_stuff_get_root_window (), 0 ) ) {
+ g_timeout_add ( 1, lazy_grab_pointer, NULL );
+ }
+ }
+ return TRUE;
}
xcb_window_t xcb_stuff_get_root_window ( void )