From b95d555a426e56be7c343502cfedb72d3750d9ef Mon Sep 17 00:00:00 2001 From: DashieTM Date: Tue, 11 Jun 2024 18:13:28 +0200 Subject: [PATCH] monitors: Add scaling test --- monitors/Cargo.lock | 46 ++++++------------------------- monitors/Cargo.toml | 1 - monitors/src/frontend/handlers.rs | 2 +- monitors/src/tests.rs | 35 ++++++++++++++++++++++- 4 files changed, 43 insertions(+), 41 deletions(-) diff --git a/monitors/Cargo.lock b/monitors/Cargo.lock index c0d2ce5..3fc9592 100644 --- a/monitors/Cargo.lock +++ b/monitors/Cargo.lock @@ -568,12 +568,6 @@ version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" -[[package]] -name = "hermit-abi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" - [[package]] name = "indexmap" version = "2.2.6" @@ -761,16 +755,6 @@ dependencies = [ "autocfg", ] -[[package]] -name = "num_cpus" -version = "1.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" -dependencies = [ - "hermit-abi", - "libc", -] - [[package]] name = "object" version = "0.35.0" @@ -940,7 +924,6 @@ dependencies = [ "re_set-lib", "serde", "serde_json", - "tokio", "wayland-client", "wayland-protocols-plasma", "wayland-protocols-wlr", @@ -1173,24 +1156,11 @@ dependencies = [ "backtrace", "libc", "mio", - "num_cpus", "pin-project-lite", "socket2", - "tokio-macros", "windows-sys 0.48.0", ] -[[package]] -name = "tokio-macros" -version = "2.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f5ae998a069d4b5aba8ee9dad856af7d520c3699e6159b185c2acd48155d39a" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.66", -] - [[package]] name = "toml" version = "0.8.13" @@ -1256,9 +1226,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wayland-backend" -version = "0.3.3" +version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d50fa61ce90d76474c87f5fc002828d81b32677340112b4ef08079a9d459a40" +checksum = "34e9e6b6d4a2bb4e7e69433e0b35c7923b95d4dc8503a84d25ec917a4bbfdf07" dependencies = [ "cc", "downcast-rs", @@ -1270,9 +1240,9 @@ dependencies = [ [[package]] name = "wayland-client" -version = "0.31.2" +version = "0.31.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "82fb96ee935c2cea6668ccb470fb7771f6215d1691746c2d896b447a00ad3f1f" +checksum = "1e63801c85358a431f986cffa74ba9599ff571fc5774ac113ed3b490c19a1133" dependencies = [ "bitflags 2.5.0", "rustix", @@ -1320,9 +1290,9 @@ dependencies = [ [[package]] name = "wayland-scanner" -version = "0.31.1" +version = "0.31.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "63b3a62929287001986fb58c789dce9b67604a397c15c611ad9f747300b6c283" +checksum = "67da50b9f80159dec0ea4c11c13e24ef9e7574bd6ce24b01860a175010cea565" dependencies = [ "proc-macro2", "quick-xml", @@ -1331,9 +1301,9 @@ dependencies = [ [[package]] name = "wayland-sys" -version = "0.31.1" +version = "0.31.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "15a0c8eaff5216d07f226cb7a549159267f3467b289d9a2e52fd3ef5aae2b7af" +checksum = "105b1842da6554f91526c14a2a2172897b7f745a805d62af4ce698706be79c12" dependencies = [ "dlib", "log", diff --git a/monitors/Cargo.toml b/monitors/Cargo.toml index e707afe..db4c912 100644 --- a/monitors/Cargo.toml +++ b/monitors/Cargo.toml @@ -21,7 +21,6 @@ wayland-protocols-plasma = { version = "0.2.0", features = ["client"] } wayland-protocols-wlr = { version = "0.2.0", features = ["client"] } wayland-client = "0.31.0" once_cell = "1.19.0" -tokio = { version = "1.33.0", features = ["rt", "time", "net", "macros", "rt-multi-thread", "sync"] } [build-dependencies] glib-build-tools = "0.19.0" diff --git a/monitors/src/frontend/handlers.rs b/monitors/src/frontend/handlers.rs index 2f9aa2e..e4e368c 100644 --- a/monitors/src/frontend/handlers.rs +++ b/monitors/src/frontend/handlers.rs @@ -1162,7 +1162,7 @@ fn is_nonfunctional_scale(width: i32, height: i32, scale: f64) -> bool { width as f64 % scale != 0.0 && height as f64 % scale != 0.0 && scale != 1.0 } -fn search_nearest_scale( +pub fn search_nearest_scale( amount: usize, search_scale: &mut f64, monitor: &Monitor, diff --git a/monitors/src/tests.rs b/monitors/src/tests.rs index 8911d92..d2e258e 100644 --- a/monitors/src/tests.rs +++ b/monitors/src/tests.rs @@ -6,7 +6,7 @@ use crate::{ hyprland::{HyprMonitor, HYPRFEATURES}, kde::{KDEMode, KDEMonitor, KDE_FEATURES}, }, - frontend::handlers::monitor_drag_end, + frontend::handlers::{monitor_drag_end, search_nearest_scale}, utils::{AvailableMode, DragInformation, Monitor, Offset, Size}, }; @@ -173,6 +173,37 @@ fn snap_right_to_right() { assert_eq!(monitors.get(1).unwrap().offset.1, -500); } +#[test] +fn snap_intersect() { + // detect intersect and move to origin + let monitors = create_monitor_pair(Offset(400, 0)); + let monitors = monitors.borrow(); + assert_eq!(monitors.get(1).unwrap().offset.0, 1000); + assert_eq!(monitors.get(1).unwrap().offset.1, 1000); +} + +#[test] +fn search_upper_scale() { + let monitor = Monitor { + size: Size(1920, 1200), + scale: 1.0, + ..Default::default() + }; + let scale: f64 = 1.08; + // 1920 * 1.08 -> 2073.60000... + // not a valid resolution + let mut search_scale = (scale * 120.0).round(); + let mut found = false; + search_nearest_scale(6, &mut search_scale, &monitor, true, &mut found, true); + if !found { + search_nearest_scale(100, &mut search_scale, &monitor, true, &mut found, false); + } + assert!(found); + assert_eq!((search_scale * 100.0).round() / 100.0, 1.07); + // 1920 * 1.0666666667 -> 2048 + // Ok +} + fn create_monitor_pair(offset: Offset) -> Rc>> { let mut dragging_monitor = Monitor { id: 2, @@ -183,6 +214,8 @@ fn create_monitor_pair(offset: Offset) -> Rc>> { drag_information: DragInformation { width: 500, height: 500, + origin_x: 1000, + origin_y: 1000, ..Default::default() }, ..Default::default()