Skip to content

Commit

Permalink
monitors: Add scaling test
Browse files Browse the repository at this point in the history
  • Loading branch information
DashieTM committed Jun 11, 2024
1 parent da88c29 commit b95d555
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 41 deletions.
46 changes: 8 additions & 38 deletions monitors/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion monitors/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
2 changes: 1 addition & 1 deletion monitors/src/frontend/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
35 changes: 34 additions & 1 deletion monitors/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
};

Expand Down Expand Up @@ -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<RefCell<Vec<Monitor>>> {
let mut dragging_monitor = Monitor {
id: 2,
Expand All @@ -183,6 +214,8 @@ fn create_monitor_pair(offset: Offset) -> Rc<RefCell<Vec<Monitor>>> {
drag_information: DragInformation {
width: 500,
height: 500,
origin_x: 1000,
origin_y: 1000,
..Default::default()
},
..Default::default()
Expand Down

0 comments on commit b95d555

Please sign in to comment.