summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
Diffstat (limited to 'source')
-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
7 files changed, 258 insertions, 261 deletions
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;
+cairo_surface_t *fake_bg = NULL;
+cairo_t *draw = NULL;
static char * get_matching_state ( void )
{
@@ -204,12 +201,12 @@ static void calculate_window_position ( RofiViewState *state )
}
}
-void rofi_view_queue_redraw ( void )
+void rofi_view_queue_redraw ( void )
{
if ( current_active_menu ) {
current_active_menu->update = TRUE;
- xcb_clear_area ( xcb_connection, current_active_menu->window, 1, 0, 0, 1, 1 );
- xcb_flush ( xcb_connection );
+ xcb_clear_area ( xcb->connection, current_active_menu->window, 1, 0, 0, 1, 1 );
+ xcb_flush ( xcb->connection );
}
}
@@ -243,8 +240,8 @@ void rofi_view_set_selected_line ( RofiViewState *state, unsigned int selected_l
}
state->update = TRUE;
- xcb_clear_area ( xcb_connection, state->window, 1, 0, 0, 1, 1 );
- xcb_flush ( xcb_connection );
+ xcb_clear_area ( xcb->connection, state->window, 1, 0, 0, 1, 1 );
+ xcb_flush ( xcb->connection );
}
void rofi_view_free ( RofiViewState *state )
@@ -377,8 +374,8 @@ void rofi_view_itterrate ( RofiViewState *state, xcb_generic_event_t *event, xkb
case XCB_XKB_MAP_NOTIFY:
xkb_state_unref ( xkb->state );
xkb_keymap_unref ( xkb->keymap );
- xkb->keymap = xkb_x11_keymap_new_from_device ( xkb->context, xkb->xcb_connection, xkb->device_id, 0 );
- xkb->state = xkb_x11_state_new_from_device ( xkb->keymap, xkb->xcb_connection, xkb->device_id );
+ xkb->keymap = xkb_x11_keymap_new_from_device ( xkb->context, xcb->connection, xkb->device_id, 0 );
+ xkb->state = xkb_x11_state_new_from_device ( xkb->keymap, xcb->connection, xkb->device_id );
break;
case XCB_XKB_STATE_NOTIFY:
{
@@ -492,7 +489,7 @@ static void check_is_ascii ( thread_state *t, G_GNUC_UNUSED gpointer user_data )
g_mutex_unlock ( t->mutex );
}
-static xcb_window_t __create_window ( xcb_connection_t *xcb_connection, xcb_screen_t *xcb_screen, MenuFlags menu_flags )
+static xcb_window_t __create_window ( MenuFlags menu_flags )
{
uint32_t selmask = XCB_CW_BACK_PIXEL | XCB_CW_BORDER_PIXEL | XCB_CW_EVENT_MASK | XCB_CW_COLORMAP;
uint32_t selval[] =
@@ -501,11 +498,11 @@ static xcb_window_t __create_window ( xcb_connection_t *xcb_connection, xcb_scre
XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_BUTTON_PRESS | XCB_EVENT_MASK_BUTTON_RELEASE | XCB_EVENT_MASK_KEY_PRESS |
XCB_EVENT_MASK_KEY_RELEASE | XCB_EVENT_MASK_STRUCTURE_NOTIFY | XCB_EVENT_MASK_FOCUS_CHANGE | XCB_EVENT_MASK_BUTTON_1_MOTION,map };
- xcb_window_t box = xcb_generate_id ( xcb_connection );
- xcb_create_window ( xcb_connection,
+ xcb_window_t box = xcb_generate_id ( xcb->connection );
+ xcb_create_window ( xcb->connection,
depth->depth,
box,
- xcb_screen->root,
+ xcb_stuff_get_root_window(xcb),
0,
0,
200,
@@ -516,7 +513,7 @@ static xcb_window_t __create_window ( xcb_connection_t *xcb_connection, xcb_scre
selmask,
selval );
- surface = cairo_xcb_surface_create ( xcb_connection, box, visual, 200, 100 );
+ surface = cairo_xcb_surface_create ( xcb->connection, box, visual, 200, 100 );
// Create a drawable.
draw = cairo_create ( surface );
g_assert ( draw != NULL );
@@ -546,26 +543,26 @@ static xcb_window_t __create_window ( xcb_connection_t *xcb_connection, xcb_scre
// // make it an unmanaged window
if ( ( ( menu_flags & MENU_NORMAL_WINDOW ) == 0 ) && !config.fullscreen ) {
- window_set_atom_prop ( xcb_connection, box, xcb_ewmh._NET_WM_STATE, &xcb_ewmh._NET_WM_STATE_ABOVE, 1 );
+ window_set_atom_prop ( box, xcb->ewmh._NET_WM_STATE, &(xcb->ewmh._NET_WM_STATE_ABOVE), 1 );
uint32_t values[] = { 1 };
- xcb_change_window_attributes ( xcb_connection, box, XCB_CW_OVERRIDE_REDIRECT, values );
+ xcb_change_window_attributes ( xcb->connection, box, XCB_CW_OVERRIDE_REDIRECT, values );
}
else{
- window_set_atom_prop ( xcb_connection, box, xcb_ewmh._NET_WM_WINDOW_TYPE, &xcb_ewmh._NET_WM_WINDOW_TYPE_NORMAL, 1 );
+ window_set_atom_prop ( box, xcb->ewmh._NET_WM_WINDOW_TYPE, &(xcb->ewmh._NET_WM_WINDOW_TYPE_NORMAL), 1 );
}
if ( config.fullscreen ) {
xcb_atom_t atoms[] = {
- xcb_ewmh._NET_WM_STATE_FULLSCREEN,
- xcb_ewmh._NET_WM_STATE_ABOVE
+ xcb->ewmh._NET_WM_STATE_FULLSCREEN,
+ xcb->ewmh._NET_WM_STATE_ABOVE
};
- window_set_atom_prop ( xcb_connection, box, xcb_ewmh._NET_WM_STATE, atoms, sizeof ( atoms ) / sizeof ( xcb_atom_t ) );
+ window_set_atom_prop ( box, xcb->ewmh._NET_WM_STATE, atoms, sizeof ( atoms ) / sizeof ( xcb_atom_t ) );
}
// Set the WM_NAME
- xcb_change_property ( xcb_connection, XCB_PROP_MODE_REPLACE, box, xcb_ewmh._NET_WM_NAME, xcb_ewmh.UTF8_STRING, 8, 4, "rofi" );
- xcb_change_property ( xcb_connection, XCB_PROP_MODE_REPLACE, box, XCB_ATOM_WM_NAME, XCB_ATOM_STRING, 8, 4, "rofi" );
+ xcb_change_property ( xcb->connection, XCB_PROP_MODE_REPLACE, box, xcb->ewmh._NET_WM_NAME, xcb->ewmh.UTF8_STRING, 8, 4, "rofi" );
+ xcb_change_property ( xcb->connection, XCB_PROP_MODE_REPLACE, box, XCB_ATOM_WM_NAME, XCB_ATOM_STRING, 8, 4, "rofi" );
- x11_set_window_opacity ( xcb_connection, box, config.window_opacity );
+ x11_set_window_opacity ( box, config.window_opacity );
return box;
}
@@ -993,7 +990,7 @@ void rofi_view_update ( RofiViewState *state )
// Flush the surface.
cairo_surface_flush ( surface );
- xcb_flush ( xcb_connection );
+ xcb_flush ( xcb->connection );
TICK ();
}
@@ -1008,8 +1005,8 @@ static void rofi_view_paste ( RofiViewState *state, xcb_selection_notify_event_t
if ( xse->property == XCB_ATOM_NONE ) {
fprintf ( stderr, "Failed to convert selection\n" );
}
- else if ( xse->property == xcb_ewmh.UTF8_STRING ) {
- gchar *text = window_get_text_prop ( xcb_connection, state->window, xcb_ewmh.UTF8_STRING );
+ else if ( xse->property == xcb->ewmh.UTF8_STRING ) {
+ gchar *text = window_get_text_prop ( state->window, xcb->ewmh.UTF8_STRING );
if ( text != NULL && text[0] != '\0' ) {
unsigned int dl = strlen ( text );
// Strip new line
@@ -1267,14 +1264,14 @@ void rofi_view_finalize ( RofiViewState *state )
state->finalize ( state );
}
}
-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 )
{
if ( fake_bg == NULL ) {
- cairo_surface_t *s = cairo_xcb_surface_create ( xcb_connection,
- xcb_screen->root,
+ cairo_surface_t *s = cairo_xcb_surface_create ( xcb->connection,
+ xcb_stuff_get_root_window(xcb),
root_visual,
- xcb_screen->width_in_pixels,
- xcb_screen->height_in_pixels );
+ xcb->screen->width_in_pixels,
+ xcb->screen->height_in_pixels );
fake_bg = cairo_image_surface_create ( CAIRO_FORMAT_ARGB32, state->mon.w, state->mon.h );
cairo_t *dr = cairo_create ( fake_bg );
@@ -1292,12 +1289,12 @@ static void rofi_view_mainloop_iter ( RofiViewState *state, xcb_generic_event_t
{
case XCB_FOCUS_IN:
if ( ( state->menu_flags & MENU_NORMAL_WINDOW ) == 0 ) {
- take_keyboard ( xcb_connection, state->window );
+ take_keyboard ( state->window );
}
break;
case XCB_FOCUS_OUT:
if ( ( state->menu_flags & MENU_NORMAL_WINDOW ) == 0 ) {
- release_keyboard ( xcb_connection );
+ release_keyboard ( );
}
break;
case XCB_MOTION_NOTIFY:
@@ -1355,14 +1352,14 @@ static void rofi_view_mainloop_iter ( RofiViewState *state, xcb_generic_event_t
if ( key != XKB_KEY_NoSymbol ) {
// Handling of paste
if ( abe_test_action ( PASTE_PRIMARY, modstate, key ) ) {
- xcb_convert_selection ( xcb_connection, state->window, XCB_ATOM_PRIMARY,
- xcb_ewmh.UTF8_STRING, xcb_ewmh.UTF8_STRING, XCB_CURRENT_TIME );
- xcb_flush ( xcb_connection );
+ xcb_convert_selection ( xcb->connection, state->window, XCB_ATOM_PRIMARY,
+ xcb->ewmh.UTF8_STRING, xcb->ewmh.UTF8_STRING, XCB_CURRENT_TIME );
+ xcb_flush ( xcb->connection );
}
else if ( abe_test_action ( PASTE_SECONDARY, modstate, key ) ) {
- xcb_convert_selection ( xcb_connection, state->window, XCB_ATOM_SECONDARY,
- xcb_ewmh.UTF8_STRING, xcb_ewmh.UTF8_STRING, XCB_CURRENT_TIME );
- xcb_flush ( xcb_connection );
+ xcb_convert_selection ( xcb->connection, state->window, XCB_ATOM_SECONDARY,
+ xcb->ewmh.UTF8_STRING, xcb->ewmh.UTF8_STRING, XCB_CURRENT_TIME );
+ xcb_flush ( xcb->connection );
}
if ( abe_test_action ( SCREENSHOT, modstate, key ) ) {
menu_capture_screenshot ( );
@@ -1506,9 +1503,9 @@ RofiViewState *rofi_view_create ( Mode *sw,
// main window isn't explicitly destroyed in case we switch modes. Reusing it prevents flicker
if ( main_window == XCB_WINDOW_NONE ) {
- main_window = __create_window ( xcb_connection, xcb_screen, menu_flags );
- if ( sncontext != NULL ) {
- sn_launchee_context_setup_window ( sncontext, state->window );
+ main_window = __create_window ( menu_flags );
+ if ( xcb->sncontext != NULL ) {
+ sn_launchee_context_setup_window ( xcb->sncontext, state->window );
}
}
state->window = main_window;
@@ -1555,7 +1552,7 @@ RofiViewState *rofi_view_create ( Mode *sw,
// We grab this using the rootwindow (as dmenu does it).
// this seems to result in the smallest delay for most people.
if ( ( menu_flags & MENU_NORMAL_WINDOW ) == 0 ) {
- int has_keyboard = take_keyboard ( xcb_connection, xcb_screen->root );
+ int has_keyboard = take_keyboard ( xcb_stuff_get_root_window(xcb) );
if ( !has_keyboard ) {
fprintf ( stderr, "Failed to grab keyboard, even after %d uS.", 500 * 1000 );
@@ -1566,10 +1563,10 @@ RofiViewState *rofi_view_create ( Mode *sw,
}
TICK_N ( "Grab keyboard" );
// Get active monitor size.
- monitor_active ( xcb_connection, &( state->mon ) );
+ monitor_active ( &( state->mon ) );
TICK_N ( "Get active monitor" );
if ( config.fake_transparency ) {
- rofi_view_setup_fake_transparency ( xcb_connection, xcb_screen, state );
+ rofi_view_setup_fake_transparency ( state );
}
// we need this at this point so we can get height.
@@ -1674,7 +1671,7 @@ RofiViewState *rofi_view_create ( Mode *sw,
uint32_t vals[] = { state->x, state-&