summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Davenport <qball@gmpclient.org>2016-03-01 18:11:55 +0100
committerDave Davenport <qball@gmpclient.org>2016-03-01 18:11:55 +0100
commit7d046a1f5bcc3a55f250aed0cbfaf8a54a8d6875 (patch)
treede42f664183bf2bb6c474c13bb4404ad6a181a09
parentfb2c23a429d0206043069ca1f571b49d7cbc275f (diff)
Pack magic externs into a xcb_stuff.
-rw-r--r--Makefile.am8
-rw-r--r--include/helper.h2
-rw-r--r--include/i3-support.h2
-rw-r--r--include/rofi.h1
-rw-r--r--include/view.h2
-rw-r--r--include/x11-helper.h25
-rw-r--r--include/xkb.h3
-rw-r--r--include/xrmoptions.h5
-rw-r--r--source/dialogs/window.c87
-rw-r--r--source/helper.c6
-rw-r--r--source/i3-support.c12
-rw-r--r--source/rofi.c108
-rw-r--r--source/view.c138
-rw-r--r--source/x11-helper.c159
-rw-r--r--source/xrmoptions.c9
-rw-r--r--test/helper-test.c5
16 files changed, 288 insertions, 284 deletions
diff --git a/Makefile.am b/Makefile.am
index 880c511d..148e2e2b 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -35,6 +35,8 @@ rofi_SOURCES=\
source/dialogs/combi.c\
source/dialogs/window.c\
source/dialogs/script.c\
+ include/xcb.h\
+ include/xcb-internal.h\
include/rofi.h\
include/mode.h\
include/mode-private.h\
@@ -147,6 +149,7 @@ check_PROGRAMS=rofi_test textbox_test helper_test
rofi_test_CFLAGS=\
$(AM_CFLAGS)\
$(glib_CFLAGS)\
+ $(libsn_CFLAGS)\
-I$(top_srcdir)/include/\
-I$(top_srcdir)/config/\
-I$(top_builddir)/
@@ -173,6 +176,7 @@ textbox_test_CFLAGS=\
$(xinerama_CFLAGS)\
$(GW_XCB_CFLAGS)\
$(cairo_CFLAGS)\
+ $(libsn_CFLAGS)\
-I$(top_srcdir)/include/\
-I$(top_srcdir)/config/\
-I$(top_builddir)/
@@ -183,7 +187,8 @@ textbox_test_LDADD=\
$(x11_LIBS)\
$(xinerama_LIBS)\
$(GW_XCB_LIBS)\
- $(cairo_LIBS)
+ $(cairo_LIBS)\
+ $(libsn_LIBS)
textbox_test_SOURCES=\
source/widget.c\
@@ -221,6 +226,7 @@ helper_test_CFLAGS=\
$(xinerama_CFLAGS)\
$(GW_XCB_CFLAGS)\
$(cairo_CFLAGS)\
+ $(libsn_CFLAGS)\
-I$(top_srcdir)/include/\
-I$(top_srcdir)/config/\
-I$(top_builddir)/
diff --git a/include/helper.h b/include/helper.h
index d479ce92..eae59ce1 100644
--- a/include/helper.h
+++ b/include/helper.h
@@ -137,7 +137,7 @@ void remove_pid_file ( int fd );
*
* This functions exits the program with 1 when it finds an invalid configuration.
*/
-int config_sanity_check ( xcb_connection_t *xcb_connection );
+int config_sanity_check ( void );
/**
* @param arg string to parse.
diff --git a/include/i3-support.h b/include/i3-support.h
index 25e5ef48..cc14e4ea 100644
--- a/include/i3-support.h
+++ b/include/i3-support.h
@@ -28,7 +28,7 @@ void i3_support_focus_window ( xcb_window_t id );
* @returns TRUE when i3 is running, FALSE when not.
*/
-int i3_support_initialize ( xcb_connection_t *xcb_connection );
+int i3_support_initialize ( xcb_stuff *xcb );
/**
* Cleanup.
diff --git a/include/rofi.h b/include/rofi.h
index 343e49ac..fc6c2a1c 100644
--- a/include/rofi.h
+++ b/include/rofi.h
@@ -14,6 +14,7 @@
* @defgroup Main Main
* @{
*/
+
/**
* Pointer to xdg cache directory.
*/
diff --git a/include/view.h b/include/view.h
index 758894ef..a266d165 100644
--- a/include/view.h
+++ b/include/view.h
@@ -90,7 +90,7 @@ void rofi_view_update ( RofiViewState *state );
*
* Enables fake transparancy on this view.
*/
-void rofi_view_setup_fake_transparency ( xcb_connection_t *xcb_connection, xcb_screen_t *xcb_screen, RofiViewState *state );
+void rofi_view_setup_fake_transparency ( RofiViewState *state );
/**
* @param state The handle to the view
diff --git a/include/x11-helper.h b/include/x11-helper.h
index d6479bc6..e75e0643 100644
--- a/include/x11-helper.h
+++ b/include/x11-helper.h
@@ -21,9 +21,9 @@
*
* @returns a newly allocated string with the result or NULL
*/
-char* window_get_text_prop ( xcb_connection_t *xcb_connection, xcb_window_t w, xcb_atom_t atom );
+char* window_get_text_prop ( xcb_window_t w, xcb_atom_t atom );
-void window_set_atom_prop ( xcb_connection_t *xcb_connection, xcb_window_t w, xcb_atom_t prop, xcb_atom_t *atoms, int count );
+void window_set_atom_prop ( xcb_window_t w, xcb_atom_t prop, xcb_atom_t *atoms, int count );
/**
* xcb_window_t info.
@@ -47,30 +47,27 @@ typedef struct
int l, r, t, b;
} workarea;
-void monitor_active ( xcb_connection_t *xcb_connection, workarea *mon );
+void monitor_active ( workarea *mon );
// find the dimensions of the monitor displaying point x,y
-void monitor_dimensions ( xcb_connection_t *xcb_connection, xcb_screen_t *screen, int x, int y, workarea *mon );
+void monitor_dimensions ( int x, int y, workarea *mon );
// Find the dimensions of the monitor specified by user.
-int monitor_get_dimension ( xcb_connection_t *xcb_connection, xcb_screen_t *screen, int monitor, workarea *mon );
-int monitor_get_smallest_size ( xcb_connection_t *xcb_connection );
+int monitor_get_dimension ( int monitor, workarea *mon );
+int monitor_get_smallest_size ( void );
/**
- * @param display The display.
- *
* Release keyboard.
*/
-void release_keyboard ( xcb_connection_t *xcb_connection );
+void release_keyboard ( void );
/**
- * @param display The display.
* @param w xcb_window_t we want to grab keyboard on.
*
* Grab keyboard and mouse.
*
* @return 1 when keyboard is grabbed, 0 not.
*/
-int take_keyboard ( xcb_connection_t *xcb_connection, xcb_window_t w );
+int take_keyboard ( xcb_window_t w );
/**
* @param mask The mask to canonilize
@@ -95,7 +92,7 @@ void x11_parse_key ( char *combo, unsigned int *mod, xkb_keysym_t *key );
*
* Set the opacity of the window and sub-windows.
*/
-void x11_set_window_opacity ( xcb_connection_t *xcb_connection, xcb_window_t box, unsigned int opacity );
+void x11_set_window_opacity ( xcb_window_t box, unsigned int opacity );
/**
* Setup several items required.
@@ -103,7 +100,7 @@ void x11_set_window_opacity ( xcb_connection_t *xcb_connection, xcb_window_t box
* * Numlock detection
* * Cache
*/
-void x11_setup ( xcb_connection_t *xcb_connection, xkb_stuff *xkb );
+void x11_setup ( xkb_stuff *xkb );
extern xcb_depth_t *depth;
extern xcb_visualtype_t *visual;
@@ -114,7 +111,7 @@ extern xcb_visualtype_t *root_visual;
* This function tries to create a 32bit TrueColor colormap.
* If this fails, it falls back to the default for the connected display.
*/
-void x11_create_visual_and_colormap ( xcb_connection_t *xcb_connection, xcb_screen_t *xcb_screen );
+void x11_create_visual_and_colormap ( void );
typedef struct
{
diff --git a/include/xkb.h b/include/xkb.h
index 8e648665..cd415c60 100644
--- a/include/xkb.h
+++ b/include/xkb.h
@@ -1,6 +1,5 @@
#ifndef ROFI_XKB_H
#define ROFI_XKB_H
-typedef struct xkb_stuff xkb_stuff;
-
+typedef struct xkb_stuff xkb_stuff;
#endif
diff --git a/include/xrmoptions.h b/include/xrmoptions.h
index ea8ea758..e8967158 100644
--- a/include/xrmoptions.h
+++ b/include/xrmoptions.h
@@ -1,5 +1,6 @@
#ifndef ROFI_XRMOPTIONS_H
#define ROFI_XRMOPTIONS_H
+#include "xcb.h"
// Big thanks to Sean Pringle for this code.
/**
@@ -52,7 +53,7 @@ typedef enum
*
* @ingroup CONFXServer
*/
-void config_parse_xresource_options ( xcb_connection_t *xcb_connection, xcb_screen_t *xcb_screen );
+void config_parse_xresource_options ( xcb_stuff *xcb );
/**
* @ingroup CONFFile
@@ -79,7 +80,7 @@ void config_parse_cmd_options_dynamic ( void );
*
* @ingroup CONFXServer
*/
-void config_parse_xresource_options_dynamic ( xcb_connection_t *xcb_connection, xcb_screen_t *xcb_screen );
+void config_parse_xresource_options_dynamic ( xcb_stuff *xcb );
/**
* @ingroup CONFFile
diff --git a/source/dialogs/window.c b/source/dialogs/window.c
index 9c36bcbf..a0dc6249 100644
--- a/source/dialogs/window.c
+++ b/source/dialogs/window.c
@@ -38,6 +38,9 @@
#include <xcb/xcb_ewmh.h>
#include <xcb/xcb_icccm.h>
+#include "xcb-internal.h"
+#include "xcb.h"
+
#include "rofi.h"
#include "settings.h"
#include "helper.h"
@@ -54,10 +57,6 @@
#define CLIENTWINDOWTYPE 10
#define CLIENTROLE 50
-extern xcb_connection_t *xcb_connection;
-extern xcb_ewmh_connection_t xcb_ewmh;
-extern xcb_screen_t *xcb_screen;
-extern int xcb_screen_nbr;
// a manageable window
typedef struct
{
@@ -205,10 +204,10 @@ static void x11_cache_free ( void )
*
* @returns a XWindowAttributes
*/
-static xcb_get_window_attributes_reply_t * window_get_attributes ( xcb_connection_t *xcb_connection, xcb_window_t w )
+static xcb_get_window_attributes_reply_t * window_get_attributes ( xcb_window_t w )
{
- xcb_get_window_attributes_cookie_t c = xcb_get_window_attributes ( xcb_connection, w );
- xcb_get_window_attributes_reply_t *r = xcb_get_window_attributes_reply ( xcb_connection, c, NULL );
+ xcb_get_window_attributes_cookie_t c = xcb_get_window_attributes ( xcb->connection, w );
+ xcb_get_window_attributes_reply_t *r = xcb_get_window_attributes_reply ( xcb->connection, c, NULL );
if ( r ) {
return r;
}
@@ -236,7 +235,7 @@ static int client_has_window_type ( client *c, xcb_atom_t type )
return 0;
}
-static client* window_client ( xcb_connection_t *xcb_connection, xcb_window_t win )
+static client* window_client ( xcb_window_t win )
{
if ( win == XCB_WINDOW_NONE ) {
return NULL;
@@ -249,7 +248,7 @@ static client* window_client ( xcb_connection_t *xcb_connection, xcb_window_t wi
}
// if this fails, we're up that creek
- xcb_get_window_attributes_reply_t *attr = window_get_attributes ( xcb_connection, win );
+ xcb_get_window_attributes_reply_t *attr = window_get_attributes ( win );
if ( !attr ) {
return NULL;
@@ -260,37 +259,37 @@ static client* window_client ( xcb_connection_t *xcb_connection, xcb_window_t wi
// copy xattr so we don't have to care when stuff is freed
memmove ( &c->xattr, attr, sizeof ( xcb_get_window_attributes_reply_t ) );
- xcb_get_property_cookie_t cky = xcb_ewmh_get_wm_state ( &xcb_ewmh, win );
+ xcb_get_property_cookie_t cky = xcb_ewmh_get_wm_state ( &xcb->ewmh, win );
xcb_ewmh_get_atoms_reply_t states;
- if ( xcb_ewmh_get_wm_state_reply ( &xcb_ewmh, cky, &states, NULL ) ) {
+ if ( xcb_ewmh_get_wm_state_reply ( &xcb->ewmh, cky, &states, NULL ) ) {
c->states = MIN ( CLIENTSTATE, states.atoms_len );
memcpy ( c->state, states.atoms, MIN ( CLIENTSTATE, states.atoms_len ) );
xcb_ewmh_get_atoms_reply_wipe ( &states );
}
- cky = xcb_ewmh_get_wm_window_type ( &xcb_ewmh, win );
- if ( xcb_ewmh_get_wm_window_type_reply ( &xcb_ewmh, cky, &states, NULL ) ) {
+ cky = xcb_ewmh_get_wm_window_type ( &xcb->ewmh, win );
+ if ( xcb_ewmh_get_wm_window_type_reply ( &xcb->ewmh, cky, &states, NULL ) ) {
c->window_types = MIN ( CLIENTWINDOWTYPE, states.atoms_len );
memcpy ( c->window_type, states.atoms, MIN ( CLIENTWINDOWTYPE, states.atoms_len ) );
xcb_ewmh_get_atoms_reply_wipe ( &states );
}
- c->title = window_get_text_prop ( xcb_connection, c->window, xcb_ewmh._NET_WM_NAME );
+ c->title = window_get_text_prop ( c->window, xcb->ewmh._NET_WM_NAME );
if ( c->title == NULL ) {
- c->title = window_get_text_prop ( xcb_connection, c->window, XCB_ATOM_WM_NAME );
+ c->title = window_get_text_prop ( c->window, XCB_ATOM_WM_NAME );
}
- c->role = window_get_text_prop ( xcb_connection, c->window, netatoms[WM_WINDOW_ROLE] );
+ c->role = window_get_text_prop ( c->window, netatoms[WM_WINDOW_ROLE] );
- cky = xcb_icccm_get_wm_class ( xcb_connection, c->window );
+ cky = xcb_icccm_get_wm_class ( xcb->connection, c->window );
xcb_icccm_get_wm_class_reply_t wcr;
- if ( xcb_icccm_get_wm_class_reply ( xcb_connection, cky, &wcr, NULL ) ) {
+ if ( xcb_icccm_get_wm_class_reply ( xcb->connection, cky, &wcr, NULL ) ) {
c->class = g_strdup ( wcr.class_name );
xcb_icccm_get_wm_class_reply_wipe ( &wcr );
}
- xcb_get_property_cookie_t cc = xcb_icccm_get_wm_hints ( xcb_connection, c->window );
+ xcb_get_property_cookie_t cc = xcb_icccm_get_wm_hints ( xcb->connection, c->window );
xcb_icccm_wm_hints_t r;
- if ( xcb_icccm_get_wm_hints_reply ( xcb_connection, cc, &r, NULL ) ) {
+ if ( xcb_icccm_get_wm_hints_reply ( xcb->connection, cc, &r, NULL ) ) {
c->hint_flags = r.flags;
}
@@ -372,29 +371,29 @@ static void _window_mode_load_data ( Mode *sw, unsigned int cd )
x11_cache_create ();
// Check for i3
- pd->config_i3_mode = i3_support_initialize ( xcb_connection );
- xcb_get_property_cookie_t c = xcb_ewmh_get_active_window ( &xcb_ewmh, xcb_screen_nbr );
- if ( !xcb_ewmh_get_active_window_reply ( &xcb_ewmh, c, &curr_win_id, NULL ) ) {
+ pd->config_i3_mode = i3_support_initialize ( xcb );
+ xcb_get_property_cookie_t c = xcb_ewmh_get_active_window ( &(xcb->ewmh), xcb->screen_nbr );
+ if ( !xcb_ewmh_get_active_window_reply ( &xcb->ewmh, c, &curr_win_id, NULL ) ) {
curr_win_id = 0;
}
// Get the current desktop.
unsigned int current_desktop = 0;
- c = xcb_ewmh_get_current_desktop ( &xcb_ewmh, xcb_screen_nbr );
- if ( !xcb_ewmh_get_current_desktop_reply ( &xcb_ewmh, c, &current_desktop, NULL ) ) {
+ c = xcb_ewmh_get_current_desktop ( &xcb->ewmh, xcb->screen_nbr );
+ if ( !xcb_ewmh_get_current_desktop_reply ( &xcb->ewmh, c, &current_desktop, NULL ) ) {
current_desktop = 0;
}
- c = xcb_ewmh_get_client_list_stacking ( &xcb_ewmh, 0 );
+ c = xcb_ewmh_get_client_list_stacking ( &xcb->ewmh, 0 );
xcb_ewmh_get_windows_reply_t clients;
- if ( xcb_ewmh_get_client_list_stacking_reply ( &xcb_ewmh, c, &clients, NULL ) ) {
+ if ( xcb_ewmh_get_client_list_stacking_reply ( &xcb->ewmh, c, &clients, NULL ) ) {
nwins = MIN ( 100, clients.windows_len );
memcpy ( wins, clients.windows, nwins * sizeof ( xcb_window_t ) );
xcb_ewmh_get_windows_reply_wipe ( &clients );
}
else {
- c = xcb_ewmh_get_client_list ( &xcb_ewmh, xcb_screen_nbr );
- if ( xcb_ewmh_get_client_list_reply ( &xcb_ewmh, c, &clients, NULL ) ) {
+ c = xcb_ewmh_get_client_list ( &xcb->ewmh, xcb->screen_nbr );
+ if ( xcb_ewmh_get_client_list_reply ( &xcb->ewmh, c, &clients, NULL ) ) {
nwins = MIN ( 100, clients.windows_len );
memcpy ( wins, clients.windows, nwins * sizeof ( xcb_window_t ) );
xcb_ewmh_get_windows_reply_wipe ( &clients );
@@ -411,16 +410,16 @@ static void _window_mode_load_data ( Mode *sw, unsigned int cd )
// calc widths of fields
for ( i = nwins - 1; i > -1; i-- ) {
- client *c = window_client ( xcb_connection, wins[i] );
+ client *c = window_client ( wins[i] );
if ( ( c != NULL )
&& !c->xattr.override_redirect
- && !client_has_window_type ( c, xcb_ewmh._NET_WM_WINDOW_TYPE_DOCK )
- && !client_has_window_type ( c, xcb_ewmh._NET_WM_WINDOW_TYPE_DESKTOP )
- && !client_has_state ( c, xcb_ewmh._NET_WM_STATE_SKIP_PAGER )
- && !client_has_state ( c, xcb_ewmh._NET_WM_STATE_SKIP_TASKBAR ) ) {
+ && !client_has_window_type ( c, xcb->ewmh._NET_WM_WINDOW_TYPE_DOCK )
+ && !client_has_window_type ( c, xcb->ewmh._NET_WM_WINDOW_TYPE_DESKTOP )
+ && !client_has_state ( c, xcb->ewmh._NET_WM_STATE_SKIP_PAGER )
+ && !client_has_state ( c, xcb->ewmh._NET_WM_STATE_SKIP_TASKBAR ) ) {
classfield = MAX ( classfield, strlen ( c->class ) );
- if ( client_has_state ( c, xcb_ewmh._NET_WM_STATE_DEMANDS_ATTENTION ) ) {
+ if ( client_has_state ( c, xcb->ewmh._NET_WM_STATE_DEMANDS_ATTENTION ) ) {
c->demands = TRUE;
}
if ( ( c->hint_flags & XCB_ICCCM_WM_HINT_X_URGENCY ) != 0 ) {
@@ -435,8 +434,8 @@ static void _window_mode_load_data ( Mode *sw, unsigned int cd )
}
// Create pattern for printing the line.
- xcb_get_property_cookie_t c = xcb_ewmh_get_number_of_desktops ( &xcb_ewmh, xcb_screen_nbr );
- if ( !xcb_ewmh_get_number_of_desktops_reply ( &xcb_ewmh, c, &desktops, NULL ) ) {
+ xcb_get_property_cookie_t c = xcb_ewmh_get_number_of_desktops ( &xcb->ewmh, xcb->screen_nbr );
+ if ( !xcb_ewmh_get_number_of_desktops_reply ( &xcb->ewmh, c, &desktops, NULL ) ) {
desktops = 1;
}
@@ -454,7 +453,7 @@ static void _window_mode_load_data ( Mode *sw, unsigned int cd )
xcb_window_t w = pd->ids->array[i];
client *c;
- if ( ( c = window_client ( xcb_connection, w ) ) ) {
+ if ( ( c = window_client ( w ) ) ) {
// final line format
unsigned int wmdesktop;
char desktop[5];
@@ -468,9 +467,9 @@ static void _window_mode_load_data ( Mode *sw, unsigned int cd )
xcb_get_property_reply_t *r;
cookie =
- xcb_get_property ( xcb_connection, 0, c->window, xcb_ewmh._NET_WM_DESKTOP, XCB_GET_PROPERTY, 0,
+ xcb_get_property ( xcb->connection, 0, c->window, xcb->ewmh._NET_WM_DESKTOP, XCB_GET_PROPERTY, 0,
sizeof ( unsigned int ) );
- r = xcb_get_property_reply ( xcb_connection, cookie, NULL );
+ r = xcb_get_property_reply ( xcb->connection, cookie, NULL );
if ( r && r->type == XCB_ATOM_INTEGER ) {
wmdesktop = *( (int *) xcb_get_property_value ( r ) );
}
@@ -538,10 +537,10 @@ static ModeMode window_mode_result ( Mode *sw, int mretv, G_GNUC_UNUSED char **i
i3_support_focus_window ( rmpd->ids->array[selected_line] );
}
else{
- xcb_ewmh_request_change_active_window ( &xcb_ewmh, xcb_screen_nbr, rmpd->ids->array[selected_line],
+ xcb_ewmh_request_change_active_window ( &xcb->ewmh, xcb->screen_nbr, rmpd->ids->array[selected_line],
XCB_EWMH_CLIENT_SOURCE_TYPE_OTHER,
XCB_CURRENT_TIME, XCB_WINDOW_NONE );
- xcb_flush ( xcb_connection );
+ xcb_flush ( xcb->connection );
}
}
return retv;
@@ -564,10 +563,10 @@ static void window_mode_destroy ( Mode *sw )
static char *_get_display_value ( const Mode *sw, unsigned int selected_line, int *state, int get_entry )
{
ModeModePrivateData *rmpd = mode_get_private_data ( sw );
- if ( window_client ( xcb_connection, rmpd->ids->array[selected_line] )->demands ) {
+ if ( window_client ( rmpd->ids->array[selected_line] )->demands ) {
*state |= URGENT;
}
- if ( window_client ( xcb_connection, rmpd->ids->array[selected_line] )->active ) {
+ if ( window_client ( rmpd->ids->array[selected_line] )->active ) {
*state |= ACTIVE;
}
return get_entry ? g_strdup ( rmpd->cmd_list[selected_line] ) : NULL;
diff --git a/source/helper.c b/source/helper.c
index 5665928a..d32e6b9d 100644
--- a/source/helper.c
+++ b/source/helper.c
@@ -511,7 +511,7 @@ void remove_pid_file ( int fd )
*
* This functions exits the program with 1 when it finds an invalid configuration.
*/
-int config_sanity_check ( xcb_connection_t* xcb_connection )
+int config_sanity_check ( void )
{
// If alternative row is not set, copy the normal background color.
// Do this at the beginning as we might use it in the error dialog.
@@ -554,10 +554,10 @@ int config_sanity_check ( xcb_connection_t* xcb_connection )
// Check size
{
- int ssize = monitor_get_smallest_size ( xcb_connection );
+ int ssize = monitor_get_smallest_size ( );
if ( config.monitor >= 0 ) {
workarea mon;
- if ( monitor_get_dimension ( xcb_connection, xcb_screen, config.monitor, &mon ) ) {
+ if ( monitor_get_dimension ( config.monitor, &mon ) ) {
ssize = MIN ( mon.w, mon.h );
}
else{
diff --git a/source/i3-support.c b/source/i3-support.c
index fa9d6cdd..7335930b 100644
--- a/source/i3-support.c
+++ b/source/i3-support.c
@@ -36,7 +36,7 @@
#include <xcb/xcb.h>
#include <sys/socket.h>
#include <sys/un.h>
-
+#include "xcb.h"
#include "rofi.h"
#include "x11-helper.h"
#include "i3-support.h"
@@ -45,9 +45,7 @@
#ifdef HAVE_I3_IPC_H
#include <i3/ipc.h>
// Path to HAVE_I3_IPC_H socket.
-char *i3_socket_path = NULL;
-extern xcb_screen_t *xcb_screen;
-
+char *i3_socket_path = NULL;
void i3_support_focus_window ( xcb_window_t id )
{
i3_ipc_header_t head;
@@ -113,13 +111,13 @@ void i3_support_focus_window ( xcb_window_t id )
close ( s );
}
-int i3_support_initialize ( xcb_connection_t *xcb_connection )
+int i3_support_initialize ( xcb_stuff *xcb )
{
// If we where initialized, clean this first.
i3_support_free_internals ();
// Get atom for I3_SOCKET_PATH
- i3_socket_path = window_get_text_prop ( xcb_connection, xcb_screen->root, netatoms[I3_SOCKET_PATH] );
+ i3_socket_path = window_get_text_prop ( xcb_stuff_get_root_window(xcb), netatoms[I3_SOCKET_PATH] );
// If we find it, go into i3 mode.
return ( i3_socket_path != NULL ) ? TRUE : FALSE;
}
@@ -141,7 +139,7 @@ void i3_support_free_internals ( void )
{
}
-int i3_support_initialize ( xcb_connection_t *xcb_connection )
+int i3_support_initialize ( void )
{
return FALSE;
}
diff --git a/source/rofi.c b/source/rofi.c
index 6d5e0508..439df164 100644
--- a/source/rofi.c
+++ b/source/rofi.c
@@ -47,8 +47,8 @@
#include <libgwater-xcb.h>
-#define SN_API_NOT_YET_FROZEN
-#include <libsn/sn.h>
+#include "xcb-internal.h"
+#include "xkb-internal.h"
#include "settings.h"
#include "mode.h"
@@ -61,33 +61,33 @@
#include "view.h"
#include "view-internal.h"
-#include "xkb-internal.h"
// Pidfile.
-char *pidfile = NULL;
-const char *cache_dir = NULL;
-SnDisplay *sndisplay = NULL;
-SnLauncheeContext *sncontext = NULL;
-xcb_connection_t *xcb_connection = NULL;
-xcb_ewmh_connection_t xcb_ewmh;
-xcb_screen_t *xcb_screen = NULL;
-int xcb_screen_nbr = -1;
-struct xkb_stuff xkb = { NULL };
-char *display_str = NULL;
-char *config_path = NULL;
+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.
-Mode **modi = NULL;
-unsigned int num_modi = 0;
+Mode **modi = NULL;
+unsigned int num_modi = 0;
// Current selected switcher.
-unsigned int curr_switcher = 0;
+unsigned int curr_switcher = 0;
-GMainLoop *main_loop = NULL;
-GWaterXcbSource *main_loop_source = NULL;
-gboolean quiet = FALSE;
+GMainLoop *main_loop = NULL;
+GWaterXcbSource *main_loop_source = NULL;
+gboolean quiet = FALSE;
-static int dmenu_mode = FALSE;
+static int dmenu_mode = FALSE;
-int return_code = EXIT_SUCCESS;
+int return_code = EXIT_SUCCESS;
void process_result ( RofiViewState *state );
void process_result_error ( RofiViewState *state );
@@ -133,7 +133,7 @@ static int setup ()
int pfd = create_pid_file ( pidfile );
if ( pfd >= 0 ) {
// Request truecolor visual.
- x11_create_visual_and_colormap ( xcb_connection, xcb_screen );
+ x11_create_visual_and_colormap ( );
textbox_setup ();
}
return pfd;
@@ -148,7 +148,7 @@ static void teardown ( int pfd )
textbox_cleanup ( );
// Release the window.
- release_keyboard ( xcb_connection );
+ release_keyboard ( );
// Cleanup view
rofi_view_cleanup ();
@@ -315,17 +315,17 @@ static void cleanup ()
main_loop = NULL;
}
// Cleanup
- if ( xcb_connection != NULL ) {
- if ( sncontext != NULL ) {
- sn_launchee_context_unref ( sncontext );
- sncontext = NULL;
+ if ( xcb->connection != NULL ) {
+ if ( xcb->sncontext != NULL ) {
+ sn_launchee_context_unref ( xcb->sncontext );
+ xcb->sncontext = NULL;
}
- if ( sndisplay != NULL ) {
- sn_display_unref ( sndisplay );
- sndisplay = NULL;
+ if ( xcb->sndisplay != NULL ) {
+ sn_display_unref ( xcb->sndisplay );
+ xcb->sndisplay = NULL;
}
- xcb_disconnect ( xcb_connection );
- xcb_connection = NULL;
+ xcb_disconnect ( xcb->connection );
+ xcb->connection = NULL;
}
// Cleaning up memory allocated by the Xresources file.
@@ -435,7 +435,7 @@ static void setup_modi ( void )
static inline void load_configuration ( )
{
// Load in config from X resources.
- config_parse_xresource_options ( xcb_connection, xcb_screen );
+ config_parse_xresource_options ( xcb );
config_parse_xresource_options_file ( config_path );
// Parse command line for settings.
@@ -444,7 +444,7 @@ static inline void load_configuration ( )
static inline void load_configuration_dynamic ( )
{
// Load in config from X resources.
- config_parse_xresource_options_dynamic ( xcb_connection, xcb_screen );
+ config_parse_xresource_options_dynamic ( xcb );
config_parse_xresource_options_dynamic_file ( config_path );
config_parse_cmd_options_dynamic ( );
}
@@ -455,8 +455,8 @@ static inline void load_configuration_dynamic ( )
static gboolean main_loop_x11_event_handler ( xcb_generic_event_t *ev, G_GNUC_UNUSED gpointer data )
{
RofiViewState *state = rofi_view_get_active ();
- if ( sndisplay != NULL ) {
- sn_xcb_display_process_event ( sndisplay, ev );
+ if ( xcb->sndisplay != NULL ) {
+ sn_xcb_display_process_event ( xcb->sndisplay, ev );
}
if ( state != NULL ) {
rofi_view_itterrate ( state, ev, &xkb );
@@ -505,7 +505,7 @@ static gboolean startup ( G_GNUC_UNUSED gpointer data )
char *msg = NULL;
//
// Sanity check
- if ( config_sanity_check ( xcb_connection ) ) {
+ if ( config_sanity_check ( ) ) {
return G_SOURCE_REMOVE;
}
TICK_N ( "Config sanity check" );
@@ -620,7 +620,7 @@ int main ( int argc, char *argv[] )
TICK ();
// Get DISPLAY, first env, then argument.
- display_str = getenv ( "DISPLAY" );
+ char *display_str = getenv ( "DISPLAY" );
find_arg_str ( "-display", &display_str );
if ( setlocale ( LC_ALL, "" ) == NULL ) {
@@ -628,19 +628,19 @@ int main ( int argc, char *argv[] )
return EXIT_FAILURE;
}
- xcb_connection = xcb_connect ( display_str, &xcb_screen_nbr );
+ xcb->connection = xcb_connect ( display_str, &xcb->screen_nbr );
TICK_N ( "Open Display" );
- xcb_screen = xcb_aux_get_screen ( xcb_connection, xcb_screen_nbr );
+ 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_intern_atom_cookie_t *ac = xcb_ewmh_init_atoms ( xcb->connection, &xcb->ewmh );
xcb_generic_error_t **errors = NULL;
- xcb_ewmh_init_atoms_replies ( &xcb_ewmh, ac, errors );
+ xcb_ewmh_init_atoms_replies ( &xcb->ewmh, ac, errors );
if ( errors ) {
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 ) {
fprintf ( stderr, "cannot setup XKB extension!\n" );
return EXIT_FAILURE;
@@ -651,9 +651,9 @@ int main ( int argc, char *argv[] )
fprintf ( stderr, "cannot create XKB context!\n" );
return EXIT_FAILURE;
}
- xkb.xcb_connection = xcb_connection;
+ xkb.xcb_connection = xcb->connection;
- xkb.device_id = xkb_x11_get_core_keyboard_device_id ( xcb_connection );
+ xkb.device_id = xkb_x11_get_core_keyboard_device_id ( xcb->connection );
enum
{
@@ -689,28 +689,28 @@ int main ( int argc, char *argv[] )
.affectState = required_state_details,
.stateDetails = required_state_details,
};
- xcb_xkb_select_events ( xcb_connection, xkb.device_id, required_events, /* affectWhich */
+ xcb_xkb_select_events ( xcb->connection, xkb.device_id, required_events, /* affectWhich */
0, /* clear */
0, /* selectAll */
required_map_parts, /* affectMap */
required_map_parts, /* map */
&details );
- xkb.keymap = xkb_x11_keymap_new_from_device ( xkb.context, xcb_connection, xkb.device_id, XKB_KEYMAP_COMPILE_NO_FLAGS );
- xkb.state = xkb_x11_state_new_from_device ( xkb.keymap, xcb_connection, xkb.device_id );
+ xkb.keymap = xkb_x11_keymap_new_from_device ( xkb.context, xcb->connection, xkb.device_id, XKB_KEYMAP_COMPILE_NO_FLAGS );
+ xkb.state = xkb_x11_state_new_from_device ( xkb.keymap, xcb->connection, xkb.device_id );
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 );
+ x11_setup ( &xkb );
main_loop = g_main_loop_new ( NULL, FALSE );
TICK_N ( "Setup mainloop" );
// startup not.
- sndisplay = sn_xcb_display_new ( xcb_connection, error_trap_push, error_trap_pop );
+ xcb->sndisplay = sn_xcb_display_new ( xcb->connection, error_trap_push, error_trap_pop );
- if ( sndisplay != NULL ) {
- sncontext = sn_launchee_context_new_from_environment ( sndisplay, xcb_screen_nbr );
+ if ( xcb->sndisplay != NULL ) {
+ xcb->sncontext = sn_launchee_context_new_from_environment ( xcb->sndisplay, xcb->screen_nbr );
}
TICK_N ( "Startup Notification" );
@@ -751,7 +751,7 @@ int main ( int argc, char *argv[] )
exit ( EXIT_SUCCESS );
}
- 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 " );
diff --git a/source/view.c b/source/view.c
index e9f42df5..35ca5b95 100644
--- a/source/view.c
+++ b/source/view.c
@@ -50,6 +50,7 @@
#include "rofi.h"
#include "mode.h"
+#include "xcb-internal.h"
#include "xkb-internal.h"
#include "helper.h"
#include "textbox.h"
@@ -61,19 +62,15 @@
#include "view.h"
#include "view-internal.h"
-// What todo with these.
-extern xcb_connection_t *xcb_connection;
-extern xcb_screen_t *xcb_screen;
-extern SnLauncheeContext *sncontext;
-extern xcb_ewmh_connection_t xcb_ewmh;
+#include "xcb.h"
-GThreadPool *tpool = NULL;
+GThreadPool *tpool = NULL;
-RofiViewState *current_active_menu = NULL;
-xcb_window_t main_window = XCB_WINDOW_NONE;
-cairo_surface_t *surface = NULL;
-cairo_surface_t *fake_bg = NULL;
-cairo_t *draw = NULL;
+RofiViewState *current_active_menu = NULL;
+xcb_window_t main_window = XCB_WINDOW_NONE;
+cairo_surface_t *surface = NULL;</