2012-01-03 18:10:56 -05:00
|
|
|
/*
|
|
|
|
* vim:ts=4:sw=4:expandtab
|
|
|
|
*
|
|
|
|
* © 2010-2012 Michael Stapelberg
|
|
|
|
*
|
|
|
|
* See LICENSE for licensing information
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <math.h>
|
|
|
|
#include <xcb/xcb.h>
|
|
|
|
#include <xcb/xinerama.h>
|
|
|
|
|
2012-03-26 13:54:47 -04:00
|
|
|
#include "i3lock.h"
|
2012-01-03 18:10:56 -05:00
|
|
|
#include "xcb.h"
|
|
|
|
#include "xinerama.h"
|
|
|
|
|
|
|
|
/* Number of Xinerama screens which are currently present. */
|
|
|
|
int xr_screens = 0;
|
|
|
|
|
|
|
|
/* The resolutions of the currently present Xinerama screens. */
|
|
|
|
Rect *xr_resolutions;
|
|
|
|
|
|
|
|
static bool xinerama_active;
|
2012-03-26 13:54:47 -04:00
|
|
|
extern bool debug_mode;
|
2012-01-03 18:10:56 -05:00
|
|
|
|
2012-04-01 06:28:28 -04:00
|
|
|
void xinerama_init(void) {
|
2012-01-03 18:10:56 -05:00
|
|
|
if (!xcb_get_extension_data(conn, &xcb_xinerama_id)->present) {
|
2012-03-26 13:54:47 -04:00
|
|
|
DEBUG("Xinerama extension not found, disabling.\n");
|
2012-01-03 18:10:56 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
xcb_xinerama_is_active_cookie_t cookie;
|
|
|
|
xcb_xinerama_is_active_reply_t *reply;
|
|
|
|
|
|
|
|
cookie = xcb_xinerama_is_active(conn);
|
|
|
|
reply = xcb_xinerama_is_active_reply(conn, cookie, NULL);
|
|
|
|
if (!reply)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!reply->state) {
|
|
|
|
free(reply);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
xinerama_active = true;
|
|
|
|
}
|
|
|
|
|
2012-04-01 06:28:28 -04:00
|
|
|
void xinerama_query_screens(void) {
|
2012-01-03 18:10:56 -05:00
|
|
|
if (!xinerama_active)
|
|
|
|
return;
|
|
|
|
|
|
|
|
xcb_xinerama_query_screens_cookie_t cookie;
|
|
|
|
xcb_xinerama_query_screens_reply_t *reply;
|
|
|
|
xcb_xinerama_screen_info_t *screen_info;
|
|
|
|
|
|
|
|
cookie = xcb_xinerama_query_screens_unchecked(conn);
|
|
|
|
reply = xcb_xinerama_query_screens_reply(conn, cookie, NULL);
|
|
|
|
if (!reply) {
|
2012-03-26 13:54:47 -04:00
|
|
|
if (debug_mode)
|
|
|
|
fprintf(stderr, "Couldn't get Xinerama screens\n");
|
2012-01-03 18:10:56 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
screen_info = xcb_xinerama_query_screens_screen_info(reply);
|
|
|
|
int screens = xcb_xinerama_query_screens_screen_info_length(reply);
|
|
|
|
|
|
|
|
Rect *resolutions = malloc(screens * sizeof(Rect));
|
|
|
|
/* No memory? Just keep on using the old information. */
|
|
|
|
if (!resolutions) {
|
|
|
|
free(reply);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
xr_resolutions = resolutions;
|
|
|
|
xr_screens = screens;
|
|
|
|
|
|
|
|
for (int screen = 0; screen < xr_screens; screen++) {
|
|
|
|
xr_resolutions[screen].x = screen_info[screen].x_org;
|
|
|
|
xr_resolutions[screen].y = screen_info[screen].y_org;
|
|
|
|
xr_resolutions[screen].width = screen_info[screen].width;
|
|
|
|
xr_resolutions[screen].height = screen_info[screen].height;
|
2012-03-26 13:54:47 -04:00
|
|
|
DEBUG("found Xinerama screen: %d x %d at %d x %d\n",
|
2012-01-03 18:10:56 -05:00
|
|
|
screen_info[screen].width, screen_info[screen].height,
|
|
|
|
screen_info[screen].x_org, screen_info[screen].y_org);
|
|
|
|
}
|
|
|
|
|
|
|
|
free(reply);
|
|
|
|
}
|