Implement 'workspace next/prev' (+test)

This commit is contained in:
Michael Stapelberg
2011-06-10 16:03:59 +02:00
parent c5a44f12d4
commit 60ae26c19d
6 changed files with 145 additions and 9 deletions

View File

@ -71,6 +71,11 @@ EOL (\r?\n)
cmdyycolumn = 1;
}
/* the next/prev tokens are here to recognize them *before* handling
* strings ('workspace' command) */
next { return TOK_NEXT; }
prev { return TOK_PREV; }
<WANT_STRING>\"[^\"]+\" {
BEGIN(INITIAL);
/* strip quotes */
@ -120,7 +125,6 @@ workspace { WS_STRING; return TOK_WORKSPACE; }
focus { return TOK_FOCUS; }
move { return TOK_MOVE; }
open { return TOK_OPEN; }
prev { return TOK_PREV; }
split { return TOK_SPLIT; }
horizontal { return TOK_HORIZONTAL; }
vertical { return TOK_VERTICAL; }

View File

@ -142,6 +142,7 @@ char *parse_cmd(const char *new) {
%token TOK_FOCUS "focus"
%token TOK_MOVE "move"
%token TOK_OPEN "open"
%token TOK_NEXT "next"
%token TOK_PREV "prev"
%token TOK_SPLIT "split"
%token TOK_HORIZONTAL "horizontal"
@ -487,7 +488,17 @@ optional_kill_mode:
;
workspace:
TOK_WORKSPACE STR
TOK_WORKSPACE TOK_NEXT
{
workspace_next();
tree_render();
}
| TOK_WORKSPACE TOK_PREV
{
workspace_prev();
tree_render();
}
| TOK_WORKSPACE STR
{
printf("should switch to workspace %s\n", $2);
workspace_show($2);

View File

@ -231,6 +231,32 @@ void workspace_show(const char *num) {
ipc_send_event("workspace", I3_IPC_EVENT_WORKSPACE, "{\"change\":\"focus\"}");
}
/*
* Focuses the next workspace.
*
*/
void workspace_next() {
Con *ws = con_get_workspace(focused);
Con *next = TAILQ_NEXT(ws, nodes);
if (!next)
next = TAILQ_FIRST(&(ws->parent->nodes_head));
workspace_show(next->name);
}
/*
* Focuses the previous workspace.
*
*/
void workspace_prev() {
Con *ws = con_get_workspace(focused);
Con *prev = TAILQ_PREV(ws, nodes_head, nodes);
if (!prev)
prev = TAILQ_LAST(&(ws->parent->nodes_head), nodes_head);
workspace_show(prev->name);
}
static bool get_urgency_flag(Con *con) {
Con *child;
TAILQ_FOREACH(child, &(con->nodes_head), nodes)