diff --git a/README.md b/README.md index 3ca8ae2..942057a 100644 --- 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 7204efe..b0d9c28 100644 --- 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" diff --git a/messages.c b/messages.c index b363190..d5cd052 100644 --- a/messages.c +++ b/messages.c @@ -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) { diff --git a/messages.h b/messages.h index 8f7d5d6..794a73e 100644 --- a/messages.h +++ b/messages.h @@ -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 c8fbeb6..6835263 100644 --- 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,