Created
June 7, 2012 02:43
-
-
Save spion/2886226 to your computer and use it in GitHub Desktop.
i3wm "reorient v|h" command to change orientation of selected container. Don't forget to focus parent before running it.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/i3.config b/i3.config | |
index 1a457fc..bf85f02 100644 | |
--- a/i3.config | |
+++ b/i3.config | |
@@ -54,6 +54,13 @@ bindsym Mod1+h split h | |
# split in vertical orientation | |
bindsym Mod1+v split v | |
+# change to horizontal orientation | |
+bindsym Mod1+Shift+h reorient h | |
+ | |
+# change to vertical orientation | |
+bindsym Mod1+Shift+v reorient v | |
+ | |
+ | |
# enter fullscreen mode for the focused container | |
bindsym Mod1+f fullscreen | |
diff --git a/include/commands.h b/include/commands.h | |
index 85057d1..ff483da 100644 | |
--- a/include/commands.h | |
+++ b/include/commands.h | |
@@ -145,6 +145,14 @@ void cmd_floating(I3_CMD, char *floating_mode); | |
*/ | |
void cmd_move_workspace_to_output(I3_CMD, char *name); | |
+ | |
+/** | |
+ * Implementation of 'reorient v|h|vertical|horizontal'. | |
+ * | |
+ */ | |
+void cmd_reorient(I3_CMD, char *direction); | |
+ | |
+ | |
/** | |
* Implementation of 'split v|h|vertical|horizontal'. | |
* | |
diff --git a/include/tree.h b/include/tree.h | |
index b9159e3..8fff5b1 100644 | |
--- a/include/tree.h | |
+++ b/include/tree.h | |
@@ -39,6 +39,15 @@ Con *tree_open_con(Con *con, i3Window *window); | |
void tree_split(Con *con, orientation_t orientation); | |
/** | |
+ * Reorients (horizontally or vertically) the given container by changing | |
+ * its orientation and forcing a redraw. | |
+ * | |
+ */ | |
+void tree_reorient(Con *con, orientation_t orientation); | |
+ | |
+ | |
+ | |
+/** | |
* Moves focus one level up. | |
* | |
*/ | |
diff --git a/parser-specs/commands.spec b/parser-specs/commands.spec | |
index 684fd23..d8913c2 100644 | |
--- a/parser-specs/commands.spec | |
+++ b/parser-specs/commands.spec | |
@@ -28,6 +28,7 @@ state INITIAL: | |
'open' -> call cmd_open() | |
'fullscreen' -> FULLSCREEN | |
'split' -> SPLIT | |
+ 'reorient' -> REORIENT | |
'floating' -> FLOATING | |
'mark' -> MARK | |
'resize' -> RESIZE | |
@@ -133,6 +134,11 @@ state SPLIT: | |
direction = 'v', 'h', 'vertical', 'horizontal' | |
-> call cmd_split($direction) | |
+# split v|h|vertical|horizontal | |
+state REORIENT: | |
+ direction = 'v', 'h', 'vertical', 'horizontal' | |
+ -> call cmd_reorient($direction) | |
+ | |
# floating enable|disable|toggle | |
state FLOATING: | |
floating = 'enable', 'disable', 'toggle' | |
diff --git a/src/commands.c b/src/commands.c | |
index 1e1ee0f..6f8e4a9 100644 | |
--- a/src/commands.c | |
+++ b/src/commands.c | |
@@ -1084,6 +1084,19 @@ void cmd_split(I3_CMD, char *direction) { | |
ysuccess(true); | |
} | |
+/** | |
+ * Implementation of 'reorient v|h|vertical|horizontal' | |
+ */ | |
+void cmd_reorient(I3_CMD, char *direction) { | |
+ /* TODO: use matches */ | |
+ LOG("splitting in direction %c\n", direction[0]); | |
+ tree_reorient(focused, (direction[0] == 'v' ? VERT : HORIZ)); | |
+ | |
+ cmd_output->needs_tree_render = true; | |
+ // XXX: default reply for now, make this a better reply | |
+ ysuccess(true); | |
+} | |
+ | |
/* | |
* Implementaiton of 'kill [window|client]'. | |
* | |
diff --git a/src/tree.c b/src/tree.c | |
index f29369c..327603e 100644 | |
--- a/src/tree.c | |
+++ b/src/tree.c | |
@@ -328,6 +328,24 @@ void tree_close_con(kill_window_t kill_window) { | |
tree_close(focused, kill_window, false, false); | |
} | |
+ | |
+/* | |
+ * Changes the orientation (split and navigation of the given container) | |
+ * container which contains the old one and the future ones. | |
+ * | |
+ */ | |
+ | |
+void tree_reorient(Con *con, orientation_t orientation) { | |
+ /* Just change the orientation */ | |
+ DLOG("Changing orientation to %d\n", orientation); | |
+ con->orientation = orientation; | |
+ | |
+ /* Force re-rendering. TODO: verify if this is needed or not. */ | |
+ FREE(con->deco_render_params); | |
+ | |
+ | |
+} | |
+ | |
/* | |
* Splits (horizontally or vertically) the given container by creating a new | |
* container which contains the old one and the future ones. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Looks like it was implemented with
split h|v
.