Skip to content

Commit

Permalink
#2203 implement window scratchpad
Browse files Browse the repository at this point in the history
  • Loading branch information
koekeishiya committed Apr 3, 2024
1 parent 9fd250b commit ddd2931
Show file tree
Hide file tree
Showing 9 changed files with 302 additions and 38 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
## [Unreleased]
### Added
- Added window commands `--raise ['<WINDOW_SEL>']` and `--lower ['<WINDOW_SEL>']` [#2198](https://github.com/koekeishiya/yabai/issues/2198)
- Added window commands `--scratchpad ['<LABEL>']` and `--toggle <LABEL>` [#2203](https://github.com/koekeishiya/yabai/issues/2203)
- Added rule property `scratchpad='<LABEL>'` to automatically assign a window to a scratchpad [#2203](https://github.com/koekeishiya/yabai/issues/2203)

### Changed
- Config *global setting* `auto_balance` is now categorized as a *space setting* instead [#2200](https://github.com/koekeishiya/yabai/issues/2200)
Expand Down
42 changes: 39 additions & 3 deletions doc/yabai.1
Original file line number Diff line number Diff line change
Expand Up @@ -618,11 +618,11 @@ If type is \fIrel\fP the split ratio of the selected window is changed by \fIdr\
A positive/negative delta will increase/decrease the size of the left\-child.
.RE
.sp
\fB\-\-toggle\fP \fIfloat|sticky|pip|shadow|split|zoom\-parent|zoom\-fullscreen|native\-fullscreen|expose\fP
\fB\-\-toggle\fP \fIfloat|sticky|pip|shadow|split|zoom\-parent|zoom\-fullscreen|native\-fullscreen|expose|<LABEL>\fP
.RS 4
Toggle the given property of the selected window.
.br
The following properties require System Integrity Protection to be partially disabled: sticky, pip, shadow.
The following properties require System Integrity Protection to be partially disabled: sticky, pip, shadow, LABEL (scratchpad identifier) .
.RE
.sp
\fB\-\-sub\-layer\fP \fI<LAYER>\fP
Expand Down Expand Up @@ -660,6 +660,23 @@ Orders the selected window below the given window, or to the back within its lay
.br
System Integrity Protection must be partially disabled.
.RE
.sp
\fB\-\-scratchpad\fP [\fI<LABEL>\fP]
.RS 4
Unique identifier used to identify a window scratchpad.
.br
An identifier may only be assigned to a single window at any given time.
.br
A scratchpad window will automatically be treated as a (manage=off) floating window.
.br
If the scratchpad is already taken by another window, this assignment will fail.
.br
If the scratchpad is re\-assigned, the previous identifier will become available.
.br
If no value is given, the window will seize to be a scratchpad window.
.br
System Integrity Protection must be partially disabled.
.RE
.SS "Query"
.SS "General Syntax"
.sp
Expand Down Expand Up @@ -835,7 +852,7 @@ If multiple rules specify a value for the same property, the latter rule will en
.br
If the display and space properties are both set, the space property will take precedence.
.br
The following properties require System Integrity Protection to be partially disabled: sticky, sub\-layer, opacity.
The following properties require System Integrity Protection to be partially disabled: sticky, sub\-layer, opacity, scratchpad.
.SS "General Syntax"
.sp
yabai \-m rule \fI<COMMAND>\fP
Expand Down Expand Up @@ -919,6 +936,8 @@ Most windows will be managed automatically, so this should mainly be used to mak
\fBsticky=\fI<BOOL_SEL>\fP\fP
.RS 4
Window appears on all spaces.
.br
System Integrity Protection must be partially disabled.
.RE
.sp
\fBmouse_follows_focus=\fI<BOOL_SEL>\fP\fP
Expand All @@ -933,6 +952,8 @@ Window is ordered within the given stacking sub\-layer.
The window will no longer be eligible for automatic change in sub\-layer when managed/unmanaged.
.br
Specify the value \fIauto\fP to reset back to normal and make it become automatically managed.
.br
System Integrity Protection must be partially disabled.
.RE
.sp
\fBopacity=\fI<FLOAT_SEL>\fP\fP
Expand All @@ -942,6 +963,8 @@ Set window opacity.
The window will no longer be eligible for automatic change in opacity upon focus change.
.br
Specify the value \fI0.0\fP to reset back to full opacity and make it become automatically managed.
.br
System Integrity Protection must be partially disabled.
.RE
.sp
\fBnative\-fullscreen=\fI<BOOL_SEL>\fP\fP
Expand All @@ -953,6 +976,19 @@ Window should enter native macOS fullscreen mode.
.RS 4
Set window frame based on a self\-defined grid.
.RE
.sp
\fBscratchpad=\fI<LABEL>\fP\fP
.RS 4
Unique identifier used to identify a window scratchpad.
.br
An identifier may only be assigned to a single window at any given time.
.br
A scratchpad window will automatically be treated as a (manage=off) floating window.
.br
If this rule matches multiple windows, only the first window that matched will be assigned this scratchpad identifier.
.br
System Integrity Protection must be partially disabled.
.RE
.SS "DATAFORMAT"
.sp
.if n .RS 4
Expand Down
31 changes: 25 additions & 6 deletions doc/yabai.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -416,9 +416,9 @@ COMMAND
If type is 'rel' the split ratio of the selected window is changed by 'dr', otherwise 'dr' will become the new split ratio. +
A positive/negative delta will increase/decrease the size of the left-child.

*--toggle* 'float|sticky|pip|shadow|split|zoom-parent|zoom-fullscreen|native-fullscreen|expose'::
*--toggle* 'float|sticky|pip|shadow|split|zoom-parent|zoom-fullscreen|native-fullscreen|expose|<LABEL>'::
Toggle the given property of the selected window. +
The following properties require System Integrity Protection to be partially disabled: sticky, pip, shadow.
The following properties require System Integrity Protection to be partially disabled: sticky, pip, shadow, LABEL (scratchpad identifier) .

*--sub-layer* '<LAYER>'::
Set the stacking sub-layer of the selected window. +
Expand All @@ -440,6 +440,15 @@ COMMAND
Orders the selected window below the given window, or to the back within its layer. +
System Integrity Protection must be partially disabled.

*--scratchpad* ['<LABEL>']::
Unique identifier used to identify a window scratchpad. +
An identifier may only be assigned to a single window at any given time. +
A scratchpad window will automatically be treated as a (manage=off) floating window. +
If the scratchpad is already taken by another window, this assignment will fail. +
If the scratchpad is re-assigned, the previous identifier will become available. +
If no value is given, the window will seize to be a scratchpad window. +
System Integrity Protection must be partially disabled.

Query
~~~~~~

Expand Down Expand Up @@ -588,7 +597,7 @@ Rule
All rules that match the given filter will be applied in the order they were registered. +
If multiple rules specify a value for the same property, the latter rule will end up overriding that value. +
If the display and space properties are both set, the space property will take precedence. +
The following properties require System Integrity Protection to be partially disabled: sticky, sub-layer, opacity.
The following properties require System Integrity Protection to be partially disabled: sticky, sub-layer, opacity, scratchpad.

General Syntax
^^^^^^^^^^^^^^
Expand Down Expand Up @@ -644,27 +653,37 @@ ARGUMENT
Most windows will be managed automatically, so this should mainly be used to make a window float.

*sticky='<BOOL_SEL>'*::
Window appears on all spaces.
Window appears on all spaces. +
System Integrity Protection must be partially disabled.

*mouse_follows_focus='<BOOL_SEL>'*::
When focusing the window, put the mouse at its center. Overrides the global *mouse_follows_focus* setting.

*sub-layer='<LAYER>'*::
Window is ordered within the given stacking sub-layer. +
The window will no longer be eligible for automatic change in sub-layer when managed/unmanaged. +
Specify the value 'auto' to reset back to normal and make it become automatically managed.
Specify the value 'auto' to reset back to normal and make it become automatically managed. +
System Integrity Protection must be partially disabled.

*opacity='<FLOAT_SEL>'*::
Set window opacity. +
The window will no longer be eligible for automatic change in opacity upon focus change. +
Specify the value '0.0' to reset back to full opacity and make it become automatically managed.
Specify the value '0.0' to reset back to full opacity and make it become automatically managed. +
System Integrity Protection must be partially disabled.

*native-fullscreen='<BOOL_SEL>'*::
Window should enter native macOS fullscreen mode.

*grid='<rows>:<cols>:<start-x>:<start-y>:<width>:<height>'*::
Set window frame based on a self-defined grid.

*scratchpad='<LABEL>'*::
Unique identifier used to identify a window scratchpad. +
An identifier may only be assigned to a single window at any given time. +
A scratchpad window will automatically be treated as a (manage=off) floating window. +
If this rule matches multiple windows, only the first window that matched will be assigned this scratchpad identifier. +
System Integrity Protection must be partially disabled.

DATAFORMAT
^^^^^^^^^^

Expand Down
14 changes: 11 additions & 3 deletions src/event_loop.c
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ static EVENT_HANDLER(APPLICATION_TERMINATED)

for (int i = 0; i < window_count; ++i) {
struct window *window = window_list[i];
__atomic_store_n(&window->id_ptr, NULL, __ATOMIC_RELEASE);
if (!__sync_bool_compare_and_swap(&window->id_ptr, &window->id, NULL)) continue;

struct view *view = window_manager_find_managed_window(&g_window_manager, window);
if (view) {
Expand Down Expand Up @@ -251,6 +251,7 @@ static EVENT_HANDLER(APPLICATION_TERMINATED)
event_signal_push(SIGNAL_WINDOW_DESTROYED, window);
}

window_manager_remove_scratchpad_for_window(&g_window_manager, window, false);
window_manager_remove_window(&g_window_manager, window->id);
window_unobserve(window);
window_destroy(window);
Expand Down Expand Up @@ -528,6 +529,7 @@ static EVENT_HANDLER(WINDOW_DESTROYED)
event_signal_push(SIGNAL_WINDOW_DESTROYED, window);
}

window_manager_remove_scratchpad_for_window(&g_window_manager, window, false);
window_manager_remove_window(&g_window_manager, window->id);
window_destroy(window);
}
Expand Down Expand Up @@ -1342,8 +1344,9 @@ static int is_menu_open = 0;
static EVENT_HANDLER(MENU_OPENED)
{
debug("%s\n", __FUNCTION__);
++is_menu_open;

if (++is_menu_open == 1) {
if (is_menu_open == 1) {
ffm_value = g_window_manager.ffm_mode;
g_window_manager.ffm_mode = FFM_DISABLED;
}
Expand All @@ -1352,8 +1355,13 @@ static EVENT_HANDLER(MENU_OPENED)
static EVENT_HANDLER(MENU_CLOSED)
{
debug("%s\n", __FUNCTION__);
--is_menu_open;

if (--is_menu_open == 0) {
if (is_menu_open < 0) {
is_menu_open = 0;
}

if (is_menu_open == 0) {
g_window_manager.ffm_mode = ffm_value;
}
}
Expand Down
Loading

0 comments on commit ddd2931

Please sign in to comment.