diff --git a/crates/komorebi-bar-core/Cargo.toml b/crates/komorebi-bar-core/Cargo.toml index c788591e..cac9f4ed 100644 --- a/crates/komorebi-bar-core/Cargo.toml +++ b/crates/komorebi-bar-core/Cargo.toml @@ -28,4 +28,10 @@ schemars = { workspace = true, optional = true } [features] default = ["schemars"] -schemars = ["dep:schemars", "komorebi-config/schemars", "komorebi-layouts/schemars", "komorebi-themes/schemars", "komorebi-protocol/schemars"] +schemars = [ + "dep:schemars", + "komorebi-config/schemars", + "komorebi-layouts/schemars", + "komorebi-themes/schemars", + "komorebi-protocol/schemars", +] diff --git a/crates/komorebi-bar-core/src/platform.rs b/crates/komorebi-bar-core/src/platform.rs index c7c2316e..7117872d 100644 --- a/crates/komorebi-bar-core/src/platform.rs +++ b/crates/komorebi-bar-core/src/platform.rs @@ -31,6 +31,9 @@ pub trait BarPlatform: Send + Sync { /// The GitHub API URL that says which release of this platform's komorebi is the latest. fn latest_release_api_url(&self) -> &'static str; + /// The page of this platform's release `version` that the update widget opens when clicked. + fn release_page_url(&self, version: &str) -> String; + /// The icon of the program a command string would start (Windows: the executable's icon; /// macOS: none). fn command_icon(&self, command: &str) -> Option; diff --git a/crates/komorebi-bar-core/src/widgets/update.rs b/crates/komorebi-bar-core/src/widgets/update.rs index 04c068ea..c7bd51be 100644 --- a/crates/komorebi-bar-core/src/widgets/update.rs +++ b/crates/komorebi-bar-core/src/widgets/update.rs @@ -83,7 +83,7 @@ impl Update { { let client = reqwest::blocking::Client::new(); if let Ok(response) = client - .get("https://api.github.com/repos/LGUG2Z/komorebi/releases/latest") + .get(platform().latest_release_api_url()) .header("User-Agent", "komorebi-bar-version-checker") .send() { @@ -143,10 +143,9 @@ impl BarWidget for Update { if SelectableFrame::new(false) .show(ui, |ui| ui.add(Label::new(layout_job).selectable(false))) .clicked() - && let Err(error) = platform().open_system_tool(SystemTool::Url(format!( - "https://github.com/LGUG2Z/komorebi/releases/v{}", - self.latest_version - ))) + && let Err(error) = platform().open_system_tool(SystemTool::Url( + platform().release_page_url(&self.latest_version), + )) { eprintln!("{error}") } diff --git a/crates/komorebi-core/src/workspace.rs b/crates/komorebi-core/src/workspace.rs index 67e8f689..9462957d 100644 --- a/crates/komorebi-core/src/workspace.rs +++ b/crates/komorebi-core/src/workspace.rs @@ -1378,13 +1378,13 @@ impl Workspace

{ 0 | 1 => self.enforce_no_resize(), _ => { // Zero is actually on the right - if let Some(left) = resize_dimensions[1].as_mut() { - left.top = 0; - left.bottom = 0; - left.right = 0; + if let Some(right) = resize_dimensions[0].as_mut() { + right.top = 0; + right.bottom = 0; + right.right = 0; } - // Handle stack on the right + // Handle stack on the left let stack_size = resize_dimensions[1..].len(); for (i, rect) in resize_dimensions[1..].iter_mut().enumerate() { if let Some(rect) = rect { diff --git a/crates/komorebi-core/tests/e2e_layouts.rs b/crates/komorebi-core/tests/e2e_layouts.rs new file mode 100644 index 00000000..fb0bc47f --- /dev/null +++ b/crates/komorebi-core/tests/e2e_layouts.rs @@ -0,0 +1,244 @@ +//! What the Windows `layouts`, `flipping`, `layout_flip`, `padding`, `closing`, `tiling` and +//! `stacks` scenarios (shared with KDE, and the only place macOS-or-Windows tiling used to be +//! checked) assert about where `Workspace::update_shared` puts the windows, run on the stub +//! platform: the tiles the shared code hands to the platform (`latest_layout`, which the scenarios +//! compare the OS frames with) for every layout, count, padding and flip. +//! +//! These protect all three daemons (Windows, KDE, macOS: each calls `update_shared`). Platform +//! choice: the stub platform adds no border and adjusts nothing, so a daemon's own `adjust_layout` +//! (the Windows border of 7 px, macOS or KDE frame corrections) is NOT covered and stays e2e +//! (`windows_padding`). +//! +//! The Windows fixture `kfw-tiled.json` of the e2e library is the same state shape these +//! workspaces serialize to (see `state_roundtrip.rs`). + +mod common; + +use common::*; +use komorebi_core::Workspace; +use komorebi_layouts::Axis; +use komorebi_layouts::DefaultLayout; +use komorebi_layouts::Layout; +use komorebi_layouts::Rect; + +const LAYOUTS: [DefaultLayout; 8] = [ + DefaultLayout::BSP, + DefaultLayout::Columns, + DefaultLayout::Rows, + DefaultLayout::VerticalStack, + DefaultLayout::HorizontalStack, + DefaultLayout::UltrawideVerticalStack, + DefaultLayout::Grid, + DefaultLayout::RightMainVerticalStack, +]; + +const AREA: Rect = Rect { + left: 0, + top: 0, + right: 1920, + bottom: 1080, +}; + +fn workspace( + layout: DefaultLayout, + ids: &[u32], + container_padding: Option, + workspace_padding: Option, + flip: Option, +) -> Workspace { + let mut workspace = workspace_of(ids); + workspace.layout = Layout::Default(layout); + workspace.layout_flip = flip; + workspace.globals.work_area = AREA; + workspace.globals.container_padding = container_padding; + workspace.globals.workspace_padding = workspace_padding; + workspace +} + +fn tiles( + layout: DefaultLayout, + count: u32, + container_padding: Option, + workspace_padding: Option, + flip: Option, +) -> Vec { + fresh(); + let ids: Vec = (1..=count).collect(); + let mut workspace = workspace(layout, &ids, container_padding, workspace_padding, flip); + workspace.update_shared().unwrap(); + workspace.latest_layout.clone() +} + +fn inside(r: &Rect, a: &Rect) -> bool { + r.left >= a.left + && r.top >= a.top + && r.left + r.right <= a.left + a.right + && r.top + r.bottom <= a.top + a.bottom +} + +fn overlap(a: &Rect, b: &Rect) -> bool { + a.left < b.left + b.right + && b.left < a.left + a.right + && a.top < b.top + b.bottom + && b.top < a.top + a.bottom +} + +fn area(r: &Rect) -> i64 { + i64::from(r.right) * i64::from(r.bottom) +} + +// mirrors: layouts / , windows: every window is where the layout says +// mirrors: layouts / ... inside the work area +// mirrors: layouts / ... and not on each other +// mirrors: tiling / every window is where the layout says; and do not overlap +#[test] +fn every_layout_tiles_every_container_inside_the_work_area_and_off_the_others() { + for layout in LAYOUTS { + for count in 1..=8 { + for (cp, wp) in [(None, None), (Some(10), Some(20)), (Some(0), Some(0))] { + let t = tiles(layout, count, cp, wp, None); + assert_eq!(t.len(), count as usize, "{layout} {count}"); + for (i, r) in t.iter().enumerate() { + assert!( + inside(r, &AREA), + "{layout} {count} {cp:?}/{wp:?}: {i} {r:?}" + ); + assert!( + r.right > 0 && r.bottom > 0, + "{layout} {count}: {i} is empty" + ); + for (j, o) in t.iter().enumerate().skip(i + 1) { + assert!(!overlap(r, o), "{layout} {count}: {i} {r:?} over {j} {o:?}"); + } + } + } + } + } +} + +// mirrors: padding / a workspace padding 40 px more moves the windows 40 px in from the edge +// mirrors: padding / a container padding 30 px more leaves the windows less room +// mirrors: padding / with the padding as it was, the windows are as far from the edge as they were +#[test] +fn the_workspace_padding_moves_the_tiles_in_and_the_container_padding_shrinks_them() { + for layout in LAYOUTS { + let base = tiles(layout, 3, None, None, None); + let more = tiles(layout, 3, None, Some(40), None); + let edge = |t: &[Rect]| t.iter().map(|r| r.left).min().unwrap(); + assert_eq!( + edge(&more), + edge(&base) + 40, + "{layout}: workspace padding 40" + ); + assert!(inside(more.first().unwrap(), &AREA)); + + let padded = tiles(layout, 3, Some(30), None, None); + for (a, b) in base.iter().zip(&padded) { + assert!( + area(b) < area(a), + "{layout}: container padding 30 did not shrink {a:?}" + ); + } + + assert_eq!( + base, + tiles(layout, 3, None, None, None), + "{layout}: back as it was" + ); + } +} + +// mirrors: flipping / after 'flip-layout horizontal' every window is where the mirror of its place is +// mirrors: flipping / flipped again, every window is where it was +// mirrors: layout_flip /