Implement switching to different screens when focusing left/right/up/down at the edge of a screen

This commit is contained in:
Michael Stapelberg 2009-03-04 13:06:14 +01:00
parent 05747c4a1c
commit bb83dd6727
1 changed files with 41 additions and 9 deletions

View File

@ -22,6 +22,7 @@
#include "table.h" #include "table.h"
#include "layout.h" #include "layout.h"
#include "i3.h" #include "i3.h"
#include "xinerama.h"
static bool focus_window_in_container(xcb_connection_t *connection, Container *container, static bool focus_window_in_container(xcb_connection_t *connection, Container *container,
direction_t direction) { direction_t direction) {
@ -52,14 +53,15 @@ static void focus_window(xcb_connection_t *connection, direction_t direction) {
int new_row = current_row, int new_row = current_row,
new_col = current_col; new_col = current_col;
Container *container = CUR_CELL;
Workspace *t_ws = c_ws;
/* There always is a container. If not, current_col or current_row is wrong */
assert(container != NULL);
/* TODO: for horizontal default layout, this has to be expanded to LEFT/RIGHT */ /* TODO: for horizontal default layout, this has to be expanded to LEFT/RIGHT */
if (direction == D_UP || direction == D_DOWN) { if (direction == D_UP || direction == D_DOWN) {
/* Lets see if we can perform up/down focus in the current container */ /* Lets see if we can perform up/down focus in the current container */
Container *container = CUR_CELL;
/* There always is a container. If not, current_col or current_row is wrong */
assert(container != NULL);
if (focus_window_in_container(connection, container, direction)) if (focus_window_in_container(connection, container, direction))
return; return;
@ -67,22 +69,52 @@ static void focus_window(xcb_connection_t *connection, direction_t direction) {
new_row++; new_row++;
else if (direction == D_UP && cell_exists(current_col, current_row-1)) else if (direction == D_UP && cell_exists(current_col, current_row-1))
new_row--; new_row--;
else {
/* Lets see if there is a screen down/up there to which we can switch */
printf("container is at %d with height %d\n", container->y, container->height);
i3Screen *screen;
int destination_y = (direction == D_UP ? (container->y - 1) : (container->y + container->height + 1));
if ((screen = get_screen_containing(container->x, destination_y)) == NULL) {
printf("Not possible, no screen found.\n");
return;
}
t_ws = &(workspaces[screen->current_workspace]);
new_row = (direction == D_UP ? (t_ws->rows - 1) : 0);
/* Bounds checking */
if (new_col >= t_ws->cols)
new_col = (t_ws->cols - 1);
if (new_row >= t_ws->rows)
new_row = (t_ws->rows - 1);
}
} else if (direction == D_LEFT || direction == D_RIGHT) { } else if (direction == D_LEFT || direction == D_RIGHT) {
if (direction == D_RIGHT && cell_exists(current_col+1, current_row)) if (direction == D_RIGHT && cell_exists(current_col+1, current_row))
new_col++; new_col++;
else if (direction == D_LEFT && cell_exists(current_col-1, current_row)) else if (direction == D_LEFT && cell_exists(current_col-1, current_row))
new_col--; new_col--;
else { else {
printf("nah, not possible\n"); /* Lets see if there is a screen left/right here to which we can switch */
return; printf("container is at %d with width %d\n", container->x, container->width);
i3Screen *screen;
int destination_x = (direction == D_LEFT ? (container->x - 1) : (container->x + container->width + 1));
if ((screen = get_screen_containing(destination_x, container->y)) == NULL) {
printf("Not possible, no screen found.\n");
return;
}
t_ws = &(workspaces[screen->current_workspace]);
new_col = (direction == D_LEFT ? (t_ws->cols - 1) : 0);
/* Bounds checking */
if (new_col >= t_ws->cols)
new_col = (t_ws->cols - 1);
if (new_row >= t_ws->rows)
new_row = (t_ws->rows - 1);
} }
} else { } else {
printf("direction unhandled\n"); printf("direction unhandled\n");
return; return;
} }
if (c_ws->table[new_col][new_row]->currently_focused != NULL) if (t_ws->table[new_col][new_row]->currently_focused != NULL)
set_focus(connection, c_ws->table[new_col][new_row]->currently_focused); set_focus(connection, t_ws->table[new_col][new_row]->currently_focused);
} }
/* /*