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 }
char * name
Name of the output.
Definition: data.h:297
#define DLOG(fmt,...)
Definition: log.h:28
#define TAILQ_INSERT_TAIL(head, elm, field)
Definition: queue.h:363
uint32_t y
Definition: data.h:109
static void query_screens(xcb_connection_t *conn)
Definition: xinerama.c:39
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:252
static int num_screens
Definition: xinerama.c:19
uint32_t height
Definition: data.h:33
#define TAILQ_INSERT_HEAD(head, elm, field)
Definition: queue.h:353
void * scalloc(size_t size)
Safe-wrapper around calloc which exits if malloc returns NULL (meaning that there is no more memory a...
#define FREE(pointer)
Definition: util.h:47
xcb_connection_t * conn
Definition: main.c:42
uint32_t width
Definition: data.h:32
static Output * get_screen_at(int x, int y)
Definition: xinerama.c:25
struct outputs_head outputs
Definition: randr.c:28
Rect rect
x, y, width, height
Definition: data.h:303
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...
uint32_t x
Definition: data.h:30
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
bool active
Whether the output is currently active (has a CRTC attached with a valid mode)
Definition: data.h:288
An Output is a physical output on your graphics driver.
Definition: data.h:282
#define TAILQ_FOREACH(var, head, field)
Definition: queue.h:335
uint32_t y
Definition: data.h:31
int min(int a, int b)
Definition: util.c:28
Con * output_get_content(Con *output)
Returns the output container below the given output container.
Definition: output.c:18
uint32_t x
Definition: data.h:108
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:356
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:228
Con * con
Pointer to the Con which represents this output.
Definition: data.h:300
uint32_t height
Definition: data.h:111
#define ELOG(fmt,...)
Definition: libi3.h:80
uint32_t width
Definition: data.h:110