mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-11-18 22:58:34 +01:00
fix(wm): handle ghost tiles from electron apps hijacking cmd+w
Some Electron apps like Discord hijack CMD+W to send `AXApplicationHidden` instead of properly closing/destroying the window. This causes ghost tiles because the window still exists in the accessibility API with valid geometry even though it is no longer visible on the screen. When `AXApplicationHidden` fires for an app with exactly 1 window, we now force-reap that window by passing an empty `valid_window_ids` list. This treats single- window hide events as closes, which is the correct behavior for apps that hijack CMD+W. Apps with multiple windows continue to use normal orphan reaping. I'm still not sure if this is too broad; we may need to use an allowlist approach for this if it causes changes with other apps.
This commit is contained in:
1 parent
63409addb1
commit
7c1ab9a6cc
4 files changed
+62
-4
No files matched your search
@@ -73,7 +73,6 @@ jsonschema:
|
||||
cargo run --package komorebic -- application-specific-configuration-schema > schema.asc.json
|
||||
cargo run --package komorebi-bar -- --schema > schema.bar.json
|
||||
|
||||
|
||||
nixgen:
|
||||
schemars-nixgen schema.json -o nix/komorebi-options.nix --name komorebi --description "komorebi for Mac configuration"
|
||||
schemars-nixgen schema.bar.json -o nix/komorebi-bar-options.nix --name komorebi-bar --description "komorebi for Mac bar configuration"
|
||||
|
||||
@@ -649,8 +649,40 @@ impl WindowManager {
|
||||
// self.update_focused_workspace(false, false)?;
|
||||
}
|
||||
}
|
||||
WindowManagerEvent::Destroy(_, process_id) => {
|
||||
self.reap_invalid_windows_for_application(process_id)?;
|
||||
WindowManagerEvent::Destroy(notification, process_id) => {
|
||||
// some apps like Discord in all of their relentless Electron slop stupidity
|
||||
// hijack CMD+W to send a HIDE instead of a close (i.e. the equivalent of pressing CMD+H)
|
||||
let mut should_force_reap = false;
|
||||
if matches!(
|
||||
notification,
|
||||
SystemNotification::Accessibility(
|
||||
AccessibilityNotification::AXApplicationHidden
|
||||
)
|
||||
) {
|
||||
let application = self.application(process_id)?;
|
||||
let window_count = application
|
||||
.window_elements()
|
||||
.map(|elements| elements.len())
|
||||
.unwrap_or(0);
|
||||
|
||||
// force reap if the app has exactly 1 window (i.e. the one being hidden)
|
||||
if window_count == 1 {
|
||||
tracing::debug!(
|
||||
"app {} has only 1 window and sent AXApplicationHidden, treating as window close",
|
||||
application.name().unwrap_or_default()
|
||||
);
|
||||
should_force_reap = true;
|
||||
}
|
||||
}
|
||||
|
||||
if should_force_reap {
|
||||
let workspace = self.focused_workspace_mut()?;
|
||||
workspace.reap_invalid_windows_for_application(process_id, &[])?;
|
||||
} else {
|
||||
// app has multiple windows, use normal orphan reaping strategy
|
||||
self.reap_invalid_windows_for_application(process_id)?;
|
||||
}
|
||||
|
||||
self.update_focused_workspace(false, false)?;
|
||||
}
|
||||
WindowManagerEvent::Unmanage(_, _, window_id) => {
|
||||
|
||||
@@ -81,7 +81,10 @@ impl WindowManagerEvent {
|
||||
SystemNotification::Accessibility(AccessibilityNotification::AXUIElementDestroyed)
|
||||
| SystemNotification::AppKitWorkspace(
|
||||
AppKitWorkspaceNotification::NSWorkspaceDidTerminateApplicationNotification,
|
||||
) => Some(WindowManagerEvent::Destroy(notification, process_id)),
|
||||
)
|
||||
| SystemNotification::Accessibility(AccessibilityNotification::AXApplicationHidden) => {
|
||||
Some(WindowManagerEvent::Destroy(notification, process_id))
|
||||
}
|
||||
// TODO: figure out if we wanna handle the hide/unhide notifications separately
|
||||
// TODO: maybe turn window id into a vec of window IDs for hidden apps
|
||||
SystemNotification::Accessibility(AccessibilityNotification::AXWindowMiniaturized) => {
|
||||
|
||||
@@ -407,6 +407,14 @@ impl Workspace {
|
||||
&& focused_window.application.process_id == process_id
|
||||
{
|
||||
if !valid_window_ids.contains(&focused_window.id) {
|
||||
if let Ok(rect) = MacosApi::window_rect(&focused_window.element) {
|
||||
tracing::debug!(
|
||||
"reaping window {} ({}): rect = {:?}",
|
||||
focused_window.id,
|
||||
focused_window.title().unwrap_or_default(),
|
||||
rect
|
||||
);
|
||||
}
|
||||
invalid_window_ids.push(focused_window.id);
|
||||
}
|
||||
|
||||
@@ -424,6 +432,14 @@ impl Workspace {
|
||||
if focused_window.application.process_id == process_id
|
||||
&& !valid_window_ids.contains(&focused_window.id)
|
||||
{
|
||||
if let Ok(rect) = MacosApi::window_rect(&focused_window.element) {
|
||||
tracing::debug!(
|
||||
"reaping monocle window {} ({}): rect = {:?}",
|
||||
focused_window.id,
|
||||
focused_window.title().unwrap_or_default(),
|
||||
rect
|
||||
);
|
||||
}
|
||||
invalid_window_ids.push(focused_window.id);
|
||||
}
|
||||
|
||||
@@ -437,6 +453,14 @@ impl Workspace {
|
||||
for window in self.floating_windows() {
|
||||
if window.application.process_id == process_id {
|
||||
if !valid_window_ids.contains(&window.id) {
|
||||
if let Ok(rect) = MacosApi::window_rect(&window.element) {
|
||||
tracing::debug!(
|
||||
"reaping floating window {} ({}): rect = {:?}",
|
||||
window.id,
|
||||
window.title().unwrap_or_default(),
|
||||
rect
|
||||
);
|
||||
}
|
||||
invalid_floating_window_ids.push(window.id);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user