Skip to content

Commit

Permalink
#2123 rework window rules
Browse files Browse the repository at this point in the history
  • Loading branch information
koekeishiya committed Feb 27, 2024
1 parent b0b0eeb commit b7d75d4
Show file tree
Hide file tree
Showing 11 changed files with 357 additions and 266 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
- Make space visible on display without stealing focus (the space must belong to the display) [#2113](https://github.com/koekeishiya/yabai/issues/2113)
- Allow re-applying existing rules to all known windows [#2121](https://github.com/koekeishiya/yabai/issues/2121)
- Restore application_activated and application_deactivated signals [#2122](https://github.com/koekeishiya/yabai/issues/2122)
- Rules can now be configured to apply *only once* for all known windows [#2123](https://github.com/koekeishiya/yabai/issues/2123)
- Restore system_woke signal [#2124](https://github.com/koekeishiya/yabai/issues/2124)
- Added new window rules command `--apply` to apply the effects of (specific or all existing rules), or an ad-hoc rule that should only apply once, to all known windows [#2123](https://github.com/koekeishiya/yabai/issues/2123)
- Added new argument `--one-shot` to window rules command `--add` to specify that this rule only runs once [#2123](https://github.com/koekeishiya/yabai/issues/2123)
- Window rules marked as `--one-shot` will be ignored completely by the `--apply` command [#2123](https://github.com/koekeishiya/yabai/issues/2123)

### Changed
- Preserve relative space ordering when moving spaces to other displays [#2114](https://github.com/koekeishiya/yabai/issues/2114)
Expand All @@ -20,6 +22,10 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
- Managed windows should correct their frame when modified by external means [#2117](https://github.com/koekeishiya/yabai/issues/2117)
- Window frame would sometimes not be set correctly when using window animations [#2120](https://github.com/koekeishiya/yabai/issues/2120)
- Allow resetting window opacity in window rules [#2127](https://github.com/koekeishiya/yabai/issues/2127)
- When adding new window rules, their effects will only apply to *windows that open after the rule has been added* [#2123](https://github.com/koekeishiya/yabai/issues/2123)

### Removed
- When adding new window rules, their effects will only apply to *windows that open after the rule has been added*. To restore old behavior, run `yabai -m rule --apply` after adding all rules [#2123](https://github.com/koekeishiya/yabai/issues/2123)

## [6.0.15] - 2024-02-22
### Changed
Expand Down
32 changes: 20 additions & 12 deletions doc/yabai.1
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
.\" Title: yabai
.\" Author: [see the "AUTHOR(S)" section]
.\" Generator: Asciidoctor 2.0.20
.\" Date: 2024-02-26
.\" Date: 2024-02-27
.\" Manual: Yabai Manual
.\" Source: Yabai
.\" Language: English
.\"
.TH "YABAI" "1" "2024-02-26" "Yabai" "Yabai Manual"
.TH "YABAI" "1" "2024-02-27" "Yabai" "Yabai Manual"
.ie \n(.g .ds Aq \(aq
.el .ds Aq '
.ss \n[.ss] 0
Expand Down Expand Up @@ -685,9 +685,9 @@ WINDOW
.if n .RE
.SS "Rule"
.sp
All registered rules that match the given filter will apply to a window in the order they were added.
All rules that match the given filter will be applied in the order they were registered.
.br
If multiple rules specify a value for the same argument, the latter rule will override that value as it was applied last.
If multiple rules specify a value for the same property, the latter rule will end up overriding that value.
.br
The following properties require System Integrity Protection to be partially disabled: sticky, layer, opacity.
.SS "General Syntax"
Expand All @@ -697,19 +697,25 @@ yabai \-m rule \fI<COMMAND>\fP
.sp
\fB\-\-add [\-\-one\-shot] [\fI<ARGUMENT>\fP]\fP
.RS 4
Add a new rule. If \fI\-\-one\-shot\fP is present, only apply once to all known windows.
Add a new rule. Rules apply to windows that spawn after said rule has been added.
.br
If \fI\-\-one\-shot\fP is present it will apply once and automatically remove itself.
.RE
.sp
\fB\-\-remove \fI<RULE_SEL>\fP\fP
\fB\-\-apply [\fI<RULE_SEL>\fP | \fI<ARGUMENT>\fP]\fP
.RS 4
Remove an existing rule with the given index or label.
Apply a rule to currently known windows.
.br
If no argument is given, all existing rules will apply.
.br
If an index or label is given, that particular rule will apply.
.br
Arguments can also be provided directly, just like in the \fB\-\-add\fP command.
.RE
.sp
\fB\-\-reapply [\fI<RULE_SEL>\fP]\fP
\fB\-\-remove \fI<RULE_SEL>\fP\fP
.RS 4
Apply an existing rule with the given index or label to all known windows.
.br
Will apply all rules if no index or label is specified.
Remove an existing rule with the given index or label.
.RE
.sp
\fB\-\-list\fP
Expand Down Expand Up @@ -816,7 +822,9 @@ Set window frame based on a self\-defined grid.
"mouse_follows_focus": bool (optional),
"layer": string,
"native\-fullscreen": bool (optional),
"grid": string
"grid": string,
"one\-shot": bool,
"flags": string
}
.fam
.fi
Expand Down
21 changes: 13 additions & 8 deletions doc/yabai.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -498,8 +498,8 @@ WINDOW
Rule
~~~~

All registered rules that match the given filter will apply to a window in the order they were added. +
If multiple rules specify a value for the same argument, the latter rule will override that value as it was applied last. +
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. +
The following properties require System Integrity Protection to be partially disabled: sticky, layer, opacity.

General Syntax
Expand All @@ -511,15 +511,18 @@ COMMAND
^^^^^^^

*--add [--one-shot] ['<ARGUMENT>']*::
Add a new rule. If '--one-shot' is present, only apply once to all known windows.
Add a new rule. Rules apply to windows that spawn after said rule has been added. +
If '--one-shot' is present it will apply once and automatically remove itself.

*--apply ['<RULE_SEL>' | '<ARGUMENT>']*::
Apply a rule to currently known windows. +
If no argument is given, all existing rules will apply. +
If an index or label is given, that particular rule will apply. +
Arguments can also be provided directly, just like in the *--add* command.

*--remove '<RULE_SEL>'*::
Remove an existing rule with the given index or label.

*--reapply ['<RULE_SEL>']*::
Apply an existing rule with the given index or label to all known windows. +
Will apply all rules if no index or label is specified.

*--list*::
Output list of registered rules.

Expand Down Expand Up @@ -592,7 +595,9 @@ DATAFORMAT
"mouse_follows_focus": bool (optional),
"layer": string,
"native-fullscreen": bool (optional),
"grid": string
"grid": string,
"one-shot": bool,
"flags": string
}
----

Expand Down
13 changes: 12 additions & 1 deletion src/event_loop.c
Original file line number Diff line number Diff line change
Expand Up @@ -468,9 +468,20 @@ static EVENT_HANDLER(WINDOW_CREATED)
struct application *application = window_manager_find_application(&g_window_manager, window_pid);
if (!application) { CFRelease(context); return; }

struct window *window = window_manager_create_and_add_window(&g_space_manager, &g_window_manager, application, context, window_id);
struct window *window = window_manager_create_and_add_window(&g_space_manager, &g_window_manager, application, context, window_id, true);
if (!window) return;

int rule_len = buf_len(g_window_manager.rules);
for (int i = 0; i < rule_len; ++i) {
if (rule_check_flag(&g_window_manager.rules[i], RULE_ONE_SHOT_REMOVE)) {
rule_destroy(&g_window_manager.rules[i]);
if (buf_del(g_window_manager.rules, i)) {
--i;
--rule_len;
}
}
}

if (window_manager_should_manage_window(window) && !window_manager_find_managed_window(&g_window_manager, window)) {
uint64_t sid;

Expand Down
Loading

0 comments on commit b7d75d4

Please sign in to comment.