1
0
Fork 0
mirror of https://github.com/davatorium/rofi.git synced 2024-11-18 13:54:36 -05:00

Pack magic externs into a xcb_stuff.

This commit is contained in:
Dave Davenport 2016-03-01 18:11:55 +01:00
parent fb2c23a429
commit 7d046a1f5b
16 changed files with 288 additions and 284 deletions

View file

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

View file

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

View file

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

View file

@ -14,6 +14,7 @@
* @defgroup Main Main
* @{
*/
/**
* Pointer to xdg cache directory.
*/

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -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 " );

View file

@ -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->y, state->w, state->h };
// Display it.
xcb_configure_window ( xcb_connection, state->window, mask, vals );
xcb_configure_window ( xcb->connection, state->window, mask, vals );
cairo_xcb_surface_set_size ( surface, state->w, state->h );
// if grabbing keyboard failed, fall through
@ -1685,10 +1682,10 @@ RofiViewState *rofi_view_create ( Mode *sw,
rofi_view_refilter ( state );
rofi_view_update ( state );
xcb_map_window ( xcb_connection, state->window );
xcb_flush ( xcb_connection );
if ( sncontext != NULL ) {
sn_launchee_context_complete ( sncontext );
xcb_map_window ( xcb->connection, state->window );
xcb_flush ( xcb->connection );
if ( xcb->sncontext != NULL ) {
sn_launchee_context_complete ( xcb->sncontext );
}
return state;
}
@ -1714,20 +1711,20 @@ void rofi_view_error_dialog ( const char *msg, int markup )
state->finalize = process_result_error;
// Get active monitor size.
monitor_active ( xcb_connection, &( state->mon ) );
monitor_active ( &( state->mon ) );
if ( config.fake_transparency ) {
rofi_view_setup_fake_transparency ( xcb_connection, xcb_screen, state );
rofi_view_setup_fake_transparency ( state );
}
// 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_NORMAL );
main_window = __create_window ( MENU_NORMAL );
}
state->window = main_window;
// Try to grab the keyboard as early as possible.
// We grab this using the rootwindow (as dmenu does it).
// this seems to result in the smallest delay for most people.
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 );
return;
@ -1748,14 +1745,14 @@ void rofi_view_error_dialog ( const char *msg, int markup )
uint16_t mask = XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y | XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT;
uint32_t vals[] = { state->x, state->y, state->w, state->h };
xcb_configure_window ( xcb_connection, state->window, mask, vals );
xcb_configure_window ( xcb->connection, state->window, mask, vals );
calculate_window_position ( state );
cairo_xcb_surface_set_size ( surface, state->w, state->h );
// Display it.
xcb_map_window ( xcb_connection, state->window );
xcb_map_window ( xcb->connection, state->window );
if ( sncontext != NULL ) {
sn_launchee_context_complete ( sncontext );
if ( xcb->sncontext != NULL ) {
sn_launchee_context_complete ( xcb->sncontext );
}
rofi_view_set_active ( state );
}
@ -1775,12 +1772,12 @@ void rofi_view_cleanup ()
surface = NULL;
}
if ( main_window != XCB_WINDOW_NONE ) {
xcb_unmap_window ( xcb_connection, main_window );
xcb_destroy_window ( xcb_connection, main_window );
xcb_unmap_window ( xcb->connection, main_window );
xcb_destroy_window ( xcb->connection, main_window );
main_window = XCB_WINDOW_NONE;
}
if ( map != XCB_COLORMAP_NONE ) {
xcb_free_colormap ( xcb_connection, map );
xcb_free_colormap ( xcb->connection, map );
map = XCB_COLORMAP_NONE;
}
}
@ -1825,3 +1822,4 @@ Mode * rofi_view_get_mode ( RofiViewState *state )
return state->sw;
}

View file

