Remove opening of display.

This commit is contained in:
Dave Davenport 2016-02-28 01:08:12 +01:00
parent 764992e4bb
commit 93cb9ee7eb
5 changed files with 36 additions and 53 deletions

View File

@ -34,6 +34,8 @@ void window_set_atom_prop ( xcb_connection_t *xcb_connection, xcb_window_t w, xc
// usable space on a monitor // usable space on a monitor
#define EWMH_ATOMS( X ) \ #define EWMH_ATOMS( X ) \
X ( _NET_WM_WINDOW_OPACITY ), \ X ( _NET_WM_WINDOW_OPACITY ), \
X ( RESOURCE_MANAGER ), \
X ( I3_SOCKET_PATH ), \
X ( WM_WINDOW_ROLE) X ( WM_WINDOW_ROLE)
enum { EWMH_ATOMS ( ATOM_ENUM ), NUM_NETATOMS }; enum { EWMH_ATOMS ( ATOM_ENUM ), NUM_NETATOMS };

View File

@ -52,7 +52,7 @@ typedef enum
* *
* @ingroup CONFXServer * @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 * @ingroup CONFFile
@ -79,7 +79,7 @@ void config_parse_cmd_options_dynamic ( void );
* *
* @ingroup CONFXServer * @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 * @ingroup CONFFile

View File

@ -119,12 +119,7 @@ int i3_support_initialize ( xcb_connection_t *xcb_connection )
i3_support_free_internals (); i3_support_free_internals ();
// Get atom for I3_SOCKET_PATH // 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" ); i3_socket_path = window_get_text_prop ( xcb_connection, xcb_screen->root, netatoms[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 );
}
// If we find it, go into i3 mode. // If we find it, go into i3 mode.
return ( i3_socket_path != NULL ) ? TRUE : FALSE; return ( i3_socket_path != NULL ) ? TRUE : FALSE;
} }

View File

@ -41,14 +41,6 @@
#include <xkbcommon/xkbcommon.h> #include <xkbcommon/xkbcommon.h>
#include <xkbcommon/xkbcommon-compose.h> #include <xkbcommon/xkbcommon-compose.h>
#include <xkbcommon/xkbcommon-x11.h> #include <xkbcommon/xkbcommon-x11.h>
#include <X11/X.h>
#include <X11/Xatom.h>
#include <X11/Xlib.h>
#include <X11/Xlib-xcb.h>
#include <X11/Xutil.h>
#include <X11/Xproto.h>
#include <X11/keysym.h>
#include <X11/XKBlib.h>
#include <sys/types.h> #include <sys/types.h>
#include <glib-unix.h> #include <glib-unix.h>
@ -81,7 +73,6 @@ xcb_ewmh_connection_t xcb_ewmh;
xcb_screen_t *xcb_screen = NULL; xcb_screen_t *xcb_screen = NULL;
int xcb_screen_nbr = -1; int xcb_screen_nbr = -1;
struct xkb_stuff xkb = { NULL }; struct xkb_stuff xkb = { NULL };
Display *display = NULL;
char *display_str = NULL; char *display_str = NULL;
char *config_path = NULL; char *config_path = NULL;
// Array of modi. // Array of modi.
@ -324,7 +315,7 @@ static void cleanup ()
main_loop = NULL; main_loop = NULL;
} }
// Cleanup // Cleanup
if ( display != NULL ) { if ( xcb_connection != NULL ) {
if ( sncontext != NULL ) { if ( sncontext != NULL ) {
sn_launchee_context_unref ( sncontext ); sn_launchee_context_unref ( sncontext );
sncontext = NULL; sncontext = NULL;
@ -333,8 +324,8 @@ static void cleanup ()
sn_display_unref ( sndisplay ); sn_display_unref ( sndisplay );
sndisplay = NULL; sndisplay = NULL;
} }
XCloseDisplay ( display ); xcb_disconnect( xcb_connection );
display = NULL; xcb_connection = NULL;
} }
// Cleaning up memory allocated by the Xresources file. // Cleaning up memory allocated by the Xresources file.
@ -441,19 +432,19 @@ static void setup_modi ( void )
* Load configuration. * Load configuration.
* Following priority: (current), X, commandline arguments * Following priority: (current), X, commandline arguments
*/ */
static inline void load_configuration ( Display *display ) static inline void load_configuration ( )
{ {
// Load in config from X resources. // 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 ); config_parse_xresource_options_file ( config_path );
// Parse command line for settings. // Parse command line for settings.
config_parse_cmd_options ( ); config_parse_cmd_options ( );
} }
static inline void load_configuration_dynamic ( Display *display ) static inline void load_configuration_dynamic ( )
{ {
// Load in config from X resources. // 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_xresource_options_dynamic_file ( config_path );
config_parse_cmd_options_dynamic ( ); config_parse_cmd_options_dynamic ( );
} }
@ -651,15 +642,10 @@ int main ( int argc, char *argv[] )
fprintf ( stderr, "Failed to set locale modifier.\n" ); fprintf ( stderr, "Failed to set locale modifier.\n" );
return EXIT_FAILURE; return EXIT_FAILURE;
} }
if ( !( display = XOpenDisplay ( display_str ) ) ) { xcb_connection = xcb_connect ( display_str, &xcb_screen_nbr );
fprintf ( stderr, "cannot open display!\n" );
return EXIT_FAILURE;
}
TICK_N ( "Open Display" ); TICK_N ( "Open Display" );
xcb_connection = XGetXCBConnection ( display ); xcb_screen = xcb_aux_get_screen ( xcb_connection, xcb_screen_nbr );
xcb_screen = xcb_aux_get_screen ( xcb_connection, DefaultScreen ( display ) );
xcb_screen_nbr = DefaultScreen (display);
xcb_intern_atom_cookie_t *ac = xcb_ewmh_init_atoms(xcb_connection, &xcb_ewmh); xcb_intern_atom_cookie_t *ac = xcb_ewmh_init_atoms(xcb_connection, &xcb_ewmh);
xcb_generic_error_t **errors = NULL; xcb_generic_error_t **errors = NULL;
@ -668,6 +654,7 @@ int main ( int argc, char *argv[] )
fprintf(stderr, "Failed to create EWMH atoms\n"); 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, 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 ) { XKB_X11_SETUP_XKB_EXTENSION_NO_FLAGS, NULL, NULL, &xkb.first_event, NULL ) < 0 ) {
fprintf ( stderr, "cannot setup XKB extension!\n" ); 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.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 ); xkb.compose.state = xkb_compose_state_new ( xkb.compose.table, 0 );
x11_setup ( xcb_connection, &xkb );
main_loop = g_main_loop_new ( NULL, FALSE ); main_loop = g_main_loop_new ( NULL, FALSE );
TICK_N ( "Setup mainloop" ); TICK_N ( "Setup mainloop" );
@ -749,7 +737,7 @@ int main ( int argc, char *argv[] )
TICK_N ( "Setup abe" ); TICK_N ( "Setup abe" );
if ( find_arg ( "-no-config" ) < 0 ) { if ( find_arg ( "-no-config" ) < 0 ) {
load_configuration ( display ); load_configuration ( );
} }
if ( !dmenu_mode ) { if ( !dmenu_mode ) {
// setup_modi // setup_modi
@ -761,7 +749,7 @@ int main ( int argc, char *argv[] )
} }
if ( find_arg ( "-no-config" ) < 0 ) { if ( find_arg ( "-no-config" ) < 0 ) {
// Reload for dynamic part. // Reload for dynamic part.
load_configuration_dynamic ( display ); load_configuration_dynamic ( );
} }
// Dump. // Dump.
// catch help request // catch help request
@ -778,7 +766,6 @@ int main ( int argc, char *argv[] )
exit ( EXIT_SUCCESS ); 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 ); main_loop_source = g_water_xcb_source_new_for_connection ( NULL, xcb_connection, main_loop_x11_event_handler, NULL, NULL );
TICK_N ( "X11 Setup " ); TICK_N ( "X11 Setup " );

