Bugfix: Correctly disable Xinerama, use TAILQ_HEAD_INITIALIZER where possible

This commit is contained in:
Michael Stapelberg 2009-02-15 02:12:14 +01:00
parent 09cd7bd2d0
commit 658c302031
2 changed files with 30 additions and 8 deletions

View File

@ -47,7 +47,7 @@
Display *xkbdpy; Display *xkbdpy;
TAILQ_HEAD(bindings_head, Binding) bindings; TAILQ_HEAD(bindings_head, Binding) bindings = TAILQ_HEAD_INITIALIZER(bindings);
xcb_event_handlers_t evenths; xcb_event_handlers_t evenths;
xcb_window_t root_win; xcb_window_t root_win;
@ -264,8 +264,6 @@ int main(int argc, char *argv[], char *env[]) {
byChild = alloc_table(); byChild = alloc_table();
byParent = alloc_table(); byParent = alloc_table();
TAILQ_INIT(&bindings);
c = xcb_connect(NULL, &screens); c = xcb_connect(NULL, &screens);
/* TODO: this has to be more beautiful somewhen */ /* TODO: this has to be more beautiful somewhen */

View File

@ -22,10 +22,14 @@
#include "util.h" #include "util.h"
#include "xinerama.h" #include "xinerama.h"
/* This TAILQ of Rects stores the virtual screens, used for handling overlapping screens /* This TAILQ of i3Screens stores the virtual screens, used for handling overlapping screens
* (xrandr --same-as) */ * (xrandr --same-as) */
struct screens_head virtual_screens; struct screens_head virtual_screens = TAILQ_HEAD_INITIALIZER(virtual_screens);
/*
* Looks in virtual_screens for the i3Screen whose start coordinates are x, y
*
*/
i3Screen *get_screen_at(int x, int y) { i3Screen *get_screen_at(int x, int y) {
i3Screen *screen; i3Screen *screen;
TAILQ_FOREACH(screen, &virtual_screens, screens) TAILQ_FOREACH(screen, &virtual_screens, screens)
@ -35,6 +39,10 @@ i3Screen *get_screen_at(int x, int y) {
return NULL; return NULL;
} }
/*
* Looks in virtual_screens for the i3Screen which contains coordinates x, y
*
*/
i3Screen *get_screen_containing(int x, int y) { i3Screen *get_screen_containing(int x, int y) {
i3Screen *screen; i3Screen *screen;
TAILQ_FOREACH(screen, &virtual_screens, screens) TAILQ_FOREACH(screen, &virtual_screens, screens)
@ -45,6 +53,22 @@ i3Screen *get_screen_containing(int x, int y) {
return NULL; return NULL;
} }
/*
* Fills virtual_screens with exactly one screen with width/height of the whole X server.
*
*/
static void disable_xinerama(xcb_connection_t *connection) {
xcb_screen_t *root_screen = xcb_setup_roots_iterator(xcb_get_setup(connection)).data;
i3Screen *s = calloc(sizeof(i3Screen), 1);
s->rect.x = 0;
s->rect.y = 0;
s->rect.width = root_screen->width_in_pixels;
s->rect.height = root_screen->height_in_pixels;
TAILQ_INSERT_TAIL(&virtual_screens, s, screens);
}
/* /*
* We have just established a connection to the X server and need the initial Xinerama * We have just established a connection to the X server and need the initial Xinerama
@ -58,11 +82,13 @@ void initialize_xinerama(xcb_connection_t *conn) {
if (!xcb_get_extension_data(conn, &xcb_xinerama_id)->present) { if (!xcb_get_extension_data(conn, &xcb_xinerama_id)->present) {
printf("Xinerama extension not found, disabling.\n"); printf("Xinerama extension not found, disabling.\n");
disable_xinerama(conn);
return; return;
} }
if (!xcb_xinerama_is_active_reply(conn, xcb_xinerama_is_active(conn), NULL)->state) { if (!xcb_xinerama_is_active_reply(conn, xcb_xinerama_is_active(conn), NULL)->state) {
printf("Xinerama is not active (in your X-Server), disabling.\n"); printf("Xinerama is not active (in your X-Server), disabling.\n");
disable_xinerama(conn);
return; return;
} }
@ -74,8 +100,6 @@ void initialize_xinerama(xcb_connection_t *conn) {
screen_info = xcb_xinerama_query_screens_screen_info(reply); screen_info = xcb_xinerama_query_screens_screen_info(reply);
num_screens = xcb_xinerama_query_screens_screen_info_length(reply); num_screens = xcb_xinerama_query_screens_screen_info_length(reply);
TAILQ_INIT(&virtual_screens);
/* Just go through each workspace and associate as many screens as we can. */ /* Just go through each workspace and associate as many screens as we can. */
for (screen = 0; screen < num_screens; screen++) { for (screen = 0; screen < num_screens; screen++) {
i3Screen *s = get_screen_at(screen_info[screen].x_org, screen_info[screen].y_org); i3Screen *s = get_screen_at(screen_info[screen].x_org, screen_info[screen].y_org);
@ -85,7 +109,7 @@ void initialize_xinerama(xcb_connection_t *conn) {
s->rect.width = min(s->rect.width, screen_info[screen].width); s->rect.width = min(s->rect.width, screen_info[screen].width);
s->rect.height = min(s->rect.height, screen_info[screen].height); s->rect.height = min(s->rect.height, screen_info[screen].height);
} else { } else {
s = calloc(sizeof(Screen), 1); s = calloc(sizeof(i3Screen), 1);
s->rect.x = screen_info[screen].x_org; s->rect.x = screen_info[screen].x_org;
s->rect.y = screen_info[screen].y_org; s->rect.y = screen_info[screen].y_org;
s->rect.width = screen_info[screen].width; s->rect.width = screen_info[screen].width;