2 * vim:ts=4:sw=4:expandtab
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*.
16 #include <xcb/xinerama.h>
20 static int num_screens;
23 * Looks in outputs for the Output whose start coordinates are x, y
26 static Output *get_screen_at(int x, int y) {
28 TAILQ_FOREACH(output, &outputs, outputs)
29 if (output->rect.x == x && output->rect.y == y)
36 * Gets the Xinerama screens and converts them to virtual Outputs (only one screen for two
37 * Xinerama screen which are configured in clone mode) in the given screenlist
40 static void query_screens(xcb_connection_t *conn) {
41 xcb_xinerama_query_screens_reply_t *reply;
42 xcb_xinerama_screen_info_t *screen_info;
44 reply = xcb_xinerama_query_screens_reply(conn, xcb_xinerama_query_screens_unchecked(conn), NULL);
46 ELOG("Couldn't get Xinerama screens\n");
49 screen_info = xcb_xinerama_query_screens_screen_info(reply);
50 int screens = xcb_xinerama_query_screens_screen_info_length(reply);
52 for (int screen = 0; screen < screens; screen++) {
53 Output *s = get_screen_at(screen_info[screen].x_org, screen_info[screen].y_org);
55 DLOG("Re-used old Xinerama screen %p\n", s);
56 /* This screen already exists. We use the littlest screen so that the user
57 can always see the complete workspace */
58 s->rect.width = min(s->rect.width, screen_info[screen].width);
59 s->rect.height = min(s->rect.height, screen_info[screen].height);
61 s = scalloc(sizeof(Output));
62 asprintf(&(s->name), "xinerama-%d", num_screens);
63 DLOG("Created new Xinerama screen %s (%p)\n", s->name, s);
65 s->rect.x = screen_info[screen].x_org;
66 s->rect.y = screen_info[screen].y_org;
67 s->rect.width = screen_info[screen].width;
68 s->rect.height = screen_info[screen].height;
69 /* We always treat the screen at 0x0 as the primary screen */
70 if (s->rect.x == 0 && s->rect.y == 0)
71 TAILQ_INSERT_HEAD(&outputs, s, outputs);
72 else TAILQ_INSERT_TAIL(&outputs, s, outputs);
76 DLOG("found Xinerama screen: %d x %d at %d x %d\n",
77 screen_info[screen].width, screen_info[screen].height,
78 screen_info[screen].x_org, screen_info[screen].y_org);
83 if (num_screens == 0) {
84 ELOG("No screens found. Please fix your setup. i3 will exit now.\n");
90 * We have just established a connection to the X server and need the initial Xinerama
91 * information to setup workspaces for each screen.
94 void xinerama_init() {
95 if (!xcb_get_extension_data(conn, &xcb_xinerama_id)->present) {
96 DLOG("Xinerama extension not found, disabling.\n");
99 xcb_xinerama_is_active_reply_t *reply;
100 reply = xcb_xinerama_is_active_reply(conn, xcb_xinerama_is_active(conn), NULL);
102 if (reply == NULL || !reply->state) {
103 DLOG("Xinerama is not active (in your X-Server), disabling.\n");
114 /* Just go through each active output and associate one workspace */
115 TAILQ_FOREACH(output, &outputs, outputs) {
116 ws = get_first_workspace_for_output(output);
117 initialize_output(conn, output, ws);