From 93cb9ee7eb81172b6258dfdae998cefc2b78f0cb Mon Sep 17 00:00:00 2001 From: Dave Davenport Date: Sun, 28 Feb 2016 01:08:12 +0100 Subject: [PATCH] Remove opening of display. --- include/x11-helper.h | 2 ++ include/xrmoptions.h | 4 ++-- source/i3-support.c | 7 +------ source/rofi.c | 39 +++++++++++++-------------------------- source/xrmoptions.c | 37 ++++++++++++++++++------------------- 5 files changed, 36 insertions(+), 53 deletions(-) diff --git a/include/x11-helper.h b/include/x11-helper.h index d2cb6904..34454405 100644 --- a/include/x11-helper.h +++ b/include/x11-helper.h @@ -34,6 +34,8 @@ void window_set_atom_prop ( xcb_connection_t *xcb_connection, xcb_window_t w, xc // usable space on a monitor #define EWMH_ATOMS( X ) \ X ( _NET_WM_WINDOW_OPACITY ), \ + X ( RESOURCE_MANAGER ), \ + X ( I3_SOCKET_PATH ), \ X ( WM_WINDOW_ROLE) enum { EWMH_ATOMS ( ATOM_ENUM ), NUM_NETATOMS }; diff --git a/include/xrmoptions.h b/include/xrmoptions.h index 88b57183..ea8ea758 100644 --- a/include/xrmoptions.h +++ b/include/xrmoptions.h @@ -52,7 +52,7 @@ typedef enum * * @ingroup CONFXServer */ -void config_parse_xresource_options ( Display *display ); +void config_parse_xresource_options ( xcb_connection_t *xcb_connection, xcb_screen_t *xcb_screen ); /** * @ingroup CONFFile @@ -79,7 +79,7 @@ void config_parse_cmd_options_dynamic ( void ); * * @ingroup CONFXServer */ -void config_parse_xresource_options_dynamic ( Display *display ); +void config_parse_xresource_options_dynamic ( xcb_connection_t *xcb_connection, xcb_screen_t *xcb_screen ); /** * @ingroup CONFFile diff --git a/source/i3-support.c b/source/i3-support.c index 713a29ac..9b932678 100644 --- a/source/i3-support.c +++ b/source/i3-support.c @@ -119,12 +119,7 @@ int i3_support_initialize ( xcb_connection_t *xcb_connection ) i3_support_free_internals (); // Get atom for I3_SOCKET_PATH - xcb_intern_atom_cookie_t cookie = xcb_intern_atom ( xcb_connection, FALSE, strlen ( "I3_SOCKET_PATH" ), "I3_SOCKET_PATH" ); - xcb_intern_atom_reply_t *reply = xcb_intern_atom_reply ( xcb_connection, cookie, NULL ); - if ( reply != NULL ) { - // Get the i3 path property. - i3_socket_path = window_get_text_prop ( xcb_connection, xcb_screen->root, reply->atom ); - } + i3_socket_path = window_get_text_prop ( xcb_connection, xcb_screen->root, netatoms[I3_SOCKET_PATH]); // If we find it, go into i3 mode. return ( i3_socket_path != NULL ) ? TRUE : FALSE; } diff --git a/source/rofi.c b/source/rofi.c index 75f49d79..972b9771 100644 --- a/source/rofi.c +++ b/source/rofi.c @@ -41,14 +41,6 @@ #include #include #include -#include -#include -#include -#include -#include -#include -#include -#include #include #include @@ -81,7 +73,6 @@ xcb_ewmh_connection_t xcb_ewmh; xcb_screen_t *xcb_screen = NULL; int xcb_screen_nbr = -1; struct xkb_stuff xkb = { NULL }; -Display *display = NULL; char *display_str = NULL; char *config_path = NULL; // Array of modi. @@ -324,7 +315,7 @@ static void cleanup () main_loop = NULL; } // Cleanup - if ( display != NULL ) { + if ( xcb_connection != NULL ) { if ( sncontext != NULL ) { sn_launchee_context_unref ( sncontext ); sncontext = NULL; @@ -333,8 +324,8 @@ static void cleanup () sn_display_unref ( sndisplay ); sndisplay = NULL; } - XCloseDisplay ( display ); - display = NULL; + xcb_disconnect( xcb_connection ); + xcb_connection = NULL; } // Cleaning up memory allocated by the Xresources file. @@ -441,19 +432,19 @@ static void setup_modi ( void ) * Load configuration. * Following priority: (current), X, commandline arguments */ -static inline void load_configuration ( Display *display ) +static inline void load_configuration ( ) { // Load in config from X resources. - config_parse_xresource_options ( display ); + config_parse_xresource_options ( xcb_connection, xcb_screen ); config_parse_xresource_options_file ( config_path ); // Parse command line for settings. config_parse_cmd_options ( ); } -static inline void load_configuration_dynamic ( Display *display ) +static inline void load_configuration_dynamic ( ) { // Load in config from X resources. - config_parse_xresource_options_dynamic ( display ); + config_parse_xresource_options_dynamic ( xcb_connection, xcb_screen ); config_parse_xresource_options_dynamic_file ( config_path ); config_parse_cmd_options_dynamic ( ); } @@ -651,15 +642,10 @@ int main ( int argc, char *argv[] ) fprintf ( stderr, "Failed to set locale modifier.\n" ); return EXIT_FAILURE; } - if ( !( display = XOpenDisplay ( display_str ) ) ) { - fprintf ( stderr, "cannot open display!\n" ); - return EXIT_FAILURE; - } + xcb_connection = xcb_connect ( display_str, &xcb_screen_nbr ); TICK_N ( "Open Display" ); - xcb_connection = XGetXCBConnection ( display ); - xcb_screen = xcb_aux_get_screen ( xcb_connection, DefaultScreen ( display ) ); - xcb_screen_nbr = DefaultScreen (display); + xcb_screen = xcb_aux_get_screen ( xcb_connection, xcb_screen_nbr ); xcb_intern_atom_cookie_t *ac = xcb_ewmh_init_atoms(xcb_connection, &xcb_ewmh); xcb_generic_error_t **errors = NULL; @@ -668,6 +654,7 @@ int main ( int argc, char *argv[] ) fprintf(stderr, "Failed to create EWMH atoms\n"); } + if ( xkb_x11_setup_xkb_extension ( xcb_connection, XKB_X11_MIN_MAJOR_XKB_VERSION, XKB_X11_MIN_MINOR_XKB_VERSION, XKB_X11_SETUP_XKB_EXTENSION_NO_FLAGS, NULL, NULL, &xkb.first_event, NULL ) < 0 ) { fprintf ( stderr, "cannot setup XKB extension!\n" ); @@ -730,6 +717,7 @@ int main ( int argc, char *argv[] ) xkb.compose.table = xkb_compose_table_new_from_locale ( xkb.context, setlocale ( LC_CTYPE, NULL ), 0 ); xkb.compose.state = xkb_compose_state_new ( xkb.compose.table, 0 ); + x11_setup ( xcb_connection, &xkb ); main_loop = g_main_loop_new ( NULL, FALSE ); TICK_N ( "Setup mainloop" ); @@ -749,7 +737,7 @@ int main ( int argc, char *argv[] ) TICK_N ( "Setup abe" ); if ( find_arg ( "-no-config" ) < 0 ) { - load_configuration ( display ); + load_configuration ( ); } if ( !dmenu_mode ) { // setup_modi @@ -761,7 +749,7 @@ int main ( int argc, char *argv[] ) } if ( find_arg ( "-no-config" ) < 0 ) { // Reload for dynamic part. - load_configuration_dynamic ( display ); + load_configuration_dynamic ( ); } // Dump. // catch help request @@ -778,7 +766,6 @@ int main ( int argc, char *argv[] ) exit ( EXIT_SUCCESS ); } - x11_setup ( xcb_connection, &xkb ); main_loop_source = g_water_xcb_source_new_for_connection ( NULL, xcb_connection, main_loop_x11_event_handler, NULL, NULL ); TICK_N ( "X11 Setup " ); diff --git a/source/xrmoptions.c b/source/xrmoptions.c index c25794af..f829b1b8 100644 --- a/source/xrmoptions.c +++ b/source/xrmoptions.c @@ -30,7 +30,13 @@ #include #include #include +#include +#include +#include +#include +#include #include +#include "x11-helper.h" #include "rofi.h" #include "xrmoptions.h" #include "settings.h" @@ -217,18 +223,16 @@ static void __config_parse_xresource_options ( XrmDatabase xDB ) g_free ( name ); } } -void config_parse_xresource_options ( Display *display ) +void config_parse_xresource_options ( xcb_connection_t *xcb_connection, xcb_screen_t *xcb_screen ) { - char *xRMS; - // Map Xresource entries to rofi config options. - xRMS = XResourceManagerString ( display ); - - if ( xRMS == NULL ) { - return; + char *name = window_get_text_prop ( xcb_connection, xcb_screen->root, netatoms[RESOURCE_MANAGER]); + if ( name ) { + // Map Xresource entries to rofi config options. + XrmDatabase xDB = XrmGetStringDatabase ( name ); + __config_parse_xresource_options ( xDB ); + XrmDestroyDatabase ( xDB ); + g_free ( name ); } - XrmDatabase xDB = XrmGetStringDatabase ( xRMS ); - __config_parse_xresource_options ( xDB ); - XrmDestroyDatabase ( xDB ); } void config_parse_xresource_options_file ( const char *filename ) { @@ -325,18 +329,13 @@ static void __config_parse_xresource_options_dynamic ( XrmDatabase xDB ) } } -void config_parse_xresource_options_dynamic ( Display *display ) +void config_parse_xresource_options_dynamic ( xcb_connection_t *xcb_connection, xcb_screen_t *xcb_screen ) { - char *xRMS; - // Map Xresource entries to rofi config options. - xRMS = XResourceManagerString ( display ); - - if ( xRMS == NULL ) { - return; - } - XrmDatabase xDB = XrmGetStringDatabase ( xRMS ); + char *name = window_get_text_prop ( xcb_connection, xcb_screen->root, netatoms[RESOURCE_MANAGER]); + XrmDatabase xDB = XrmGetStringDatabase ( name ); __config_parse_xresource_options_dynamic ( xDB ); XrmDestroyDatabase ( xDB ); + g_free ( name ); } void config_parse_xresource_options_dynamic_file ( const char *filename ) {