2009-02-13 20:33:31 -05:00
|
|
|
|
/*
|
|
|
|
|
* vim:ts=8:expandtab
|
|
|
|
|
*
|
|
|
|
|
* i3 - an improved dynamic tiling window manager
|
|
|
|
|
*
|
2009-02-14 21:07:29 -05:00
|
|
|
|
* © 2009 Michael Stapelberg and contributors
|
2009-02-13 20:33:31 -05:00
|
|
|
|
*
|
|
|
|
|
* See file LICENSE for license information.
|
|
|
|
|
*
|
|
|
|
|
*/
|
2009-02-13 13:04:45 -05:00
|
|
|
|
#include <stdbool.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <assert.h>
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
|
|
#include <xcb/xcb.h>
|
|
|
|
|
|
|
|
|
|
#include "util.h"
|
|
|
|
|
#include "data.h"
|
|
|
|
|
#include "table.h"
|
|
|
|
|
#include "layout.h"
|
|
|
|
|
#include "i3.h"
|
2009-03-04 07:06:14 -05:00
|
|
|
|
#include "xinerama.h"
|
2009-05-16 11:32:36 -04:00
|
|
|
|
#include "client.h"
|
2009-05-23 10:34:03 -04:00
|
|
|
|
#include "floating.h"
|
2009-06-25 07:46:47 -04:00
|
|
|
|
#include "xcb.h"
|
2009-07-23 12:14:24 -04:00
|
|
|
|
#include "config.h"
|
2009-08-02 16:31:52 -04:00
|
|
|
|
#include "workspace.h"
|
2009-08-05 13:24:21 -04:00
|
|
|
|
#include "commands.h"
|
2009-09-26 11:18:50 -04:00
|
|
|
|
#include "resize.h"
|
2009-02-13 13:04:45 -05:00
|
|
|
|
|
2009-04-01 06:31:13 -04:00
|
|
|
|
bool focus_window_in_container(xcb_connection_t *conn, Container *container, direction_t direction) {
|
2009-02-13 20:33:31 -05:00
|
|
|
|
/* If this container is empty, we’re done */
|
|
|
|
|
if (container->currently_focused == NULL)
|
|
|
|
|
return false;
|
|
|
|
|
|
2009-03-04 17:45:44 -05:00
|
|
|
|
/* Get the previous/next client or wrap around */
|
2009-03-03 17:51:02 -05:00
|
|
|
|
Client *candidate = NULL;
|
2009-03-04 17:45:44 -05:00
|
|
|
|
if (direction == D_UP) {
|
|
|
|
|
if ((candidate = CIRCLEQ_PREV_OR_NULL(&(container->clients), container->currently_focused, clients)) == NULL)
|
|
|
|
|
candidate = CIRCLEQ_LAST(&(container->clients));
|
|
|
|
|
}
|
|
|
|
|
else if (direction == D_DOWN) {
|
|
|
|
|
if ((candidate = CIRCLEQ_NEXT_OR_NULL(&(container->clients), container->currently_focused, clients)) == NULL)
|
|
|
|
|
candidate = CIRCLEQ_FIRST(&(container->clients));
|
2009-03-06 00:46:43 -05:00
|
|
|
|
} else LOG("Direction not implemented!\n");
|
2009-02-13 20:33:31 -05:00
|
|
|
|
|
2009-03-05 13:47:16 -05:00
|
|
|
|
/* If we could not switch, the container contains exactly one client. We return false */
|
|
|
|
|
if (candidate == container->currently_focused)
|
|
|
|
|
return false;
|
|
|
|
|
|
2009-03-04 17:45:44 -05:00
|
|
|
|
/* Set focus */
|
2009-04-01 06:50:42 -04:00
|
|
|
|
set_focus(conn, candidate, true);
|
2009-02-13 20:33:31 -05:00
|
|
|
|
|
|
|
|
|
return true;
|
2009-02-13 13:04:45 -05:00
|
|
|
|
}
|
|
|
|
|
|
2009-08-05 13:24:21 -04:00
|
|
|
|
typedef enum { THING_WINDOW, THING_CONTAINER, THING_SCREEN } thing_t;
|
2009-03-04 17:45:44 -05:00
|
|
|
|
|
2009-09-20 10:54:29 -04:00
|
|
|
|
static void jump_to_mark(xcb_connection_t *conn, const char *mark) {
|
|
|
|
|
Client *current;
|
|
|
|
|
LOG("Jumping to \"%s\"\n", mark);
|
|
|
|
|
|
2009-09-27 08:00:54 -04:00
|
|
|
|
for (int c = 0; c < num_workspaces; c++)
|
2009-09-20 10:54:29 -04:00
|
|
|
|
SLIST_FOREACH(current, &(workspaces[c].focus_stack), focus_clients) {
|
|
|
|
|
if (current->mark == NULL || strcmp(current->mark, mark) != 0)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
set_focus(conn, current, true);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LOG("No window with this mark found\n");
|
|
|
|
|
}
|
|
|
|
|
|
2009-03-04 17:45:44 -05:00
|
|
|
|
static void focus_thing(xcb_connection_t *conn, direction_t direction, thing_t thing) {
|
2009-03-06 00:46:43 -05:00
|
|
|
|
LOG("focusing direction %d\n", direction);
|
2009-03-02 20:28:26 -05:00
|
|
|
|
|
|
|
|
|
int new_row = current_row,
|
|
|
|
|
new_col = current_col;
|
2009-03-04 07:06:14 -05:00
|
|
|
|
Container *container = CUR_CELL;
|
|
|
|
|
Workspace *t_ws = c_ws;
|
|
|
|
|
|
2009-06-25 22:21:30 -04:00
|
|
|
|
/* Makes sure new_col and new_row are within bounds of the new workspace */
|
|
|
|
|
void check_colrow_boundaries() {
|
|
|
|
|
if (new_col >= t_ws->cols)
|
|
|
|
|
new_col = (t_ws->cols - 1);
|
|
|
|
|
if (new_row >= t_ws->rows)
|
|
|
|
|
new_row = (t_ws->rows - 1);
|
|
|
|
|
}
|
|
|
|
|
|
2009-03-04 07:06:14 -05:00
|
|
|
|
/* There always is a container. If not, current_col or current_row is wrong */
|
|
|
|
|
assert(container != NULL);
|
|
|
|
|
|
2009-03-06 10:53:47 -05:00
|
|
|
|
if (container->workspace->fullscreen_client != NULL) {
|
|
|
|
|
LOG("You're in fullscreen mode. Won't switch focus\n");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2009-08-05 13:24:21 -04:00
|
|
|
|
/* For focusing screens, situation is different: we get the rect
|
|
|
|
|
* of the current screen, then get the screen which is on its
|
|
|
|
|
* right/left/bottom/top and just switch to the workspace on
|
|
|
|
|
* the target screen. */
|
|
|
|
|
if (thing == THING_SCREEN) {
|
|
|
|
|
i3Screen *cs = c_ws->screen;
|
|
|
|
|
assert(cs != NULL);
|
|
|
|
|
Rect bounds = cs->rect;
|
|
|
|
|
|
|
|
|
|
if (direction == D_RIGHT)
|
|
|
|
|
bounds.x += bounds.width;
|
|
|
|
|
else if (direction == D_LEFT)
|
|
|
|
|
bounds.x -= bounds.width;
|
|
|
|
|
else if (direction == D_UP)
|
|
|
|
|
bounds.y -= bounds.height;
|
|
|
|
|
else bounds.y += bounds.height;
|
|
|
|
|
|
|
|
|
|
i3Screen *target = get_screen_containing(bounds.x, bounds.y);
|
|
|
|
|
if (target == NULL) {
|
|
|
|
|
LOG("Target screen NULL\n");
|
|
|
|
|
/* Wrap around if the target screen is out of bounds */
|
|
|
|
|
if (direction == D_RIGHT)
|
2009-08-11 09:02:30 -04:00
|
|
|
|
target = get_screen_most(D_LEFT, cs);
|
2009-08-05 13:24:21 -04:00
|
|
|
|
else if (direction == D_LEFT)
|
2009-08-11 09:02:30 -04:00
|
|
|
|
target = get_screen_most(D_RIGHT, cs);
|
2009-08-05 13:24:21 -04:00
|
|
|
|
else if (direction == D_UP)
|
2009-08-11 09:02:30 -04:00
|
|
|
|
target = get_screen_most(D_DOWN, cs);
|
|
|
|
|
else target = get_screen_most(D_UP, cs);
|
2009-08-05 13:24:21 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LOG("Switching to ws %d\n", target->current_workspace + 1);
|
2009-08-08 13:51:51 -04:00
|
|
|
|
workspace_show(conn, target->current_workspace + 1);
|
2009-08-05 13:24:21 -04:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2009-02-13 20:33:31 -05:00
|
|
|
|
/* TODO: for horizontal default layout, this has to be expanded to LEFT/RIGHT */
|
|
|
|
|
if (direction == D_UP || direction == D_DOWN) {
|
2009-03-04 17:45:44 -05:00
|
|
|
|
if (thing == THING_WINDOW)
|
|
|
|
|
/* Let’s see if we can perform up/down focus in the current container */
|
|
|
|
|
if (focus_window_in_container(conn, container, direction))
|
|
|
|
|
return;
|
2009-02-22 19:41:26 -05:00
|
|
|
|
|
|
|
|
|
if (direction == D_DOWN && cell_exists(current_col, current_row+1))
|
2009-05-09 13:59:36 -04:00
|
|
|
|
new_row = current_row + t_ws->table[current_col][current_row]->rowspan;
|
|
|
|
|
else if (direction == D_UP && cell_exists(current_col, current_row-1)) {
|
|
|
|
|
/* Set new_row as a sane default, but it may get overwritten in a second */
|
2009-03-02 20:28:26 -05:00
|
|
|
|
new_row--;
|
2009-05-09 13:59:36 -04:00
|
|
|
|
|
|
|
|
|
/* Search from the top to correctly handle rowspanned containers */
|
|
|
|
|
for (int rows = 0; rows < current_row; rows += t_ws->table[current_col][rows]->rowspan) {
|
|
|
|
|
if (new_row > (rows + (t_ws->table[current_col][rows]->rowspan - 1)))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
new_row = rows;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2009-03-04 07:06:14 -05:00
|
|
|
|
/* Let’s see if there is a screen down/up there to which we can switch */
|
2009-03-06 00:46:43 -05:00
|
|
|
|
LOG("container is at %d with height %d\n", container->y, container->height);
|
2009-03-04 07:06:14 -05:00
|
|
|
|
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) {
|
2009-03-09 02:39:19 -04:00
|
|
|
|
LOG("Wrapping screen around vertically\n");
|
|
|
|
|
/* No screen found? Then wrap */
|
2009-08-11 09:02:30 -04:00
|
|
|
|
screen = get_screen_most((direction == D_UP ? D_DOWN : D_UP), container->workspace->screen);
|
2009-03-04 07:06:14 -05:00
|
|
|
|
}
|
2009-09-27 08:00:54 -04:00
|
|
|
|
t_ws = workspace_get(screen->current_workspace);
|
2009-03-04 07:06:14 -05:00
|
|
|
|
new_row = (direction == D_UP ? (t_ws->rows - 1) : 0);
|
|
|
|
|
}
|
2009-06-24 15:10:12 -04:00
|
|
|
|
|
2009-06-25 22:21:30 -04:00
|
|
|
|
check_colrow_boundaries();
|
|
|
|
|
|
2009-06-24 15:10:12 -04:00
|
|
|
|
LOG("new_col = %d, new_row = %d\n", new_col, new_row);
|
|
|
|
|
if (t_ws->table[new_col][new_row]->currently_focused == NULL) {
|
|
|
|
|
LOG("Cell empty, checking for colspanned client above...\n");
|
|
|
|
|
for (int cols = 0; cols < new_col; cols += t_ws->table[cols][new_row]->colspan) {
|
|
|
|
|
if (new_col > (cols + (t_ws->table[cols][new_row]->colspan - 1)))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
new_col = cols;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
LOG("Fixed it to new col %d\n", new_col);
|
|
|
|
|
}
|
2009-02-13 20:33:31 -05:00
|
|
|
|
} else if (direction == D_LEFT || direction == D_RIGHT) {
|
|
|
|
|
if (direction == D_RIGHT && cell_exists(current_col+1, current_row))
|
2009-05-09 13:59:36 -04:00
|
|
|
|
new_col = current_col + t_ws->table[current_col][current_row]->colspan;
|
|
|
|
|
else if (direction == D_LEFT && cell_exists(current_col-1, current_row)) {
|
|
|
|
|
/* Set new_col as a sane default, but it may get overwritten in a second */
|
2009-03-02 20:28:26 -05:00
|
|
|
|
new_col--;
|
2009-05-09 13:59:36 -04:00
|
|
|
|
|
|
|
|
|
/* Search from the left to correctly handle colspanned containers */
|
|
|
|
|
for (int cols = 0; cols < current_col; cols += t_ws->table[cols][current_row]->colspan) {
|
|
|
|
|
if (new_col > (cols + (t_ws->table[cols][current_row]->colspan - 1)))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
new_col = cols;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2009-03-04 07:06:14 -05:00
|
|
|
|
/* Let’s see if there is a screen left/right here to which we can switch */
|
2009-03-06 00:46:43 -05:00
|
|
|
|
LOG("container is at %d with width %d\n", container->x, container->width);
|
2009-03-04 07:06:14 -05:00
|
|
|
|
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) {
|
2009-03-09 02:39:19 -04:00
|
|
|
|
LOG("Wrapping screen around horizontally\n");
|
2009-08-11 09:02:30 -04:00
|
|
|
|
screen = get_screen_most((direction == D_LEFT ? D_RIGHT : D_LEFT), container->workspace->screen);
|
2009-03-04 07:06:14 -05:00
|
|
|
|
}
|
2009-09-27 08:00:54 -04:00
|
|
|
|
t_ws = workspace_get(screen->current_workspace);
|
2009-03-04 07:06:14 -05:00
|
|
|
|
new_col = (direction == D_LEFT ? (t_ws->cols - 1) : 0);
|
2009-02-13 20:33:31 -05:00
|
|
|
|
}
|
2009-06-24 15:10:12 -04:00
|
|
|
|
|
2009-06-25 22:21:30 -04:00
|
|
|
|
check_colrow_boundaries();
|
|
|
|
|
|
2009-06-24 15:10:12 -04:00
|
|
|
|
LOG("new_col = %d, new_row = %d\n", new_col, new_row);
|
|
|
|
|
if (t_ws->table[new_col][new_row]->currently_focused == NULL) {
|
|
|
|
|
LOG("Cell empty, checking for rowspanned client above...\n");
|
|
|
|
|
for (int rows = 0; rows < new_row; rows += t_ws->table[new_col][rows]->rowspan) {
|
|
|
|
|
if (new_row > (rows + (t_ws->table[new_col][rows]->rowspan - 1)))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
new_row = rows;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
LOG("Fixed it to new row %d\n", new_row);
|
|
|
|
|
}
|
2009-02-13 20:33:31 -05:00
|
|
|
|
} else {
|
2009-03-06 00:46:43 -05:00
|
|
|
|
LOG("direction unhandled\n");
|
2009-02-22 19:41:26 -05:00
|
|
|
|
return;
|
2009-02-13 20:33:31 -05:00
|
|
|
|
}
|
2009-02-22 19:41:26 -05:00
|
|
|
|
|
2009-06-25 22:21:30 -04:00
|
|
|
|
check_colrow_boundaries();
|
2009-03-09 02:39:19 -04:00
|
|
|
|
|
2009-03-04 07:06:14 -05:00
|
|
|
|
if (t_ws->table[new_col][new_row]->currently_focused != NULL)
|
2009-04-01 06:50:42 -04:00
|
|
|
|
set_focus(conn, t_ws->table[new_col][new_row]->currently_focused, true);
|
2009-02-13 13:04:45 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Tries to move the window inside its current container.
|
|
|
|
|
*
|
|
|
|
|
* Returns true if the window could be moved, false otherwise.
|
|
|
|
|
*
|
|
|
|
|
*/
|
2009-03-04 09:45:12 -05:00
|
|
|
|
static bool move_current_window_in_container(xcb_connection_t *conn, Client *client,
|
2009-02-13 20:33:31 -05:00
|
|
|
|
direction_t direction) {
|
2009-02-22 21:44:10 -05:00
|
|
|
|
assert(client->container != NULL);
|
|
|
|
|
|
2009-02-13 20:33:31 -05:00
|
|
|
|
Client *other = (direction == D_UP ? CIRCLEQ_PREV(client, clients) :
|
2009-03-03 17:51:02 -05:00
|
|
|
|
CIRCLEQ_NEXT(client, clients));
|
2009-02-13 20:33:31 -05:00
|
|
|
|
|
|
|
|
|
if (other == CIRCLEQ_END(&(client->container->clients)))
|
|
|
|
|
return false;
|
|
|
|
|
|
2009-03-06 00:46:43 -05:00
|
|
|
|
LOG("i can do that\n");
|
2009-02-13 20:33:31 -05:00
|
|
|
|
/* We can move the client inside its current container */
|
|
|
|
|
CIRCLEQ_REMOVE(&(client->container->clients), client, clients);
|
|
|
|
|
if (direction == D_UP)
|
|
|
|
|
CIRCLEQ_INSERT_BEFORE(&(client->container->clients), other, client, clients);
|
|
|
|
|
else CIRCLEQ_INSERT_AFTER(&(client->container->clients), other, client, clients);
|
2009-03-04 09:45:12 -05:00
|
|
|
|
render_layout(conn);
|
2009-02-13 20:33:31 -05:00
|
|
|
|
return true;
|
2009-02-13 13:04:45 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
2009-03-11 13:56:31 -04:00
|
|
|
|
* Moves the current window or whole container to the given direction, creating a column/row if
|
|
|
|
|
* necessary.
|
2009-02-13 13:04:45 -05:00
|
|
|
|
*
|
|
|
|
|
*/
|
2009-03-04 09:45:12 -05:00
|
|
|
|
static void move_current_window(xcb_connection_t *conn, direction_t direction) {
|
2009-03-06 00:46:43 -05:00
|
|
|
|
LOG("moving window to direction %s\n", (direction == D_UP ? "up" : (direction == D_DOWN ? "down" :
|
2009-03-11 13:56:31 -04:00
|
|
|
|
(direction == D_LEFT ? "left" : "right"))));
|
2009-02-13 20:33:31 -05:00
|
|
|
|
/* Get current window */
|
|
|
|
|
Container *container = CUR_CELL,
|
2009-02-14 19:58:09 -05:00
|
|
|
|
*new = NULL;
|
2009-02-13 20:33:31 -05:00
|
|
|
|
|
|
|
|
|
/* There has to be a container, see focus_window() */
|
|
|
|
|
assert(container != NULL);
|
|
|
|
|
|
2009-02-22 19:41:26 -05:00
|
|
|
|
/* If there is no window or the dock window is focused, we’re done */
|
|
|
|
|
if (container->currently_focused == NULL ||
|
|
|
|
|
container->currently_focused->dock)
|
2009-02-13 20:33:31 -05:00
|
|
|
|
return;
|
|
|
|
|
|
2009-04-07 10:48:42 -04:00
|
|
|
|
/* As soon as the client is moved away, the last focused client in the old
|
2009-02-13 20:33:31 -05:00
|
|
|
|
* container needs to get focus, if any. Therefore, we save it here. */
|
|
|
|
|
Client *current_client = container->currently_focused;
|
2009-04-11 08:08:19 -04:00
|
|
|
|
Client *to_focus = get_last_focused_client(conn, container, current_client);
|
2009-04-07 10:48:42 -04:00
|
|
|
|
|
|
|
|
|
if (to_focus == NULL) {
|
|
|
|
|
to_focus = CIRCLEQ_NEXT_OR_NULL(&(container->clients), current_client, clients);
|
|
|
|
|
if (to_focus == NULL)
|
|
|
|
|
to_focus = CIRCLEQ_PREV_OR_NULL(&(container->clients), current_client, clients);
|
|
|
|
|
}
|
2009-02-13 20:33:31 -05:00
|
|
|
|
|
|
|
|
|
switch (direction) {
|
|
|
|
|
case D_LEFT:
|
2009-03-10 20:55:10 -04:00
|
|
|
|
/* If we’re at the left-most position, move the rest of the table right */
|
|
|
|
|
if (current_col == 0) {
|
|
|
|
|
expand_table_cols_at_head(c_ws);
|
2009-03-11 13:56:31 -04:00
|
|
|
|
new = CUR_CELL;
|
2009-03-10 20:55:10 -04:00
|
|
|
|
} else
|
|
|
|
|
new = CUR_TABLE[--current_col][current_row];
|
2009-02-13 20:33:31 -05:00
|
|
|
|
break;
|
|
|
|
|
case D_RIGHT:
|
|
|
|
|
if (current_col == (c_ws->cols-1))
|
|
|
|
|
expand_table_cols(c_ws);
|
|
|
|
|
|
|
|
|
|
new = CUR_TABLE[++current_col][current_row];
|
|
|
|
|
break;
|
|
|
|
|
case D_UP:
|
2009-03-11 13:56:31 -04:00
|
|
|
|
if (move_current_window_in_container(conn, current_client, D_UP))
|
2009-02-13 20:33:31 -05:00
|
|
|
|
return;
|
|
|
|
|
|
2009-03-11 13:56:31 -04:00
|
|
|
|
/* if we’re at the up-most position, move the rest of the table down */
|
|
|
|
|
if (current_row == 0) {
|
|
|
|
|
expand_table_rows_at_head(c_ws);
|
|
|
|
|
new = CUR_CELL;
|
|
|
|
|
} else
|
|
|
|
|
new = CUR_TABLE[current_col][--current_row];
|
2009-02-13 20:33:31 -05:00
|
|
|
|
break;
|
|
|
|
|
case D_DOWN:
|
2009-03-04 09:45:12 -05:00
|
|
|
|
if (move_current_window_in_container(conn, current_client, D_DOWN))
|
2009-02-13 20:33:31 -05:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (current_row == (c_ws->rows-1))
|
|
|
|
|
expand_table_rows(c_ws);
|
|
|
|
|
|
|
|
|
|
new = CUR_TABLE[current_col][++current_row];
|
|
|
|
|
break;
|
2009-06-10 13:59:36 -04:00
|
|
|
|
/* To make static analyzers happy: */
|
|
|
|
|
default:
|
|
|
|
|
return;
|
2009-02-13 20:33:31 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Remove it from the old container and put it into the new one */
|
2009-05-30 05:35:32 -04:00
|
|
|
|
client_remove_from_container(conn, current_client, container, true);
|
2009-05-03 10:24:12 -04:00
|
|
|
|
|
|
|
|
|
if (new->currently_focused != NULL)
|
|
|
|
|
CIRCLEQ_INSERT_AFTER(&(new->clients), new->currently_focused, current_client, clients);
|
|
|
|
|
else CIRCLEQ_INSERT_TAIL(&(new->clients), current_client, clients);
|
2009-04-01 06:02:22 -04:00
|
|
|
|
SLIST_INSERT_HEAD(&(new->workspace->focus_stack), current_client, focus_clients);
|
2009-02-13 20:33:31 -05:00
|
|
|
|
|
|
|
|
|
/* Update data structures */
|
|
|
|
|
current_client->container = new;
|
2009-05-27 06:27:29 -04:00
|
|
|
|
current_client->workspace = new->workspace;
|
2009-02-13 20:33:31 -05:00
|
|
|
|
container->currently_focused = to_focus;
|
|
|
|
|
new->currently_focused = current_client;
|
|
|
|
|
|
2009-03-09 03:14:00 -04:00
|
|
|
|
Workspace *workspace = container->workspace;
|
|
|
|
|
|
2009-02-24 14:29:30 -05:00
|
|
|
|
/* delete all empty columns/rows */
|
2009-03-09 03:14:00 -04:00
|
|
|
|
cleanup_table(conn, workspace);
|
2009-03-05 11:17:37 -05:00
|
|
|
|
|
|
|
|
|
/* Fix colspan/rowspan if it’d overlap */
|
2009-03-09 03:14:00 -04:00
|
|
|
|
fix_colrowspan(conn, workspace);
|
2009-03-05 11:17:37 -05:00
|
|
|
|
|
2009-05-26 11:16:51 -04:00
|
|
|
|
render_workspace(conn, workspace->screen, workspace);
|
|
|
|
|
xcb_flush(conn);
|
2009-02-22 19:41:26 -05:00
|
|
|
|
|
2009-04-01 06:50:42 -04:00
|
|
|
|
set_focus(conn, current_client, true);
|
2009-02-13 13:04:45 -05:00
|
|
|
|
}
|
|
|
|
|
|
2009-03-11 13:56:31 -04:00
|
|
|
|
static void move_current_container(xcb_connection_t *conn, direction_t direction) {
|
|
|
|
|
LOG("moving container to direction %s\n", (direction == D_UP ? "up" : (direction == D_DOWN ? "down" :
|
|
|
|
|
(direction == D_LEFT ? "left" : "right"))));
|
|
|
|
|
/* Get current window */
|
|
|
|
|
Container *container = CUR_CELL,
|
|
|
|
|
*new = NULL;
|
|
|
|
|
|
|
|
|
|
Container **old = &CUR_CELL;
|
|
|
|
|
|
|
|
|
|
/* There has to be a container, see focus_window() */
|
|
|
|
|
assert(container != NULL);
|
|
|
|
|
|
|
|
|
|
switch (direction) {
|
|
|
|
|
case D_LEFT:
|
|
|
|
|
/* If we’re at the left-most position, move the rest of the table right */
|
|
|
|
|
if (current_col == 0) {
|
|
|
|
|
expand_table_cols_at_head(c_ws);
|
|
|
|
|
new = CUR_CELL;
|
|
|
|
|
old = &CUR_TABLE[current_col+1][current_row];
|
|
|
|
|
} else
|
|
|
|
|
new = CUR_TABLE[--current_col][current_row];
|
|
|
|
|
break;
|
|
|
|
|
case D_RIGHT:
|
|
|
|
|
if (current_col == (c_ws->cols-1))
|
|
|
|
|
expand_table_cols(c_ws);
|
|
|
|
|
|
|
|
|
|
new = CUR_TABLE[++current_col][current_row];
|
|
|
|
|
break;
|
|
|
|
|
case D_UP:
|
|
|
|
|
/* if we’re at the up-most position, move the rest of the table down */
|
|
|
|
|
if (current_row == 0) {
|
|
|
|
|
expand_table_rows_at_head(c_ws);
|
|
|
|
|
new = CUR_CELL;
|
|
|
|
|
old = &CUR_TABLE[current_col][current_row+1];
|
|
|
|
|
} else
|
|
|
|
|
new = CUR_TABLE[current_col][--current_row];
|
|
|
|
|
break;
|
|
|
|
|
case D_DOWN:
|
|
|
|
|
if (current_row == (c_ws->rows-1))
|
|
|
|
|
expand_table_rows(c_ws);
|
|
|
|
|
|
|
|
|
|
new = CUR_TABLE[current_col][++current_row];
|
|
|
|
|
break;
|
2009-06-10 13:59:36 -04:00
|
|
|
|
/* To make static analyzers happy: */
|
|
|
|
|
default:
|
|
|
|
|
return;
|
2009-03-11 13:56:31 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LOG("old = %d,%d and new = %d,%d\n", container->col, container->row, new->col, new->row);
|
|
|
|
|
|
|
|
|
|
/* Swap the containers */
|
|
|
|
|
int col = new->col;
|
|
|
|
|
int row = new->row;
|
|
|
|
|
|
|
|
|
|
*old = new;
|
|
|
|
|
new->col = container->col;
|
|
|
|
|
new->row = container->row;
|
|
|
|
|
|
|
|
|
|
CUR_CELL = container;
|
|
|
|
|
container->col = col;
|
|
|
|
|
container->row = row;
|
|
|
|
|
|
|
|
|
|
Workspace *workspace = container->workspace;
|
|
|
|
|
|
|
|
|
|
/* delete all empty columns/rows */
|
|
|
|
|
cleanup_table(conn, workspace);
|
|
|
|
|
|
|
|
|
|
/* Fix colspan/rowspan if it’d overlap */
|
|
|
|
|
fix_colrowspan(conn, workspace);
|
|
|
|
|
|
|
|
|
|
render_layout(conn);
|
|
|
|
|
}
|
|
|
|
|
|
2009-02-13 13:04:45 -05:00
|
|
|
|
/*
|
|
|
|
|
* "Snaps" the current container (not possible for windows, because it works at table base)
|
|
|
|
|
* to the given direction, that is, adjusts cellspan/rowspan
|
|
|
|
|
*
|
|
|
|
|
*/
|
2009-03-04 09:45:12 -05:00
|
|
|
|
static void snap_current_container(xcb_connection_t *conn, direction_t direction) {
|
2009-03-06 00:46:43 -05:00
|
|
|
|
LOG("snapping container to direction %d\n", direction);
|
2009-02-13 20:33:31 -05:00
|
|
|
|
|
|
|
|
|
Container *container = CUR_CELL;
|
|
|
|
|
|
|
|
|
|
assert(container != NULL);
|
|
|
|
|
|
|
|
|
|
switch (direction) {
|
|
|
|
|
case D_LEFT:
|
|
|
|
|
/* Snap to the left is actually a move to the left and then a snap right */
|
2009-03-05 11:17:37 -05:00
|
|
|
|
if (!cell_exists(container->col - 1, container->row) ||
|
2009-06-19 16:39:03 -04:00
|
|
|
|
CUR_TABLE[container->col-1][container->row]->currently_focused != NULL) {
|
2009-03-06 00:46:43 -05:00
|
|
|
|
LOG("cannot snap to left - the cell is already used\n");
|
2009-03-05 11:17:37 -05:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2009-03-04 09:45:12 -05:00
|
|
|
|
move_current_window(conn, D_LEFT);
|
|
|
|
|
snap_current_container(conn, D_RIGHT);
|
2009-02-13 20:33:31 -05:00
|
|
|
|
return;
|
2009-03-05 11:23:13 -05:00
|
|
|
|
case D_RIGHT: {
|
2009-02-13 20:33:31 -05:00
|
|
|
|
/* Check if the cell is used */
|
2009-03-05 11:23:13 -05:00
|
|
|
|
int new_col = container->col + container->colspan;
|
2009-06-19 16:39:03 -04:00
|
|
|
|
for (int i = 0; i < container->rowspan; i++)
|
|
|
|
|
if (!cell_exists(new_col, container->row + i) ||
|
|
|
|
|
CUR_TABLE[new_col][container->row + i]->currently_focused != NULL) {
|
|
|
|
|
LOG("cannot snap to right - the cell is already used\n");
|
|
|
|
|
return;
|
|
|
|
|
}
|
2009-02-13 20:33:31 -05:00
|
|
|
|
|
|
|
|
|
/* Check if there are other cells with rowspan, which are in our way.
|
|
|
|
|
* If so, reduce their rowspan. */
|
2009-02-14 20:30:18 -05:00
|
|
|
|
for (int i = container->row-1; i >= 0; i--) {
|
2009-03-06 00:46:43 -05:00
|
|
|
|
LOG("we got cell %d, %d with rowspan %d\n",
|
2009-03-05 11:23:13 -05:00
|
|
|
|
new_col, i, CUR_TABLE[new_col][i]->rowspan);
|
|
|
|
|
while ((CUR_TABLE[new_col][i]->rowspan-1) >= (container->row - i))
|
|
|
|
|
CUR_TABLE[new_col][i]->rowspan--;
|
2009-03-06 00:46:43 -05:00
|
|
|
|
LOG("new rowspan = %d\n", CUR_TABLE[new_col][i]->rowspan);
|
2009-02-13 20:33:31 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
container->colspan++;
|
|
|
|
|
break;
|
2009-03-05 11:23:13 -05:00
|
|
|
|
}
|
2009-02-13 20:33:31 -05:00
|
|
|
|
case D_UP:
|
2009-03-05 11:23:13 -05:00
|
|
|
|
if (!cell_exists(container->col, container->row - 1) ||
|
2009-06-19 16:39:03 -04:00
|
|
|
|
CUR_TABLE[container->col][container->row-1]->currently_focused != NULL) {
|
2009-03-06 00:46:43 -05:00
|
|
|
|
LOG("cannot snap to top - the cell is already used\n");
|
2009-03-05 11:23:13 -05:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2009-03-04 09:45:12 -05:00
|
|
|
|
move_current_window(conn, D_UP);
|
|
|
|
|
snap_current_container(conn, D_DOWN);
|
2009-02-13 20:33:31 -05:00
|
|
|
|
return;
|
2009-03-05 11:23:13 -05:00
|
|
|
|
case D_DOWN: {
|
2009-03-06 00:46:43 -05:00
|
|
|
|
LOG("snapping down\n");
|
2009-03-05 11:23:13 -05:00
|
|
|
|
int new_row = container->row + container->rowspan;
|
2009-06-19 16:39:03 -04:00
|
|
|
|
for (int i = 0; i < container->colspan; i++)
|
|
|
|
|
if (!cell_exists(container->col + i, new_row) ||
|
|
|
|
|
CUR_TABLE[container->col + i][new_row]->currently_focused != NULL) {
|
|
|
|
|
LOG("cannot snap down - the cell is already used\n");
|
|
|
|
|
return;
|
|
|
|
|
}
|
2009-02-13 20:33:31 -05:00
|
|
|
|
|
2009-02-14 20:30:18 -05:00
|
|
|
|
for (int i = container->col-1; i >= 0; i--) {
|
2009-03-06 00:46:43 -05:00
|
|
|
|
LOG("we got cell %d, %d with colspan %d\n",
|
2009-03-05 11:23:13 -05:00
|
|
|
|
i, new_row, CUR_TABLE[i][new_row]->colspan);
|
|
|
|
|
while ((CUR_TABLE[i][new_row]->colspan-1) >= (container->col - i))
|
|
|
|
|
CUR_TABLE[i][new_row]->colspan--;
|
2009-03-06 00:46:43 -05:00
|
|
|
|
LOG("new colspan = %d\n", CUR_TABLE[i][new_row]->colspan);
|
2009-02-13 20:33:31 -05:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
container->rowspan++;
|
|
|
|
|
break;
|
2009-03-05 11:23:13 -05:00
|
|
|
|
}
|
2009-06-10 13:59:36 -04:00
|
|
|
|
/* To make static analyzers happy: */
|
|
|
|
|
default:
|
|
|
|
|
return;
|
2009-02-13 20:33:31 -05:00
|
|
|
|
}
|
|
|
|
|
|
2009-03-04 09:45:12 -05:00
|
|
|
|
render_layout(conn);
|
2009-02-13 13:04:45 -05:00
|
|
|
|
}
|
|
|
|
|
|
2009-05-23 10:34:03 -04:00
|
|
|
|
static void move_floating_window_to_workspace(xcb_connection_t *conn, Client *client, int workspace) {
|
|
|
|
|
/* t_ws (to workspace) is just a container pointer to the workspace we’re switching to */
|
2009-09-27 08:00:54 -04:00
|
|
|
|
Workspace *t_ws = workspace_get(workspace-1),
|
2009-06-23 18:34:03 -04:00
|
|
|
|
*old_ws = client->workspace;
|
2009-05-23 10:34:03 -04:00
|
|
|
|
|
|
|
|
|
LOG("moving floating\n");
|
|
|
|
|
|
2009-09-12 12:34:03 -04:00
|
|
|
|
workspace_initialize(t_ws, c_ws->screen);
|
2009-09-12 12:18:41 -04:00
|
|
|
|
|
|
|
|
|
/* Check if there is already a fullscreen client on the destination workspace and
|
|
|
|
|
* stop moving if so. */
|
|
|
|
|
if (client->fullscreen && (t_ws->fullscreen_client != NULL)) {
|
|
|
|
|
LOG("Not moving: Fullscreen client already existing on destination workspace.\n");
|
|
|
|
|
return;
|
2009-05-23 10:34:03 -04:00
|
|
|
|
}
|
|
|
|
|
|
2009-06-24 11:12:12 -04:00
|
|
|
|
floating_assign_to_workspace(client, t_ws);
|
2009-05-23 10:34:03 -04:00
|
|
|
|
|
|
|
|
|
/* If we’re moving it to an invisible screen, we need to unmap it */
|
2009-08-02 16:31:52 -04:00
|
|
|
|
if (!workspace_is_visible(t_ws)) {
|
2009-05-23 10:34:03 -04:00
|
|
|
|
LOG("This workspace is not visible, unmapping\n");
|
2009-08-11 06:16:10 -04:00
|
|
|
|
client_unmap(conn, client);
|
2009-06-23 18:34:03 -04:00
|
|
|
|
} else {
|
|
|
|
|
/* If this is not the case, we move the window to a workspace
|
|
|
|
|
* which is on another screen, so we also need to adjust its
|
|
|
|
|
* coordinates. */
|
|
|
|
|
LOG("before x = %d, y = %d\n", client->rect.x, client->rect.y);
|
|
|
|
|
uint32_t relative_x = client->rect.x - old_ws->rect.x,
|
|
|
|
|
relative_y = client->rect.y - old_ws->rect.y;
|
|
|
|
|
LOG("rel_x = %d, rel_y = %d\n", relative_x, relative_y);
|
|
|
|
|
client->rect.x = t_ws->rect.x + relative_x;
|
|
|
|
|
client->rect.y = t_ws->rect.y + relative_y;
|
|
|
|
|
LOG("after x = %d, y = %d\n", client->rect.x, client->rect.y);
|
|
|
|
|
reposition_client(conn, client);
|
|
|
|
|
xcb_flush(conn);
|
2009-05-23 10:34:03 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LOG("done\n");
|
|
|
|
|
|
|
|
|
|
render_layout(conn);
|
2009-06-23 18:35:05 -04:00
|
|
|
|
|
2009-08-02 16:31:52 -04:00
|
|
|
|
if (workspace_is_visible(t_ws))
|
2009-06-25 07:31:58 -04:00
|
|
|
|
set_focus(conn, client, true);
|
2009-05-23 10:34:03 -04:00
|
|
|
|
}
|
|
|
|
|
|
2009-03-04 02:59:03 -05:00
|
|
|
|
/*
|
|
|
|
|
* Moves the currently selected window to the given workspace
|
|
|
|
|
*
|
|
|
|
|
*/
|
2009-03-04 09:45:12 -05:00
|
|
|
|
static void move_current_window_to_workspace(xcb_connection_t *conn, int workspace) {
|
2009-03-06 00:46:43 -05:00
|
|
|
|
LOG("Moving current window to workspace %d\n", workspace);
|
2009-03-04 02:59:03 -05:00
|
|
|
|
|
|
|
|
|
Container *container = CUR_CELL;
|
|
|
|
|
|
|
|
|
|
assert(container != NULL);
|
|
|
|
|
|
|
|
|
|
/* t_ws (to workspace) is just a container pointer to the workspace we’re switching to */
|
2009-09-27 08:00:54 -04:00
|
|
|
|
Workspace *t_ws = workspace_get(workspace-1);
|
2009-03-04 02:59:03 -05:00
|
|
|
|
|
|
|
|
|
Client *current_client = container->currently_focused;
|
|
|
|
|
if (current_client == NULL) {
|
2009-03-06 00:46:43 -05:00
|
|
|
|
LOG("No currently focused client in current container.\n");
|
2009-03-04 02:59:03 -05:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
Client *to_focus = CIRCLEQ_NEXT_OR_NULL(&(container->clients), current_client, clients);
|
|
|
|
|
if (to_focus == NULL)
|
|
|
|
|
to_focus = CIRCLEQ_PREV_OR_NULL(&(container->clients), current_client, clients);
|
|
|
|
|
|
2009-09-12 12:15:32 -04:00
|
|
|
|
workspace_initialize(t_ws, container->workspace->screen);
|
|
|
|
|
/* Check if there is already a fullscreen client on the destination workspace and
|
|
|
|
|
* stop moving if so. */
|
|
|
|
|
if (current_client->fullscreen && (t_ws->fullscreen_client != NULL)) {
|
|
|
|
|
LOG("Not moving: Fullscreen client already existing on destination workspace.\n");
|
|
|
|
|
return;
|
2009-03-04 02:59:03 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Container *to_container = t_ws->table[t_ws->current_col][t_ws->current_row];
|
|
|
|
|
|
|
|
|
|
assert(to_container != NULL);
|
|
|
|
|
|
2009-05-30 05:35:32 -04:00
|
|
|
|
client_remove_from_container(conn, current_client, container, true);
|
2009-04-17 15:01:33 -04:00
|
|
|
|
if (container->workspace->fullscreen_client == current_client)
|
|
|
|
|
container->workspace->fullscreen_client = NULL;
|
2009-03-04 19:48:30 -05:00
|
|
|
|
|
2009-05-23 10:34:03 -04:00
|
|
|
|
/* TODO: insert it to the correct position */
|
2009-03-04 02:59:03 -05:00
|
|
|
|
CIRCLEQ_INSERT_TAIL(&(to_container->clients), current_client, clients);
|
2009-05-23 10:34:03 -04:00
|
|
|
|
|
2009-03-04 19:48:30 -05:00
|
|
|
|
SLIST_INSERT_HEAD(&(to_container->workspace->focus_stack), current_client, focus_clients);
|
2009-03-06 00:46:43 -05:00
|
|
|
|
LOG("Moved.\n");
|
2009-03-04 02:59:03 -05:00
|
|
|
|
|
|
|
|
|
current_client->container = to_container;
|
2009-05-27 06:27:29 -04:00
|
|
|
|
current_client->workspace = to_container->workspace;
|
2009-03-04 02:59:03 -05:00
|
|
|
|
container->currently_focused = to_focus;
|
|
|
|
|
to_container->currently_focused = current_client;
|
|
|
|
|
|
|
|
|
|
/* If we’re moving it to an invisible screen, we need to unmap it */
|
2009-08-02 16:31:52 -04:00
|
|
|
|
if (!workspace_is_visible(to_container->workspace)) {
|
2009-03-06 00:46:43 -05:00
|
|
|
|
LOG("This workspace is not visible, unmapping\n");
|
2009-08-11 06:16:10 -04:00
|
|
|
|
client_unmap(conn, current_client);
|
2009-06-25 07:46:47 -04:00
|
|
|
|
} else {
|
|
|
|
|
if (current_client->fullscreen) {
|
|
|
|
|
LOG("Calling client_enter_fullscreen again\n");
|
|
|
|
|
client_enter_fullscreen(conn, current_client);
|
|
|
|
|
}
|
2009-03-04 02:59:03 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* delete all empty columns/rows */
|
2009-03-04 09:45:12 -05:00
|
|
|
|
cleanup_table(conn, container->workspace);
|
2009-03-04 02:59:03 -05:00
|
|
|
|
|
2009-03-04 09:45:12 -05:00
|
|
|
|
render_layout(conn);
|
2009-06-25 07:46:47 -04:00
|
|
|
|
|
2009-08-02 16:31:52 -04:00
|
|
|
|
if (workspace_is_visible(to_container->workspace))
|
2009-06-25 07:46:47 -04:00
|
|
|
|
set_focus(conn, current_client, true);
|
2009-03-04 02:59:03 -05:00
|
|
|
|
}
|
|
|
|
|
|
2009-03-31 04:46:12 -04:00
|
|
|
|
/*
|
|
|
|
|
* Jumps to the given window class / title.
|
|
|
|
|
* Title is matched using strstr, that is, matches if it appears anywhere
|
|
|
|
|
* in the string. Regular expressions seem to be a bit overkill here. However,
|
|
|
|
|
* if we need them for something else somewhen, we may introduce them here, too.
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
static void jump_to_window(xcb_connection_t *conn, const char *arguments) {
|
2009-05-16 11:32:36 -04:00
|
|
|
|
char *classtitle;
|
|
|
|
|
Client *client;
|
2009-03-31 04:46:12 -04:00
|
|
|
|
|
|
|
|
|
/* The first character is a quote, this was checked before */
|
2009-05-16 11:32:36 -04:00
|
|
|
|
classtitle = sstrdup(arguments+1);
|
2009-03-31 04:46:12 -04:00
|
|
|
|
/* The last character is a quote, we just set it to NULL */
|
2009-05-16 11:32:36 -04:00
|
|
|
|
classtitle[strlen(classtitle)-1] = '\0';
|
2009-03-31 04:46:12 -04:00
|
|
|
|
|
2009-05-16 11:32:36 -04:00
|
|
|
|
if ((client = get_matching_client(conn, classtitle, NULL)) == NULL) {
|
|
|
|
|
free(classtitle);
|
|
|
|
|
LOG("No matching client found.\n");
|
|
|
|
|
return;
|
2009-03-31 04:46:12 -04:00
|
|
|
|
}
|
|
|
|
|
|
2009-05-16 11:32:36 -04:00
|
|
|
|
free(classtitle);
|
|
|
|
|
set_focus(conn, client, true);
|
2009-03-31 04:46:12 -04:00
|
|
|
|
}
|
|
|
|
|
|
2009-03-29 08:53:48 -04:00
|
|
|
|
/*
|
|
|
|
|
* Jump directly to the specified workspace, row and col.
|
2009-03-31 04:46:12 -04:00
|
|
|
|
* Great for reaching windows that you always keep in the same spot (hello irssi, I'm looking at you)
|
2009-03-30 03:25:30 -04:00
|
|
|
|
*
|
2009-03-29 08:53:48 -04:00
|
|
|
|
*/
|
2009-03-31 04:46:12 -04:00
|
|
|
|
static void jump_to_container(xcb_connection_t *conn, const char *arguments) {
|
2009-03-30 03:25:30 -04:00
|
|
|
|
int ws, row, col;
|
2009-03-29 08:53:48 -04:00
|
|
|
|
int result;
|
|
|
|
|
|
2009-03-31 04:46:12 -04:00
|
|
|
|
result = sscanf(arguments, "%d %d %d", &ws, &col, &row);
|
|
|
|
|
LOG("Jump called with %d parameters (\"%s\")\n", result, arguments);
|
2009-03-29 08:53:48 -04:00
|
|
|
|
|
2009-03-30 03:25:30 -04:00
|
|
|
|
/* No match? Either no arguments were specified, or no numbers */
|
|
|
|
|
if (result < 1) {
|
|
|
|
|
LOG("At least one valid argument required\n");
|
|
|
|
|
return;
|
|
|
|
|
}
|
2009-03-29 08:53:48 -04:00
|
|
|
|
|
|
|
|
|
/* Move to the target workspace */
|
2009-08-08 13:51:51 -04:00
|
|
|
|
workspace_show(conn, ws);
|
2009-03-29 08:53:48 -04:00
|
|
|
|
|
2009-03-30 03:25:30 -04:00
|
|
|
|
if (result < 3)
|
|
|
|
|
return;
|
2009-03-29 08:53:48 -04:00
|
|
|
|
|
2009-05-05 10:57:21 -04:00
|
|
|
|
LOG("Boundary-checking col %d, row %d... (max cols %d, max rows %d)\n", col, row, c_ws->cols, c_ws->rows);
|
|
|
|
|
|
2009-03-29 08:53:48 -04:00
|
|
|
|
/* Move to row/col */
|
2009-03-30 03:25:30 -04:00
|
|
|
|
if (row >= c_ws->rows)
|
|
|
|
|
row = c_ws->rows - 1;
|
|
|
|
|
if (col >= c_ws->cols)
|
|
|
|
|
col = c_ws->cols - 1;
|
2009-03-29 08:53:48 -04:00
|
|
|
|
|
2009-05-05 10:57:21 -04:00
|
|
|
|
LOG("Jumping to col %d, row %d\n", col, row);
|
2009-03-29 08:53:48 -04:00
|
|
|
|
if (c_ws->table[col][row]->currently_focused != NULL)
|
2009-05-05 11:25:56 -04:00
|
|
|
|
set_focus(conn, c_ws->table[col][row]->currently_focused, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Travels the focus stack by the given number of times (or once, if no argument
|
|
|
|
|
* was specified). That is, selects the window you were in before you focused
|
|
|
|
|
* the current window.
|
|
|
|
|
*
|
2009-06-21 10:14:15 -04:00
|
|
|
|
* The special values 'floating' (select the next floating window), 'tiling'
|
|
|
|
|
* (select the next tiling window), 'ft' (if the current window is floating,
|
|
|
|
|
* select the next tiling window and vice-versa) are also valid
|
|
|
|
|
*
|
2009-05-05 11:25:56 -04:00
|
|
|
|
*/
|
|
|
|
|
static void travel_focus_stack(xcb_connection_t *conn, const char *arguments) {
|
|
|
|
|
/* Start count at -1 to always skip the first element */
|
|
|
|
|
int times, count = -1;
|
|
|
|
|
Client *current;
|
2009-06-21 10:14:15 -04:00
|
|
|
|
bool floating_criteria;
|
|
|
|
|
|
|
|
|
|
/* Either it’s one of the special values… */
|
|
|
|
|
if (strcasecmp(arguments, "floating") == 0) {
|
|
|
|
|
floating_criteria = true;
|
|
|
|
|
} else if (strcasecmp(arguments, "tiling") == 0) {
|
|
|
|
|
floating_criteria = false;
|
|
|
|
|
} else if (strcasecmp(arguments, "ft") == 0) {
|
|
|
|
|
Client *last_focused = SLIST_FIRST(&(c_ws->focus_stack));
|
|
|
|
|
if (last_focused == SLIST_END(&(c_ws->focus_stack))) {
|
|
|
|
|
LOG("Cannot select the next floating/tiling client because there is no client at all\n");
|
|
|
|
|
return;
|
|
|
|
|
}
|
2009-05-05 11:25:56 -04:00
|
|
|
|
|
2009-06-21 10:14:15 -04:00
|
|
|
|
floating_criteria = !client_is_floating(last_focused);
|
|
|
|
|
} else {
|
|
|
|
|
/* …or a number was specified */
|
|
|
|
|
if (sscanf(arguments, "%u", ×) != 1) {
|
|
|
|
|
LOG("No or invalid argument given (\"%s\"), using default of 1 times\n", arguments);
|
|
|
|
|
times = 1;
|
|
|
|
|
}
|
2009-05-05 11:25:56 -04:00
|
|
|
|
|
2009-06-21 10:14:15 -04:00
|
|
|
|
SLIST_FOREACH(current, &(CUR_CELL->workspace->focus_stack), focus_clients) {
|
|
|
|
|
if (++count < times) {
|
|
|
|
|
LOG("Skipping\n");
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2009-05-05 11:25:56 -04:00
|
|
|
|
|
2009-06-21 10:14:15 -04:00
|
|
|
|
LOG("Focussing\n");
|
|
|
|
|
set_focus(conn, current, true);
|
|
|
|
|
break;
|
2009-05-05 11:25:56 -04:00
|
|
|
|
}
|
2009-06-21 10:14:15 -04:00
|
|
|
|
return;
|
2009-05-05 11:25:56 -04:00
|
|
|
|
}
|
2009-06-21 10:14:15 -04:00
|
|
|
|
|
|
|
|
|
/* Select the next client matching the criteria parsed above */
|
|
|
|
|
SLIST_FOREACH(current, &(CUR_CELL->workspace->focus_stack), focus_clients)
|
|
|
|
|
if (client_is_floating(current) == floating_criteria) {
|
|
|
|
|
set_focus(conn, current, true);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2009-03-29 08:53:48 -04:00
|
|
|
|
}
|
|
|
|
|
|
2009-05-26 11:09:34 -04:00
|
|
|
|
/*
|
|
|
|
|
* Goes through the list of arguments (for exec()) and checks if the given argument
|
|
|
|
|
* is present. If not, it copies the arguments (because we cannot realloc it) and
|
|
|
|
|
* appends the given argument.
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
static char **append_argument(char **original, char *argument) {
|
|
|
|
|
int num_args;
|
|
|
|
|
for (num_args = 0; original[num_args] != NULL; num_args++) {
|
|
|
|
|
LOG("original argument: \"%s\"\n", original[num_args]);
|
|
|
|
|
/* If the argument is already present we return the original pointer */
|
|
|
|
|
if (strcmp(original[num_args], argument) == 0)
|
|
|
|
|
return original;
|
|
|
|
|
}
|
|
|
|
|
/* Copy the original array */
|
|
|
|
|
char **result = smalloc((num_args+2) * sizeof(char*));
|
|
|
|
|
memcpy(result, original, num_args * sizeof(char*));
|
|
|
|
|
result[num_args] = argument;
|
|
|
|
|
result[num_args+1] = NULL;
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
2009-07-21 18:16:16 -04:00
|
|
|
|
|
2009-07-21 15:32:29 -04:00
|
|
|
|
/*
|
2009-07-21 18:16:16 -04:00
|
|
|
|
* Switch to next or previous existing workspace
|
|
|
|
|
*
|
2009-07-21 15:32:29 -04:00
|
|
|
|
*/
|
|
|
|
|
static void next_previous_workspace(xcb_connection_t *conn, int direction) {
|
2009-07-21 18:16:16 -04:00
|
|
|
|
Workspace *t_ws;
|
|
|
|
|
int i;
|
2009-07-21 15:32:29 -04:00
|
|
|
|
|
2009-07-21 18:16:16 -04:00
|
|
|
|
if (direction == 'n') {
|
|
|
|
|
/* If we are on the last workspace, we cannot go any further */
|
2009-09-27 08:00:54 -04:00
|
|
|
|
if (c_ws->num == (num_workspaces-1))
|
2009-07-21 18:16:16 -04:00
|
|
|
|
return;
|
|
|
|
|
|
2009-09-27 08:00:54 -04:00
|
|
|
|
for (i = c_ws->num + 1; i < num_workspaces; i++) {
|
2009-07-21 18:16:16 -04:00
|
|
|
|
t_ws = &(workspaces[i]);
|
|
|
|
|
if (t_ws->screen != NULL)
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
} else if (direction == 'p') {
|
|
|
|
|
if (c_ws->num == 0)
|
|
|
|
|
return;
|
|
|
|
|
for (i = c_ws->num - 1; i >= 0 ; i--) {
|
|
|
|
|
t_ws = &(workspaces[i]);
|
|
|
|
|
if (t_ws->screen != NULL)
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (t_ws->screen != NULL)
|
2009-08-08 13:51:51 -04:00
|
|
|
|
workspace_show(conn, i+1);
|
2009-07-21 18:16:16 -04:00
|
|
|
|
}
|
2009-05-26 11:09:34 -04:00
|
|
|
|
|
2009-09-26 11:18:50 -04:00
|
|
|
|
static void parse_resize_command(xcb_connection_t *conn, Client *last_focused, const char *command) {
|
|
|
|
|
int first, second;
|
|
|
|
|
resize_orientation_t orientation = O_VERTICAL;
|
|
|
|
|
Container *con = last_focused->container;
|
2009-09-27 08:00:54 -04:00
|
|
|
|
Workspace *ws = con->workspace;
|
2009-09-26 11:18:50 -04:00
|
|
|
|
|
|
|
|
|
if (STARTS_WITH(command, "left")) {
|
|
|
|
|
if (con->col == 0)
|
|
|
|
|
return;
|
|
|
|
|
first = con->col - 1;
|
|
|
|
|
second = con->col;
|
|
|
|
|
command += strlen("left");
|
|
|
|
|
} else if (STARTS_WITH(command, "right")) {
|
|
|
|
|
first = con->col + (con->colspan - 1);
|
|
|
|
|
LOG("column %d\n", first);
|
|
|
|
|
|
|
|
|
|
if (!cell_exists(first, con->row) ||
|
2009-09-27 08:00:54 -04:00
|
|
|
|
(first == (ws->cols-1)))
|
2009-09-26 11:18:50 -04:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
second = first + 1;
|
|
|
|
|
command += strlen("right");
|
|
|
|
|
} else if (STARTS_WITH(command, "top")) {
|
|
|
|
|
if (con->row == 0)
|
|
|
|
|
return;
|
|
|
|
|
first = con->row - 1;
|
|
|
|
|
second = con->row;
|
|
|
|
|
orientation = O_HORIZONTAL;
|
|
|
|
|
command += strlen("top");
|
|
|
|
|
} else if (STARTS_WITH(command, "bottom")) {
|
|
|
|
|
first = con->row + (con->rowspan - 1);
|
|
|
|
|
if (!cell_exists(con->col, first) ||
|
2009-09-27 08:00:54 -04:00
|
|
|
|
(first == (ws->rows-1)))
|
2009-09-26 11:18:50 -04:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
second = first + 1;
|
|
|
|
|
orientation = O_HORIZONTAL;
|
|
|
|
|
command += strlen("bottom");
|
|
|
|
|
} else {
|
|
|
|
|
LOG("Syntax: resize <left|right|up|down> [+|-]<pixels>\n");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int pixels = atoi(command);
|
|
|
|
|
if (pixels == 0)
|
|
|
|
|
return;
|
|
|
|
|
|
2009-09-27 08:00:54 -04:00
|
|
|
|
resize_container(conn, ws, first, second, orientation, pixels);
|
2009-09-26 11:18:50 -04:00
|
|
|
|
}
|
|
|
|
|
|
2009-02-13 13:04:45 -05:00
|
|
|
|
/*
|
|
|
|
|
* Parses a command, see file CMDMODE for more information
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
void parse_command(xcb_connection_t *conn, const char *command) {
|
2009-03-06 00:46:43 -05:00
|
|
|
|
LOG("--- parsing command \"%s\" ---\n", command);
|
2009-05-23 10:34:03 -04:00
|
|
|
|
/* Get the first client from focus stack because floating clients are not
|
|
|
|
|
* in any container, therefore CUR_CELL is not appropriate. */
|
|
|
|
|
Client *last_focused = SLIST_FIRST(&(c_ws->focus_stack));
|
|
|
|
|
if (last_focused == SLIST_END(&(c_ws->focus_stack)))
|
|
|
|
|
last_focused = NULL;
|
|
|
|
|
|
2009-02-13 20:33:31 -05:00
|
|
|
|
/* Hmm, just to be sure */
|
|
|
|
|
if (command[0] == '\0')
|
|
|
|
|
return;
|
|
|
|
|
|
2009-03-14 16:31:22 -04:00
|
|
|
|
/* Is it an <exec>? Then execute the given command. */
|
|
|
|
|
if (STARTS_WITH(command, "exec ")) {
|
2009-03-06 00:46:43 -05:00
|
|
|
|
LOG("starting \"%s\"\n", command + strlen("exec "));
|
2009-02-13 20:33:31 -05:00
|
|
|
|
start_application(command+strlen("exec "));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2009-09-20 10:54:29 -04:00
|
|
|
|
if (STARTS_WITH(command, "mark")) {
|
|
|
|
|
if (last_focused == NULL) {
|
|
|
|
|
LOG("There is no window to mark\n");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
const char *rest = command + strlen("mark");
|
|
|
|
|
while (*rest == ' ')
|
|
|
|
|
rest++;
|
|
|
|
|
if (*rest == '\0') {
|
|
|
|
|
LOG("interactive mark starting\n");
|
|
|
|
|
start_application("i3-input -p 'mark ' -l 1 -P 'Mark: '");
|
|
|
|
|
} else {
|
|
|
|
|
LOG("mark with \"%s\"\n", rest);
|
|
|
|
|
client_mark(conn, last_focused, rest);
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (STARTS_WITH(command, "goto")) {
|
|
|
|
|
const char *rest = command + strlen("goto");
|
|
|
|
|
while (*rest == ' ')
|
|
|
|
|
rest++;
|
|
|
|
|
if (*rest == '\0') {
|
|
|
|
|
LOG("interactive go to mark starting\n");
|
|
|
|
|
start_application("i3-input -p 'goto ' -l 1 -P 'Goto: '");
|
|
|
|
|
} else {
|
|
|
|
|
LOG("go to \"%s\"\n", rest);
|
|
|
|
|
jump_to_mark(conn, rest);
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2009-09-22 12:07:59 -04:00
|
|
|
|
if (STARTS_WITH(command, "stack-limit ")) {
|
|
|
|
|
if (last_focused == NULL || client_is_floating(last_focused)) {
|
|
|
|
|
LOG("No container focused\n");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
const char *rest = command + strlen("stack-limit ");
|
|
|
|
|
if (strncmp(rest, "rows ", strlen("rows ")) == 0) {
|
|
|
|
|
last_focused->container->stack_limit = STACK_LIMIT_ROWS;
|
|
|
|
|
rest += strlen("rows ");
|
|
|
|
|
} else if (strncmp(rest, "cols ", strlen("cols ")) == 0) {
|
|
|
|
|
last_focused->container->stack_limit = STACK_LIMIT_COLS;
|
|
|
|
|
rest += strlen("cols ");
|
|
|
|
|
} else {
|
|
|
|
|
LOG("Syntax: stack-limit <cols|rows> <limit>\n");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
last_focused->container->stack_limit_value = atoi(rest);
|
|
|
|
|
if (last_focused->container->stack_limit_value == 0)
|
|
|
|
|
last_focused->container->stack_limit = STACK_LIMIT_NONE;
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2009-09-26 11:18:50 -04:00
|
|
|
|
if (STARTS_WITH(command, "resize ")) {
|
|
|
|
|
if (last_focused == NULL)
|
|
|
|
|
return;
|
|
|
|
|
const char *rest = command + strlen("resize ");
|
|
|
|
|
parse_resize_command(conn, last_focused, rest);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2009-09-27 12:45:39 -04:00
|
|
|
|
if (STARTS_WITH(command, "mode ")) {
|
|
|
|
|
const char *rest = command + strlen("mode ");
|
|
|
|
|
switch_mode(conn, rest);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2009-03-14 16:31:22 -04:00
|
|
|
|
/* Is it an <exit>? */
|
2009-03-14 17:09:36 -04:00
|
|
|
|
if (STARTS_WITH(command, "exit")) {
|
|
|
|
|
LOG("User issued exit-command, exiting without error.\n");
|
|
|
|
|
exit(EXIT_SUCCESS);
|
|
|
|
|
}
|
2009-03-14 16:31:22 -04:00
|
|
|
|
|
2009-07-23 14:36:48 -04:00
|
|
|
|
/* Is it a <reload>? */
|
2009-07-23 12:14:24 -04:00
|
|
|
|
if (STARTS_WITH(command, "reload")) {
|
2009-07-23 14:36:48 -04:00
|
|
|
|
load_configuration(conn, NULL, true);
|
|
|
|
|
return;
|
2009-07-23 12:14:24 -04:00
|
|
|
|
}
|
|
|
|
|
|
2009-03-14 16:31:22 -04:00
|
|
|
|
/* Is it <restart>? Then restart in place. */
|
|
|
|
|
if (STARTS_WITH(command, "restart")) {
|
2009-05-01 10:10:02 -04:00
|
|
|
|
LOG("restarting \"%s\"...\n", start_argv[0]);
|
2009-05-26 11:09:34 -04:00
|
|
|
|
/* make sure -a is in the argument list or append it */
|
|
|
|
|
start_argv = append_argument(start_argv, "-a");
|
|
|
|
|
|
2009-05-01 10:10:02 -04:00
|
|
|
|
execvp(start_argv[0], start_argv);
|
2009-02-27 16:40:48 -05:00
|
|
|
|
/* not reached */
|
|
|
|
|
}
|
|
|
|
|
|
2009-03-14 17:09:36 -04:00
|
|
|
|
if (STARTS_WITH(command, "kill")) {
|
2009-05-23 10:34:03 -04:00
|
|
|
|
if (last_focused == NULL) {
|
2009-03-14 17:09:36 -04:00
|
|
|
|
LOG("There is no window to kill\n");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LOG("Killing current window\n");
|
2009-05-23 10:34:03 -04:00
|
|
|
|
client_kill(conn, last_focused);
|
2009-03-14 17:09:36 -04:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2009-05-23 10:34:03 -04:00
|
|
|
|
/* Is it a jump to a specified workspace, row, col? */
|
2009-03-29 08:53:48 -04:00
|
|
|
|
if (STARTS_WITH(command, "jump ")) {
|
2009-03-31 04:46:12 -04:00
|
|
|
|
const char *arguments = command + strlen("jump ");
|
|
|
|
|
if (arguments[0] == '"')
|
|
|
|
|
jump_to_window(conn, arguments);
|
|
|
|
|
else jump_to_container(conn, arguments);
|
2009-03-29 08:53:48 -04:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2009-05-05 11:25:56 -04:00
|
|
|
|
/* Should we travel the focus stack? */
|
|
|
|
|
if (STARTS_WITH(command, "focus")) {
|
2009-06-21 10:14:15 -04:00
|
|
|
|
const char *arguments = command + strlen("focus ");
|
2009-05-05 11:25:56 -04:00
|
|
|
|
travel_focus_stack(conn, arguments);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2009-02-14 14:12:50 -05:00
|
|
|
|
/* Is it 'f' for fullscreen? */
|
|
|
|
|
if (command[0] == 'f') {
|
2009-05-23 10:34:03 -04:00
|
|
|
|
if (last_focused == NULL)
|
2009-02-14 14:12:50 -05:00
|
|
|
|
return;
|
2009-05-26 10:49:57 -04:00
|
|
|
|
client_toggle_fullscreen(conn, last_focused);
|
2009-02-14 14:12:50 -05:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2009-02-23 18:30:04 -05:00
|
|
|
|
/* Is it just 's' for stacking or 'd' for default? */
|
2009-08-22 03:07:23 -04:00
|
|
|
|
if ((command[0] == 's' || command[0] == 'd' || command[0] == 'T') && (command[1] == '\0')) {
|
2009-08-05 18:15:53 -04:00
|
|
|
|
if (last_focused != NULL && client_is_floating(last_focused)) {
|
2009-05-23 10:34:03 -04:00
|
|
|
|
LOG("not switching, this is a floating client\n");
|
|
|
|
|
return;
|
|
|
|
|
}
|
2009-03-06 00:46:43 -05:00
|
|
|
|
LOG("Switching mode for current container\n");
|
2009-08-22 03:07:23 -04:00
|
|
|
|
int new_mode = MODE_DEFAULT;
|
|
|
|
|
if (command[0] == 's')
|
|
|
|
|
new_mode = MODE_STACK;
|
|
|
|
|
if (command[0] == 'T')
|
|
|
|
|
new_mode = MODE_TABBED;
|
|
|
|
|
switch_layout_mode(conn, CUR_CELL, new_mode);
|
2009-02-23 18:30:04 -05:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2009-08-05 12:33:44 -04:00
|
|
|
|
/* Is it 'bn' (border normal), 'bp' (border 1pixel) or 'bb' (border borderless)? */
|
2009-08-12 12:18:39 -04:00
|
|
|
|
/* or even 'bt' (toggle border: 'bp' -> 'bb' -> 'bn' ) */
|
2009-08-05 12:33:44 -04:00
|
|
|
|
if (command[0] == 'b') {
|
|
|
|
|
if (last_focused == NULL) {
|
|
|
|
|
LOG("No window focused, cannot change border type\n");
|
|
|
|
|
return;
|
|
|
|
|
}
|
2009-08-12 12:18:39 -04:00
|
|
|
|
|
2009-09-10 12:48:16 -04:00
|
|
|
|
char com = command[1];
|
2009-08-12 12:18:39 -04:00
|
|
|
|
if (command[1] == 't') {
|
|
|
|
|
if (last_focused->titlebar_position == TITLEBAR_TOP &&
|
2009-09-10 12:48:16 -04:00
|
|
|
|
!last_focused->borderless)
|
2009-08-12 12:18:39 -04:00
|
|
|
|
com = 'p';
|
|
|
|
|
else if (last_focused->titlebar_position == TITLEBAR_OFF &&
|
2009-09-10 12:48:16 -04:00
|
|
|
|
!last_focused->borderless)
|
2009-08-12 12:18:39 -04:00
|
|
|
|
com = 'b';
|
2009-09-10 12:48:16 -04:00
|
|
|
|
else com = 'n';
|
2009-08-12 12:18:39 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
client_change_border(conn, last_focused, com);
|
2009-08-05 12:33:44 -04:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2009-06-19 07:59:29 -04:00
|
|
|
|
if (command[0] == 'H') {
|
|
|
|
|
LOG("Hiding all floating windows\n");
|
|
|
|
|
floating_toggle_hide(conn, c_ws);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2009-08-05 13:24:21 -04:00
|
|
|
|
enum { WITH_WINDOW, WITH_CONTAINER, WITH_WORKSPACE, WITH_SCREEN } with = WITH_WINDOW;
|
2009-06-19 07:20:10 -04:00
|
|
|
|
|
|
|
|
|
/* Is it a <with>? */
|
|
|
|
|
if (command[0] == 'w') {
|
|
|
|
|
command++;
|
|
|
|
|
/* TODO: implement */
|
|
|
|
|
if (command[0] == 'c') {
|
|
|
|
|
with = WITH_CONTAINER;
|
|
|
|
|
command++;
|
|
|
|
|
} else if (command[0] == 'w') {
|
|
|
|
|
with = WITH_WORKSPACE;
|
|
|
|
|
command++;
|
2009-08-05 13:24:21 -04:00
|
|
|
|
} else if (command[0] == 's') {
|
|
|
|
|
with = WITH_SCREEN;
|
|
|
|
|
command++;
|
2009-06-19 07:20:10 -04:00
|
|
|
|
} else {
|
|
|
|
|
LOG("not yet implemented.\n");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-05-23 10:34:03 -04:00
|
|
|
|
/* Is it 't' for toggle tiling/floating? */
|
|
|
|
|
if (command[0] == 't') {
|
2009-06-19 07:20:10 -04:00
|
|
|
|
if (with == WITH_WORKSPACE) {
|
|
|
|
|
c_ws->auto_float = !c_ws->auto_float;
|
|
|
|
|
LOG("autofloat is now %d\n", c_ws->auto_float);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2009-05-23 10:34:03 -04:00
|
|
|
|
if (last_focused == NULL) {
|
|
|
|
|
LOG("Cannot toggle tiling/floating: workspace empty\n");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2009-09-27 08:00:54 -04:00
|
|
|
|
Workspace *ws = last_focused->workspace;
|
|
|
|
|
|
2009-05-30 18:31:18 -04:00
|
|
|
|
toggle_floating_mode(conn, last_focused, false);
|
2009-05-26 11:16:51 -04:00
|
|
|
|
/* delete all empty columns/rows */
|
2009-09-27 08:00:54 -04:00
|
|
|
|
cleanup_table(conn, ws);
|
2009-05-26 11:16:51 -04:00
|
|
|
|
|
|
|
|
|
/* Fix colspan/rowspan if it’d overlap */
|
2009-09-27 08:00:54 -04:00
|
|
|
|
fix_colrowspan(conn, ws);
|
2009-05-26 11:16:51 -04:00
|
|
|
|
|
2009-09-27 08:00:54 -04:00
|
|
|
|
render_workspace(conn, ws->screen, ws);
|
2009-06-25 22:34:36 -04:00
|
|
|
|
|
|
|
|
|
/* Re-focus the client because cleanup_table sets the focus to the last
|
|
|
|
|
* focused client inside a container only. */
|
|
|
|
|
set_focus(conn, last_focused, true);
|
|
|
|
|
|
2009-05-23 10:34:03 -04:00
|
|
|
|
return;
|
|
|
|
|
}
|
2009-07-21 18:16:16 -04:00
|
|
|
|
|
|
|
|
|
/* Is it 'n' or 'p' for next/previous workspace? (nw) */
|
2009-08-05 13:24:21 -04:00
|
|
|
|
if ((command[0] == 'n' || command[0] == 'p') && command[1] == 'w') {
|
2009-07-21 15:32:29 -04:00
|
|
|
|
next_previous_workspace(conn, command[0]);
|
2009-07-21 18:16:16 -04:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2009-05-23 10:34:03 -04:00
|
|
|
|
/* It’s a normal <cmd> */
|
2009-02-13 20:33:31 -05:00
|
|
|
|
char *rest = NULL;
|
|
|
|
|
enum { ACTION_FOCUS, ACTION_MOVE, ACTION_SNAP } action = ACTION_FOCUS;
|
|
|
|
|
direction_t direction;
|
2009-03-04 02:59:03 -05:00
|
|
|
|
int times = strtol(command, &rest, 10);
|
2009-02-13 20:33:31 -05:00
|
|
|
|
if (rest == NULL) {
|
2009-03-06 00:46:43 -05:00
|
|
|
|
LOG("Invalid command (\"%s\")\n", command);
|
2009-02-13 20:33:31 -05:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (*rest == '\0') {
|
2009-06-07 13:09:39 -04:00
|
|
|
|
/* No rest? This was a workspace number, not a times specification */
|
2009-08-08 13:51:51 -04:00
|
|
|
|
workspace_show(conn, times);
|
2009-02-13 20:33:31 -05:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2009-02-27 20:46:36 -05:00
|
|
|
|
if (*rest == 'm' || *rest == 's') {
|
|
|
|
|
action = (*rest == 'm' ? ACTION_MOVE : ACTION_SNAP);
|
|
|
|
|
rest++;
|
|
|
|
|
}
|
|
|
|
|
|
2009-03-04 02:59:03 -05:00
|
|
|
|
int workspace = strtol(rest, &rest, 10);
|
|
|
|
|
|
|
|
|
|
if (rest == NULL) {
|
2009-03-06 00:46:43 -05:00
|
|
|
|
LOG("Invalid command (\"%s\")\n", command);
|
2009-03-04 02:59:03 -05:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (*rest == '\0') {
|
2009-06-21 10:14:15 -04:00
|
|
|
|
if (last_focused != NULL && client_is_floating(last_focused))
|
2009-05-23 10:34:03 -04:00
|
|
|
|
move_floating_window_to_workspace(conn, last_focused, workspace);
|
|
|
|
|
else move_current_window_to_workspace(conn, workspace);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2009-06-13 19:04:59 -04:00
|
|
|
|
if (last_focused == NULL) {
|
2009-06-19 06:05:55 -04:00
|
|
|
|
LOG("Not performing (no window found)\n");
|
2009-06-13 19:04:59 -04:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2009-06-21 10:14:15 -04:00
|
|
|
|
if (client_is_floating(last_focused) &&
|
|
|
|
|
(action != ACTION_FOCUS && action != ACTION_MOVE)) {
|
2009-06-13 19:04:59 -04:00
|
|
|
|
LOG("Not performing (floating)\n");
|
2009-03-04 02:59:03 -05:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2009-02-13 20:33:31 -05:00
|
|
|
|
/* Now perform action to <where> */
|
|
|
|
|
while (*rest != '\0') {
|
|
|
|
|
if (*rest == 'h')
|
|
|
|
|
direction = D_LEFT;
|
|
|
|
|
else if (*rest == 'j')
|
|
|
|
|
direction = D_DOWN;
|
|
|
|
|
else if (*rest == 'k')
|
|
|
|
|
direction = D_UP;
|
|
|
|
|
else if (*rest == 'l')
|
|
|
|
|
direction = D_RIGHT;
|
|
|
|
|
else {
|
2009-03-06 00:46:43 -05:00
|
|
|
|
LOG("unknown direction: %c\n", *rest);
|
2009-02-13 20:33:31 -05:00
|
|
|
|
return;
|
|
|
|
|
}
|
2009-06-19 06:57:21 -04:00
|
|
|
|
rest++;
|
2009-02-13 20:33:31 -05:00
|
|
|
|
|
2009-06-13 19:04:59 -04:00
|
|
|
|
if (action == ACTION_FOCUS) {
|
2009-08-05 13:24:21 -04:00
|
|
|
|
if (with == WITH_SCREEN) {
|
|
|
|
|
focus_thing(conn, direction, THING_SCREEN);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2009-06-21 10:14:15 -04:00
|
|
|
|
if (client_is_floating(last_focused)) {
|
2009-06-13 19:04:59 -04:00
|
|
|
|
floating_focus_direction(conn, last_focused, direction);
|
2009-06-19 06:57:21 -04:00
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
focus_thing(conn, direction, (with == WITH_WINDOW ? THING_WINDOW : THING_CONTAINER));
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (action == ACTION_MOVE) {
|
2009-08-05 13:24:21 -04:00
|
|
|
|
if (with == WITH_SCREEN) {
|
|
|
|
|
/* TODO: this should swap the screen’s contents
|
|
|
|
|
* (e.g. all workspaces) with the next/previous/…
|
|
|
|
|
* screen */
|
|
|
|
|
LOG("Not yet implemented\n");
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2009-06-21 10:14:15 -04:00
|
|
|
|
if (client_is_floating(last_focused)) {
|
2009-06-19 06:57:21 -04:00
|
|
|
|
floating_move(conn, last_focused, direction);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2009-03-11 13:56:31 -04:00
|
|
|
|
if (with == WITH_WINDOW)
|
|
|
|
|
move_current_window(conn, direction);
|
|
|
|
|
else move_current_container(conn, direction);
|
2009-06-19 06:57:21 -04:00
|
|
|
|
continue;
|
2009-03-04 17:45:44 -05:00
|
|
|
|
}
|
2009-02-13 20:33:31 -05:00
|
|
|
|
|
2009-06-19 06:57:21 -04:00
|
|
|
|
if (action == ACTION_SNAP) {
|
2009-08-05 13:24:21 -04:00
|
|
|
|
if (with == WITH_SCREEN) {
|
|
|
|
|
LOG("You cannot snap a screen (it makes no sense).\n");
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2009-06-19 06:57:21 -04:00
|
|
|
|
snap_current_container(conn, direction);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2009-02-13 20:33:31 -05:00
|
|
|
|
}
|
2009-02-13 13:04:45 -05:00
|
|
|
|
}
|