i3
xinerama.c
Go to the documentation of this file.
1 #undef I3__FILE__
2 #define I3__FILE__ "xinerama.c"
3 /*
4  * vim:ts=4:sw=4:expandtab
5  *
6  * i3 - an improved dynamic tiling window manager
7  * © 2009-2011 Michael Stapelberg and contributors (see also: LICENSE)
8  *
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*.
12  *
13  */
14 #include "all.h"
15 
16 #include <xcb/xinerama.h>
17 
18 
19 static int num_screens;
20 
21 /*
22  * Looks in outputs for the Output whose start coordinates are x, y
23  *
24  */
25 static Output *get_screen_at(int x, int y) {
26  Output *output;
27  TAILQ_FOREACH(output, &outputs, outputs)
28  if (output->rect.x == x && output->rect.y == y)
29  return output;
30 
31  return NULL;
32 }
33 
34 /*
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
37  *
38  */
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;
42 
43  reply = xcb_xinerama_query_screens_reply(conn, xcb_xinerama_query_screens_unchecked(conn), NULL);
44  if (!reply) {
45  ELOG("Couldn't get Xinerama screens\n");
46  return;
47  }
48  screen_info = xcb_xinerama_query_screens_screen_info(reply);
49  int screens = xcb_xinerama_query_screens_screen_info_length(reply);
50 
51  for (int screen = 0; screen < screens; screen++) {
52  Output *s = get_screen_at(screen_info[screen].x_org, screen_info[screen].y_org);
53  if (s != NULL) {
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);
59  } else {
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);
63  s->active = true;
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)
72  output_init_con(s);
74  num_screens++;
75  }
76 
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);
80  }
81 
82  free(reply);
83 
84  if (num_screens == 0) {
85  ELOG("No screens found. Please fix your setup. i3 will exit now.\n");
86  exit(0);
87  }
88 }
89 
90 /*
91  * We have just established a connection to the X server and need the initial Xinerama
92  * information to setup workspaces for each screen.
93  *
94  */
95 void xinerama_init(void) {
96  if (!xcb_get_extension_data(conn, &xcb_xinerama_id)->present) {
97  DLOG("Xinerama extension not found, disabling.\n");
99  } else {
100  xcb_xinerama_is_active_reply_t *reply;
101  reply = xcb_xinerama_is_active_reply(conn, xcb_xinerama_is_active(conn), NULL);
102 
103  if (reply == NULL || !reply->state) {
104  DLOG("Xinerama is not active (in your X-Server), disabling.\n");
106  } else
108 
109  FREE(reply);
110  }
111 
112 #if 0
113  Output *output;
114  Workspace *ws;
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);
119  }
120 #endif
121 }