diff --git a/docs/dev/macos-handcheck.md b/docs/dev/macos-handcheck.md index 29c612b6..40b156dd 100644 --- a/docs/dev/macos-handcheck.md +++ b/docs/dev/macos-handcheck.md @@ -26,6 +26,7 @@ The real-Mac runs so far (Mac Mini, rustc and clippy 1.93, tip a35573d8) are **c | Bar: `nottqpms` 086833af, `zvuyspku` b8de056b, `uxzpkmnk` 7cd85bd4, `yopuwouu` 6da27dda (bar-core, platform hooks) | macOS now builds `sysinfo` 0.39 and `starship-battery` 0.11 (the Windows versions); cpu, battery, memory, date, update widgets are the shared code. | Bar renders; CPU %, memory, battery % and charging state show sane values; date and the calendar icon; clicking CPU, battery, network, update (see bug list D below: these click handlers are broken on macOS and stay broken). | | 11(iii) Container: `refactor(mac): the daemon's Container is komorebi_core::Container` (see `jj log -r wip-u-kfm2`) | `Container` is the shared generic type over the macOS `Window` (its id, windows, focus, `remove_*`, `idx_*` functions are the shared ones). The four functions that need the monitor's hiding corner and can fail (`add_window`, `load_focused_window`, `hide`, `restore`) stay macOS's, renamed `add_window_at`, `load_focused_window_at`, `hide_on`, `restore_focused_window` (`ContainerExt`); `Window::hide/restore/minimize/unminimize` take `&self`. State JSON must not change (pinned by two tests in container.rs). | Run `cargo test` (the container, workspace and scrolling tests use these). Then by hand: stack windows (`komorebic stack`), unstack, cycle the stack (hidden members go to the monitor's corner, the front one is restored); switch workspaces and come back (restore of the front window of each stack); `komorebic state | jq '.monitors.elements[0].workspaces.elements[0].containers.elements[0]'` still has `id`, `locked`, `windows.{elements,focused}` and nothing else. Set `window_hiding_position` per monitor in the config and check each monitor hides into its own corner. | | 11(iii) Workspace: `refactor(mac): the daemon's Workspace is komorebi_core::Workspace` (see `jj log -r wip-u-kfm2`) | About 50 workspace functions (container and focus operations, placement, resize constraints, window lookups, floating helpers, the stack and monocle operations that hide windows) are now the shared ones; `hide`, `new_container_for_window` and the stack functions pass the monitor's corner through `MacosPlatform::hide_spot` (kept in `MacosWorkspaceState`, set by the monitor with the globals), and `hide` passes the display bounds for the containers through `hide_spot_on_display`. macOS's own `update`, `apply_wallpaper`, `restore`, `remove_window`, `load_static_config`, `prune_duplicate_windows`, `visible_window_details`, `reap_invalid_windows_for_application`, `restore_windows`, `calculate_layouts` and `set_scrolling_columns` are `WorkspaceExt`; the scrolling methods are `WorkspaceScrolling`. | `cargo test` first (the workspace, scrolling and window_manager tests). Then: stack and unstack, switch workspaces both ways (each stack shows its front window, the hidden ones are in their monitor's corner), toggle monocle and back, float and unfloat a window, cycle the monocle container, move a window to another workspace, move a container across monitors; with a different `window_hiding_position` on each monitor check each monitor's windows park in their own corner and that a floating window that overhangs the edge of a display is still parked on its own display. `komorebic state` keys of a workspace are unchanged (pinned by `state_pin`). Scrolling layout: focus, move, consume and expel, pan, resize a column. | +| 11(iii) Monitor: `refactor(mac): the daemon's Monitor is komorebi_core::Monitor` (see `jj log -r wip-u-kfm2`) | The monitor is the shared generic type; the corner (`window_hiding_position`) is the platform's flattened `extra` (written last, as before), the constructors, `update_*_globals`, `load_focused_workspace`, `move_container_to_workspace(1)`, `add_container_with_direction`, `hide_unfocused_workspaces` and `restore_focused_workspace` are `MonitorExt`; `focus_workspace`, `add_container`, `remove_workspace*`, `ensure_workspace_count` and the name and layout lookups are the shared ones. The monitor gives its workspaces the corner through `workspace.state` when it updates their globals. | `cargo test` (monitor tests, `state_pin`). By hand: `komorebic state | jq '.monitors.elements[0] | keys_unsorted'` is the same list as before with `window_hiding_position` last; switch workspaces on each monitor (hide and restore of the whole workspace), focus-workspace by index and by name, move a container to another workspace and to another monitor, unplug and replug a display (the monitor and its workspaces are rebuilt through `Monitor::new` and `update_all_workspace_globals`), a config with `window_hiding_position` per monitor. | Revisions in section B change no behaviour on purpose (rename, move, route); they still need the sections C walk-through, because a mechanical mistake would show there. diff --git a/komorebi-for-mac/komorebi/src/macos_api.rs b/komorebi-for-mac/komorebi/src/macos_api.rs index 400bff6b..eb0059e4 100644 --- a/komorebi-for-mac/komorebi/src/macos_api.rs +++ b/komorebi-for-mac/komorebi/src/macos_api.rs @@ -15,6 +15,7 @@ use crate::core::rect_ext::RectExt; use crate::core_graphics::CoreGraphicsApi; use crate::ioreg::IoReg; use crate::monitor::Monitor; +use crate::monitor::MonitorExt; use crate::monitor::MonitorInfo; use crate::window::RuleDebug; use crate::window::WindowInfo; diff --git a/komorebi-for-mac/komorebi/src/monitor.rs b/komorebi-for-mac/komorebi/src/monitor.rs index 7a510c52..3b56d0f7 100644 --- a/komorebi-for-mac/komorebi/src/monitor.rs +++ b/komorebi-for-mac/komorebi/src/monitor.rs @@ -1,9 +1,15 @@ +//! [`Monitor`], the workspaces a monitor shows. +//! +//! The monitor is `komorebi_core::Monitor`, shared with the other komorebi daemons, over +//! [`MacosPlatform`]. What macOS keeps in it besides the shared fields is the corner its workspaces +//! hide their windows in ([`MacosMonitorExtra`], written into the monitor's JSON as it always +//! was), and what it does differently from the shared monitor is [`MonitorExt`]. + use crate::DEFAULT_CONTAINER_PADDING; use crate::DEFAULT_WORKSPACE_PADDING; use crate::container::Container; use crate::container::ContainerExt; use crate::core::DefaultLayout; -use crate::core::FloatingLayerBehaviour; use crate::core::Layout; use crate::core::OperationDirection; use crate::core::Rect; @@ -11,7 +17,7 @@ use crate::core::WindowHidingPosition; use crate::macos_api::MacosApi; use crate::ring::Ring; use crate::skylight::BatchedUpdates; -use crate::static_config::Wallpaper; +use crate::workspace::MacosPlatform; use crate::workspace::Workspace; use crate::workspace::WorkspaceExt; use crate::workspace::WorkspaceGlobals; @@ -20,9 +26,36 @@ use color_eyre::eyre; use color_eyre::eyre::OptionExt; use serde::Deserialize; use serde::Serialize; -use std::collections::VecDeque; use std::sync::atomic::Ordering; +/// The monitor over the macOS [`Window`](crate::window::Window), which is +/// `komorebi_core::Monitor` with this platform's methods added by [`MonitorExt`] +pub type Monitor = komorebi_core::Monitor; + +/// What only macOS keeps in a monitor, written flat into its JSON +#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] +pub struct MacosMonitorExtra { + /// The corner of the monitor that its workspaces hide their windows in + pub window_hiding_position: WindowHidingPosition, +} + +impl komorebi_core::MonitorPlatform for MacosPlatform { + type Id = u32; + type SerialNumber = String; + type Extra = MacosMonitorExtra; + #[cfg(feature = "schemars")] + type IdSchema = u32; + + fn serialize_id(id: &u32, serializer: S) -> Result { + serializer.serialize_u32(*id) + } + + fn deserialize_id<'de, D: serde::Deserializer<'de>>(deserializer: D) -> Result { + u32::deserialize(deserializer) + } +} + #[derive(Debug, Serialize, Deserialize)] pub struct MonitorInfo { pub alphanumeric_serial_number: String, @@ -54,29 +87,6 @@ impl From<&Monitor> for MonitorInformation { } } -impl_ring_elements!(Monitor, Workspace); - -#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] -#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] -pub struct Monitor { - pub id: u32, - pub device: String, - pub serial_number_id: String, - pub workspaces: Ring, - pub size: Rect, - pub work_area_offset: Option, - pub work_area_size: Rect, - pub window_based_work_area_offset: Option, - pub window_based_work_area_offset_limit: isize, - pub container_padding: Option, - pub workspace_padding: Option, - #[serde(skip_serializing_if = "Option::is_none")] - pub last_focused_workspace: Option, - pub wallpaper: Option, - pub floating_layer_behaviour: Option, - pub window_hiding_position: WindowHidingPosition, -} - pub fn new( id: u32, size: Rect, @@ -102,13 +112,70 @@ pub fn new( workspace_padding: None, wallpaper: None, floating_layer_behaviour: None, - window_hiding_position: WindowHidingPosition::default(), + extra: Default::default(), } } -impl Monitor { +/// What a macOS monitor does that the shared one does not +pub trait MonitorExt { + fn new(id: u32, size: Rect, work_area_size: Rect, device: &str, serial_number_id: &str) + -> Self; + + fn placeholder() -> Self; + + fn update_focused_workspace(&mut self, offset: Option) -> eyre::Result<()>; + + /// Updates the `globals` field of workspace with index `workspace_idx` + /// Give every workspace the work area of this monitor, not only the focused one + /// + /// A workspace that is put away is hidden on the display that its work area is on, so after + /// the display of a monitor changes, the workspaces that are not showing would be hidden on + /// the display that is gone, and their windows would be left in view. + fn update_all_workspace_globals(&mut self, offset: Option); + + fn update_workspace_globals(&mut self, workspace_idx: usize, offset: Option); + + fn load_focused_workspace(&mut self, mouse_follows_focus: bool) -> eyre::Result<()>; + + /// Put the windows of every workspace but the focused one away, which is the half of + /// [`Monitor::load_focused_workspace`] that a transition can do before it is over + fn hide_unfocused_workspaces(&mut self) -> eyre::Result<()>; + + /// Bring the windows of the focused workspace back, which is the other half of + /// [`Monitor::load_focused_workspace`] + fn restore_focused_workspace(&mut self, mouse_follows_focus: bool) -> eyre::Result<()>; + + fn move_container_to_workspace( + &mut self, + target_workspace_idx: usize, + follow: bool, + direction: Option, + ) -> eyre::Result<()>; + + fn move_container_to_workspace1( + &mut self, + target_workspace_idx: usize, + follow: bool, + direction: Option, + ) -> eyre::Result<()>; + + /// Adds a container to this `Monitor` using the move direction to calculate if the container + /// should be added in front of all containers, in the back or in place of the focused + /// container, moving the rest along. The move direction should be from the origin monitor + /// towards the target monitor or from the origin workspace towards the target workspace. + fn add_container_with_direction( + &mut self, + container: Container, + workspace_idx: Option, + direction: OperationDirection, + ) -> eyre::Result<()>; + + fn update_workspaces_globals(&mut self, offset: Option); +} + +impl MonitorExt for Monitor { #[allow(clippy::field_reassign_with_default)] - pub fn new( + fn new( id: u32, size: Rect, work_area_size: Rect, @@ -133,11 +200,11 @@ impl Monitor { last_focused_workspace: None, wallpaper: None, floating_layer_behaviour: None, - window_hiding_position: WindowHidingPosition::default(), + extra: Default::default(), } } - pub fn placeholder() -> Self { + fn placeholder() -> Self { Self { // temp id: 2051316, @@ -154,12 +221,12 @@ impl Monitor { workspace_padding: None, wallpaper: None, floating_layer_behaviour: None, - window_hiding_position: WindowHidingPosition::default(), + extra: Default::default(), } } #[tracing::instrument(skip_all)] - pub fn update_focused_workspace(&mut self, offset: Option) -> eyre::Result<()> { + fn update_focused_workspace(&mut self, offset: Option) -> eyre::Result<()> { let offset = if self.work_area_offset.is_some() { self.work_area_offset } else { @@ -175,19 +242,13 @@ impl Monitor { Ok(()) } - /// Updates the `globals` field of workspace with index `workspace_idx` - /// Give every workspace the work area of this monitor, not only the focused one - /// - /// A workspace that is put away is hidden on the display that its work area is on, so after - /// the display of a monitor changes, the workspaces that are not showing would be hidden on - /// the display that is gone, and their windows would be left in view. - pub fn update_all_workspace_globals(&mut self, offset: Option) { + fn update_all_workspace_globals(&mut self, offset: Option) { for idx in 0..self.workspaces().len() { self.update_workspace_globals(idx, offset); } } - pub fn update_workspace_globals(&mut self, workspace_idx: usize, offset: Option) { + fn update_workspace_globals(&mut self, workspace_idx: usize, offset: Option) { let container_padding = self .container_padding .or(Some(DEFAULT_CONTAINER_PADDING.load(Ordering::Relaxed))); @@ -200,7 +261,7 @@ impl Monitor { let window_based_work_area_offset = self.window_based_work_area_offset; let window_based_work_area_offset_limit = self.window_based_work_area_offset_limit; let floating_layer_behaviour = self.floating_layer_behaviour; - let window_hiding_position = self.window_hiding_position; + let window_hiding_position = self.extra.window_hiding_position; if let Some(workspace) = self.workspaces_mut().get_mut(workspace_idx) { workspace.globals = WorkspaceGlobals { @@ -218,24 +279,7 @@ impl Monitor { } } - #[tracing::instrument(skip(self))] - pub fn focus_workspace(&mut self, idx: usize) -> eyre::Result<()> { - tracing::info!("focusing workspace"); - - { - let workspaces = self.workspaces_mut(); - - if workspaces.get(idx).is_none() { - workspaces.resize(idx + 1, Workspace::default()); - } - self.last_focused_workspace = Some(self.workspaces.focused_idx()); - self.workspaces.focus(idx); - } - - Ok(()) - } - - pub fn load_focused_workspace(&mut self, mouse_follows_focus: bool) -> eyre::Result<()> { + fn load_focused_workspace(&mut self, mouse_follows_focus: bool) -> eyre::Result<()> { let focused_idx = self.focused_workspace_idx(); let monitor_id = self.id; let monitor_wp = self.wallpaper.clone(); @@ -267,9 +311,7 @@ impl Monitor { Ok(()) } - /// Put the windows of every workspace but the focused one away, which is the half of - /// [`Monitor::load_focused_workspace`] that a transition can do before it is over - pub fn hide_unfocused_workspaces(&mut self) -> eyre::Result<()> { + fn hide_unfocused_workspaces(&mut self) -> eyre::Result<()> { let focused_idx = self.focused_workspace_idx(); for (i, workspace) in self.workspaces_mut().iter_mut().enumerate() { @@ -281,9 +323,7 @@ impl Monitor { Ok(()) } - /// Bring the windows of the focused workspace back, which is the other half of - /// [`Monitor::load_focused_workspace`] - pub fn restore_focused_workspace(&mut self, mouse_follows_focus: bool) -> eyre::Result<()> { + fn restore_focused_workspace(&mut self, mouse_follows_focus: bool) -> eyre::Result<()> { let monitor_id = self.id; let monitor_wp = self.wallpaper.clone(); @@ -300,12 +340,8 @@ impl Monitor { Ok(()) } - pub fn new_workspace_idx(&self) -> usize { - self.workspaces().len() - } - #[tracing::instrument(skip(self))] - pub fn move_container_to_workspace( + fn move_container_to_workspace( &mut self, target_workspace_idx: usize, follow: bool, @@ -394,7 +430,7 @@ impl Monitor { } #[tracing::instrument(skip(self))] - pub fn move_container_to_workspace1( + fn move_container_to_workspace1( &mut self, target_workspace_idx: usize, follow: bool, @@ -440,11 +476,7 @@ impl Monitor { Ok(()) } - /// Adds a container to this `Monitor` using the move direction to calculate if the container - /// should be added in front of all containers, in the back or in place of the focused - /// container, moving the rest along. The move direction should be from the origin monitor - /// towards the target monitor or from the origin workspace towards the target workspace. - pub fn add_container_with_direction( + fn add_container_with_direction( &mut self, container: Container, workspace_idx: Option, @@ -518,7 +550,7 @@ impl Monitor { Ok(()) } - pub fn update_workspaces_globals(&mut self, offset: Option) { + fn update_workspaces_globals(&mut self, offset: Option) { let container_padding = self .container_padding .or(Some(DEFAULT_CONTAINER_PADDING.load(Ordering::SeqCst))); @@ -531,7 +563,7 @@ impl Monitor { let window_based_work_area_offset = self.window_based_work_area_offset; let window_based_work_area_offset_limit = self.window_based_work_area_offset_limit; let floating_layer_behaviour = self.floating_layer_behaviour; - let window_hiding_position = self.window_hiding_position; + let window_hiding_position = self.extra.window_hiding_position; for workspace in self.workspaces_mut() { workspace.globals = WorkspaceGlobals { @@ -548,66 +580,6 @@ impl Monitor { workspace.state.window_hiding_position = window_hiding_position; } } - - pub fn remove_workspace_by_idx(&mut self, idx: usize) -> Option { - if idx < self.workspaces().len() { - return self.workspaces_mut().remove(idx); - } - - if idx == 0 { - self.workspaces_mut().push_back(Workspace::default()); - } else { - self.focus_workspace(idx.saturating_sub(1)).ok()?; - }; - - None - } - - pub fn add_container( - &mut self, - container: Container, - workspace_idx: Option, - ) -> eyre::Result<()> { - let workspace = if let Some(idx) = workspace_idx { - self.workspaces_mut() - .get_mut(idx) - .ok_or_eyre(format!("there is no workspace at index {}", idx))? - } else { - self.focused_workspace_mut() - .ok_or_eyre("there is no workspace")? - }; - - workspace.add_container_to_back(container); - - Ok(()) - } - - pub fn remove_workspaces(&mut self) -> VecDeque { - std::mem::take(self.workspaces_mut()) - } - - pub fn ensure_workspace_count(&mut self, ensure_count: usize) { - if self.workspaces().len() < ensure_count { - self.workspaces_mut() - .resize(ensure_count, Workspace::default()); - } - } - - pub fn focused_workspace_name(&self) -> Option { - self.focused_workspace() - .map(|w| w.name.clone()) - .unwrap_or(None) - } - - pub fn focused_workspace_layout(&self) -> Option { - self.focused_workspace().and_then(|workspace| { - if workspace.tile { - Some(workspace.layout.clone()) - } else { - None - } - }) - } } #[cfg(test)] @@ -897,3 +869,43 @@ mod tests { assert_eq!(m.workspaces().len(), 5, "Monitor should have 5 workspaces"); } } + +#[cfg(test)] +mod state_pin { + use super::*; + + /// `komorebic state` prints a monitor with these keys in this order, the corner last: the + /// macOS monitor is the shared `komorebi_core::Monitor`, whose platform fields are flattened + /// at the end. + #[test] + fn a_monitor_is_written_with_the_keys_it_always_had_and_the_corner_last() { + let mut monitor = new(7, Rect::default(), Rect::default(), "d".into(), "s".into()); + monitor.workspaces_mut().clear(); + let json = serde_json::to_string(&monitor).unwrap(); + + let keys = [ + "\"id\":7", + "\"device\"", + "\"serial_number_id\"", + "\"workspaces\"", + "\"size\"", + "\"work_area_offset\"", + "\"work_area_size\"", + "\"window_based_work_area_offset\"", + "\"window_based_work_area_offset_limit\"", + "\"container_padding\"", + "\"workspace_padding\"", + "\"wallpaper\"", + "\"floating_layer_behaviour\"", + "\"window_hiding_position\"", + ]; + + let mut at = 0; + for key in keys { + let found = json[at..] + .find(key) + .unwrap_or_else(|| panic!("{key} is missing or out of order in {json}")); + at += found + key.len(); + } + } +} diff --git a/komorebi-for-mac/komorebi/src/monitor_reconciliator.rs b/komorebi-for-mac/komorebi/src/monitor_reconciliator.rs index 2d943c5e..0642f567 100644 --- a/komorebi-for-mac/komorebi/src/monitor_reconciliator.rs +++ b/komorebi-for-mac/komorebi/src/monitor_reconciliator.rs @@ -6,6 +6,7 @@ use crate::border_manager; use crate::core::config_generation::WorkspaceMatchingRule; use crate::macos_api::MacosApi; use crate::monitor::Monitor; +use crate::monitor::MonitorExt; use crate::notify_subscribers; use crate::state::State; use crate::window_manager::WindowManager; @@ -447,7 +448,7 @@ pub fn handle_notifications(wm: Arc>) -> color_eyre::Result workspace_padding: cached.workspace_padding, wallpaper: cached.wallpaper.clone(), floating_layer_behaviour: cached.floating_layer_behaviour, - window_hiding_position: cached.window_hiding_position, + extra: cached.extra.clone(), }; let focused_workspace_idx = m.focused_workspace_idx(); diff --git a/komorebi-for-mac/komorebi/src/process_command.rs b/komorebi-for-mac/komorebi/src/process_command.rs index c799eba7..af0e0757 100644 --- a/komorebi-for-mac/komorebi/src/process_command.rs +++ b/komorebi-for-mac/komorebi/src/process_command.rs @@ -1,5 +1,3 @@ -use crate::workspace::WorkspaceExt; -use crate::scrolling::WorkspaceScrolling; use crate::DATA_DIR; use crate::DISPLAY_INDEX_PREFERENCES; use crate::FLOATING_APPLICATIONS; @@ -38,6 +36,9 @@ use crate::core::config_generation::IdWithIdentifier; use crate::core::config_generation::MatchingRule; use crate::core::config_generation::MatchingStrategy; use crate::core::config_generation::WorkspaceMatchingRule; +use crate::monitor::MonitorExt; +use crate::scrolling::WorkspaceScrolling; +use crate::workspace::WorkspaceExt; use crate::core_graphics::CoreGraphicsApi; use crate::current_space_id; @@ -618,6 +619,7 @@ impl WindowManager { let hiding_position = self .focused_monitor() .ok_or_eyre("there is no monitor")? + .extra .window_hiding_position; let workspace = self.focused_workspace_mut()?; @@ -637,8 +639,7 @@ impl WindowManager { // Sort by window area window_idx_pairs.sort_by_key(|(_, w)| { - let rect = - Rect::from(w.window_rect().unwrap_or_default()); + let rect = Rect::from(w.window_rect().unwrap_or_default()); rect.right * rect.bottom }); window_idx_pairs.reverse(); @@ -707,9 +708,7 @@ impl WindowManager { // Sort by window area window_idx_pairs.sort_by_key(|w| { - let rect = Rect::from( - w.window_rect().unwrap_or_default(), - ); + let rect = Rect::from(w.window_rect().unwrap_or_default()); rect.right * rect.bottom }); @@ -1882,8 +1881,7 @@ impl WindowManager { | SocketMessage::WatchConfiguration(..) | SocketMessage::WindowHidingBehaviour(..) | SocketMessage::WorkspaceLayoutCustom(..) - | SocketMessage::WorkspaceLayoutCustomRule(..) - => { + | SocketMessage::WorkspaceLayoutCustomRule(..) => { reply.write_all(message.not_supported_reply().as_bytes())?; return Ok(()); } @@ -1911,10 +1909,7 @@ impl WindowManager { } } -pub fn read_commands_uds( - wm: &Arc>, - stream: UnixStream, -) -> eyre::Result<()> { +pub fn read_commands_uds(wm: &Arc>, stream: UnixStream) -> eyre::Result<()> { komorebi_transport::read_commands::(wm, stream, &NoPolicy) } diff --git a/komorebi-for-mac/komorebi/src/state.rs b/komorebi-for-mac/komorebi/src/state.rs index ef3c942f..046838c2 100644 --- a/komorebi-for-mac/komorebi/src/state.rs +++ b/komorebi-for-mac/komorebi/src/state.rs @@ -163,7 +163,7 @@ impl From<&WindowManager> for State { workspace_padding: monitor.workspace_padding, wallpaper: monitor.wallpaper.clone(), floating_layer_behaviour: monitor.floating_layer_behaviour, - window_hiding_position: monitor.window_hiding_position, + extra: monitor.extra.clone(), }) .collect::>(); stripped_monitors.focus(wm.monitors.focused_idx()); diff --git a/komorebi-for-mac/komorebi/src/static_config.rs b/komorebi-for-mac/komorebi/src/static_config.rs index f29ca071..041a2811 100644 --- a/komorebi-for-mac/komorebi/src/static_config.rs +++ b/komorebi-for-mac/komorebi/src/static_config.rs @@ -42,6 +42,7 @@ use crate::core::config_generation::WorkspaceMatchingRule; use crate::current_space_id; use crate::monitor; use crate::monitor::Monitor; +use crate::monitor::MonitorExt; use crate::monitor_reconciliator; use crate::ring::Ring; use crate::theme_manager; @@ -183,43 +184,42 @@ fn workspace_config(value: &Workspace) -> WorkspaceConfig { } } -impl From<&Monitor> for MonitorConfig { - fn from(value: &Monitor) -> Self { - let mut workspaces = vec![]; - for w in value.workspaces() { - workspaces.push(workspace_config(w)); +/// The configuration entry that a monitor would be loaded from (what `komorebic` writes out) +fn monitor_config(value: &Monitor) -> MonitorConfig { + let mut workspaces = vec![]; + for w in value.workspaces() { + workspaces.push(workspace_config(w)); + } + + let default_container_padding = DEFAULT_CONTAINER_PADDING.load(Ordering::SeqCst); + let default_workspace_padding = DEFAULT_WORKSPACE_PADDING.load(Ordering::SeqCst); + + let container_padding = value.container_padding.and_then(|container_padding| { + if container_padding == default_container_padding { + None + } else { + Option::from(container_padding) } + }); - let default_container_padding = DEFAULT_CONTAINER_PADDING.load(Ordering::SeqCst); - let default_workspace_padding = DEFAULT_WORKSPACE_PADDING.load(Ordering::SeqCst); - - let container_padding = value.container_padding.and_then(|container_padding| { - if container_padding == default_container_padding { - None - } else { - Option::from(container_padding) - } - }); - - let workspace_padding = value.workspace_padding.and_then(|workspace_padding| { - if workspace_padding == default_workspace_padding { - None - } else { - Option::from(workspace_padding) - } - }); - - Self { - workspaces, - work_area_offset: value.work_area_offset, - window_based_work_area_offset: value.window_based_work_area_offset, - window_based_work_area_offset_limit: Some(value.window_based_work_area_offset_limit), - container_padding, - workspace_padding, - wallpaper: value.wallpaper.clone(), - floating_layer_behaviour: value.floating_layer_behaviour, - window_hiding_position: Some(value.window_hiding_position), + let workspace_padding = value.workspace_padding.and_then(|workspace_padding| { + if workspace_padding == default_workspace_padding { + None + } else { + Option::from(workspace_padding) } + }); + + MonitorConfig { + workspaces, + work_area_offset: value.work_area_offset, + window_based_work_area_offset: value.window_based_work_area_offset, + window_based_work_area_offset_limit: Some(value.window_based_work_area_offset_limit), + container_padding, + workspace_padding, + wallpaper: value.wallpaper.clone(), + floating_layer_behaviour: value.floating_layer_behaviour, + window_hiding_position: Some(value.extra.window_hiding_position), } } @@ -268,7 +268,7 @@ impl From<&WindowManager> for StaticConfig { fn from(value: &WindowManager) -> Self { let mut monitors = vec![]; for m in value.monitors() { - monitors.push(MonitorConfig::from(m)); + monitors.push(monitor_config(m)); } let border_colours = if border_manager::FOCUSED.load(Ordering::SeqCst) == 0 { @@ -891,7 +891,7 @@ impl StaticConfigExt for StaticConfig { monitor.workspace_padding = monitor_config.workspace_padding; monitor.wallpaper = monitor_config.wallpaper.clone(); monitor.floating_layer_behaviour = monitor_config.floating_layer_behaviour; - monitor.window_hiding_position = + monitor.extra.window_hiding_position = monitor_config.window_hiding_position.unwrap_or_default(); monitor.update_workspaces_globals(offset); @@ -965,7 +965,7 @@ impl StaticConfigExt for StaticConfig { m.container_padding = monitor_config.container_padding; m.workspace_padding = monitor_config.workspace_padding; m.floating_layer_behaviour = monitor_config.floating_layer_behaviour; - m.window_hiding_position = + m.extra.window_hiding_position = monitor_config.window_hiding_position.unwrap_or_default(); m.update_workspaces_globals(offset); @@ -1055,7 +1055,7 @@ impl StaticConfigExt for StaticConfig { monitor.workspace_padding = monitor_config.workspace_padding; monitor.wallpaper = monitor_config.wallpaper.clone(); monitor.floating_layer_behaviour = monitor_config.floating_layer_behaviour; - monitor.window_hiding_position = + monitor.extra.window_hiding_position = monitor_config.window_hiding_position.unwrap_or_default(); monitor.update_workspaces_globals(offset); @@ -1130,7 +1130,7 @@ impl StaticConfigExt for StaticConfig { m.container_padding = monitor_config.container_padding; m.workspace_padding = monitor_config.workspace_padding; m.floating_layer_behaviour = monitor_config.floating_layer_behaviour; - m.window_hiding_position = + m.extra.window_hiding_position = monitor_config.window_hiding_position.unwrap_or_default(); m.update_workspaces_globals(offset); diff --git a/komorebi-for-mac/komorebi/src/window_manager.rs b/komorebi-for-mac/komorebi/src/window_manager.rs index 042f3a43..2f3f0471 100644 --- a/komorebi-for-mac/komorebi/src/window_manager.rs +++ b/komorebi-for-mac/komorebi/src/window_manager.rs @@ -1,3 +1,4 @@ +use crate::monitor::MonitorExt; use crate::AccessibilityUiElement; use crate::CoreFoundationRunLoop; use crate::DATA_DIR; @@ -1547,7 +1548,7 @@ impl WindowManager { let hiding_position = self .focused_monitor() .ok_or_eyre("there is no monitor")? - .window_hiding_position; + .extra.window_hiding_position; let workspace = self.focused_workspace_mut()?; workspace.new_monocle_container()?; @@ -1583,7 +1584,7 @@ impl WindowManager { let hiding_position = self .focused_monitor() .ok_or_eyre("there is no monitor")? - .window_hiding_position; + .extra.window_hiding_position; self.focused_workspace_mut()? .cycle_monocle_container(direction)?; diff --git a/komorebi-for-mac/komorebi/src/workspace_reconciliator.rs b/komorebi-for-mac/komorebi/src/workspace_reconciliator.rs index a066e37e..7de79476 100644 --- a/komorebi-for-mac/komorebi/src/workspace_reconciliator.rs +++ b/komorebi-for-mac/komorebi/src/workspace_reconciliator.rs @@ -1,5 +1,6 @@ #![deny(clippy::unwrap_used, clippy::expect_used)] +use crate::monitor::MonitorExt; use crate::window_manager::WindowManager; use crate::window_manager_event::WindowManagerEvent; use crossbeam_channel::Receiver;