@ -36,7 +36,8 @@
#include <xcb/xcb.h>
#include <xcb/xinerama.h>
#include <xcb/xcb_ewmh.h>
#include "xcb-internal.h"
#include "xcb.h"
#include "settings.h"
#include <rofi.h>
@ -62,24 +63,21 @@ enum
NUM_X11MOD
};
xcb_depth_t *depth = NULL;
xcb_visualtype_t *visual = NULL;
xcb_colormap_t map = XCB_COLORMAP_NONE;
xcb_depth_t *root_depth = NULL;
xcb_visualtype_t *root_visual = NULL;
xcb_atom_t netatoms[NUM_NETATOMS];
const char *netatom_names[] = { EWMH_ATOMS ( ATOM_CHAR ) };
static unsigned int x11_mod_masks[NUM_X11MOD];
extern xcb_ewmh_connection_t xcb_ewmh;
extern xcb_connection_t *xcb_connection;
xcb_depth_t *depth = NULL;
xcb_visualtype_t *visual = NULL;
xcb_colormap_t map = XCB_COLORMAP_NONE;
xcb_depth_t *root_depth = NULL;
xcb_visualtype_t *root_visual = NULL;
xcb_atom_t netatoms[NUM_NETATOMS];
const char *netatom_names[] = { EWMH_ATOMS ( ATOM_CHAR ) };
static unsigned int x11_mod_masks[NUM_X11MOD];
// retrieve a text property from a window
// technically we could use window_get_prop(), but this is better for character set support
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 )
{
xcb_get_property_cookie_t c = xcb_get_property ( xcb_connection, 0, w, atom, XCB_GET_PROPERTY_TYPE_ANY, 0, UINT_MAX );
xcb_get_property_reply_t *r = xcb_get_property_reply ( xcb_connection, c, NULL );
xcb_get_property_cookie_t c = xcb_get_property ( xcb->connection, 0, w, atom, XCB_GET_PROPERTY_TYPE_ANY, 0, UINT_MAX );
xcb_get_property_reply_t *r = xcb_get_property_reply ( xcb->connection, c, NULL );
if ( r ) {
char *str = g_malloc ( xcb_get_property_value_length ( r ) + 1 );
memcpy ( str, xcb_get_property_value ( r ), xcb_get_property_value_length ( r ) );
@ -90,19 +88,17 @@ char* window_get_text_prop ( xcb_connection_t *xcb_connection, xcb_window_t w, x
return NULL;
}
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_change_property ( xcb_connection, XCB_PROP_MODE_REPLACE, w, prop, XCB_ATOM_ATOM, 32, count, atoms );
xcb_change_property ( xcb->connection, XCB_PROP_MODE_REPLACE, w, prop, XCB_ATOM_ATOM, 32, count, atoms );
}
extern xcb_screen_t *xcb_screen;
extern int xcb_screen_nbr;
int monitor_get_smallest_size ( xcb_connection_t *xcb_connection )
int monitor_get_smallest_size ( void )
{
xcb_generic_error_t *error;
int size = MIN ( xcb_screen->width_in_pixels, xcb_screen->height_in_pixels );
xcb_xinerama_is_active_cookie_t is_active_req = xcb_xinerama_is_active ( xcb_connection );
xcb_xinerama_is_active_reply_t *is_active = xcb_xinerama_is_active_reply ( xcb_connection, is_active_req, &error );
int size = MIN ( xcb->screen->width_in_pixels, xcb->screen->height_in_pixels );
xcb_xinerama_is_active_cookie_t is_active_req = xcb_xinerama_is_active ( xcb->connection );
xcb_xinerama_is_active_reply_t *is_active = xcb_xinerama_is_active_reply ( xcb->connection, is_active_req, &error );
if ( error ) {
fprintf ( stderr, "Couldn't query Xinerama\n" );
return size;
@ -114,9 +110,9 @@ int monitor_get_smallest_size ( xcb_connection_t *xcb_connection )
free ( is_active );
xcb_xinerama_query_screens_cookie_t cookie_screen;
cookie_screen = xcb_xinerama_query_screens ( xcb_connection );
cookie_screen = xcb_xinerama_query_screens ( xcb->connection );
xcb_xinerama_query_screens_reply_t *query_screens;
query_screens = xcb_xinerama_query_screens_reply ( xcb_connection, cookie_screen, &error );
query_screens = xcb_xinerama_query_screens_reply ( xcb->connection, cookie_screen, &error );
if ( error ) {
fprintf ( stderr, "Error getting screen info\n" );
return size;
@ -132,15 +128,15 @@ int monitor_get_smallest_size ( xcb_connection_t *xcb_connection )
return size;
}
int monitor_get_dimension ( xcb_connection_t *xcb_connection, xcb_screen_t *screen, int monitor, workarea *mon )
int monitor_get_dimension ( int monitor, workarea *mon )
{
xcb_generic_error_t *error = NULL;
memset ( mon, 0, sizeof ( workarea ) );
mon->w = screen->width_in_pixels;
mon->h = screen->height_in_pixels;
mon->w = xcb->screen->width_in_pixels;
mon->h = xcb->screen->height_in_pixels;
xcb_xinerama_is_active_cookie_t is_active_req = xcb_xinerama_is_active ( xcb_connection );
xcb_xinerama_is_active_reply_t *is_active = xcb_xinerama_is_active_reply ( xcb_connection, is_active_req, &error );
xcb_xinerama_is_active_cookie_t is_active_req = xcb_xinerama_is_active ( xcb->connection );
xcb_xinerama_is_active_reply_t *is_active = xcb_xinerama_is_active_reply ( xcb->connection, is_active_req, &error );
if ( error ) {
fprintf ( stderr, "Error getting screen info\n" );
return FALSE;
@ -152,9 +148,9 @@ int monitor_get_dimension ( xcb_connection_t *xcb_connection, xcb_screen_t *scre
free ( is_active );
xcb_xinerama_query_screens_cookie_t cookie_screen;
cookie_screen = xcb_xinerama_query_screens ( xcb_connection );
cookie_screen = xcb_xinerama_query_screens ( xcb->connection );
xcb_xinerama_query_screens_reply_t *query_screens;
query_screens = xcb_xinerama_query_screens_reply ( xcb_connection, cookie_screen, &error );
query_screens = xcb_xinerama_query_screens_reply ( xcb->connection, cookie_screen, &error );
if ( error ) {
fprintf ( stderr, "Error getting screen info\n" );
return FALSE;
@ -175,15 +171,15 @@ int monitor_get_dimension ( xcb_connection_t *xcb_connection, xcb_screen_t *scre
return FALSE;
}
// 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 )
{
xcb_generic_error_t *error = NULL;
memset ( mon, 0, sizeof ( workarea ) );
mon->w = screen->width_in_pixels;
mon->h = screen->height_in_pixels;
mon->w = xcb->screen->width_in_pixels;
mon->h = xcb->screen->height_in_pixels;
xcb_xinerama_is_active_cookie_t is_active_req = xcb_xinerama_is_active ( xcb_connection );
xcb_xinerama_is_active_reply_t *is_active = xcb_xinerama_is_active_reply ( xcb_connection, is_active_req, &error );
xcb_xinerama_is_active_cookie_t is_active_req = xcb_xinerama_is_active ( xcb->connection );
xcb_xinerama_is_active_reply_t *is_active = xcb_xinerama_is_active_reply ( xcb->connection, is_active_req, &error );
if ( error ) {
fprintf ( stderr, "Couldn't query Xinerama\n" );
return;
@ -195,9 +191,9 @@ void monitor_dimensions ( xcb_connection_t *xcb_connection, xcb_screen_t *screen
free ( is_active );
xcb_xinerama_query_screens_cookie_t cookie_screen;
cookie_screen = xcb_xinerama_query_screens ( xcb_connection );
cookie_screen = xcb_xinerama_query_screens ( xcb->connection );
xcb_xinerama_query_screens_reply_t *query_screens;
query_screens = xcb_xinerama_query_screens_reply ( xcb_connection, cookie_screen, &error );
query_screens = xcb_xinerama_query_screens_reply ( xcb->connection, cookie_screen, &error );
if ( error ) {
fprintf ( stderr, "Error getting screen info\n" );
return;
@ -225,12 +221,12 @@ void monitor_dimensions ( xcb_connection_t *xcb_connection, xcb_screen_t *screen
*
* @returns 1 when found
*/
static int pointer_get ( xcb_connection_t *xcb_connection, xcb_window_t root, int *x, int *y )
static int pointer_get ( xcb_window_t root, int *x, int *y )
{
*x = 0;
*y = 0;
xcb_query_pointer_cookie_t c = xcb_query_pointer ( xcb_connection, root );
xcb_query_pointer_reply_t *r = xcb_query_pointer_reply ( xcb_connection, c, NULL );
xcb_query_pointer_cookie_t c = xcb_query_pointer ( xcb->connection, root );
xcb_query_pointer_reply_t *r = xcb_query_pointer_reply ( xcb->connection, c, NULL );
if ( r ) {
*x = r->root_x;
*y = r->root_y;
@ -242,27 +238,27 @@ static int pointer_get ( xcb_connection_t *xcb_connection, xcb_window_t root, in
}
// determine which monitor holds the active window, or failing that the mouse pointer
void monitor_active ( xcb_connection_t *xcb_connection, workarea *mon )
void monitor_active ( workarea *mon )
{
xcb_window_t root = xcb_screen->root;
xcb_window_t root = xcb->screen->root;
int x, y;
if ( config.monitor >= 0 ) {
if ( monitor_get_dimension ( xcb_connection, xcb_screen, config.monitor, mon ) ) {
if ( monitor_get_dimension ( config.monitor, mon ) ) {
return;
}
fprintf ( stderr, "Failed to find selected monitor.\n" );
}
// Get the current desktop.
unsigned int current_desktop = 0;
if ( config.monitor != -2 && xcb_ewmh_get_current_desktop_reply ( &xcb_ewmh,
xcb_ewmh_get_current_desktop ( &xcb_ewmh, xcb_screen_nbr ),
if ( config.monitor != -2 && xcb_ewmh_get_current_desktop_reply ( &xcb->ewmh,
xcb_ewmh_get_current_desktop ( &xcb->ewmh, xcb->screen_nbr ),
&current_desktop, NULL ) ) {
xcb_get_property_cookie_t c = xcb_ewmh_get_desktop_viewport ( &xcb_ewmh, xcb_screen_nbr );
xcb_get_property_cookie_t c = xcb_ewmh_get_desktop_viewport ( &xcb->ewmh, xcb->screen_nbr );
xcb_ewmh_get_desktop_viewport_reply_t vp;
if ( xcb_ewmh_get_desktop_viewport_reply ( &xcb_ewmh, c, &vp, NULL ) ) {
if ( xcb_ewmh_get_desktop_viewport_reply ( &xcb->ewmh, c, &vp, NULL ) ) {
if ( current_desktop < vp.desktop_viewport_len ) {
monitor_dimensions ( xcb_connection, xcb_screen, vp.desktop_viewport[current_desktop].x,
monitor_dimensions ( vp.desktop_viewport[current_desktop].x,
vp.desktop_viewport[current_desktop].y, mon );
xcb_ewmh_get_desktop_viewport_reply_wipe ( &vp );
return;
@ -272,15 +268,15 @@ void monitor_active ( xcb_connection_t *xcb_connection, workarea *mon )
}
xcb_window_t active_window;
if ( xcb_ewmh_get_active_window_reply ( &xcb_ewmh,
xcb_ewmh_get_active_window ( &xcb_ewmh, xcb_screen_nbr ), &active_window, NULL ) ) {
if ( xcb_ewmh_get_active_window_reply ( &xcb->ewmh,
xcb_ewmh_get_active_window ( &xcb->ewmh, xcb->screen_nbr ), &active_window, NULL ) ) {
// get geometry.
xcb_get_geometry_cookie_t c = xcb_get_geometry ( xcb_connection, active_window );
xcb_get_geometry_reply_t *r = xcb_get_geometry_reply ( xcb_connection, c, NULL );
xcb_get_geometry_cookie_t c = xcb_get_geometry ( xcb->connection, active_window );
xcb_get_geometry_reply_t *r = xcb_get_geometry_reply ( xcb->connection, c, NULL );
if ( r ) {
if ( config.monitor == -2 ) {
xcb_translate_coordinates_cookie_t ct = xcb_translate_coordinates ( xcb_connection, active_window, root, r->x, r->y );
xcb_translate_coordinates_reply_t *t = xcb_translate_coordinates_reply ( xcb_connection, ct, NULL );
xcb_translate_coordinates_cookie_t ct = xcb_translate_coordinates ( xcb->connection, active_window, root, r->x, r->y );
xcb_translate_coordinates_reply_t *t = xcb_translate_coordinates_reply ( xcb->connection, ct, NULL );
if ( t ) {
// place the menu above the window
// if some window is focused, place menu above window, else fall
@ -298,26 +294,26 @@ void monitor_active ( xcb_connection_t *xcb_connection, workarea *mon )
return;
}
}
monitor_dimensions ( xcb_connection, xcb_screen, r->x, r->y, mon );
monitor_dimensions ( r->x, r->y, mon );
free ( r );
return;
}
}
if ( pointer_get ( xcb_connection, root, &x, &y ) ) {
monitor_dimensions ( xcb_connection, xcb_screen, x, y, mon );
if ( pointer_get ( xcb->screen->root, &x, &y ) ) {
monitor_dimensions ( x, y, mon );
return;
}
monitor_dimensions ( xcb_connection, xcb_screen, 0, 0, mon );
monitor_dimensions ( 0, 0, mon );
}
int take_keyboard ( xcb_connection_t *xcb_connection, xcb_window_t w )
int take_keyboard ( xcb_window_t w )
{
for ( int i = 0; i < 500; i++ ) {
xcb_grab_keyboard_cookie_t cc = xcb_grab_keyboard ( xcb_connection,
xcb_grab_keyboard_cookie_t cc = xcb_grab_keyboard ( xcb->connection,
1, w, XCB_CURRENT_TIME, XCB_GRAB_MODE_ASYNC,
XCB_GRAB_MODE_ASYNC );
xcb_grab_keyboard_reply_t *r = xcb_grab_keyboard_reply ( xcb_connection, cc, NULL );
xcb_grab_keyboard_reply_t *r = xcb_grab_keyboard_reply ( xcb->connection, cc, NULL );
if ( r ) {
if ( r->status == XCB_GRAB_STATUS_SUCCESS ) {
free ( r );
@ -331,9 +327,9 @@ int take_keyboard ( xcb_connection_t *xcb_connection, xcb_window_t w )
return 0;
}
void release_keyboard ( xcb_connection_t *xcb_connection )
void release_keyboard ( void )
{
xcb_ungrab_keyboard ( xcb_connection, XCB_CURRENT_TIME );
xcb_ungrab_keyboard ( xcb->connection, XCB_CURRENT_TIME );
}
static unsigned int x11_find_mod_mask ( xkb_stuff *xkb, ... )
@ -474,12 +470,12 @@ void x11_parse_key ( char *combo, unsigned int *mod, xkb_keysym_t *key )
*key = sym;
}
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 )
{
// Scale 0-100 to 0 - UINT32_MAX.
unsigned int opacity_set = ( unsigned int ) ( ( opacity / 100.0 ) * UINT32_MAX );
xcb_change_property ( xcb_connection, XCB_PROP_MODE_REPLACE, box,
xcb_change_property ( xcb->connection, XCB_PROP_MODE_REPLACE, box,
netatoms[_NET_WM_WINDOW_OPACITY], XCB_ATOM_CARDINAL, 32, 1L, &opacity_set );
}
@ -488,12 +484,12 @@ void x11_set_window_opacity ( xcb_connection_t *xcb_connection, xcb_window_t box
*
* Fill in the list of Atoms.
*/
static void x11_create_frequently_used_atoms ( xcb_connection_t *xcb_connection )
static void x11_create_frequently_used_atoms ( void )
{
// X atom values
for ( int i = 0; i < NUM_NETATOMS; i++ ) {
xcb_intern_atom_cookie_t cc = xcb_intern_atom ( xcb_connection, 0, strlen ( netatom_names[i] ), netatom_names[i] );
xcb_intern_atom_reply_t *r = xcb_intern_atom_reply ( xcb_connection, cc, NULL );
xcb_intern_atom_cookie_t cc = xcb_intern_atom ( xcb->connection, 0, strlen ( netatom_names[i] ), netatom_names[i] );
xcb_intern_atom_reply_t *r = xcb_intern_atom_reply ( xcb->connection, cc, NULL );
if ( r ) {
netatoms[i] = r->atom;
free ( r );
@ -501,17 +497,17 @@ static void x11_create_frequently_used_atoms ( xcb_connection_t *xcb_connection
}
}
void x11_setup ( xcb_connection_t *xcb_connection, xkb_stuff *xkb )
void x11_setup ( xkb_stuff *xkb )
{
// determine numlock mask so we can bind on keys with and without it
x11_figure_out_masks ( xkb );
x11_create_frequently_used_atoms ( xcb_connection );
x11_create_frequently_used_atoms ( );
}
void x11_create_visual_and_colormap ( xcb_connection_t *xcb_connection, xcb_screen_t *xcb_screen )
void x11_create_visual_and_colormap ( void )
{
xcb_depth_iterator_t depth_iter;
for ( depth_iter = xcb_screen_allowed_depths_iterator ( xcb_screen ); depth_iter.rem; xcb_depth_next ( &depth_iter ) ) {
for ( depth_iter = xcb_screen_allowed_depths_iterator ( xcb->screen ); depth_iter.rem; xcb_depth_next ( &depth_iter ) ) {
xcb_depth_t *d = depth_iter.data;
xcb_visualtype_iterator_t visual_iter;
@ -521,7 +517,7 @@ void x11_create_visual_and_colormap ( xcb_connection_t *xcb_connection, xcb_scre
depth = d;
visual = v;
}
if ( xcb_screen->root_visual == v->visual_id ) {
if ( xcb->screen->root_visual == v->visual_id ) {
root_depth = d;
root_visual = v;
}
@ -530,9 +526,9 @@ void x11_create_visual_and_colormap ( xcb_connection_t *xcb_connection, xcb_scre
if ( visual != NULL ) {
xcb_void_cookie_t c;
xcb_generic_error_t *e;
map = xcb_generate_id ( xcb_connection );
c = xcb_create_colormap_checked ( xcb_connection, XCB_COLORMAP_ALLOC_NONE, map, xcb_screen->root, visual->visual_id );
e = xcb_request_check ( xcb_connection, c );
map = xcb_generate_id ( xcb->connection );
c = xcb_create_colormap_checked ( xcb->connection, XCB_COLORMAP_ALLOC_NONE, map, xcb->screen->root, visual->visual_id );
e = xcb_request_check ( xcb->connection, c );
if ( e ) {
depth = NULL;
visual = NULL;
@ -543,7 +539,7 @@ void x11_create_visual_and_colormap ( xcb_connection_t *xcb_connection, xcb_scre
if ( visual == NULL ) {
depth = root_depth;
visual = root_visual;
map = xcb_screen->default_colormap;
map = xcb->screen->default_colormap;
}
}
@ -671,3 +667,8 @@ void color_separator ( cairo_t *d )
}
x11_helper_set_cairo_rgba ( d, color_cache[SEPARATOR].color );
}
xcb_window_t xcb_stuff_get_root_window ( xcb_stuff *xcb )
{
return xcb->screen->root;
}

View file

@ -36,6 +36,7 @@
#include <xkbcommon/xkbcommon-compose.h>
#include <xkbcommon/xkbcommon-x11.h>
#include <X11/Xresource.h>
#include "xcb.h"
#include "x11-helper.h"
#include "rofi.h"
#include "xrmoptions.h"
@ -223,9 +224,9 @@ static void __config_parse_xresource_options ( XrmDatabase xDB )
g_free ( name );
}
}
void config_parse_xresource_options ( xcb_connection_t *xcb_connection, xcb_screen_t *xcb_screen )
void config_parse_xresource_options ( xcb_stuff *xcb )
{
char *name = window_get_text_prop ( xcb_connection, xcb_screen->root, XCB_ATOM_RESOURCE_MANAGER );
char *name = window_get_text_prop ( xcb_stuff_get_root_window ( xcb ), XCB_ATOM_RESOURCE_MANAGER );
if ( name ) {
// Map Xresource entries to rofi config options.
XrmDatabase xDB = XrmGetStringDatabase ( name );
@ -329,9 +330,9 @@ static void __config_parse_xresource_options_dynamic ( XrmDatabase xDB )
}
}
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 )
{
char *name = window_get_text_prop ( xcb_connection, xcb_screen->root, XCB_ATOM_RESOURCE_MANAGER );
char *name = window_get_text_prop ( xcb_stuff_get_root_window ( xcb ), XCB_ATOM_RESOURCE_MANAGER );
XrmDatabase xDB = XrmGetStringDatabase ( name );
__config_parse_xresource_options_dynamic ( xDB );
XrmDestroyDatabase ( xDB );

View file

@ -5,9 +5,12 @@
#include <helper.h>
#include <string.h>
#include <xcb/xcb_ewmh.h>
#include "xcb-internal.h"
#include "rofi.h"
#include "settings.h"
static int test = 0;
static int test = 0;
struct xcb_stuff *xcb;
#define TASSERT( a ) { \
assert ( a ); \