diff --git a/include/xcb.h b/include/xcb.h index d8d39f9f..befc95f3 100644 --- a/include/xcb.h +++ b/include/xcb.h @@ -6,4 +6,5 @@ typedef struct _xcb_stuff xcb_stuff; extern xcb_stuff *xcb; xcb_window_t xcb_stuff_get_root_window ( xcb_stuff *xcb ); +void xcb_stuff_wipe ( xcb_stuff *xcb ); #endif diff --git a/source/rofi.c b/source/rofi.c index 439df164..b641b292 100644 --- a/source/rofi.c +++ b/source/rofi.c @@ -65,14 +65,6 @@ // Pidfile. char *pidfile = NULL; const char *cache_dir = NULL; -struct _xcb_stuff xcb_int = { - .connection = NULL, - .screen = NULL, - .screen_nbr = -1, - .sndisplay = NULL, - .sncontext = NULL, -}; -xcb_stuff *xcb = &xcb_int; struct xkb_stuff xkb = { NULL }; char *config_path = NULL; // Array of modi. @@ -315,19 +307,7 @@ static void cleanup () main_loop = NULL; } // Cleanup - if ( xcb->connection != NULL ) { - 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; - } - xcb_disconnect ( xcb->connection ); - xcb->connection = NULL; - } - + xcb_stuff_wipe ( xcb ); // Cleaning up memory allocated by the Xresources file. config_xresource_free (); for ( unsigned int i = 0; i < num_modi; i++ ) { diff --git a/source/view.c b/source/view.c index 35ca5b95..85ff6f18 100644 --- a/source/view.c +++ b/source/view.c @@ -1822,4 +1822,3 @@ Mode * rofi_view_get_mode ( RofiViewState *state ) return state->sw; } - diff --git a/source/x11-helper.c b/source/x11-helper.c index 0de0b845..c2d7b9e5 100644 --- a/source/x11-helper.c +++ b/source/x11-helper.c @@ -51,6 +51,16 @@ #include "x11-helper.h" #include "xkb-internal.h" + +struct _xcb_stuff xcb_int = { + .connection = NULL, + .screen = NULL, + .screen_nbr = -1, + .sndisplay = NULL, + .sncontext = NULL, +}; +xcb_stuff *xcb = &xcb_int; + enum { X11MOD_SHIFT, @@ -672,3 +682,21 @@ xcb_window_t xcb_stuff_get_root_window ( xcb_stuff *xcb ) { return xcb->screen->root; } + +void xcb_stuff_wipe ( xcb_stuff *xcb ) +{ + if ( xcb->connection != NULL ) { + 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; + } + xcb_disconnect ( xcb->connection ); + xcb->connection = NULL; + xcb->screen = NULL; + xcb->screen_nbr = 0; + } +}