mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-11-16 05:41:16 +01:00
feat(wm): handle show events for apps that don't emit them
This commit introduces a little hack to emit a WindowManagerEvent::Show every time the input event listener callback is triggered. This is needed because some apps like Ghostty and Safari do not trigger any events when a tab is split out into an independent window. To keep things a little cleaner, a new SystemNotification::Manual variant has been added which takes a ManualNotification variant. The idea is to be able to use one of these whenever we manually emit a notification to the window manager event listener to hopefully save my sanity when we have to debug something in the future.
This commit is contained in:
1 parent
712f2d86a0
commit
0ede90ae5d
9 files changed
+120
-56
No files matched your search
@@ -13,10 +13,10 @@ use crate::accessibility::notification_constants::kAXApplicationShownNotificatio
|
||||
use crate::accessibility::notification_constants::kAXMainWindowChangedNotification;
|
||||
use crate::accessibility::notification_constants::kAXUIElementDestroyedNotification;
|
||||
use crate::accessibility::notification_constants::kAXWindowCreatedNotification;
|
||||
use crate::ax_event_listener::event_tx;
|
||||
use crate::window::Window;
|
||||
use crate::window_manager_event::SystemNotification;
|
||||
use crate::window_manager_event::WindowManagerEvent;
|
||||
use crate::window_manager_event_listener;
|
||||
use objc2_application_services::AXObserver;
|
||||
use objc2_application_services::AXUIElement;
|
||||
use objc2_core_foundation::CFArray;
|
||||
@@ -76,13 +76,11 @@ unsafe extern "C-unwind" fn application_observer_callback(
|
||||
None,
|
||||
)
|
||||
{
|
||||
if let Err(error) = event_tx().send(event) {
|
||||
tracing::error!("failed to send window manager event: {error}");
|
||||
} else {
|
||||
tracing::debug!(
|
||||
"notification: {notification}, process: {process_id}, name: \"{name}\"",
|
||||
);
|
||||
}
|
||||
tracing::debug!(
|
||||
"notification: {notification}, process: {process_id}, name: \"{name}\"",
|
||||
);
|
||||
|
||||
window_manager_event_listener::send_notification(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
use crate::accessibility::AccessibilityApi;
|
||||
use crate::macos_api::MacosApi;
|
||||
use crate::reaper;
|
||||
use crate::reaper::ReaperNotification;
|
||||
use crate::window_manager_event::ManualNotification;
|
||||
use crate::window_manager_event::SystemNotification;
|
||||
use crate::window_manager_event::WindowManagerEvent;
|
||||
use crate::window_manager_event_listener;
|
||||
use objc2_core_foundation::CFMachPort;
|
||||
use objc2_core_foundation::CFRetained;
|
||||
use objc2_core_foundation::CFRunLoop;
|
||||
@@ -24,6 +30,22 @@ extern "C-unwind" fn callback(
|
||||
_listener: *mut c_void,
|
||||
) -> *mut CGEvent {
|
||||
reaper::send_notification(ReaperNotification::MouseUpKeyUp);
|
||||
if let Some(element) = MacosApi::foreground_window() {
|
||||
let mut pid = 0;
|
||||
unsafe {
|
||||
element.pid(NonNull::from_mut(&mut pid));
|
||||
}
|
||||
|
||||
if pid != 0
|
||||
&& let Some(event) = WindowManagerEvent::from_system_notification(
|
||||
SystemNotification::Manual(ManualNotification::ShowOnInputEvent),
|
||||
pid,
|
||||
AccessibilityApi::window_id(&element).ok(),
|
||||
)
|
||||
{
|
||||
window_manager_event_listener::send_notification(event);
|
||||
}
|
||||
}
|
||||
unsafe { event_ref.as_mut() }
|
||||
}
|
||||
impl InputEventListener {
|
||||
|
||||
+7
-16
@@ -39,7 +39,6 @@ pub mod ring;
|
||||
pub mod accessibility;
|
||||
pub mod app_kit_notification_constants;
|
||||
pub mod application;
|
||||
pub mod ax_event_listener;
|
||||
pub mod container;
|
||||
pub mod core;
|
||||
pub mod core_graphics;
|
||||
@@ -59,6 +58,7 @@ pub mod static_config;
|
||||
pub mod window;
|
||||
pub mod window_manager;
|
||||
pub mod window_manager_event;
|
||||
pub mod window_manager_event_listener;
|
||||
pub mod workspace;
|
||||
|
||||
lazy_static! {
|
||||
@@ -89,23 +89,12 @@ lazy_static! {
|
||||
static ref REGEX_IDENTIFIERS: Arc<Mutex<HashMap<String, Regex>>> =
|
||||
Arc::new(Mutex::new(HashMap::new()));
|
||||
static ref MANAGE_IDENTIFIERS: Arc<Mutex<Vec<MatchingRule>>> = Arc::new(Mutex::new(vec![]));
|
||||
static ref IGNORE_IDENTIFIERS: Arc<Mutex<Vec<MatchingRule>>> = Arc::new(Mutex::new(vec![
|
||||
MatchingRule::Simple(IdWithIdentifier {
|
||||
kind: ApplicationIdentifier::Class,
|
||||
id: String::from("OPContainerClass"),
|
||||
matching_strategy: Option::from(MatchingStrategy::Equals),
|
||||
}),
|
||||
MatchingRule::Simple(IdWithIdentifier {
|
||||
kind: ApplicationIdentifier::Class,
|
||||
id: String::from("IHWindowClass"),
|
||||
matching_strategy: Option::from(MatchingStrategy::Equals),
|
||||
}),
|
||||
MatchingRule::Simple(IdWithIdentifier {
|
||||
static ref IGNORE_IDENTIFIERS: Arc<Mutex<Vec<MatchingRule>>> =
|
||||
Arc::new(Mutex::new(vec![MatchingRule::Simple(IdWithIdentifier {
|
||||
kind: ApplicationIdentifier::Exe,
|
||||
id: String::from("komorebi-bar.exe"),
|
||||
id: String::from("Spotlight"),
|
||||
matching_strategy: Option::from(MatchingStrategy::Equals),
|
||||
})
|
||||
]));
|
||||
})]));
|
||||
static ref SESSION_FLOATING_APPLICATIONS: Arc<Mutex<Vec<MatchingRule>>> =
|
||||
Arc::new(Mutex::new(Vec::new()));
|
||||
static ref FLOATING_APPLICATIONS: Arc<Mutex<Vec<MatchingRule>>> =
|
||||
@@ -120,6 +109,8 @@ lazy_static! {
|
||||
"Finder".to_string(),
|
||||
"Ghostty".to_string()
|
||||
]));
|
||||
static ref DO_NOT_OBSERVE_APPLICATIONS: Arc<Mutex<Vec<String>>> =
|
||||
Arc::new(Mutex::new(vec!["Spotlight".to_string(),]));
|
||||
}
|
||||
|
||||
shadow_rs::shadow!(build);
|
||||
|
||||
@@ -7,7 +7,6 @@ use color_eyre::eyre::OptionExt;
|
||||
use komorebi::DATA_DIR;
|
||||
use komorebi::HOME_DIR;
|
||||
use komorebi::UPDATE_MONITOR_WORK_AREAS;
|
||||
use komorebi::ax_event_listener;
|
||||
use komorebi::core::pathext::replace_env_in_path;
|
||||
use komorebi::display_reconfiguration_listener::DisplayReconfigurationListener;
|
||||
use komorebi::input_event_listener::InputEventListener;
|
||||
@@ -19,6 +18,7 @@ use komorebi::process_event::listen_for_events;
|
||||
use komorebi::reaper;
|
||||
use komorebi::static_config::StaticConfig;
|
||||
use komorebi::window_manager::WindowManager;
|
||||
use komorebi::window_manager_event_listener;
|
||||
use objc2::rc::autoreleasepool;
|
||||
use objc2_application_services::AXIsProcessTrusted;
|
||||
use objc2_core_foundation::CFRunLoop;
|
||||
@@ -213,14 +213,14 @@ fn main() -> eyre::Result<()> {
|
||||
|
||||
Arc::new(Mutex::new(StaticConfig::preload(
|
||||
config,
|
||||
ax_event_listener::event_rx(),
|
||||
window_manager_event_listener::event_rx(),
|
||||
None,
|
||||
&run_loop,
|
||||
)?))
|
||||
} else {
|
||||
Arc::new(Mutex::new(WindowManager::new(
|
||||
&run_loop,
|
||||
ax_event_listener::event_rx(),
|
||||
window_manager_event_listener::event_rx(),
|
||||
None,
|
||||
)?))
|
||||
};
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
use crate::app_kit_notification_constants::AppKitWorkspaceNotification;
|
||||
use crate::application::Application;
|
||||
use crate::ax_event_listener::event_tx;
|
||||
use crate::window_manager_event::SystemNotification;
|
||||
use crate::window_manager_event::WindowManagerEvent;
|
||||
use crate::window_manager_event_listener;
|
||||
use objc2::AnyThread;
|
||||
use objc2::define_class;
|
||||
use objc2::msg_send;
|
||||
@@ -74,9 +74,8 @@ define_class! {
|
||||
process_id,
|
||||
window_id,
|
||||
)
|
||||
&& let Err(error) = event_tx().send(event)
|
||||
{
|
||||
tracing::error!("failed to send window manager event: {error}");
|
||||
window_manager_event_listener::send_notification(event);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,15 +4,16 @@ use crate::accessibility::AccessibilityApi;
|
||||
use crate::accessibility::error::AccessibilityApiError;
|
||||
use crate::accessibility::error::AccessibilityError;
|
||||
use crate::accessibility::notification_constants::AccessibilityNotification;
|
||||
use crate::ax_event_listener::event_tx;
|
||||
use crate::core::config_generation::MatchingRule;
|
||||
use crate::core::default_layout::DefaultLayout;
|
||||
use crate::core::layout::Layout;
|
||||
use crate::macos_api::MacosApi;
|
||||
use crate::window::Window;
|
||||
use crate::window_manager::WindowManager;
|
||||
use crate::window_manager_event::ManualNotification;
|
||||
use crate::window_manager_event::SystemNotification;
|
||||
use crate::window_manager_event::WindowManagerEvent;
|
||||
use crate::window_manager_event_listener;
|
||||
use crate::workspace::WorkspaceLayer;
|
||||
use color_eyre::eyre;
|
||||
use parking_lot::Mutex;
|
||||
@@ -72,11 +73,18 @@ impl WindowManager {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
tracing::info!(
|
||||
"processing event: {event} for process {} with notification {}",
|
||||
event.process_id(),
|
||||
event.notification(),
|
||||
);
|
||||
// don't want to spam logs for manually triggered hacks triggered
|
||||
// from the input listener
|
||||
if !matches!(
|
||||
event,
|
||||
WindowManagerEvent::Show(SystemNotification::Manual(_), _)
|
||||
) {
|
||||
tracing::info!(
|
||||
"processing event: {event} for process {} with notification {}",
|
||||
event.process_id(),
|
||||
event.notification(),
|
||||
);
|
||||
}
|
||||
|
||||
self.enforce_workspace_rules()?;
|
||||
|
||||
@@ -113,10 +121,19 @@ impl WindowManager {
|
||||
)) => {
|
||||
// this means we have closed the 1st tab, so we need this window object to be reaped
|
||||
// and for the new 1st tab to be the key element of the window struct
|
||||
event_tx().send(WindowManagerEvent::Show(
|
||||
notification,
|
||||
event.process_id(),
|
||||
))?;
|
||||
if let Some(event) =
|
||||
WindowManagerEvent::from_system_notification(
|
||||
SystemNotification::Manual(
|
||||
ManualNotification::ShowOnFocusChangeFirstTabDestroyed,
|
||||
),
|
||||
event.process_id(),
|
||||
Some(window_id),
|
||||
)
|
||||
{
|
||||
window_manager_event_listener::send_notification(
|
||||
event,
|
||||
);
|
||||
}
|
||||
|
||||
first_tab_destroyed = true;
|
||||
|
||||
@@ -215,10 +232,19 @@ impl WindowManager {
|
||||
// if this fails, the app was probably open but windowless when komorebi
|
||||
// launched, so the window hasn't been registered - we should treat it
|
||||
// as a "Show" event
|
||||
event_tx().send(WindowManagerEvent::Show(
|
||||
notification,
|
||||
event.process_id(),
|
||||
))?
|
||||
if let Some(event) =
|
||||
WindowManagerEvent::from_system_notification(
|
||||
SystemNotification::Manual(
|
||||
ManualNotification::ShowOnFocusChangeWindowlessAppRestored,
|
||||
),
|
||||
event.process_id(),
|
||||
Some(window_id),
|
||||
)
|
||||
{
|
||||
window_manager_event_listener::send_notification(
|
||||
event,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -297,8 +323,16 @@ impl WindowManager {
|
||||
drop(tabbed_applications);
|
||||
|
||||
if workspace.contains_window(window_id) {
|
||||
if !matches!(
|
||||
event,
|
||||
WindowManagerEvent::Show(SystemNotification::Manual(_), _)
|
||||
) {
|
||||
// don't want to spam logs for manually triggered hacks triggered
|
||||
// from the input listener
|
||||
tracing::debug!("ignoring show event for window already on workspace");
|
||||
}
|
||||
|
||||
// ignore bogus show events
|
||||
tracing::debug!("ignoring show event for window already on workspace");
|
||||
create = false;
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,6 @@ use crate::accessibility::notification_constants::kAXWindowMiniaturizedNotificat
|
||||
use crate::accessibility::notification_constants::kAXWindowMovedNotification;
|
||||
use crate::accessibility::notification_constants::kAXWindowResizedNotification;
|
||||
use crate::application::Application;
|
||||
use crate::ax_event_listener::event_tx;
|
||||
use crate::cf_dictionary_value;
|
||||
use crate::core::ApplicationIdentifier;
|
||||
use crate::core::config_generation::IdWithIdentifier;
|
||||
@@ -39,6 +38,7 @@ use crate::macos_api::MacosApi;
|
||||
use crate::reaper;
|
||||
use crate::window_manager_event::SystemNotification;
|
||||
use crate::window_manager_event::WindowManagerEvent;
|
||||
use crate::window_manager_event_listener;
|
||||
use color_eyre::eyre;
|
||||
use color_eyre::eyre::OptionExt;
|
||||
use objc2::__framework_prelude::Retained;
|
||||
@@ -115,14 +115,12 @@ unsafe extern "C-unwind" fn window_observer_callback(
|
||||
window_id,
|
||||
)
|
||||
{
|
||||
if let Err(error) = event_tx().send(event) {
|
||||
tracing::error!("failed to send window manager event: {error}");
|
||||
} else {
|
||||
tracing::debug!(
|
||||
"notification: {}, process: {process_id}, name: \"{name}\"",
|
||||
notification,
|
||||
);
|
||||
}
|
||||
tracing::debug!(
|
||||
"notification: {}, process: {process_id}, name: \"{name}\"",
|
||||
notification,
|
||||
);
|
||||
|
||||
window_manager_event_listener::send_notification(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,14 @@ use strum::Display;
|
||||
pub enum SystemNotification {
|
||||
Accessibility(AccessibilityNotification),
|
||||
AppKitWorkspace(AppKitWorkspaceNotification),
|
||||
Manual(ManualNotification),
|
||||
}
|
||||
|
||||
#[derive(Debug, Copy, Clone, Serialize, Deserialize, Display)]
|
||||
pub enum ManualNotification {
|
||||
ShowOnInputEvent,
|
||||
ShowOnFocusChangeFirstTabDestroyed,
|
||||
ShowOnFocusChangeWindowlessAppRestored,
|
||||
}
|
||||
|
||||
#[derive(Debug, Copy, Clone, Serialize, Deserialize, Display)]
|
||||
@@ -45,7 +53,14 @@ impl WindowManagerEvent {
|
||||
| SystemNotification::Accessibility(AccessibilityNotification::AXApplicationShown)
|
||||
| SystemNotification::AppKitWorkspace(
|
||||
AppKitWorkspaceNotification::NSWorkspaceDidLaunchApplicationNotification,
|
||||
) => Some(WindowManagerEvent::Show(notification, process_id)),
|
||||
)
|
||||
| SystemNotification::Manual(
|
||||
ManualNotification::ShowOnFocusChangeWindowlessAppRestored,
|
||||
)
|
||||
| SystemNotification::Manual(ManualNotification::ShowOnFocusChangeFirstTabDestroyed)
|
||||
| SystemNotification::Manual(ManualNotification::ShowOnInputEvent) => {
|
||||
Some(WindowManagerEvent::Show(notification, process_id))
|
||||
}
|
||||
SystemNotification::Accessibility(AccessibilityNotification::AXUIElementDestroyed)
|
||||
| SystemNotification::AppKitWorkspace(
|
||||
AppKitWorkspaceNotification::NSWorkspaceDidTerminateApplicationNotification,
|
||||
@@ -88,6 +103,7 @@ impl WindowManagerEvent {
|
||||
| WindowManagerEvent::Restore(n, _, _) => match n {
|
||||
SystemNotification::Accessibility(a) => a.to_string(),
|
||||
SystemNotification::AppKitWorkspace(a) => a.to_string(),
|
||||
SystemNotification::Manual(m) => m.to_string(),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,10 +10,16 @@ fn channel() -> &'static (Sender<WindowManagerEvent>, Receiver<WindowManagerEven
|
||||
CHANNEL.get_or_init(|| crossbeam_channel::bounded(20))
|
||||
}
|
||||
|
||||
pub fn event_tx() -> Sender<WindowManagerEvent> {
|
||||
fn event_tx() -> Sender<WindowManagerEvent> {
|
||||
channel().0.clone()
|
||||
}
|
||||
|
||||
pub fn event_rx() -> Receiver<WindowManagerEvent> {
|
||||
channel().1.clone()
|
||||
}
|
||||
|
||||
pub fn send_notification(notification: WindowManagerEvent) {
|
||||
if event_tx().try_send(notification).is_err() {
|
||||
tracing::warn!("channel is full; dropping notification")
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user