Skip to content

Commit

Permalink
#1887 rework automatic window opacity
Browse files Browse the repository at this point in the history
  • Loading branch information
koekeishiya committed Oct 10, 2023
1 parent 7a4e553 commit 8a4312a
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 81 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
### Changed
- Fix issue causing window animations to flicker on macOS Ventura and Sonoma [#1879](https://github.com/koekeishiya/yabai/issues/1879)
- All managed (read: tiled) windows are now automatically placed in the *below* layer. All unmanaged (read: floating) windows will use the default macOS *normal* layer and appear above the tiled layer, replicating the `window_topmost` functionality in a robust way [#1887](https://github.com/koekeishiya/yabai/issues/1887)
- Automatic window opacity changes will now only apply to focus switches within the same space [#1887](https://github.com/koekeishiya/yabai/issues/1887)

### Removed
- Config option `window_topmost` has been removed [#1887](https://github.com/koekeishiya/yabai/issues/1887)
- Window command `--toggle` option `topmost` has been removed [#1887](https://github.com/koekeishiya/yabai/issues/1887)
- Window query property `is-topmost` has been removed [#1887](https://github.com/koekeishiya/yabai/issues/1887)
- Signal `application_activated` and `application_deactivated` has been removed; use `application_front_switched` instead [#1887](https://github.com/koekeishiya/yabai/issues/1887)

## [5.0.9] - 2023-10-01
### Changed
Expand Down
18 changes: 0 additions & 18 deletions doc/yabai.1
Original file line number Diff line number Diff line change
Expand Up @@ -890,24 +890,6 @@ Triggered when the front\-most application changes.
Passes two arguments: $YABAI_PROCESS_ID, $YABAI_RECENT_PROCESS_ID
.RE
.sp
\fBapplication_activated\fP
.RS 4
Triggered when an application is activated.
.br
Eligible for \fBapp\fP filter.
.br
Passes one argument: $YABAI_PROCESS_ID
.RE
.sp
\fBapplication_deactivated\fP
.RS 4
Triggered when an application is deactivated.
.br
Eligible for \fBapp\fP filter.
.br
Passes one argument: $YABAI_PROCESS_ID
.RE
.sp
\fBapplication_visible\fP
.RS 4
Triggered when an application is unhidden.
Expand Down
10 changes: 0 additions & 10 deletions doc/yabai.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -648,16 +648,6 @@ EVENT
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

*application_deactivated*::
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. +
Expand Down
62 changes: 19 additions & 43 deletions src/event_loop.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ extern int g_layer_below_window_level;

static void window_did_receive_focus(struct window_manager *wm, struct mouse_state *ms, struct window *window)
{
struct window *focused_window = window_manager_find_window(wm, wm->focused_window_id);
if (focused_window && focused_window != window && window_space(focused_window) == window_space(window)) {
window_manager_set_window_opacity(wm, focused_window, g_window_manager.normal_window_opacity);
border_deactivate(focused_window);
}

window_manager_set_window_opacity(wm, window, wm->active_window_opacity);
border_activate(window);

Expand Down Expand Up @@ -249,28 +255,20 @@ static EVENT_HANDLER(APPLICATION_FRONT_SWITCHED)
return;
}

event_loop_post(&g_event_loop, APPLICATION_DEACTIVATED, (void *)(intptr_t) g_process_manager.front_pid, 0);
event_loop_post(&g_event_loop, APPLICATION_ACTIVATED, (void *)(intptr_t) process->pid, 0);

debug("%s: %s (%d)\n", __FUNCTION__, process->name, process->pid);
g_process_manager.switch_event_time = GetCurrentEventTime();
g_process_manager.last_front_pid = g_process_manager.front_pid;
g_process_manager.front_pid = process->pid;

event_signal_push(SIGNAL_APPLICATION_FRONT_SWITCHED, NULL);
}
#pragma clang diagnostic pop

static EVENT_HANDLER(APPLICATION_ACTIVATED)
{
struct application *application = window_manager_find_application(&g_window_manager, (pid_t)(intptr_t) context);
if (!application) return;

debug("%s: %s\n", __FUNCTION__, application->name);
event_signal_push(SIGNAL_APPLICATION_ACTIVATED, application);

uint32_t application_focused_window_id = application_focused_window(application);
if (!application_focused_window_id) {
struct window *focused_window = window_manager_find_window(&g_window_manager, g_window_manager.focused_window_id);
if (focused_window) {
window_manager_set_window_opacity(&g_window_manager, focused_window, g_window_manager.normal_window_opacity);
border_deactivate(focused_window);
}

g_window_manager.last_window_id = g_window_manager.focused_window_id;
g_window_manager.focused_window_id = 0;
g_window_manager.focused_window_psn = application->psn;
Expand All @@ -280,36 +278,20 @@ static EVENT_HANDLER(APPLICATION_ACTIVATED)

struct window *window = window_manager_find_window(&g_window_manager, application_focused_window_id);
if (!window) {
struct window *focused_window = window_manager_find_window(&g_window_manager, g_window_manager.focused_window_id);
if (focused_window) {
window_manager_set_window_opacity(&g_window_manager, focused_window, g_window_manager.normal_window_opacity);
border_deactivate(focused_window);
}

window_manager_add_lost_focused_event(&g_window_manager, application_focused_window_id);
return;
}

window_did_receive_focus(&g_window_manager, &g_mouse_state, window);
event_signal_push(SIGNAL_WINDOW_FOCUSED, window);
}

static EVENT_HANDLER(APPLICATION_DEACTIVATED)
{
struct application *application = window_manager_find_application(&g_window_manager, (pid_t)(intptr_t) context);
if (!application) return;

debug("%s: %s\n", __FUNCTION__, application->name);
event_signal_push(SIGNAL_APPLICATION_DEACTIVATED, application);

struct window *focused_window = window_manager_find_window(&g_window_manager, application_focused_window(application));
if (!focused_window) return;

window_manager_set_window_opacity(&g_window_manager, focused_window, g_window_manager.normal_window_opacity);
border_deactivate(focused_window);

if (!window_level_is_standard(focused_window) || !window_is_standard(focused_window)) {
struct window *main_window = window_manager_find_window(&g_window_manager, application_main_window(application));
if (main_window && main_window != focused_window) {
window_manager_set_window_opacity(&g_window_manager, main_window, g_window_manager.normal_window_opacity);
border_deactivate(main_window);
}
}
}
#pragma clang diagnostic pop

static EVENT_HANDLER(APPLICATION_VISIBLE)
{
Expand Down Expand Up @@ -515,12 +497,6 @@ static EVENT_HANDLER(WINDOW_FOCUSED)
return;
}

struct window *focused_window = window_manager_find_window(&g_window_manager, g_window_manager.focused_window_id);
if (focused_window && focused_window != window) {
window_manager_set_window_opacity(&g_window_manager, focused_window, g_window_manager.normal_window_opacity);
border_deactivate(focused_window);
}

debug("%s: %s %d\n", __FUNCTION__, window->application->name, window->id);
window_did_receive_focus(&g_window_manager, &g_mouse_state, window);
event_signal_push(SIGNAL_WINDOW_FOCUSED, window);
Expand Down
2 changes: 0 additions & 2 deletions src/event_loop.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
EVENT_TYPE_ENTRY(APPLICATION_LAUNCHED) \
EVENT_TYPE_ENTRY(APPLICATION_TERMINATED) \
EVENT_TYPE_ENTRY(APPLICATION_FRONT_SWITCHED) \
EVENT_TYPE_ENTRY(APPLICATION_ACTIVATED) \
EVENT_TYPE_ENTRY(APPLICATION_DEACTIVATED) \
EVENT_TYPE_ENTRY(APPLICATION_VISIBLE) \
EVENT_TYPE_ENTRY(APPLICATION_HIDDEN) \
EVENT_TYPE_ENTRY(WINDOW_CREATED) \
Expand Down
4 changes: 0 additions & 4 deletions src/event_signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ static bool event_signal_filter(struct event_signal *es, struct signal *signal)
default: return false;

case SIGNAL_APPLICATION_LAUNCHED:
case SIGNAL_APPLICATION_ACTIVATED:
case SIGNAL_APPLICATION_DEACTIVATED:
case SIGNAL_APPLICATION_VISIBLE: {
int regex_match_app = signal->app_regex_exclude ? REGEX_MATCH_YES : REGEX_MATCH_NO;
return regex_match(signal->app_regex_valid, &signal->app_regex, es->app) == regex_match_app;
Expand Down Expand Up @@ -115,8 +113,6 @@ void event_signal_push(enum signal_type type, void *context)
default: break;

case SIGNAL_APPLICATION_LAUNCHED:
case SIGNAL_APPLICATION_ACTIVATED:
case SIGNAL_APPLICATION_DEACTIVATED:
case SIGNAL_APPLICATION_VISIBLE: {
struct application *application = context;

Expand Down
4 changes: 0 additions & 4 deletions src/event_signal.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ enum signal_type
SIGNAL_APPLICATION_LAUNCHED,
SIGNAL_APPLICATION_TERMINATED,
SIGNAL_APPLICATION_FRONT_SWITCHED,
SIGNAL_APPLICATION_ACTIVATED,
SIGNAL_APPLICATION_DEACTIVATED,
SIGNAL_APPLICATION_VISIBLE,
SIGNAL_APPLICATION_HIDDEN,

Expand Down Expand Up @@ -49,8 +47,6 @@ static const char *signal_type_str[] =
[SIGNAL_APPLICATION_LAUNCHED] = "application_launched",
[SIGNAL_APPLICATION_TERMINATED] = "application_terminated",
[SIGNAL_APPLICATION_FRONT_SWITCHED] = "application_front_switched",
[SIGNAL_APPLICATION_ACTIVATED] = "application_activated",
[SIGNAL_APPLICATION_DEACTIVATED] = "application_deactivated",
[SIGNAL_APPLICATION_VISIBLE] = "application_visible",
[SIGNAL_APPLICATION_HIDDEN] = "application_hidden",

Expand Down

0 comments on commit 8a4312a

Please sign in to comment.