feat(wm): ignore events on other spaces

This commit ensures that events and commands on spaces other than the
one that komorebi was started on will be ignored.
This commit is contained in:
LGUG2Z committed 2025-09-27 13:26:32 -07:00
1 parent cd5f660455
commit e5468dc036
9 files changed
+60 -12

No files matched your search

+1 -1
View File
@@ -6,5 +6,5 @@ use objc2_core_graphics::CGWindowID;
// https://github.com/nikitabobko/AeroSpace?tab=readme-ov-file#project-values
unsafe extern "C" {
/// Extract `window_id` from an AXUIElement.
pub(crate) fn _AXUIElementGetWindow(elem: &AXUIElement, window_id: *mut CGWindowID) -> AXError;
pub fn _AXUIElementGetWindow(elem: &AXUIElement, window_id: *mut CGWindowID) -> AXError;
}
+8
View File
@@ -38,6 +38,7 @@ use std::collections::HashMap;
use std::io::Write;
use std::ops::Deref;
use std::os::unix::net::UnixStream;
use std::panic;
use std::path::PathBuf;
use std::ptr::NonNull;
use std::sync::Arc;
@@ -64,6 +65,7 @@ pub mod notification_center_listener;
pub mod process_command;
pub mod process_event;
pub mod reaper;
pub mod skylight;
pub mod state;
pub mod static_config;
pub mod window;
@@ -149,6 +151,12 @@ shadow_rs::shadow!(build);
pub static DEFAULT_WORKSPACE_PADDING: AtomicI32 = AtomicI32::new(5);
pub static DEFAULT_CONTAINER_PADDING: AtomicI32 = AtomicI32::new(5);
#[must_use]
pub fn current_space_id() -> Option<u64> {
panic::catch_unwind(|| unsafe { skylight::CGSGetActiveSpace(skylight::CGSMainConnectionID()) })
.ok()
}
#[derive(Clone, Debug, Serialize, Deserialize)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
#[serde(untagged)]
-5
View File
@@ -26,8 +26,6 @@ use objc2::rc::autoreleasepool;
use objc2_application_services::AXIsProcessTrusted;
use objc2_core_foundation::CFRunLoop;
use objc2_core_foundation::kCFRunLoopDefaultMode;
use objc2_core_graphics::CGDisplayBounds;
use objc2_core_graphics::CGMainDisplayID;
use objc2_core_graphics::CGPreflightScreenCaptureAccess;
use objc2_core_graphics::CGRequestScreenCaptureAccess;
use parking_lot::Mutex;
@@ -217,9 +215,6 @@ fn main() -> eyre::Result<()> {
let _notification_center_listener = NotificationCenterListener::init();
let _display_reconfiguration_listener = DisplayReconfigurationListener::init();
let display_size = unsafe { CGDisplayBounds(CGMainDisplayID()) };
tracing::info!("display size for main display is: {:?}", display_size);
let run_loop = CFRunLoop::current().ok_or_eyre("couldn't get CFRunLoop::current")?;
let _input_listener = InputEventListener::init(&run_loop);
+9
View File
@@ -29,6 +29,7 @@ use crate::core::layout::Layout;
use crate::core::operation_direction::OperationDirection;
use crate::core::rect::Rect;
use crate::core_graphics::CoreGraphicsApi;
use crate::current_space_id;
use crate::macos_api::MacosApi;
use crate::monitor::MonitorInformation;
use crate::notify_subscribers;
@@ -107,6 +108,14 @@ impl WindowManager {
message: SocketMessage,
mut reply: impl std::io::Write,
) -> eyre::Result<()> {
if let Some(space_id) = &self.space_id
&& let Some(current_space_id) = current_space_id()
&& *space_id != current_space_id
{
tracing::trace!("ignoring events and commands while not on space {space_id}");
return Ok(());
}
tracing::info!("processing command: {message}");
#[allow(clippy::useless_asref)]
+9
View File
@@ -17,6 +17,7 @@ use crate::core::default_layout::DefaultLayout;
use crate::core::layout::Layout;
use crate::core::operation_direction::OperationDirection;
use crate::core::rect::Rect;
use crate::current_space_id;
use crate::macos_api::MacosApi;
use crate::notify_subscribers;
use crate::state::State;
@@ -68,6 +69,14 @@ impl WindowManager {
return Ok(());
}
if let Some(space_id) = &self.space_id
&& let Some(current_space_id) = current_space_id()
&& *space_id != current_space_id
{
tracing::trace!("ignoring events and commands while not on space {space_id}");
return Ok(());
}
let mut rule_debug = RuleDebug::default();
let mut should_manage = true;
+6
View File
@@ -0,0 +1,6 @@
// Only read operations are permitted, and their usage and potential failure must
// never disrupt the window manager
unsafe extern "C" {
pub fn CGSMainConnectionID() -> i32;
pub fn CGSGetActiveSpace(cid: i32) -> u64;
}
+2
View File
@@ -28,6 +28,7 @@ use crate::core::default_layout::LayoutOptions;
use crate::core::layout::Layout;
use crate::core::pathext::ResolvedPathBuf;
use crate::core::rect::Rect;
use crate::current_space_id;
use crate::monitor;
use crate::monitor::Monitor;
use crate::monitor_reconciliator;
@@ -1126,6 +1127,7 @@ impl StaticConfig {
applications: Default::default(),
incoming_events: incoming,
command_listener: listener,
space_id: current_space_id(),
is_paused: false,
// virtual_desktop_id: current_virtual_desktop(),
work_area_offset: value.global_work_area_offset,
+4 -1
View File
@@ -23,6 +23,7 @@ use crate::core::default_layout::DefaultLayout;
use crate::core::layout::Layout;
use crate::core::operation_direction::OperationDirection;
use crate::core::rect::Rect;
use crate::current_space_id;
use crate::lockable_sequence::Lockable;
use crate::macos_api::MacosApi;
use crate::monitor::Monitor;
@@ -63,6 +64,7 @@ pub struct WindowManager {
pub applications: HashMap<i32, Application>,
pub run_loop: CoreFoundationRunLoop,
pub command_listener: UnixListener,
pub space_id: Option<u64>,
pub is_paused: bool,
pub resize_delta: i32,
pub hotwatch: Hotwatch,
@@ -145,6 +147,7 @@ impl WindowManager {
applications: Default::default(),
run_loop: CoreFoundationRunLoop(run_loop.clone()),
command_listener: listener,
space_id: current_space_id(),
is_paused: false,
resize_delta: 50,
hotwatch: Hotwatch::new()?,
@@ -1136,7 +1139,7 @@ impl WindowManager {
tracing::info!("removing window");
if self.focused_container()?.windows().len() == 1 {
eyre::bail!("a container must have at least one window");
bail!("a container must have at least one window");
}
let workspace = self.focused_workspace_mut()?;
+21 -5
View File
@@ -1249,18 +1249,34 @@ fn main() -> eyre::Result<()> {
current_exe.pop();
let komorebi_exe = current_exe.join("komorebi");
println!("\nPlease grant Accessibility permissions to \"{}\"", komorebi_exe.display());
println!(
"\nPlease grant Accessibility permissions to \"{}\"",
komorebi_exe.display()
);
println!("Accessibility permissions are required for komorebi to to manage windows");
Command::new("open").arg("x-apple.systempreferences:com.apple.preference.security?Privacy_Accessibility").spawn()?;
Command::new("open")
.arg(
"x-apple.systempreferences:com.apple.preference.security?Privacy_Accessibility",
)
.spawn()?;
println!("\nHit return when done...");
std::io::stdout().flush()?;
let mut input = String::new();
std::io::stdin().read_line(&mut input)?;
println!("Please grant Screen Recording permissions to \"{}\"", komorebi_exe.display());
println!("Screen Recording permissions are required to for komorebi to read window titles");
Command::new("open").arg("x-apple.systempreferences:com.apple.preference.security?Privacy_ScreenCapture").spawn()?;
println!(
"Please grant Screen Recording permissions to \"{}\"",
komorebi_exe.display()
);
println!(
"Screen Recording permissions are required to for komorebi to read window titles"
);
Command::new("open")
.arg(
"x-apple.systempreferences:com.apple.preference.security?Privacy_ScreenCapture",
)
.spawn()?;
println!("\nHit return when done...");
std::io::stdout().flush()?;