From 48a21eba61363264bb8a09f06488d6a609c2a59b Mon Sep 17 00:00:00 2001 From: LGUG2Z Date: Tue, 25 Nov 2025 20:02:00 -0800 Subject: [PATCH] fix(wm): explicitly init and process nsapplication events For reasons unknown, CFRunLoop::run_in_mode no longer processes NSApplication events on Tahoe. Display callbacks seem to now be more tightly coupled to the NSApplication event loop, so we initialize NSApplication with sharedApplication as early as possible to establish a window server connection, and then in our main loop we poll app.nextEvent every 0.1s for NSApplication events, which is where the DisplayReconfigurationListener callback will finally kick in again. --- komorebi/src/main.rs | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/komorebi/src/main.rs b/komorebi/src/main.rs index 7cccd778..8a8558e2 100644 --- a/komorebi/src/main.rs +++ b/komorebi/src/main.rs @@ -21,12 +21,17 @@ use komorebi::theme_manager; use komorebi::window_manager::WindowManager; use komorebi::window_manager_event_listener; use komorebi::workspace_reconciliator; +use objc2::MainThreadMarker; use objc2::rc::autoreleasepool; +use objc2_app_kit::NSApplication; +use objc2_app_kit::NSEventMask; use objc2_application_services::AXIsProcessTrusted; use objc2_core_foundation::CFRunLoop; use objc2_core_foundation::kCFRunLoopDefaultMode; use objc2_core_graphics::CGPreflightScreenCaptureAccess; use objc2_core_graphics::CGRequestScreenCaptureAccess; +use objc2_foundation::NSDate; +use objc2_foundation::NSDefaultRunLoopMode; use parking_lot::Mutex; use serde::Deserialize; use std::net::Shutdown; @@ -211,6 +216,12 @@ fn main() -> eyre::Result<()> { std::fs::create_dir_all(&*DATA_DIR)?; } + let mtm = MainThreadMarker::new().ok_or_eyre("failed to create main thread marker")?; + // apparently this establishes the window server connection which is needed super early on tahoe + let app = NSApplication::sharedApplication(mtm); + // this lets us complete initialization without using a blocking method like run + app.finishLaunching(); + let _notification_center_listener = NotificationCenterListener::init(); let _display_reconfiguration_listener = DisplayReconfigurationListener::init(); @@ -297,8 +308,23 @@ fn main() -> eyre::Result<()> { break; } - // this gets our observer notification callbacks firing - autoreleasepool(|_| unsafe { CFRunLoop::run_in_mode(kCFRunLoopDefaultMode, 0.1, false) }); + autoreleasepool(|_| { + // process NSApplication events explicitly - this is what makes display + // reconfiguration callbacks work on tahoe + if let Some(event) = unsafe { + app.nextEventMatchingMask_untilDate_inMode_dequeue( + NSEventMask::Any, + Some(&NSDate::dateWithTimeIntervalSinceNow(0.1)), + NSDefaultRunLoopMode, + true, + ) + } { + app.sendEvent(&event); + } + + // this gets our observer notification callbacks firing + unsafe { CFRunLoop::run_in_mode(kCFRunLoopDefaultMode, 0.1, false) }; + }); } wm.lock().restore_all_windows(false)?;