Skip to content

Commit

Permalink
#127 new command space --swap SPACE_SEL (with caveat) to swap positio…
Browse files Browse the repository at this point in the history
…n of the selected and given space
  • Loading branch information
koekeishiya committed Feb 13, 2020
1 parent cd31bd6 commit bd6e7fd
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Added
- New command *space --swap SPACE_SEL* command to swap the position of a selected space with the position of a given space. The selected and given space must belong to the same display [#127](https://github.com/koekeishiya/yabai/issues/127)

### Changed
- Allow use of *DISPLAY_SEL* and *SPACE_SEL* for specifying display and space in rules [#378](https://github.com/koekeishiya/yabai/issues/378)
- Extend *space --move* command to operate on *SPACE_SEL* instead of prev/next. However, the selected and given space must belong to the same display [#127](https://github.com/koekeishiya/yabai/issues/127)
Expand Down
5 changes: 5 additions & 0 deletions doc/yabai.1
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,11 @@ Remove the selected space.
Move position of the selected space to the position of the given space. The selected space and given space must both belong to the same display.
.RE
.sp
\fB\-\-swap\fP \fI<SPACE_SEL>\fP
.RS 4
Swap the selected space with the given space. The selected space and given space must both belong to the same display.
.RE
.sp
\fB\-\-display\fP \fI<DISPLAY_SEL>\fP
.RS 4
Send the selected space to the given display.
Expand Down
3 changes: 3 additions & 0 deletions doc/yabai.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,9 @@ COMMAND
*--move* '<SPACE_SEL>'::
Move position of the selected space to the position of the given space. The selected space and given space must both belong to the same display.

*--swap* '<SPACE_SEL>'::
Swap the selected space with the given space. The selected space and given space must both belong to the same display.

*--display* '<DISPLAY_SEL>'::
Send the selected space to the given display.

Expand Down
32 changes: 32 additions & 0 deletions src/message.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ extern bool g_verbose;
#define COMMAND_SPACE_CREATE "--create"
#define COMMAND_SPACE_DESTROY "--destroy"
#define COMMAND_SPACE_MOVE "--move"
#define COMMAND_SPACE_SWAP "--swap"
#define COMMAND_SPACE_DISPLAY "--display"
#define COMMAND_SPACE_BALANCE "--balance"
#define COMMAND_SPACE_MIRROR "--mirror"
Expand Down Expand Up @@ -1319,6 +1320,37 @@ static void handle_domain_space(FILE *rsp, struct token domain, char *message)
}
}
}
} else if (token_equals(command, COMMAND_SPACE_SWAP)) {
struct selector selector = parse_space_selector(rsp, &message, acting_sid);
if (selector.did_parse && selector.sid) {
if (acting_sid == selector.sid) {
daemon_fail(rsp, "cannot swap space with itself.\n");
} else if (space_display_id(acting_sid) != space_display_id(selector.sid)) {
daemon_fail(rsp, "cannot swap space across display boundaries. use --display instead.\n");
} else {
int acting_mci = space_manager_mission_control_index(acting_sid);
int selector_mci = space_manager_mission_control_index(selector.sid);
if (selector_mci == 1 && acting_mci == 2) {
space_manager_move_space_after_space(selector.sid, acting_sid, false);
} else if (selector_mci == 1 && acting_mci > 2) {
uint64_t prev_space = space_manager_prev_space(acting_sid);
space_manager_move_space_after_space(acting_sid, selector.sid, acting_sid == space_manager_active_space());
space_manager_move_space_after_space(selector.sid, prev_space, false);
} else if (acting_mci == 1 && selector_mci > 2) {
uint64_t prev_space = space_manager_prev_space(selector.sid);
space_manager_move_space_after_space(selector.sid, acting_sid, false);
space_manager_move_space_after_space(acting_sid, prev_space, acting_sid == space_manager_active_space());
} else if (acting_mci > selector_mci) {
uint64_t prev_space = space_manager_prev_space(selector.sid);
space_manager_move_space_after_space(selector.sid, acting_sid, false);
space_manager_move_space_after_space(acting_sid, prev_space, acting_sid == space_manager_active_space());
} else {
uint64_t prev_space = space_manager_prev_space(acting_sid);
space_manager_move_space_after_space(acting_sid, selector.sid, acting_sid == space_manager_active_space());
space_manager_move_space_after_space(selector.sid, prev_space, false);
}
}
}
} else if (token_equals(command, COMMAND_SPACE_DISPLAY)) {
struct selector selector = parse_display_selector(rsp, &message, display_manager_active_display_id());
if (selector.did_parse && selector.did) {
Expand Down

0 comments on commit bd6e7fd

Please sign in to comment.