diff options
-rw-r--r-- | Makefile.am | 1 | ||||
-rw-r--r-- | include/xcb-internal.h | 1 | ||||
-rw-r--r-- | source/dialogs/window.c | 2 | ||||
-rw-r--r-- | source/rofi.c | 33 | ||||
-rw-r--r-- | source/x11-helper.c | 66 | ||||
-rw-r--r-- | test/helper-test.c | 3 |
6 files changed, 61 insertions, 45 deletions
diff --git a/Makefile.am b/Makefile.am index 148e2e2b..a9905a92 100644 --- a/Makefile.am +++ b/Makefile.am @@ -237,6 +237,7 @@ helper_test_LDADD=\ $(x11_LIBS)\ $(GW_XCB_LIBS)\ $(xinerama_LIBS)\ + $(libsn_LIBS)\ $(cairo_LIBS) TESTS=\ diff --git a/include/xcb-internal.h b/include/xcb-internal.h index 2b1a6dd4..2f437d20 100644 --- a/include/xcb-internal.h +++ b/include/xcb-internal.h @@ -18,6 +18,7 @@ struct _xcb_stuff int screen_nbr; SnDisplay *sndisplay; SnLauncheeContext *sncontext; + gboolean has_xinerama; }; #endif diff --git a/source/dialogs/window.c b/source/dialogs/window.c index cff9d052..f224f0e6 100644 --- a/source/dialogs/window.c +++ b/source/dialogs/window.c @@ -38,6 +38,8 @@ #include <xcb/xcb_ewmh.h> #include <xcb/xcb_icccm.h> +#include <glib.h> + #include "xcb-internal.h" #include "xcb.h" diff --git a/source/rofi.c b/source/rofi.c index fad7da5e..4055316d 100644 --- a/source/rofi.c +++ b/source/rofi.c @@ -37,6 +37,7 @@ #include <xcb/xcb.h> #include <xcb/xcb_aux.h> #include <xcb/xcb_ewmh.h> +#include <xcb/xinerama.h> #include <xcb/xkb.h> #include <xkbcommon/xkbcommon.h> #include <xkbcommon/xkbcommon-compose.h> @@ -446,6 +447,12 @@ static inline void load_configuration_dynamic ( ) */ static gboolean main_loop_x11_event_handler ( xcb_generic_event_t *ev, G_GNUC_UNUSED gpointer data ) { + if ( ev == NULL ) { + int status = xcb_connection_has_error ( xcb->connection ); + fprintf ( stderr, "The XCB connection to X server had a fatal error: %d\n", status ); + g_main_loop_quit ( main_loop ); + return G_SOURCE_REMOVE; + } uint8_t type = ev->response_type & ~0x80; if ( type == xkb.first_event ) { switch ( ev->pad0 ) @@ -739,16 +746,42 @@ int main ( int argc, char *argv[] ) fprintf ( stderr, "Failed to get keyboard compose table. Trying to limp on.\n" ); } + if ( xcb_connection_has_error ( xcb->connection ) ) { + fprintf ( stderr, "Connection has error\n" ); + exit ( EXIT_FAILURE ); + } x11_setup ( &xkb ); + if ( xcb_connection_has_error ( xcb->connection ) ) { + fprintf ( stderr, "Connection has error\n" ); + exit ( EXIT_FAILURE ); + } + + const xcb_query_extension_reply_t *er = xcb_get_extension_data ( xcb->connection, &xcb_xinerama_id ); + if ( er ) { + if ( er->present ) { + xcb_xinerama_is_active_cookie_t is_active_req = xcb_xinerama_is_active ( xcb->connection ); + xcb_xinerama_is_active_reply_t *is_active = xcb_xinerama_is_active_reply ( xcb->connection, is_active_req, NULL ); + xcb->has_xinerama = is_active->state; + free ( is_active ); + } + } main_loop = g_main_loop_new ( NULL, FALSE ); TICK_N ( "Setup mainloop" ); // startup not. xcb->sndisplay = sn_xcb_display_new ( xcb->connection, error_trap_push, error_trap_pop ); + if ( xcb_connection_has_error ( xcb->connection ) ) { + fprintf ( stderr, "Connection has error\n" ); + exit ( EXIT_FAILURE ); + } if ( xcb->sndisplay != NULL ) { xcb->sncontext = sn_launchee_context_new_from_environment ( xcb->sndisplay, xcb->screen_nbr ); } + if ( xcb_connection_has_error ( xcb->connection ) ) { + fprintf ( stderr, "Connection has error\n" ); + exit ( EXIT_FAILURE ); + } TICK_N ( "Startup Notification" ); // Initialize Xresources subsystem. diff --git a/source/x11-helper.c b/source/x11-helper.c index 98bedb62..699f611a 100644 --- a/source/x11-helper.c +++ b/source/x11-helper.c @@ -52,11 +52,12 @@ #include "xkb-internal.h" struct _xcb_stuff xcb_int = { - .connection = NULL, - .screen = NULL, - .screen_nbr = -1, - .sndisplay = NULL, - .sncontext = NULL, + .connection = NULL, + .screen = NULL, + .screen_nbr = -1, + .sndisplay = NULL, + .sncontext = NULL, + .has_xinerama = FALSE, }; xcb_stuff *xcb = &xcb_int; @@ -104,26 +105,21 @@ void window_set_atom_prop ( xcb_window_t w, xcb_atom_t prop, xcb_atom_t *atoms, int monitor_get_smallest_size ( void ) { - xcb_generic_error_t *error; - int size = MIN ( xcb->screen->width_in_pixels, xcb->screen->height_in_pixels ); - xcb_xinerama_is_active_cookie_t is_active_req = xcb_xinerama_is_active ( xcb->connection ); - xcb_xinerama_is_active_reply_t *is_active = xcb_xinerama_is_active_reply ( xcb->connection, is_active_req, &error ); - if ( error ) { - fprintf ( stderr, "Couldn't query Xinerama\n" ); - return size; - } - if ( is_active == NULL ) { - return size; - } - if ( !is_active->state ) { - free ( is_active ); + xcb_generic_error_t *error; + int size = MIN ( xcb->screen->width_in_pixels, xcb->screen->height_in_pixels ); + + if ( !xcb->has_xinerama ) { return size; } - free ( is_active ); + if ( xcb_connection_has_error ( xcb->connection ) ) { + fprintf ( stderr, "1.Connection has error\n" ); + exit ( EXIT_FAILURE ); + } xcb_xinerama_query_screens_cookie_t cookie_screen; + cookie_screen = xcb_xinerama_query_screens ( xcb->connection ); - xcb_xinerama_query_screens_reply_t *query_screens; + xcb_xinerama_query_screens_reply_t *query_screens; query_screens = xcb_xinerama_query_screens_reply ( xcb->connection, cookie_screen, &error ); if ( error ) { fprintf ( stderr, "Error getting screen info\n" ); @@ -147,20 +143,9 @@ int monitor_get_dimension ( int monitor, workarea *mon ) mon->w = xcb->screen->width_in_pixels; mon->h = xcb->screen->height_in_pixels; - xcb_xinerama_is_active_cookie_t is_active_req = xcb_xinerama_is_active ( xcb->connection ); - xcb_xinerama_is_active_reply_t *is_active = xcb_xinerama_is_active_reply ( xcb->connection, is_active_req, &error ); - if ( error ) { - fprintf ( stderr, "Error getting screen info\n" ); + if ( !xcb->has_xinerama ) { return FALSE; } - if ( is_active == NULL ) { - return FALSE; - } - if ( !is_active->state ) { - free ( is_active ); - return FALSE; - } - free ( is_active ); xcb_xinerama_query_screens_cookie_t cookie_screen; cookie_screen = xcb_xinerama_query_screens ( xcb->connection ); @@ -193,20 +178,9 @@ void monitor_dimensions ( int x, int y, workarea *mon ) mon->w = xcb->screen->width_in_pixels; mon->h = xcb->screen->height_in_pixels; - xcb_xinerama_is_active_cookie_t is_active_req = xcb_xinerama_is_active ( xcb->connection ); - xcb_xinerama_is_active_reply_t *is_active = xcb_xinerama_is_active_reply ( xcb->connection, is_active_req, &error ); - if ( error ) { - fprintf ( stderr, "Couldn't query Xinerama\n" ); + if ( !xcb->has_xinerama ) { return; } - if ( is_active == NULL ) { - return; - } - if ( !is_active->state ) { - free ( is_active ); - return; - } - free ( is_active ); xcb_xinerama_query_screens_cookie_t cookie_screen; cookie_screen = xcb_xinerama_query_screens ( xcb->connection ); @@ -328,6 +302,10 @@ void monitor_active ( workarea *mon ) int take_keyboard ( 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_keyboard_cookie_t cc = xcb_grab_keyboard ( xcb->connection, 1, w, XCB_CURRENT_TIME, XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC ); diff --git a/test/helper-test.c b/test/helper-test.c index 9c7c92fe..2339147b 100644 --- a/test/helper-test.c +++ b/test/helper-test.c @@ -25,9 +25,10 @@ struct xcb_stuff *xcb; } \ } -void rofi_view_error_dialog ( const char *msg, G_GNUC_UNUSED int markup ) +int rofi_view_error_dialog ( const char *msg, G_GNUC_UNUSED int markup ) { fputs ( msg, stderr ); + return TRUE; } int show_error_message ( const char *msg, int markup ) |