View File

@ -30,7 +30,13 @@
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
#include <X11/X.h> #include <X11/X.h>
#include <xcb/xcb.h>
#include <xcb/xkb.h>
#include <xkbcommon/xkbcommon.h>
#include <xkbcommon/xkbcommon-compose.h>
#include <xkbcommon/xkbcommon-x11.h>
#include <X11/Xresource.h> #include <X11/Xresource.h>
#include "x11-helper.h"
#include "rofi.h" #include "rofi.h"
#include "xrmoptions.h" #include "xrmoptions.h"
#include "settings.h" #include "settings.h"
@ -217,18 +223,16 @@ static void __config_parse_xresource_options ( XrmDatabase xDB )
g_free ( name ); 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; char *name = window_get_text_prop ( xcb_connection, xcb_screen->root, netatoms[RESOURCE_MANAGER]);
// Map Xresource entries to rofi config options. if ( name ) {
xRMS = XResourceManagerString ( display ); // Map Xresource entries to rofi config options.
XrmDatabase xDB = XrmGetStringDatabase ( name );
if ( xRMS == NULL ) { __config_parse_xresource_options ( xDB );
return; 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 ) 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; char *name = window_get_text_prop ( xcb_connection, xcb_screen->root, netatoms[RESOURCE_MANAGER]);
// Map Xresource entries to rofi config options. XrmDatabase xDB = XrmGetStringDatabase ( name );
xRMS = XResourceManagerString ( display );
if ( xRMS == NULL ) {
return;
}
XrmDatabase xDB = XrmGetStringDatabase ( xRMS );
__config_parse_xresource_options_dynamic ( xDB ); __config_parse_xresource_options_dynamic ( xDB );
XrmDestroyDatabase ( xDB ); XrmDestroyDatabase ( xDB );
g_free ( name );
} }
void config_parse_xresource_options_dynamic_file ( const char *filename ) void config_parse_xresource_options_dynamic_file ( const char *filename )
{ {