2 #define I3__FILE__ "xinerama.c"
4 * vim:ts=4:sw=4:expandtab
6 * i3 - an improved dynamic tiling window manager
7 * © 2009-2011 Michael Stapelberg and contributors (see also: LICENSE)
9 * This is LEGACY code (we support RandR, which can do much more than
10 * Xinerama), but necessary for the poor users of the nVidia binary
11 * driver which does not support RandR in 2011 *sigh*.
16 #include <xcb/xinerama.h>
19 static int num_screens;
22 * Looks in outputs for the Output whose start coordinates are x, y
25 static Output *get_screen_at(unsigned int x, unsigned int y) {
27 TAILQ_FOREACH(output, &outputs, outputs)
28 if (output->rect.x == x && output->rect.y == y)
35 * Gets the Xinerama screens and converts them to virtual Outputs (only one screen for two
36 * Xinerama screen which are configured in clone mode) in the given screenlist
39 static void query_screens(xcb_connection_t *conn) {
40 xcb_xinerama_query_screens_reply_t *reply;
41 xcb_xinerama_screen_info_t *screen_info;
43 reply = xcb_xinerama_query_screens_reply(conn, xcb_xinerama_query_screens_unchecked(conn), NULL);
45 ELOG("Couldn't get Xinerama screens\n");
48 screen_info = xcb_xinerama_query_screens_screen_info(reply);
49 int screens = xcb_xinerama_query_screens_screen_info_length(reply);
51 for (int screen = 0; screen < screens; screen++) {
52 Output *s = get_screen_at(screen_info[screen].x_org, screen_info[screen].y_org);
54 DLOG("Re-used old Xinerama screen %p\n", s);
55 /* This screen already exists. We use the littlest screen so that the user
56 can always see the complete workspace */
57 s->rect.width = min(s->rect.width, screen_info[screen].width);
58 s->rect.height = min(s->rect.height, screen_info[screen].height);
60 s = scalloc(sizeof(Output));
61 sasprintf(&(s->name), "xinerama-%d", num_screens);
62 DLOG("Created new Xinerama screen %s (%p)\n", s->name, s);
64 s->rect.x = screen_info[screen].x_org;
65 s->rect.y = screen_info[screen].y_org;
66 s->rect.width = screen_info[screen].width;
67 s->rect.height = screen_info[screen].height;
68 /* We always treat the screen at 0x0 as the primary screen */
69 if (s->rect.x == 0 && s->rect.y == 0)
70 TAILQ_INSERT_HEAD(&outputs, s, outputs);
71 else TAILQ_INSERT_TAIL(&outputs, s, outputs);
73 init_ws_for_output(s, output_get_content(s->con));
77 DLOG("found Xinerama screen: %d x %d at %d x %d\n",
78 screen_info[screen].width, screen_info[screen].height,
79 screen_info[screen].x_org, screen_info[screen].y_org);
84 if (num_screens == 0) {
85 ELOG("No screens found. Please fix your setup. i3 will exit now.\n");
91 * We have just established a connection to the X server and need the initial Xinerama
92 * information to setup workspaces for each screen.
95 void xinerama_init(void) {
96 if (!xcb_get_extension_data(conn, &xcb_xinerama_id)->present) {
97 DLOG("Xinerama extension not found, disabling.\n");
100 xcb_xinerama_is_active_reply_t *reply;
101 reply = xcb_xinerama_is_active_reply(conn, xcb_xinerama_is_active(conn), NULL);
103 if (reply == NULL || !reply->state) {
104 DLOG("Xinerama is not active (in your X-Server), disabling.\n");
115 /* Just go through each active output and associate one workspace */
116 TAILQ_FOREACH(output, &outputs, outputs) {
117 ws = get_first_workspace_for_output(output);
118 initialize_output(conn, output, ws);