2 * vim:ts=4:sw=4:expandtab
4 * © 2010-2012 Michael Stapelberg
6 * See LICENSE for licensing information
14 #include <xcb/xinerama.h>
20 /* Number of Xinerama screens which are currently present. */
23 /* The resolutions of the currently present Xinerama screens. */
26 static bool xinerama_active;
27 extern bool debug_mode;
29 void xinerama_init(void) {
30 if (!xcb_get_extension_data(conn, &xcb_xinerama_id)->present) {
31 DEBUG("Xinerama extension not found, disabling.\n");
35 xcb_xinerama_is_active_cookie_t cookie;
36 xcb_xinerama_is_active_reply_t *reply;
38 cookie = xcb_xinerama_is_active(conn);
39 reply = xcb_xinerama_is_active_reply(conn, cookie, NULL);
48 xinerama_active = true;
51 void xinerama_query_screens(void) {
55 xcb_xinerama_query_screens_cookie_t cookie;
56 xcb_xinerama_query_screens_reply_t *reply;
57 xcb_xinerama_screen_info_t *screen_info;
59 cookie = xcb_xinerama_query_screens_unchecked(conn);
60 reply = xcb_xinerama_query_screens_reply(conn, cookie, NULL);
63 fprintf(stderr, "Couldn't get Xinerama screens\n");
66 screen_info = xcb_xinerama_query_screens_screen_info(reply);
67 int screens = xcb_xinerama_query_screens_screen_info_length(reply);
69 Rect *resolutions = malloc(screens * sizeof(Rect));
70 /* No memory? Just keep on using the old information. */
75 xr_resolutions = resolutions;
78 for (int screen = 0; screen < xr_screens; screen++) {
79 xr_resolutions[screen].x = screen_info[screen].x_org;
80 xr_resolutions[screen].y = screen_info[screen].y_org;
81 xr_resolutions[screen].width = screen_info[screen].width;
82 xr_resolutions[screen].height = screen_info[screen].height;
83 DEBUG("found Xinerama screen: %d x %d at %d x %d\n",
84 screen_info[screen].width, screen_info[screen].height,
85 screen_info[screen].x_org, screen_info[screen].y_org);