i3
xinerama.c
Go to the documentation of this file.
1/*
2 * vim:ts=4:sw=4:expandtab
3 *
4 * i3 - an improved tiling window manager
5 * © 2009 Michael Stapelberg and contributors (see also: LICENSE)
6 *
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*.
10 *
11 */
12#include "all.h"
13
14#include <xcb/xinerama.h>
15
16static int num_screens;
17
18/*
19 * Looks in outputs for the Output whose start coordinates are x, y
20 *
21 */
22static Output *get_screen_at(unsigned int x, unsigned int y) {
23 Output *output;
24 TAILQ_FOREACH (output, &outputs, outputs) {
25 if (output->rect.x == x && output->rect.y == y) {
26 return output;
27 }
28 }
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 */
38static 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(1, sizeof(Output));
60 struct output_name *output_name = scalloc(1, sizeof(struct output_name));
61 sasprintf(&output_name->name, "xinerama-%d", num_screens);
62 SLIST_INIT(&s->names_head);
63 SLIST_INSERT_HEAD(&s->names_head, output_name, names);
64 DLOG("Created new Xinerama screen %s (%p)\n", output_primary_name(s), s);
65 s->active = true;
66 s->rect.x = screen_info[screen].x_org;
67 s->rect.y = screen_info[screen].y_org;
68 s->rect.width = screen_info[screen].width;
69 s->rect.height = screen_info[screen].height;
70 /* We always treat the screen at 0x0 as the primary screen */
71 if (s->rect.x == 0 && s->rect.y == 0) {
73 } else {
75 }
79 }
80
81 DLOG("found Xinerama screen: %d x %d at %d x %d\n",
82 screen_info[screen].width, screen_info[screen].height,
83 screen_info[screen].x_org, screen_info[screen].y_org);
84 }
85
86 free(reply);
87
88 if (num_screens == 0) {
89 ELOG("No screens found. Please fix your setup. i3 will exit now.\n");
90 exit(EXIT_SUCCESS);
91 }
92}
93
94/*
95 * This creates the root_output (borrowed from randr.c) and uses it
96 * as the sole output for this session.
97 *
98 */
99static void use_root_output(xcb_connection_t *conn) {
101 s->active = true;
105}
106
107/*
108 * We have just established a connection to the X server and need the initial Xinerama
109 * information to setup workspaces for each screen.
110 *
111 */
112void xinerama_init(void) {
113 if (!xcb_get_extension_data(conn, &xcb_xinerama_id)->present) {
114 DLOG("Xinerama extension not found, using root output.\n");
116 } else {
117 xcb_xinerama_is_active_reply_t *reply;
118 reply = xcb_xinerama_is_active_reply(conn, xcb_xinerama_is_active(conn), NULL);
119
120 if (reply == NULL || !reply->state) {
121 DLOG("Xinerama is not active (in your X-Server), using root output.\n");
123 } else {
125 }
126
127 FREE(reply);
128 }
129}
#define y(x,...)
Definition commands.c:18
char * output_primary_name(Output *output)
Retrieves the primary name of an output.
Definition output.c:53
void init_ws_for_output(Output *output)
Initializes at least one workspace for this output, trying the following steps until there is at leas...
Definition randr.c:455
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:346
struct outputs_head outputs
Definition randr.c:22
Output * create_root_output(xcb_connection_t *conn)
Creates an output covering the root window.
Definition randr.c:324
int min(int a, int b)
Definition util.c:24
static Output * get_screen_at(unsigned int x, unsigned int y)
Definition xinerama.c:22
static void use_root_output(xcb_connection_t *conn)
Definition xinerama.c:99
static int num_screens
Definition xinerama.c:16
static void query_screens(xcb_connection_t *conn)
Definition xinerama.c:38
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:112
xcb_connection_t * conn
XCB connection and root screen.
Definition main.c:54
#define DLOG(fmt,...)
Definition libi3.h:105
#define ELOG(fmt,...)
Definition libi3.h:100
void * scalloc(size_t num, size_t size)
Safe-wrapper around calloc which exits if malloc returns NULL (meaning that there is no more memory a...
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...
#define TAILQ_FOREACH(var, head, field)
Definition queue.h:347
#define SLIST_INIT(head)
Definition queue.h:127
#define SLIST_INSERT_HEAD(head, elm, field)
Definition queue.h:138
#define TAILQ_INSERT_TAIL(head, elm, field)
Definition queue.h:376
#define TAILQ_INSERT_HEAD(head, elm, field)
Definition queue.h:366
#define FREE(pointer)
Definition util.h:47
uint32_t height
Definition data.h:189
uint32_t x
Definition data.h:186
uint32_t y
Definition data.h:187
uint32_t width
Definition data.h:188
char * name
Definition data.h:380
An Output is a physical output on your graphics driver.
Definition data.h:391
bool active
Whether the output is currently active (has a CRTC attached with a valid mode)
Definition data.h:397
Rect rect
x, y, width, height
Definition data.h:414