From 05165a02f221d0fd26ccde004862cc3e3c2984a1 Mon Sep 17 00:00:00 2001 From: Stanislav Seletskiy Date: Wed, 31 Aug 2016 14:10:30 +0700 Subject: [PATCH 1/2] add xinerama support --- configure.ac | 2 +- include/x11-helper.h | 2 ++ source/x11-helper.c | 60 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 63 insertions(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 1350d443..3f103a88 100644 --- a/configure.ac +++ b/configure.ac @@ -94,7 +94,7 @@ dnl --------------------------------------------------------------------- dnl PKG_CONFIG based dependencies dnl --------------------------------------------------------------------- PKG_CHECK_MODULES([glib], [glib-2.0 >= 2.40]) -GW_CHECK_XCB([xcb-aux xcb-xkb xkbcommon >= 0.5.0 xkbcommon-x11 xcb-ewmh xcb-icccm xcb-xrm xcb-randr]) +GW_CHECK_XCB([xcb-aux xcb-xkb xkbcommon >= 0.5.0 xkbcommon-x11 xcb-ewmh xcb-icccm xcb-xrm xcb-randr xcb-xinerama]) PKG_CHECK_MODULES([pango], [pango pangocairo]) PKG_CHECK_MODULES([cairo], [cairo cairo-xcb]) PKG_CHECK_MODULES([libsn], [libstartup-notification-1.0]) diff --git a/include/x11-helper.h b/include/x11-helper.h index 0058fbdf..d26d12ff 100644 --- a/include/x11-helper.h +++ b/include/x11-helper.h @@ -153,6 +153,8 @@ cairo_surface_t * x11_helper_get_bg_surface ( void ); * Creates an internal represenation of the available monitors. * Used for positioning rofi. */ +uint8_t x11_is_randr_present ( void ); +void x11_build_monitor_layout_xinerama ( void ); void x11_build_monitor_layout ( void ); void x11_dump_monitor_layout ( void ); /*@}*/ diff --git a/source/x11-helper.c b/source/x11-helper.c index 560ce39f..6fc11095 100644 --- a/source/x11-helper.c +++ b/source/x11-helper.c @@ -37,7 +37,9 @@ #include #include +#include #include +#include #include "xcb-internal.h" #include "xcb.h" #include "settings.h" @@ -213,8 +215,66 @@ static workarea * x11_get_monitor_from_output ( xcb_randr_output_t out ) return retv; } +uint8_t x11_is_randr_present () { + xcb_query_extension_cookie_t randr_cookie = xcb_query_extension ( + xcb->connection, + sizeof("RANDR")-1, + "RANDR" + ); + + xcb_query_extension_reply_t *randr_reply = xcb_query_extension_reply ( + xcb->connection, + randr_cookie, + NULL + ); + + return randr_reply->present; +} + +void x11_build_monitor_layout_xinerama () { + xcb_xinerama_query_screens_cookie_t screens_cookie = xcb_xinerama_query_screens_unchecked ( + xcb->connection + ); + + xcb_xinerama_query_screens_reply_t *screens_reply = xcb_xinerama_query_screens_reply ( + xcb->connection, + screens_cookie, + NULL + ); + + xcb_xinerama_screen_info_iterator_t screens_iterator = xcb_xinerama_query_screens_screen_info_iterator ( + screens_reply + ); + + for ( ; screens_iterator.rem > 0; xcb_xinerama_screen_info_next (&screens_iterator) ) { + workarea *w = g_malloc0 ( sizeof ( workarea ) ); + + w->x = screens_iterator.data->x_org; + w->y = screens_iterator.data->y_org; + w->w = screens_iterator.data->width; + w->h = screens_iterator.data->height; + + if ( w ) { + w->next = xcb->monitors; + xcb->monitors = w; + } + } + + int index = 0; + for ( workarea *iter = xcb->monitors; iter; iter = iter->next ) { + iter->monitor_id = index++; + } + + free ( screens_reply ); +} + void x11_build_monitor_layout () { + if ( !x11_is_randr_present () ) { + fprintf ( stderr, "Using XINERAMA instead of XRANDR\n" ); + x11_build_monitor_layout_xinerama (); + } + if ( xcb->monitors ) { return; } From a6207e473aff43dc1e86d10d64943f1d071c02aa Mon Sep 17 00:00:00 2001 From: Stanislav Seletskiy Date: Wed, 31 Aug 2016 14:26:47 +0700 Subject: [PATCH 2/2] remove functions from .h, free memory, int to bool --- include/x11-helper.h | 2 -- source/x11-helper.c | 15 +++++++++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/include/x11-helper.h b/include/x11-helper.h index d26d12ff..0058fbdf 100644 --- a/include/x11-helper.h +++ b/include/x11-helper.h @@ -153,8 +153,6 @@ cairo_surface_t * x11_helper_get_bg_surface ( void ); * Creates an internal represenation of the available monitors. * Used for positioning rofi. */ -uint8_t x11_is_randr_present ( void ); -void x11_build_monitor_layout_xinerama ( void ); void x11_build_monitor_layout ( void ); void x11_dump_monitor_layout ( void ); /*@}*/ diff --git a/source/x11-helper.c b/source/x11-helper.c index 6fc11095..8e029d94 100644 --- a/source/x11-helper.c +++ b/source/x11-helper.c @@ -56,6 +56,9 @@ #include "x11-helper.h" #include "xkb-internal.h" +int x11_is_randr_present ( void ); +void x11_build_monitor_layout_xinerama ( void ); + struct _xcb_stuff xcb_int = { .connection = NULL, .screen = NULL, @@ -215,7 +218,7 @@ static workarea * x11_get_monitor_from_output ( xcb_randr_output_t out ) return retv; } -uint8_t x11_is_randr_present () { +int x11_is_randr_present () { xcb_query_extension_cookie_t randr_cookie = xcb_query_extension ( xcb->connection, sizeof("RANDR")-1, @@ -228,7 +231,15 @@ uint8_t x11_is_randr_present () { NULL ); - return randr_reply->present; + uint8_t present = randr_reply->present; + + free ( randr_reply ); + + if ( present ) { + return TRUE; + } else { + return FALSE; + } } void x11_build_monitor_layout_xinerama () {