Skip to content

Commit

Permalink
#173 support exclusion for command arguments of type REGEX
Browse files Browse the repository at this point in the history
  • Loading branch information
koekeishiya committed Mar 1, 2020
1 parent 9e8c386 commit 57a742d
Show file tree
Hide file tree
Showing 8 changed files with 118 additions and 48 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
### Changed
- Properly return focus to the active window on the current space when a window is moved through a rule [#418](https://github.com/koekeishiya/yabai/issues/418)
- Prevent space operations (create, destroy, focus, swap, move and send to display) from applying while mission-control is active or the display is animating [#417](https://github.com/koekeishiya/yabai/issues/417)
- Support exclusion for command arguments of type REGEX [#173](https://github.com/koekeishiya/yabai/issues/173)

## [2.3.0] - 2020-02-14
### Added
Expand Down
36 changes: 18 additions & 18 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.10
.\" Date: 2020-02-13
.\" Date: 2020-03-01
.\" Manual: Yabai Manual
.\" Source: Yabai
.\" Language: English
.\"
.TH "YABAI" "1" "2020-02-13" "Yabai" "Yabai Manual"
.TH "YABAI" "1" "2020-03-01" "Yabai" "Yabai Manual"
.ie \n(.g .ds Aq \(aq
.el .ds Aq '
.ss \n[.ss] 0
Expand Down Expand Up @@ -494,12 +494,12 @@ Remove an existing rule with the given label.
Label used to identify the rule with a unique name
.RE
.sp
\fBapp=\fI<REGEX>\fP\fP
\fBapp[!]=\fI<REGEX>\fP\fP
.RS 4
Name of application.
.RE
.sp
\fBtitle=\fI<REGEX>\fP\fP
\fBtitle[!]=\fI<REGEX>\fP\fP
.RS 4
Title of window.
.RE
Expand Down Expand Up @@ -556,7 +556,7 @@ A signal is a simple way for the user to react to some event that has been proce
yabai \-m signal \fI<COMMAND>\fP
.SS "COMMAND"
.sp
\fB\-\-add event=\fI<EVENT>\fP action=\fI<ACTION>\fP [label=\fI<LABEL>\fP] [app=\fI<REGEX>\fP] [title=\fI<REGEX>\fP]\fP
\fB\-\-add event=\fI<EVENT>\fP action=\fI<ACTION>\fP [label=\fI<LABEL>\fP] [app[!]=\fI<REGEX>\fP] [title[!]=\fI<REGEX>\fP]\fP
.RS 4
Add an optionally labelled signal to execute an action after processing an event of the given type. Some signals can be specified to trigger based on the application name and/or window title.
.RE
Expand All @@ -569,12 +569,12 @@ Remove an existing signal with the given label.
.sp
\fBapplication_launched\fP
.RS 4
Triggered when a new application is launched. Eligible for \fBapp=\fP filter. Passes one argument: $YABAI_PROCESS_ID
Triggered when a new application is launched. Eligible for \fBapp\fP filter. Passes one argument: $YABAI_PROCESS_ID
.RE
.sp
\fBapplication_terminated\fP
.RS 4
Triggered when an application is terminated. Eligible for \fBapp=\fP filter Passes one argument: $YABAI_PROCESS_ID
Triggered when an application is terminated. Eligible for \fBapp\fP filter Passes one argument: $YABAI_PROCESS_ID
.RE
.sp
\fBapplication_front_switched\fP
Expand All @@ -584,27 +584,27 @@ Triggered when the front\-most application changes. Passes two arguments: $YABAI
.sp
\fBapplication_activated\fP
.RS 4
Triggered when an application is activated. Eligible for \fBapp=\fP filter. Passes one argument: $YABAI_PROCESS_ID
Triggered when an application is activated. Eligible for \fBapp\fP filter. Passes one argument: $YABAI_PROCESS_ID
.RE
.sp
\fBapplication_deactivated\fP
.RS 4
Triggered when an application is deactivated. Eligible for \fBapp=\fP filter. Passes one argument: $YABAI_PROCESS_ID
Triggered when an application is deactivated. Eligible for \fBapp\fP filter. Passes one argument: $YABAI_PROCESS_ID
.RE
.sp
\fBapplication_visible\fP
.RS 4
Triggered when an application is unhidden. Eligible for \fBapp=\fP filter. Passes one argument: $YABAI_PROCESS_ID
Triggered when an application is unhidden. Eligible for \fBapp\fP filter. Passes one argument: $YABAI_PROCESS_ID
.RE
.sp
\fBapplication_hidden\fP
.RS 4
Triggered when an application is hidden. Eligible for \fBapp=\fP filter. Passes one argument: $YABAI_PROCESS_ID
Triggered when an application is hidden. Eligible for \fBapp\fP filter. Passes one argument: $YABAI_PROCESS_ID
.RE
.sp
\fBwindow_created\fP
.RS 4
Triggered when a window is created. Eligible for both \fBapp=\fP and \fBtitle=\fP filter. Passes one argument: $YABAI_WINDOW_ID
Triggered when a window is created. Eligible for both \fBapp\fP and \fBtitle\fP filter. Passes one argument: $YABAI_WINDOW_ID
.RE
.sp
\fBwindow_destroyed\fP
Expand All @@ -614,32 +614,32 @@ Triggered when a window is destroyed. Passes one argument: $YABAI_WINDOW_ID
.sp
\fBwindow_focused\fP
.RS 4
Triggered when a window becomes the key\-window for its application. Eligible for both \fBapp=\fP and \fBtitle=\fP filter. Passes one argument: $YABAI_WINDOW_ID
Triggered when a window becomes the key\-window for its application. Eligible for both \fBapp\fP and \fBtitle\fP filter. Passes one argument: $YABAI_WINDOW_ID
.RE
.sp
\fBwindow_moved\fP
.RS 4
Triggered when a window changes position. Eligible for both \fBapp=\fP and \fBtitle=\fP filter. Passes one argument: $YABAI_WINDOW_ID
Triggered when a window changes position. Eligible for both \fBapp\fP and \fBtitle\fP filter. Passes one argument: $YABAI_WINDOW_ID
.RE
.sp
\fBwindow_resized\fP
.RS 4
Triggered when a window changes dimensions. Eligible for both \fBapp=\fP and \fBtitle=\fP filter. Passes one argument: $YABAI_WINDOW_ID
Triggered when a window changes dimensions. Eligible for both \fBapp\fP and \fBtitle\fP filter. Passes one argument: $YABAI_WINDOW_ID
.RE
.sp
\fBwindow_minimized\fP
.RS 4
Triggered when a window has been minimized. Eligible for both \fBapp=\fP and \fBtitle=\fP filter. Passes one argument: $YABAI_WINDOW_ID
Triggered when a window has been minimized. Eligible for both \fBapp\fP and \fBtitle\fP filter. Passes one argument: $YABAI_WINDOW_ID
.RE
.sp
\fBwindow_deminimized\fP
.RS 4
Triggered when a window has been deminimized. Eligible for both \fBapp=\fP and \fBtitle=\fP filter. Passes one argument: $YABAI_WINDOW_ID
Triggered when a window has been deminimized. Eligible for both \fBapp\fP and \fBtitle\fP filter. Passes one argument: $YABAI_WINDOW_ID
.RE
.sp
\fBwindow_title_changed\fP
.RS 4
Triggered when a window changes its title. Eligible for both \fBapp=\fP and \fBtitle=\fP filter. Passes one argument: $YABAI_WINDOW_ID
Triggered when a window changes its title. Eligible for both \fBapp\fP and \fBtitle\fP filter. Passes one argument: $YABAI_WINDOW_ID
.RE
.sp
\fBspace_changed\fP
Expand Down
32 changes: 16 additions & 16 deletions doc/yabai.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -377,10 +377,10 @@ ARGUMENT
*label='<LABEL>'*::
Label used to identify the rule with a unique name

*app='<REGEX>'*::
*app[!]='<REGEX>'*::
Name of application.

*title='<REGEX>'*::
*title[!]='<REGEX>'*::
Title of window.

*display='[^]<DISPLAY_SEL>'*::
Expand Down Expand Up @@ -423,7 +423,7 @@ yabai -m signal '<COMMAND>'
COMMAND
^^^^^^^

*--add event='<EVENT>' action='<ACTION>' [label='<LABEL>'] [app='<REGEX>'] [title='<REGEX>']*::
*--add event='<EVENT>' action='<ACTION>' [label='<LABEL>'] [app[!]='<REGEX>'] [title[!]='<REGEX>']*::
Add an optionally labelled signal to execute an action after processing an event of the given type. Some signals can be specified to trigger based on the application name and/or window title.

*--remove '<LABEL>'*::
Expand All @@ -433,49 +433,49 @@ EVENT
^^^^^

*application_launched*::
Triggered when a new application is launched. Eligible for *app=* filter. Passes one argument: $YABAI_PROCESS_ID
Triggered when a new application is launched. Eligible for *app* filter. Passes one argument: $YABAI_PROCESS_ID

*application_terminated*::
Triggered when an application is terminated. Eligible for *app=* filter Passes one argument: $YABAI_PROCESS_ID
Triggered when an application is terminated. Eligible for *app* filter Passes one argument: $YABAI_PROCESS_ID

*application_front_switched*::
Triggered when the front-most application changes. Passes two arguments: $YABAI_PROCESS_ID, $YABAI_RECENT_PROCESS_ID

*application_activated*::
Triggered when an application is activated. Eligible for *app=* filter. Passes one argument: $YABAI_PROCESS_ID
Triggered when an application is activated. Eligible for *app* filter. Passes one argument: $YABAI_PROCESS_ID

*application_deactivated*::
Triggered when an application is deactivated. Eligible for *app=* filter. Passes one argument: $YABAI_PROCESS_ID
Triggered when an application is deactivated. Eligible for *app* filter. Passes one argument: $YABAI_PROCESS_ID

*application_visible*::
Triggered when an application is unhidden. Eligible for *app=* filter. Passes one argument: $YABAI_PROCESS_ID
Triggered when an application is unhidden. Eligible for *app* filter. Passes one argument: $YABAI_PROCESS_ID

*application_hidden*::
Triggered when an application is hidden. Eligible for *app=* filter. Passes one argument: $YABAI_PROCESS_ID
Triggered when an application is hidden. Eligible for *app* filter. Passes one argument: $YABAI_PROCESS_ID

*window_created*::
Triggered when a window is created. Eligible for both *app=* and *title=* filter. Passes one argument: $YABAI_WINDOW_ID
Triggered when a window is created. Eligible for both *app* and *title* filter. Passes one argument: $YABAI_WINDOW_ID

*window_destroyed*::
Triggered when a window is destroyed. Passes one argument: $YABAI_WINDOW_ID

*window_focused*::
Triggered when a window becomes the key-window for its application. Eligible for both *app=* and *title=* filter. Passes one argument: $YABAI_WINDOW_ID
Triggered when a window becomes the key-window for its application. Eligible for both *app* and *title* filter. Passes one argument: $YABAI_WINDOW_ID

*window_moved*::
Triggered when a window changes position. Eligible for both *app=* and *title=* filter. Passes one argument: $YABAI_WINDOW_ID
Triggered when a window changes position. Eligible for both *app* and *title* filter. Passes one argument: $YABAI_WINDOW_ID

*window_resized*::
Triggered when a window changes dimensions. Eligible for both *app=* and *title=* filter. Passes one argument: $YABAI_WINDOW_ID
Triggered when a window changes dimensions. Eligible for both *app* and *title* filter. Passes one argument: $YABAI_WINDOW_ID

*window_minimized*::
Triggered when a window has been minimized. Eligible for both *app=* and *title=* filter. Passes one argument: $YABAI_WINDOW_ID
Triggered when a window has been minimized. Eligible for both *app* and *title* filter. Passes one argument: $YABAI_WINDOW_ID

*window_deminimized*::
Triggered when a window has been deminimized. Eligible for both *app=* and *title=* filter. Passes one argument: $YABAI_WINDOW_ID
Triggered when a window has been deminimized. Eligible for both *app* and *title* filter. Passes one argument: $YABAI_WINDOW_ID

*window_title_changed*::
Triggered when a window changes its title. Eligible for both *app=* and *title=* filter. Passes one argument: $YABAI_WINDOW_ID
Triggered when a window changes its title. Eligible for both *app* and *title* filter. Passes one argument: $YABAI_WINDOW_ID

*space_changed*::
Triggered when the active space has changed. Passes two arguments: $YABAI_SPACE_ID, $YABAI_RECENT_SPACE_ID
Expand Down
15 changes: 11 additions & 4 deletions src/event.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ static bool event_signal_filter(struct signal *signal, enum event_type type, str
struct process *process = args->entity;
if (!process) return true;

return regex_match(signal->app_regex_valid, &signal->app_regex, process->name) == REGEX_MATCH_NO;
int regex_match_app = signal->app_regex_exclude ? REGEX_MATCH_YES : REGEX_MATCH_NO;
return regex_match(signal->app_regex_valid, &signal->app_regex, process->name) == regex_match_app;
} break;
case APPLICATION_ACTIVATED:
case APPLICATION_DEACTIVATED:
Expand All @@ -137,7 +138,8 @@ static bool event_signal_filter(struct signal *signal, enum event_type type, str
struct application *application = args->entity;
if (!application) return true;

return regex_match(signal->app_regex_valid, &signal->app_regex, application->name) == REGEX_MATCH_NO;
int regex_match_app = signal->app_regex_exclude ? REGEX_MATCH_YES : REGEX_MATCH_NO;
return regex_match(signal->app_regex_valid, &signal->app_regex, application->name) == regex_match_app;
} break;
case WINDOW_CREATED:
case WINDOW_FOCUSED:
Expand All @@ -149,8 +151,13 @@ static bool event_signal_filter(struct signal *signal, enum event_type type, str
struct window *window = args->entity;
if (!window) return true;

return regex_match(signal->app_regex_valid, &signal->app_regex, window->application->name) == REGEX_MATCH_NO ||
regex_match(signal->title_regex_valid, &signal->title_regex, args->param1) == REGEX_MATCH_NO;
int regex_match_app = signal->app_regex_exclude ? REGEX_MATCH_YES : REGEX_MATCH_NO;
bool app_no_match = regex_match(signal->app_regex_valid, &signal->app_regex, window->application->name) == regex_match_app;

int regex_match_title = signal->title_regex_exclude ? REGEX_MATCH_YES : REGEX_MATCH_NO;
bool title_no_match = regex_match(signal->title_regex_valid, &signal->title_regex, args->param1) == regex_match_title;

return app_no_match || title_no_match;
} break;
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/event.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,8 @@ struct signal
{
bool app_regex_valid;
bool title_regex_valid;
bool app_regex_exclude;
bool title_regex_exclude;
regex_t app_regex;
regex_t title_regex;
char *command;
Expand Down
Loading

0 comments on commit 57a742d

Please sign in to comment.