]> git.lizzy.rs Git - bspwm.git/commitdiff
New options for swap: `--{keep,swap}-focus`
authorBastien Dejean <nihilhill@gmail.com>
Thu, 30 May 2013 11:20:34 +0000 (13:20 +0200)
committerBastien Dejean <nihilhill@gmail.com>
Thu, 30 May 2013 11:20:34 +0000 (13:20 +0200)
README.md
bspwm.1
messages.c
messages.h
types.h

index 3ca8ae2d67fa8a3237832224043540c294dae288..942057a326231c441c70a6938e430f9c0eea8466 100644 (file)
--- a/README.md
+++ b/README.md
@@ -101,7 +101,7 @@ The following messages are handled:
 
 - `shift left|right|up|down` — Exchange the current window with the given neighbor.
 
-- `swap` — Swap the focused window the last focused window.
+- `swap [--swap-focus|--keep-focus]` — Swap the focused window the last focused window.
 
 - `push left|right|up|down` — Push the fence located in the given direction.
 
diff --git a/bspwm.1 b/bspwm.1
index 7204efe556044f70dbee1b5d17c00a54e93649d1..b0d9c2876e563bf12b01af48fffe2c6785d63064 100644 (file)
--- a/bspwm.1
+++ b/bspwm.1
@@ -133,7 +133,7 @@ Focus the neighbor window situated in the given direction.
 .BI shift " left|right|up|down"
 Exchange the current window with the given neighbor.
 .TP
-.BI swap
+.BI swap " [--swap-focus|--keep-focus]"
 Swap the focused window with the last focused window.
 .TP
 .BI push " left|right|up|down"
index b363190a77a2ade725a31ce4fb91a3ae45988480..d5cd052d1513fcd59d1d14d8e88d4667401ea1f6 100644 (file)
@@ -395,7 +395,12 @@ void process_message(char *msg, char *rsp)
                 remove_rule_by_uid(uid);
         return;
     } else if (strcmp(cmd, "swap") == 0) {
-        swap_nodes(mon->desk->focus, history_get(mon->desk->history, 1));
+        node_t *last_focus = history_get(mon->desk->history, 1);
+        swap_nodes(mon->desk->focus, last_focus);
+        char *opt = strtok(NULL, TOK_SEP);
+        swap_option_t o;
+        if (parse_swap_option(opt, &o) && o == SWAP_OPTION_SWAP_FOCUS)
+            focus_node(mon, mon->desk, last_focus);
     } else if (strcmp(cmd, "alternate") == 0) {
         focus_node(mon, mon->desk, history_get(mon->desk->history, 1));
         return;
@@ -753,6 +758,18 @@ bool parse_send_option(char *s, send_option_t *o)
     return false;
 }
 
+bool parse_swap_option(char *s, swap_option_t *o)
+{
+    if (s == NULL || strcmp(s, "--swap-focus") == 0) {
+        *o = SWAP_OPTION_SWAP_FOCUS;
+        return true;
+    } else if (strcmp(s, "--keep-focus") == 0) {
+        *o = SWAP_OPTION_KEEP_FOCUS;
+        return true;
+    }
+    return false;
+}
+
 bool parse_rotate(char *s, rotate_t *r)
 {
     if (strcmp(s, "clockwise") == 0) {
index 8f7d5d6d7296c32e161526e7a0656c6c4156f9c0..794a73ea3187f957d50720ddee610a5cdeb34a59 100644 (file)
@@ -16,6 +16,7 @@ bool parse_cycle_direction(char *, cycle_dir_t *);
 bool parse_circulate_direction(char *, circulate_dir_t *);
 bool parse_list_option(char *, list_option_t *);
 bool parse_send_option(char *, send_option_t *);
+bool parse_swap_option(char *, swap_option_t *);
 bool parse_skip_client(char *, skip_client_t *);
 bool parse_skip_desktop(char *, skip_desktop_t *);
 bool parse_rotate(char *, rotate_t *);
diff --git a/types.h b/types.h
index c8fbeb68367908b7f8df38dfd9838e1d6920ace6..6835263a784bd1a4aa157d35092a8d98af39665a 100644 (file)
--- a/types.h
+++ b/types.h
@@ -46,6 +46,11 @@ typedef enum {
     SEND_OPTION_DONT_FOLLOW
 } send_option_t;
 
+typedef enum {
+    SWAP_OPTION_KEEP_FOCUS,
+    SWAP_OPTION_SWAP_FOCUS
+} swap_option_t;
+
 typedef enum {
     CLIENT_SKIP_NONE,
     CLIENT_SKIP_FLOATING,