Small cleanup

This commit is contained in:
Dave Davenport 2016-03-01 18:33:26 +01:00
parent 167e9d30ce
commit 8c950a984c
4 changed files with 30 additions and 22 deletions

View file

@ -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

View file

@ -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++ ) {

View file

@ -1822,4 +1822,3 @@ Mode * rofi_view_get_mode ( RofiViewState *state )
return state->sw;
}

View file

@ -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;
}
}