mirror of
https://github.com/davatorium/rofi.git
synced 2024-11-18 13:54:36 -05:00
Check for the availability of the xinerama extension.
This commit is contained in:
parent
fd707acac5
commit
fa7ceaf580
6 changed files with 63 additions and 47 deletions
|
@ -237,6 +237,7 @@ helper_test_LDADD=\
|
|||
$(x11_LIBS)\
|
||||
$(GW_XCB_LIBS)\
|
||||
$(xinerama_LIBS)\
|
||||
$(libsn_LIBS)\
|
||||
$(cairo_LIBS)
|
||||
|
||||
TESTS=\
|
||||
|
|
|
@ -18,6 +18,7 @@ struct _xcb_stuff
|
|||
int screen_nbr;
|
||||
SnDisplay *sndisplay;
|
||||
SnLauncheeContext *sncontext;
|
||||
gboolean has_xinerama;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -38,6 +38,8 @@
|
|||
#include <xcb/xcb_ewmh.h>
|
||||
#include <xcb/xcb_icccm.h>
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
#include "xcb-internal.h"
|
||||
#include "xcb.h"
|
||||
|
||||
|
|
|
@ -37,6 +37,7 @@
|
|||
#include <xcb/xcb.h>
|
||||
#include <xcb/xcb_aux.h>
|
||||
#include <xcb/xcb_ewmh.h>
|
||||
#include <xcb/xinerama.h>
|
||||
#include <xcb/xkb.h>
|
||||
#include <xkbcommon/xkbcommon.h>
|
||||
#include <xkbcommon/xkbcommon-compose.h>
|
||||
|
@ -446,6 +447,12 @@ static inline void load_configuration_dynamic ( )
|
|||
*/
|
||||
static gboolean main_loop_x11_event_handler ( xcb_generic_event_t *ev, G_GNUC_UNUSED gpointer data )
|
||||
{
|
||||
if ( ev == NULL ) {
|
||||
int status = xcb_connection_has_error ( xcb->connection );
|
||||
fprintf ( stderr, "The XCB connection to X server had a fatal error: %d\n", status );
|
||||
g_main_loop_quit ( main_loop );
|
||||
return G_SOURCE_REMOVE;
|
||||
}
|
||||
uint8_t type = ev->response_type & ~0x80;
|
||||
if ( type == xkb.first_event ) {
|
||||
switch ( ev->pad0 )
|
||||
|
@ -739,16 +746,42 @@ int main ( int argc, char *argv[] )
|
|||
fprintf ( stderr, "Failed to get keyboard compose table. Trying to limp on.\n" );
|
||||
}
|
||||
|
||||
if ( xcb_connection_has_error ( xcb->connection ) ) {
|
||||
fprintf ( stderr, "Connection has error\n" );
|
||||
exit ( EXIT_FAILURE );
|
||||
}
|
||||
x11_setup ( &xkb );
|
||||
if ( xcb_connection_has_error ( xcb->connection ) ) {
|
||||
fprintf ( stderr, "Connection has error\n" );
|
||||
exit ( EXIT_FAILURE );
|
||||
}
|
||||
|
||||
const xcb_query_extension_reply_t *er = xcb_get_extension_data ( xcb->connection, &xcb_xinerama_id );
|
||||
if ( er ) {
|
||||
if ( er->present ) {
|
||||
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, NULL );
|
||||
xcb->has_xinerama = is_active->state;
|
||||
free ( is_active );
|
||||
}
|
||||
}
|
||||
main_loop = g_main_loop_new ( NULL, FALSE );
|
||||
|
||||
TICK_N ( "Setup mainloop" );
|
||||
// startup not.
|
||||
xcb->sndisplay = sn_xcb_display_new ( xcb->connection, error_trap_push, error_trap_pop );
|
||||
if ( xcb_connection_has_error ( xcb->connection ) ) {
|
||||
fprintf ( stderr, "Connection has error\n" );
|
||||
exit ( EXIT_FAILURE );
|
||||
}
|
||||
|
||||
if ( xcb->sndisplay != NULL ) {
|
||||
xcb->sncontext = sn_launchee_context_new_from_environment ( xcb->sndisplay, xcb->screen_nbr );
|
||||
}
|
||||
if ( xcb_connection_has_error ( xcb->connection ) ) {
|
||||
fprintf ( stderr, "Connection has error\n" );
|
||||
exit ( EXIT_FAILURE );
|
||||
}
|
||||
TICK_N ( "Startup Notification" );
|
||||
|
||||
// Initialize Xresources subsystem.
|
||||
|
|
|
@ -57,6 +57,7 @@ struct _xcb_stuff xcb_int = {
|
|||
.screen_nbr = -1,
|
||||
.sndisplay = NULL,
|
||||
.sncontext = NULL,
|
||||
.has_xinerama = FALSE,
|
||||
};
|
||||
xcb_stuff *xcb = &xcb_int;
|
||||
|
||||
|
@ -106,22 +107,17 @@ 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 );
|
||||
if ( error ) {
|
||||
fprintf ( stderr, "Couldn't query Xinerama\n" );
|
||||
return size;
|
||||
}
|
||||
if ( is_active == NULL ) {
|
||||
return size;
|
||||
}
|
||||
if ( !is_active->state ) {
|
||||
free ( is_active );
|
||||
return size;
|
||||
}
|
||||
free ( is_active );
|
||||
|
||||
if ( !xcb->has_xinerama ) {
|
||||
return size;
|
||||
}
|
||||
|
||||
if ( xcb_connection_has_error ( xcb->connection ) ) {
|
||||
fprintf ( stderr, "1.Connection has error\n" );
|
||||
exit ( EXIT_FAILURE );
|
||||
}
|
||||
xcb_xinerama_query_screens_cookie_t cookie_screen;
|
||||
|
||||
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 );
|
||||
|
@ -147,20 +143,9 @@ int monitor_get_dimension ( int monitor, workarea *mon )
|
|||
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 );
|
||||
if ( error ) {
|
||||
fprintf ( stderr, "Error getting screen info\n" );
|
||||
if ( !xcb->has_xinerama ) {
|
||||
return FALSE;
|
||||
}
|
||||
if ( is_active == NULL ) {
|
||||
return FALSE;
|
||||
}
|
||||
if ( !is_active->state ) {
|
||||
free ( is_active );
|
||||
return FALSE;
|
||||
}
|
||||
free ( is_active );
|
||||
|
||||
xcb_xinerama_query_screens_cookie_t cookie_screen;
|
||||
cookie_screen = xcb_xinerama_query_screens ( xcb->connection );
|
||||
|
@ -193,20 +178,9 @@ void monitor_dimensions ( int x, int y, workarea *mon )
|
|||
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 );
|
||||
if ( error ) {
|
||||
fprintf ( stderr, "Couldn't query Xinerama\n" );
|
||||
if ( !xcb->has_xinerama ) {
|
||||
return;
|
||||
}
|
||||
if ( is_active == NULL ) {
|
||||
return;
|
||||
}
|
||||
if ( !is_active->state ) {
|
||||
free ( is_active );
|
||||
return;
|
||||
}
|
||||
free ( is_active );
|
||||
|
||||
xcb_xinerama_query_screens_cookie_t cookie_screen;
|
||||
cookie_screen = xcb_xinerama_query_screens ( xcb->connection );
|
||||
|
@ -328,6 +302,10 @@ void monitor_active ( workarea *mon )
|
|||
int take_keyboard ( xcb_window_t w )
|
||||
{
|
||||
for ( int i = 0; i < 500; i++ ) {
|
||||
if ( xcb_connection_has_error ( xcb->connection ) ) {
|
||||
fprintf ( stderr, "Connection has error\n" );
|
||||
exit ( EXIT_FAILURE );
|
||||
}
|
||||
xcb_grab_keyboard_cookie_t cc = xcb_grab_keyboard ( xcb->connection,
|
||||
1, w, XCB_CURRENT_TIME, XCB_GRAB_MODE_ASYNC,
|
||||
XCB_GRAB_MODE_ASYNC );
|
||||
|
|
|
@ -25,9 +25,10 @@ struct xcb_stuff *xcb;
|
|||
} \
|
||||
}
|
||||
|
||||
void rofi_view_error_dialog ( const char *msg, G_GNUC_UNUSED int markup )
|
||||
int rofi_view_error_dialog ( const char *msg, G_GNUC_UNUSED int markup )
|
||||
{
|
||||
fputs ( msg, stderr );
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
int show_error_message ( const char *msg, int markup )
|
||||
|
|
Loading…
Reference in a new issue