2010-03-09 20:00:56 +01:00
|
|
|
/*
|
2010-03-27 15:25:51 +01:00
|
|
|
* vim:ts=4:sw=4:expandtab
|
2010-03-09 20:00:56 +01:00
|
|
|
*
|
|
|
|
* i3 - an improved dynamic tiling window manager
|
2015-04-04 02:17:56 +02:00
|
|
|
* © 2009 Michael Stapelberg and contributors (see also: LICENSE)
|
2010-03-09 20:00:56 +01:00
|
|
|
*
|
|
|
|
* This is LEGACY code (we support RandR, which can do much more than
|
|
|
|
* Xinerama), but necessary for the poor users of the nVidia binary
|
2011-10-23 00:40:02 +02:00
|
|
|
* driver which does not support RandR in 2011 *sigh*.
|
2010-03-09 20:00:56 +01:00
|
|
|
*
|
|
|
|
*/
|
2011-10-23 00:40:02 +02:00
|
|
|
#include "all.h"
|
2010-03-09 20:00:56 +01:00
|
|
|
|
|
|
|
#include <xcb/xinerama.h>
|
|
|
|
|
|
|
|
static int num_screens;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Looks in outputs for the Output whose start coordinates are x, y
|
|
|
|
*
|
|
|
|
*/
|
2013-12-25 20:01:37 +01:00
|
|
|
static Output *get_screen_at(unsigned int x, unsigned int y) {
|
2010-03-27 15:25:51 +01:00
|
|
|
Output *output;
|
2020-02-19 11:31:09 +01:00
|
|
|
TAILQ_FOREACH (output, &outputs, outputs) {
|
|
|
|
if (output->rect.x == x && output->rect.y == y) {
|
|
|
|
return output;
|
|
|
|
}
|
|
|
|
}
|
2010-03-09 20:00:56 +01:00
|
|
|
|
2010-03-27 15:25:51 +01:00
|
|
|
return NULL;
|
2010-03-09 20:00:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Gets the Xinerama screens and converts them to virtual Outputs (only one screen for two
|
|
|
|
* Xinerama screen which are configured in clone mode) in the given screenlist
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
static void query_screens(xcb_connection_t *conn) {
|
2010-03-27 15:25:51 +01:00
|
|
|
xcb_xinerama_query_screens_reply_t *reply;
|
|
|
|
xcb_xinerama_screen_info_t *screen_info;
|
2010-03-09 20:00:56 +01:00
|
|
|
|
2010-03-27 15:25:51 +01:00
|
|
|
reply = xcb_xinerama_query_screens_reply(conn, xcb_xinerama_query_screens_unchecked(conn), NULL);
|
|
|
|
if (!reply) {
|
|
|
|
ELOG("Couldn't get Xinerama screens\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
screen_info = xcb_xinerama_query_screens_screen_info(reply);
|
|
|
|
int screens = xcb_xinerama_query_screens_screen_info_length(reply);
|
2010-03-09 20:00:56 +01:00
|
|
|
|
2010-03-27 15:25:51 +01:00
|
|
|
for (int screen = 0; screen < screens; screen++) {
|
|
|
|
Output *s = get_screen_at(screen_info[screen].x_org, screen_info[screen].y_org);
|
|
|
|
if (s != NULL) {
|
|
|
|
DLOG("Re-used old Xinerama screen %p\n", s);
|
|
|
|
/* This screen already exists. We use the littlest screen so that the user
|
|
|
|
can always see the complete workspace */
|
|
|
|
s->rect.width = min(s->rect.width, screen_info[screen].width);
|
|
|
|
s->rect.height = min(s->rect.height, screen_info[screen].height);
|
|
|
|
} else {
|
2015-08-03 11:50:13 +02:00
|
|
|
s = scalloc(1, sizeof(Output));
|
2017-09-09 09:37:37 +02:00
|
|
|
struct output_name *output_name = scalloc(1, sizeof(struct output_name));
|
|
|
|
sasprintf(&output_name->name, "xinerama-%d", num_screens);
|
|
|
|
SLIST_INIT(&s->names_head);
|
|
|
|
SLIST_INSERT_HEAD(&s->names_head, output_name, names);
|
2017-09-09 09:18:29 +02:00
|
|
|
DLOG("Created new Xinerama screen %s (%p)\n", output_primary_name(s), s);
|
2010-03-27 15:25:51 +01:00
|
|
|
s->active = true;
|
|
|
|
s->rect.x = screen_info[screen].x_org;
|
|
|
|
s->rect.y = screen_info[screen].y_org;
|
|
|
|
s->rect.width = screen_info[screen].width;
|
|
|
|
s->rect.height = screen_info[screen].height;
|
|
|
|
/* We always treat the screen at 0x0 as the primary screen */
|
|
|
|
if (s->rect.x == 0 && s->rect.y == 0)
|
2014-06-15 19:07:02 +02:00
|
|
|
TAILQ_INSERT_HEAD(&outputs, s, outputs);
|
|
|
|
else
|
|
|
|
TAILQ_INSERT_TAIL(&outputs, s, outputs);
|
2011-01-05 00:16:10 +01:00
|
|
|
output_init_con(s);
|
2018-09-12 15:53:20 +02:00
|
|
|
init_ws_for_output(s);
|
2010-03-27 15:25:51 +01:00
|
|
|
num_screens++;
|
2010-03-09 20:00:56 +01:00
|
|
|
}
|
|
|
|
|
2010-03-27 15:25:51 +01:00
|
|
|
DLOG("found Xinerama screen: %d x %d at %d x %d\n",
|
2014-06-15 19:07:02 +02:00
|
|
|
screen_info[screen].width, screen_info[screen].height,
|
|
|
|
screen_info[screen].x_org, screen_info[screen].y_org);
|
2010-03-27 15:25:51 +01:00
|
|
|
}
|
2010-03-09 20:00:56 +01:00
|
|
|
|
2010-03-27 15:25:51 +01:00
|
|
|
free(reply);
|
|
|
|
|
|
|
|
if (num_screens == 0) {
|
|
|
|
ELOG("No screens found. Please fix your setup. i3 will exit now.\n");
|
2020-01-16 09:21:27 +01:00
|
|
|
exit(EXIT_SUCCESS);
|
2010-03-27 15:25:51 +01:00
|
|
|
}
|
2010-03-09 20:00:56 +01:00
|
|
|
}
|
|
|
|
|
2015-09-21 11:44:39 +02:00
|
|
|
/*
|
|
|
|
* This creates the root_output (borrowed from randr.c) and uses it
|
|
|
|
* as the sole output for this session.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
static void use_root_output(xcb_connection_t *conn) {
|
|
|
|
Output *s = create_root_output(conn);
|
|
|
|
s->active = true;
|
|
|
|
TAILQ_INSERT_TAIL(&outputs, s, outputs);
|
|
|
|
output_init_con(s);
|
2018-09-12 15:53:20 +02:00
|
|
|
init_ws_for_output(s);
|
2015-09-21 11:44:39 +02:00
|
|
|
}
|
|
|
|
|
2010-03-09 20:00:56 +01:00
|
|
|
/*
|
|
|
|
* We have just established a connection to the X server and need the initial Xinerama
|
|
|
|
* information to setup workspaces for each screen.
|
|
|
|
*
|
|
|
|
*/
|
2012-03-31 10:53:04 +02:00
|
|
|
void xinerama_init(void) {
|
2010-03-27 15:25:51 +01:00
|
|
|
if (!xcb_get_extension_data(conn, &xcb_xinerama_id)->present) {
|
2015-09-14 22:12:47 +02:00
|
|
|
DLOG("Xinerama extension not found, using root output.\n");
|
2015-09-21 11:44:39 +02:00
|
|
|
use_root_output(conn);
|
2010-03-27 15:25:51 +01:00
|
|
|
} else {
|
|
|
|
xcb_xinerama_is_active_reply_t *reply;
|
|
|
|
reply = xcb_xinerama_is_active_reply(conn, xcb_xinerama_is_active(conn), NULL);
|
|
|
|
|
|
|
|
if (reply == NULL || !reply->state) {
|
2015-09-14 22:12:47 +02:00
|
|
|
DLOG("Xinerama is not active (in your X-Server), using root output.\n");
|
2015-09-21 11:44:39 +02:00
|
|
|
use_root_output(conn);
|
2010-03-27 15:25:51 +01:00
|
|
|
} else
|
2010-11-29 22:35:46 +01:00
|
|
|
query_screens(conn);
|
2010-03-09 20:00:56 +01:00
|
|
|
|
2010-03-27 15:25:51 +01:00
|
|
|
FREE(reply);
|
|
|
|
}
|
2010-03-09 20:00:56 +01:00
|
|
|
}
|