2 * vim:ts=4:sw=4:expandtab
4 * i3 - an improved dynamic tiling window manager
5 * © 2009 Michael Stapelberg and contributors (see also: LICENSE)
7 * This is LEGACY code (we support RandR, which can do much more than
8 * Xinerama), but necessary for the poor users of the nVidia binary
9 * driver which does not support RandR in 2011 *sigh*.
14 #include <xcb/xinerama.h>
16 static int num_screens;
19 * Looks in outputs for the Output whose start coordinates are x, y
22 static Output *get_screen_at(unsigned int x, unsigned int y) {
24 TAILQ_FOREACH(output, &outputs, outputs)
25 if (output->rect.x == x && output->rect.y == y)
32 * Gets the Xinerama screens and converts them to virtual Outputs (only one screen for two
33 * Xinerama screen which are configured in clone mode) in the given screenlist
36 static void query_screens(xcb_connection_t *conn) {
37 xcb_xinerama_query_screens_reply_t *reply;
38 xcb_xinerama_screen_info_t *screen_info;
40 reply = xcb_xinerama_query_screens_reply(conn, xcb_xinerama_query_screens_unchecked(conn), NULL);
42 ELOG("Couldn't get Xinerama screens\n");
45 screen_info = xcb_xinerama_query_screens_screen_info(reply);
46 int screens = xcb_xinerama_query_screens_screen_info_length(reply);
48 for (int screen = 0; screen < screens; screen++) {
49 Output *s = get_screen_at(screen_info[screen].x_org, screen_info[screen].y_org);
51 DLOG("Re-used old Xinerama screen %p\n", s);
52 /* This screen already exists. We use the littlest screen so that the user
53 can always see the complete workspace */
54 s->rect.width = min(s->rect.width, screen_info[screen].width);
55 s->rect.height = min(s->rect.height, screen_info[screen].height);
57 s = scalloc(1, sizeof(Output));
58 struct output_name *output_name = scalloc(1, sizeof(struct output_name));
59 sasprintf(&output_name->name, "xinerama-%d", num_screens);
60 SLIST_INIT(&s->names_head);
61 SLIST_INSERT_HEAD(&s->names_head, output_name, names);
62 DLOG("Created new Xinerama screen %s (%p)\n", output_primary_name(s), 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);
72 TAILQ_INSERT_TAIL(&outputs, s, outputs);
74 init_ws_for_output(s, output_get_content(s->con));
78 DLOG("found Xinerama screen: %d x %d at %d x %d\n",
79 screen_info[screen].width, screen_info[screen].height,
80 screen_info[screen].x_org, screen_info[screen].y_org);
85 if (num_screens == 0) {
86 ELOG("No screens found. Please fix your setup. i3 will exit now.\n");
92 * This creates the root_output (borrowed from randr.c) and uses it
93 * as the sole output for this session.
96 static void use_root_output(xcb_connection_t *conn) {
97 Output *s = create_root_output(conn);
99 TAILQ_INSERT_TAIL(&outputs, s, outputs);
101 init_ws_for_output(s, output_get_content(s->con));
105 * We have just established a connection to the X server and need the initial Xinerama
106 * information to setup workspaces for each screen.
109 void xinerama_init(void) {
110 if (!xcb_get_extension_data(conn, &xcb_xinerama_id)->present) {
111 DLOG("Xinerama extension not found, using root output.\n");
112 use_root_output(conn);
114 xcb_xinerama_is_active_reply_t *reply;
115 reply = xcb_xinerama_is_active_reply(conn, xcb_xinerama_is_active(conn), NULL);
117 if (reply == NULL || !reply->state) {
118 DLOG("Xinerama is not active (in your X-Server), using root output.\n");
119 use_root_output(conn);