mirror of
https://github.com/davatorium/rofi.git
synced 2024-11-25 13:55:34 -05:00
I749 (#766)
* [XCB] Use randr monitor API to get monitors. Hopefully helps with issue #749. * Add check for randr header version * Fix API version check, and check the version of the server. * Add some comments to the code.
This commit is contained in:
parent
ac29c537dd
commit
521843e9be
1 changed files with 289 additions and 204 deletions
95
source/xcb.c
95
source/xcb.c
|
@ -62,6 +62,11 @@
|
|||
#include "timings.h"
|
||||
|
||||
#include <rofi.h>
|
||||
|
||||
/** Minimal randr prefered for running rofi (1.5) */
|
||||
#define RANDR_PREF_MAJOR_VERSION 1
|
||||
#define RANDR_PREF_MINOR_VERSION 5
|
||||
|
||||
/** Checks if the if x and y is inside rectangle. */
|
||||
#define INTERSECT( x, y, x1, y1, w1, h1 ) ( ( ( ( x ) >= ( x1 ) ) && ( ( x ) < ( x1 + w1 ) ) ) && ( ( ( y ) >= ( y1 ) ) && ( ( y ) < ( y1 + h1 ) ) ) )
|
||||
WindowManagerQuirk current_window_manager = WM_EWHM;
|
||||
|
@ -234,6 +239,51 @@ static workarea * x11_get_monitor_from_output ( xcb_randr_output_t out )
|
|||
return retv;
|
||||
}
|
||||
|
||||
#if ( ( (XCB_RANDR_MAJOR_VERSION >= RANDR_PREF_MAJOR_VERSION ) && (XCB_RANDR_MINOR_VERSION >= RANDR_PREF_MINOR_VERSION ) ) \
|
||||
|| XCB_RANDR_MAJOR_VERSION > RANDR_PREF_MAJOR_VERSION )
|
||||
/**
|
||||
* @param mon The randr monitor to parse.
|
||||
*
|
||||
* Create monitor based on xrandr monitor id.
|
||||
*
|
||||
* @returns A workarea representing the monitor mon
|
||||
*/
|
||||
static workarea *x11_get_monitor_from_randr_monitor ( xcb_randr_monitor_info_t *mon )
|
||||
{
|
||||
// Query to the name of the monitor.
|
||||
xcb_generic_error_t *err;
|
||||
xcb_get_atom_name_cookie_t anc = xcb_get_atom_name(xcb->connection, mon->name);
|
||||
xcb_get_atom_name_reply_t *atom_reply = xcb_get_atom_name_reply( xcb->connection, anc, &err);
|
||||
if (err != NULL) {
|
||||
g_warning ("Could not get RandR monitor name: X11 error code %d\n", err->error_code);
|
||||
free(err);
|
||||
return NULL;
|
||||
}
|
||||
workarea *retv = g_malloc0 ( sizeof ( workarea ) );
|
||||
|
||||
// Is primary monitor.
|
||||
retv->primary = mon->primary;
|
||||
|
||||
// Position and size.
|
||||
retv->x = mon->x;
|
||||
retv->y = mon->y;
|
||||
retv->w = mon->width;
|
||||
retv->h = mon->height;
|
||||
|
||||
// Physical
|
||||
retv->mw = mon->width_in_millimeters;
|
||||
retv->mh = mon->height_in_millimeters;
|
||||
|
||||
// Name
|
||||
retv->name = g_strdup_printf("%.*s", xcb_get_atom_name_name_length(atom_reply), xcb_get_atom_name_name(atom_reply));
|
||||
|
||||
// Free name atom.
|
||||
free ( atom_reply );
|
||||
|
||||
return retv;
|
||||
}
|
||||
#endif
|
||||
|
||||
static int x11_is_extension_present ( const char *extension )
|
||||
{
|
||||
xcb_query_extension_cookie_t randr_cookie = xcb_query_extension ( xcb->connection, strlen ( extension ), extension );
|
||||
|
@ -301,6 +351,38 @@ static void x11_build_monitor_layout ()
|
|||
}
|
||||
g_debug ( "Query RANDR for monitor layout." );
|
||||
|
||||
g_debug ( "Randr XCB api version: %d.%d.", XCB_RANDR_MAJOR_VERSION, XCB_RANDR_MINOR_VERSION );
|
||||
#if ( ( ( XCB_RANDR_MAJOR_VERSION == RANDR_PREF_MAJOR_VERSION ) && (XCB_RANDR_MINOR_VERSION >= RANDR_PREF_MINOR_VERSION ) ) \
|
||||
|| XCB_RANDR_MAJOR_VERSION > RANDR_PREF_MAJOR_VERSION )
|
||||
xcb_randr_query_version_cookie_t cversion = xcb_randr_query_version(xcb->connection,
|
||||
RANDR_PREF_MAJOR_VERSION, RANDR_PREF_MINOR_VERSION);
|
||||
xcb_randr_query_version_reply_t *rversion = xcb_randr_query_version_reply( xcb->connection, cversion, NULL );
|
||||
if ( rversion ) {
|
||||
g_debug ( "Found randr version: %d.%d", rversion->major_version, rversion->minor_version );
|
||||
// Check if we are 1.5 and up.
|
||||
if ( ( ( rversion->major_version == XCB_RANDR_MAJOR_VERSION ) && (rversion->minor_version >= XCB_RANDR_MINOR_VERSION ) ) ||
|
||||
( rversion->major_version > XCB_RANDR_MAJOR_VERSION ) ){
|
||||
xcb_randr_get_monitors_cookie_t t = xcb_randr_get_monitors( xcb->connection, xcb->screen->root, 1 );
|
||||
xcb_randr_get_monitors_reply_t *mreply = xcb_randr_get_monitors_reply ( xcb->connection, t, NULL );
|
||||
if( mreply ) {
|
||||
xcb_randr_monitor_info_iterator_t iter = xcb_randr_get_monitors_monitors_iterator ( mreply );
|
||||
while ( iter.rem > 0 ) {
|
||||
workarea *w = x11_get_monitor_from_randr_monitor ( iter.data );
|
||||
if ( w ) {
|
||||
w->next = xcb->monitors;
|
||||
xcb->monitors = w;
|
||||
}
|
||||
xcb_randr_monitor_info_next (&iter);
|
||||
}
|
||||
free ( mreply );
|
||||
}
|
||||
}
|
||||
free ( rversion );
|
||||
}
|
||||
#endif
|
||||
|
||||
// If no monitors found.
|
||||
if ( xcb->monitors == NULL ) {
|
||||
xcb_randr_get_screen_resources_current_reply_t *res_reply;
|
||||
xcb_randr_get_screen_resources_current_cookie_t src;
|
||||
src = xcb_randr_get_screen_resources_current ( xcb->connection, xcb->screen->root );
|
||||
|
@ -325,16 +407,19 @@ static void x11_build_monitor_layout ()
|
|||
}
|
||||
}
|
||||
}
|
||||
// Number monitor
|
||||
int index = 0;
|
||||
for ( workarea *iter = xcb->monitors; iter; iter = iter->next ) {
|
||||
iter->monitor_id = index++;
|
||||
}
|
||||
// If exists, free primary output reply.
|
||||
if ( pc_rep ) {
|
||||
free ( pc_rep );
|
||||
}
|
||||
free ( res_reply );
|
||||
|
||||
}
|
||||
|
||||
// Number monitor
|
||||
int index = 0;
|
||||
for ( workarea *iter = xcb->monitors; iter; iter = iter->next ) {
|
||||
iter->monitor_id = index++;
|
||||
}
|
||||
}
|
||||
|
||||
void display_dump_monitor_layout ( void )
|
||||
|
|
Loading…
Reference in a new issue