mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-11-16 05:41:16 +01:00
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.
This commit is contained in:
1 parent
23a2cccdf6
commit
48a21eba61
1 file changed
+28
-2
+28
-2
@@ -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)?;
|
||||
|
||||
Reference in new issue
Block a user