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 static int num_screens;
19 
20 /*
21  * Looks in outputs for the Output whose start coordinates are x, y
22  *
23  */
24 static Output *get_screen_at(unsigned int x, unsigned int y) {
25  Output *output;
26  TAILQ_FOREACH (output, &outputs, outputs)
27  if (output->rect.x == x && output->rect.y == y)
28  return output;
29 
30  return NULL;
31 }
32 
33 /*
34  * Gets the Xinerama screens and converts them to virtual Outputs (only one screen for two
35  * Xinerama screen which are configured in clone mode) in the given screenlist
36  *
37  */
38 static void query_screens(xcb_connection_t *conn) {
39  xcb_xinerama_query_screens_reply_t *reply;
40  xcb_xinerama_screen_info_t *screen_info;
41 
42  reply = xcb_xinerama_query_screens_reply(conn, xcb_xinerama_query_screens_unchecked(conn), NULL);
43  if (!reply) {
44  ELOG("Couldn't get Xinerama screens\n");
45  return;
46  }
47  screen_info = xcb_xinerama_query_screens_screen_info(reply);
48  int screens = xcb_xinerama_query_screens_screen_info_length(reply);
49 
50  for (int screen = 0; screen < screens; screen++) {
51  Output *s = get_screen_at(screen_info[screen].x_org, screen_info[screen].y_org);
52  if (s != NULL) {
53  DLOG("Re-used old Xinerama screen %p\n", s);
54  /* This screen already exists. We use the littlest screen so that the user
55  can always see the complete workspace */
56  s->rect.width = min(s->rect.width, screen_info[screen].width);
57  s->rect.height = min(s->rect.height, screen_info[screen].height);
58  } else {
59  s = scalloc(sizeof(Output));
60  sasprintf(&(s->name), "xinerama-%d", num_screens);
61  DLOG("Created new Xinerama screen %s (%p)\n", s->name, s);
62  s->active = true;
63  s->rect.x = screen_info[screen].x_org;
64  s->rect.y = screen_info[screen].y_org;
65  s->rect.width = screen_info[screen].width;
66  s->rect.height = screen_info[screen].height;
67  /* We always treat the screen at 0x0 as the primary screen */
68  if (s->rect.x == 0 && s->rect.y == 0)
70  else
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 }
char * name
Name of the output.
Definition: data.h:316
uint32_t y
Definition: data.h:124
uint32_t height
Definition: data.h:33
xcb_connection_t * conn
Definition: main.c:47
void init_ws_for_output(Output *output, Con *content)
Initializes at least one workspace for this output, trying the following steps until there is at leas...
Definition: randr.c:355
void xinerama_init(void)
We have just established a connection to the X server and need the initial Xinerama information to se...
Definition: xinerama.c:95
Rect rect
x, y, width, height
Definition: data.h:322
uint32_t width
Definition: data.h:32
An Output is a physical output on your graphics driver.
Definition: data.h:301
#define DLOG(fmt,...)
Definition: libi3.h:86
void disable_randr(xcb_connection_t *conn)
Disables RandR support by creating exactly one output with the size of the X11 screen.
Definition: randr.c:227
int sasprintf(char **strp, const char *fmt,...)
Safe-wrapper around asprintf which exits if it returns -1 (meaning that there is no more memory avail...
struct outputs_head outputs
Definition: randr.c:28
uint32_t height
Definition: data.h:126
#define TAILQ_INSERT_HEAD(head, elm, field)
Definition: queue.h:352
Con * con
Pointer to the Con which represents this output.
Definition: data.h:319
bool active
Whether the output is currently active (has a CRTC attached with a valid mode)
Definition: data.h:307
#define ELOG(fmt,...)
Definition: libi3.h:81
static int num_screens
Definition: xinerama.c:18
uint32_t x
Definition: data.h:123
void * scalloc(size_t size)
Safe-wrapper around calloc which exits if malloc returns NULL (meaning that there is no more memory a...
int min(int a, int b)
Definition: util.c:29
#define TAILQ_INSERT_TAIL(head, elm, field)
Definition: queue.h:362
Con * output_get_content(Con *output)
Returns the output container below the given output container.
Definition: output.c:18
uint32_t y
Definition: data.h:31
#define TAILQ_FOREACH(var, head, field)
Definition: queue.h:334
static Output * get_screen_at(unsigned int x, unsigned int y)
Definition: xinerama.c:24
static void query_screens(xcb_connection_t *conn)
Definition: xinerama.c:38
uint32_t x
Definition: data.h:30
#define FREE(pointer)
Definition: util.h:46
void output_init_con(Output *output)
Initializes a CT_OUTPUT Con (searches existing ones from inplace restart before) to use for the given...
Definition: randr.c:251
uint32_t width
Definition: data.h:125