-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;
+static void next_previous_workspace(xcb_connection_t *conn, int direction) {
+ Workspace *ws = c_ws;
+
+ if (direction == 'n') {
+ while (1) {
+ ws = TAILQ_NEXT(ws, workspaces);
+
+ if (ws == TAILQ_END(workspaces))
+ ws = TAILQ_FIRST(workspaces);
+
+ if (ws == c_ws)
+ return;
+
+ if (ws->output == NULL)
+ continue;
+
+ workspace_show(conn, ws->num + 1);
+ return;
+ }
+ } else if (direction == 'p') {
+ while (1) {
+ ws = TAILQ_PREV(ws, workspaces_head, workspaces);
+
+ if (ws == TAILQ_END(workspaces))
+ ws = TAILQ_LAST(workspaces, workspaces_head);
+
+ if (ws == c_ws)
+ return;
+
+ if (ws->output == NULL)
+ continue;
+
+ workspace_show(conn, ws->num + 1);
+ return;
+ }
+ }
+}
+
+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;
+ Workspace *ws = last_focused->workspace;
+
+ if (client_is_floating(last_focused)) {
+ DLOG("Resizing a floating client\n");
+ if (STARTS_WITH(command, "left")) {
+ command += strlen("left");
+ last_focused->rect.width += atoi(command);
+ last_focused->rect.x -= atoi(command);
+ } else if (STARTS_WITH(command, "right")) {
+ command += strlen("right");
+ last_focused->rect.width += atoi(command);
+ } else if (STARTS_WITH(command, "top")) {
+ command += strlen("top");
+ last_focused->rect.height += atoi(command);
+ last_focused->rect.y -= atoi(command);
+ } else if (STARTS_WITH(command, "bottom")) {
+ command += strlen("bottom");
+ last_focused->rect.height += atoi(command);
+ } else {
+ ELOG("Syntax: resize <left|right|top|bottom> [+|-]<pixels>\n");
+ return;
+ }
+
+ /* resize_client flushes */
+ resize_client(conn, last_focused);
+
+ return;
+ }
+
+ 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);
+ DLOG("column %d\n", first);
+
+ if (!cell_exists(ws, first, con->row) ||
+ (first == (ws->cols-1)))
+ 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(ws, con->col, first) ||
+ (first == (ws->rows-1)))
+ return;
+
+ second = first + 1;
+ orientation = O_HORIZONTAL;
+ command += strlen("bottom");
+ } else {
+ ELOG("Syntax: resize <left|right|top|bottom> [+|-]<pixels>\n");
+ return;
+ }
+
+ int pixels = atoi(command);
+ if (pixels == 0)
+ return;
+
+ resize_container(conn, ws, first, second, orientation, pixels);