From 6d152103f57e12d933ce1d1b9412db9ca544b4c1 Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Wed, 30 Jun 2010 22:23:32 +0200 Subject: [PATCH] parser: implement move --- include/con.h | 2 ++ src/cmdparse.y | 18 ++++++++++++++++++ src/con.c | 22 ++++++++++++++++++++++ 3 files changed, 42 insertions(+) diff --git a/include/con.h b/include/con.h index 076a5cf5..5a6f0c15 100644 --- a/include/con.h +++ b/include/con.h @@ -19,4 +19,6 @@ enum { WINDOW_ADD = 0, WINDOW_REMOVE = 1 }; void con_fix_percent(Con *con, int action); void con_toggle_fullscreen(Con *con); +void con_move_to_workspace(Con *con, Con *workspace); + #endif diff --git a/src/cmdparse.y b/src/cmdparse.y index 9925bd7c..f4ad6e07 100644 --- a/src/cmdparse.y +++ b/src/cmdparse.y @@ -495,6 +495,24 @@ move: * we should not need any of both */ tree_move(($3 == TOK_BEFORE ? 'p' : 'n'), ($5 == 'v' ? VERT : HORIZ)); } + | TOK_MOVE WHITESPACE TOK_WORKSPACE WHITESPACE STR + { + owindow *current; + + printf("should move window to workspace %s\n", $5); + /* get the workspace */ + Con *ws = workspace_get($5); + + /* check if the match is empty, not if the result is empty */ + if (match_is_empty(¤t_match)) + con_move_to_workspace(focused, ws); + else { + TAILQ_FOREACH(current, &owindows, owindows) { + printf("matching: %p / %s\n", current->con, current->con->name); + con_move_to_workspace(current->con, ws); + } + } + } ; before_after: diff --git a/src/con.c b/src/con.c index 8aa1608c..c7c1c903 100644 --- a/src/con.c +++ b/src/con.c @@ -315,3 +315,25 @@ void con_toggle_fullscreen(Con *con) { xcb_change_property(conn, XCB_PROP_MODE_REPLACE, con->window->id, atoms[_NET_WM_STATE], ATOM, 32, num, values); } + +/* + * TODO: is there a better place for this function? + * + */ +void con_move_to_workspace(Con *con, Con *workspace) { + /* 1: get the focused container of this workspace by going down as far as + * possible */ + Con *next = workspace; + + while (!TAILQ_EMPTY(&(next->focus_head))) + next = TAILQ_FIRST(&(next->focus_head)); + + /* 2: we go up one level, but only when next is a normal container */ + if (next->type != CT_WORKSPACE) + next = next->parent; + + DLOG("Re-attaching container to %p / %s\n", next, next->name); + /* 3: re-attach the con to the parent of this focused container */ + con_detach(con); + con_attach(con, next); +}