4 * i3 - an improved dynamic tiling window manager
6 * © 2009-2010 Michael Stapelberg and contributors
8 * See file LICENSE for license information.
10 * This is LEGACY code (we support RandR, which can do much more than
11 * Xinerama), but necessary for the poor users of the nVidia binary
12 * driver which does not support RandR in 2010 *sigh*.
20 #include <xcb/xinerama.h>
26 #include "workspace.h"
30 static int num_screens;
33 * Looks in outputs for the Output whose start coordinates are x, y
36 static Output *get_screen_at(int x, int y) {
38 TAILQ_FOREACH(output, &outputs, outputs)
39 if (output->rect.x == x && output->rect.y == y)
46 * Gets the Xinerama screens and converts them to virtual Outputs (only one screen for two
47 * Xinerama screen which are configured in clone mode) in the given screenlist
50 static void query_screens(xcb_connection_t *conn) {
51 xcb_xinerama_query_screens_reply_t *reply;
52 xcb_xinerama_screen_info_t *screen_info;
54 reply = xcb_xinerama_query_screens_reply(conn, xcb_xinerama_query_screens_unchecked(conn), NULL);
56 ELOG("Couldn't get Xinerama screens\n");
59 screen_info = xcb_xinerama_query_screens_screen_info(reply);
60 int screens = xcb_xinerama_query_screens_screen_info_length(reply);
62 for (int screen = 0; screen < screens; screen++) {
63 Output *s = get_screen_at(screen_info[screen].x_org, screen_info[screen].y_org);
65 DLOG("Re-used old Xinerama screen %p\n", s);
66 /* This screen already exists. We use the littlest screen so that the user
67 can always see the complete workspace */
68 s->rect.width = min(s->rect.width, screen_info[screen].width);
69 s->rect.height = min(s->rect.height, screen_info[screen].height);
71 s = scalloc(sizeof(Output));
72 asprintf(&(s->name), "xinerama-%d", num_screens);
73 DLOG("Created new Xinerama screen %s (%p)\n", s->name, s);
75 s->rect.x = screen_info[screen].x_org;
76 s->rect.y = screen_info[screen].y_org;
77 s->rect.width = screen_info[screen].width;
78 s->rect.height = screen_info[screen].height;
79 /* We always treat the screen at 0x0 as the primary screen */
80 if (s->rect.x == 0 && s->rect.y == 0)
81 TAILQ_INSERT_HEAD(&outputs, s, outputs);
82 else TAILQ_INSERT_TAIL(&outputs, s, outputs);
86 DLOG("found Xinerama screen: %d x %d at %d x %d\n",
87 screen_info[screen].width, screen_info[screen].height,
88 screen_info[screen].x_org, screen_info[screen].y_org);
93 if (num_screens == 0) {
94 ELOG("No screens found. Please fix your setup. i3 will exit now.\n");
100 * We have just established a connection to the X server and need the initial Xinerama
101 * information to setup workspaces for each screen.
104 void initialize_xinerama(xcb_connection_t *conn) {
105 if (!xcb_get_extension_data(conn, &xcb_xinerama_id)->present) {
106 DLOG("Xinerama extension not found, disabling.\n");
109 xcb_xinerama_is_active_reply_t *reply;
110 reply = xcb_xinerama_is_active_reply(conn, xcb_xinerama_is_active(conn), NULL);
112 if (reply == NULL || !reply->state) {
113 DLOG("Xinerama is not active (in your X-Server), disabling.\n");
123 /* Just go through each active output and associate one workspace */
124 TAILQ_FOREACH(output, &outputs, outputs) {
125 ws = get_first_workspace_for_output(output);
126 initialize_output(conn, output, ws);