-void initialize_xinerama(xcb_connection_t *conn) {
- xcb_xinerama_query_screens_reply_t *reply;
- xcb_xinerama_screen_info_t *screen_info;
- int screen;
-
- if (!xcb_get_extension_data(conn, &xcb_xinerama_id)->present) {
- printf("Xinerama extension not found, disabling.\n");
- return;
- }
-
- if (!xcb_xinerama_is_active_reply(conn, xcb_xinerama_is_active(conn), NULL)->state) {
- printf("Xinerama is not active (in your X-Server), disabling.\n");
- return;
- }
-
- reply = xcb_xinerama_query_screens_reply(conn, xcb_xinerama_query_screens_unchecked(conn), NULL);
- if (!reply) {
- printf("Couldn’t get active Xinerama screens\n");
- return;
+static void query_screens(xcb_connection_t *conn) {
+ xcb_xinerama_query_screens_reply_t *reply;
+ xcb_xinerama_screen_info_t *screen_info;
+
+ reply = xcb_xinerama_query_screens_reply(conn, xcb_xinerama_query_screens_unchecked(conn), NULL);
+ if (!reply) {
+ ELOG("Couldn't get Xinerama screens\n");
+ return;
+ }
+ screen_info = xcb_xinerama_query_screens_screen_info(reply);
+ int screens = xcb_xinerama_query_screens_screen_info_length(reply);
+
+ for (int screen = 0; screen < screens; screen++) {
+ Output *s = get_screen_at(screen_info[screen].x_org, screen_info[screen].y_org);
+ if (s != NULL) {
+ DLOG("Re-used old Xinerama screen %p\n", s);
+ /* This screen already exists. We use the littlest screen so that the user
+ can always see the complete workspace */
+ s->rect.width = min(s->rect.width, screen_info[screen].width);
+ s->rect.height = min(s->rect.height, screen_info[screen].height);
+ } else {
+ s = scalloc(sizeof(Output));
+ asprintf(&(s->name), "xinerama-%d", num_screens);
+ DLOG("Created new Xinerama screen %s (%p)\n", s->name, s);
+ s->active = true;
+ s->rect.x = screen_info[screen].x_org;
+ s->rect.y = screen_info[screen].y_org;
+ s->rect.width = screen_info[screen].width;
+ s->rect.height = screen_info[screen].height;
+ /* We always treat the screen at 0x0 as the primary screen */
+ if (s->rect.x == 0 && s->rect.y == 0)
+ TAILQ_INSERT_HEAD(&outputs, s, outputs);
+ else TAILQ_INSERT_TAIL(&outputs, s, outputs);
+ num_screens++;