summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
authorQuentin Glidic <sardemff7+git@sardemff7.net>2017-06-01 11:44:21 +0200
committerQuentin Glidic <sardemff7+git@sardemff7.net>2017-06-01 11:44:21 +0200
commita8aac87bb0ae999e93249c927b14d431c74f7630 (patch)
tree3e8d3d21a39abcd93eca67beffdd1ebea2f448bf /source
parentda3d78ba13050103535cc6790ad247c04d08980b (diff)
xcb: Move GWater source in xcb.c
Signed-off-by: Quentin Glidic <sardemff7+git@sardemff7.net>
Diffstat (limited to 'source')
-rw-r--r--source/rofi.c30
-rw-r--r--source/view.c2
-rw-r--r--source/xcb.c69
3 files changed, 50 insertions, 51 deletions
diff --git a/source/rofi.c b/source/rofi.c
index 1bea2436..bab587bb 100644
--- a/source/rofi.c
+++ b/source/rofi.c
@@ -97,8 +97,6 @@ unsigned int curr_switcher = 0;
/** Glib main loop. */
GMainLoop *main_loop = NULL;
-/** GWater xcb source, signalling events from the X server */
-GWaterXcbSource *main_loop_source = NULL;
/** Flag indicating we are in dmenu mode. */
static int dmenu_mode = FALSE;
@@ -414,14 +412,11 @@ static void cleanup ()
}
rofi_view_workers_finalize ();
if ( main_loop != NULL ) {
- if ( main_loop_source ) {
- g_water_xcb_source_free ( main_loop_source );
- }
g_main_loop_unref ( main_loop );
main_loop = NULL;
}
// Cleanup
- xcb_stuff_wipe ( xcb );
+ xcb_stuff_wipe ();
// Cleaning up memory allocated by the Xresources file.
config_xresource_free ();
@@ -631,7 +626,7 @@ static gboolean lazy_grab_pointer ( G_GNUC_UNUSED gpointer data )
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 ( xcb ), 0 ) ) {
+ if ( take_pointer ( xcb_stuff_get_root_window (), 0 ) ) {
return G_SOURCE_REMOVE;
}
lazy_grab_retry_count_pt++;
@@ -645,7 +640,7 @@ static gboolean lazy_grab_keyboard ( G_GNUC_UNUSED gpointer data )
g_main_loop_quit ( main_loop );
return G_SOURCE_REMOVE;
}
- if ( take_keyboard ( xcb_stuff_get_root_window ( xcb ), 0 ) ) {
+ if ( take_keyboard ( xcb_stuff_get_root_window (), 0 ) ) {
return G_SOURCE_REMOVE;
}
lazy_grab_retry_count_kb++;
@@ -672,20 +667,20 @@ static gboolean startup ( G_GNUC_UNUSED gpointer data )
// 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 ( xcb ), 500 ) ) {
+ 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 ( xcb ), 100 ) ) {
+ 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 ( xcb ), 0 ) ) {
+ 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 ( xcb ), 0 ) ) {
+ if ( !take_pointer ( xcb_stuff_get_root_window (), 0 ) ) {
g_timeout_add ( 1, lazy_grab_pointer, NULL );
}
}
@@ -857,17 +852,17 @@ int main ( int argc, char *argv[] )
rofi_collect_modi_setup ();
TICK_N ( "Collect MODI" );
- if ( !x11_setup () ) {
+ main_loop = g_main_loop_new ( NULL, FALSE );
+
+ TICK_N ( "Setup mainloop" );
+
+ if ( !x11_setup ( main_loop ) ) {
g_warning ( "Connection has error" );
cleanup ();
return EXIT_FAILURE;
}
TICK_N ( "Setup X11" );
- main_loop = g_main_loop_new ( NULL, FALSE );
-
- TICK_N ( "Setup mainloop" );
-
TICK_N ( "Startup Notification" );
// Setup keybinding
setup_abe ();
@@ -956,7 +951,6 @@ int main ( int argc, char *argv[] )
if ( find_arg_uint ( "-record-screenshots", &interval ) ) {
g_timeout_add ( 1000 / (double) interval, record, NULL );
}
- main_loop_source = g_water_xcb_source_new_for_connection ( NULL, xcb->connection, main_loop_x11_event_handler, main_loop, NULL );
TICK_N ( "X11 Setup " );
diff --git a/source/view.c b/source/view.c
index 47adad17..8d09575d 100644
--- a/source/view.c
+++ b/source/view.c
@@ -651,7 +651,7 @@ void __create_window ( MenuFlags menu_flags )
};
xcb_window_t box = xcb_generate_id ( xcb->connection );
- xcb_void_cookie_t cc = xcb_create_window_checked ( xcb->connection, depth->depth, box, xcb_stuff_get_root_window ( xcb ),
+ xcb_void_cookie_t cc = xcb_create_window_checked ( xcb->connection, depth->depth, box, xcb_stuff_get_root_window (),
0, 0, 200, 100, 0, XCB_WINDOW_CLASS_INPUT_OUTPUT,
visual->visual_id, selmask, selval );
xcb_generic_error_t *error;
diff --git a/source/xcb.c b/source/xcb.c
index e9414058..037cd44d 100644
--- a/source/xcb.c
+++ b/source/xcb.c
@@ -93,7 +93,7 @@ const char *netatom_names[] = { EWMH_ATOMS ( ATOM_CHAR ) };
cairo_surface_t *x11_helper_get_screenshot_surface ( void )
{
return cairo_xcb_surface_create ( xcb->connection,
- xcb_stuff_get_root_window ( xcb ), root_visual,
+ xcb_stuff_get_root_window (), root_visual,
xcb->screen->width_in_pixels, xcb->screen->height_in_pixels );
}
@@ -651,18 +651,20 @@ static void x11_create_frequently_used_atoms ( void )
}
}
-gboolean x11_setup ( void )
+gboolean x11_setup ( GMainLoop *main_loop )
{
// Get DISPLAY, first env, then argument.
// We never modify display_str content.
char *display_str = ( char *) g_getenv ( "DISPLAY" );
find_arg_str ( "-display", &display_str );
- xcb->connection = xcb_connect ( display_str, &xcb->screen_nbr );
- if ( xcb_connection_has_error ( xcb->connection ) ) {
+ xcb->main_loop = main_loop;
+ xcb->source = g_water_xcb_source_new ( g_main_loop_get_context ( xcb->main_loop ), display_str, &xcb->screen_nbr, main_loop_x11_event_handler, NULL, NULL );
+ if ( xcb->source == NULL ) {
g_warning ( "Failed to open display: %s", display_str );
return FALSE;
}
+ xcb->connection = g_water_xcb_source_get_connection ( xcb->source );
TICK_N ( "Open Display" );
@@ -819,7 +821,7 @@ void x11_create_visual_and_colormap ( void )
/**
* Process X11 events in the main-loop (gui-thread) of the application.
*/
-static void main_loop_x11_event_handler_view ( xcb_generic_event_t *ev, GMainLoop *main_loop )
+static void main_loop_x11_event_handler_view ( xcb_generic_event_t *ev )
{
RofiViewState *state = rofi_view_get_active ();
if ( state != NULL ) {
@@ -829,19 +831,19 @@ static void main_loop_x11_event_handler_view ( xcb_generic_event_t *ev, GMainLoo
rofi_view_finalize ( state );
// cleanup
if ( rofi_view_get_active () == NULL ) {
- g_main_loop_quit ( main_loop );
+ g_main_loop_quit ( xcb->main_loop );
}
}
}
}
-gboolean main_loop_x11_event_handler ( xcb_generic_event_t *ev, gpointer user_data )
+gboolean main_loop_x11_event_handler ( xcb_generic_event_t *ev, G_GNUC_UNUSED gpointer user_data )
{
if ( ev == NULL ) {
int status = xcb_connection_has_error ( xcb->connection );
if ( status > 0 ) {
g_warning ( "The XCB connection to X server had a fatal error: %d", status );
- g_main_loop_quit ( user_data );
+ g_main_loop_quit ( xcb->main_loop );
return G_SOURCE_REMOVE;
}
else {
@@ -874,7 +876,7 @@ gboolean main_loop_x11_event_handler ( xcb_generic_event_t *ev, gpointer user_da
ksne->lockedGroup );
xcb_generic_event_t dev;
dev.response_type = 0;
- main_loop_x11_event_handler_view ( &dev, user_data );
+ main_loop_x11_event_handler_view ( &dev );
break;
}
}
@@ -883,39 +885,42 @@ gboolean main_loop_x11_event_handler ( xcb_generic_event_t *ev, gpointer user_da
if ( xcb->sndisplay != NULL ) {
sn_xcb_display_process_event ( xcb->sndisplay, ev );
}
- main_loop_x11_event_handler_view ( ev, user_data );
+ main_loop_x11_event_handler_view ( ev );
return G_SOURCE_CONTINUE;
}
-xcb_window_t xcb_stuff_get_root_window ( xcb_stuff *xcb )
+xcb_window_t xcb_stuff_get_root_window ( void )
{
return xcb->screen->root;
}
-void xcb_stuff_wipe ( xcb_stuff *xcb )
+void xcb_stuff_wipe ( void )
{
+ if ( xcb->connection == NULL ) {
+ return;
+ }
+
+ g_debug ( "Cleaning up XCB and XKB" );
+
nk_bindings_seat_free ( xcb->bindings_seat );
nk_bindings_free ( xcb->bindings );
-
- if ( xcb->connection != NULL ) {
- g_debug ( "Cleaning up XCB and XKB" );
- if ( xcb->sncontext != NULL ) {
- sn_launchee_context_unref ( xcb->sncontext );
- xcb->sncontext = NULL;
- }
- if ( xcb->sndisplay != NULL ) {
- sn_display_unref ( xcb->sndisplay );
- xcb->sndisplay = NULL;
- }
- x11_monitors_free ();
- xcb_ewmh_connection_wipe ( &( xcb->ewmh ) );
- xcb_flush ( xcb->connection );
- xcb_aux_sync ( xcb->connection );
- xcb_disconnect ( xcb->connection );
- xcb->connection = NULL;
- xcb->screen = NULL;
- xcb->screen_nbr = 0;
+ if ( xcb->sncontext != NULL ) {
+ sn_launchee_context_unref ( xcb->sncontext );
+ xcb->sncontext = NULL;
+ }
+ if ( xcb->sndisplay != NULL ) {
+ sn_display_unref ( xcb->sndisplay );
+ xcb->sndisplay = NULL;
}
+ x11_monitors_free ();
+ xcb_ewmh_connection_wipe ( &( xcb->ewmh ) );
+ xcb_flush ( xcb->connection );
+ xcb_aux_sync ( xcb->connection );
+ g_water_xcb_source_free ( xcb->source );
+ xcb->source = NULL;
+ xcb->connection = NULL;
+ xcb->screen = NULL;
+ xcb->screen_nbr = 0;
}
void x11_disable_decoration ( xcb_window_t window )
@@ -947,7 +952,7 @@ void x11_helper_discover_window_manager ( void )
{
xcb_window_t wm_win = 0;
xcb_get_property_cookie_t cc = xcb_ewmh_get_supporting_wm_check_unchecked ( &xcb->ewmh,
- xcb_stuff_get_root_window ( xcb ) );
+ xcb_stuff_get_root_window () );
if ( xcb_ewmh_get_supporting_wm_check_reply ( &xcb->ewmh, cc, &wm_win, NULL ) ) {
xcb_ewmh_get_utf8_strings_reply_t wtitle;