From 1d41792700b64ac71d60e511f9d629e8ef8ab689 Mon Sep 17 00:00:00 2001 From: Michael Aaron Murphy Date: Thu, 15 Feb 2024 04:18:46 +0100 Subject: [PATCH] fix(display): adjust size of output based on scale --- app/src/pages/display/arrangement.rs | 26 ++++++++++---------------- app/src/pages/display/mod.rs | 6 ++---- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/app/src/pages/display/arrangement.rs b/app/src/pages/display/arrangement.rs index 3af9b5c..3699878 100644 --- a/app/src/pages/display/arrangement.rs +++ b/app/src/pages/display/arrangement.rs @@ -89,7 +89,7 @@ impl<'a, Message: Clone> Widget for Arrangemen let mut max_dimensions = (0, 0); let mut display_area = (0, 0); - for (_key, output) in self.list.outputs.iter() { + for output in self.list.outputs.values() { if !output.enabled { continue; } @@ -102,12 +102,16 @@ impl<'a, Message: Clone> Widget for Arrangemen continue; }; - let (width, height) = if output.transform.map_or(true, is_landscape) { + let (mut width, mut height) = if output.transform.map_or(true, is_landscape) { (mode.size.0, mode.size.1) } else { (mode.size.1, mode.size.0) }; + // Scale dimensions of the display with the output scale. + width = (width as f64 / output.scale) as u32; + height = (height as f64 / output.scale) as u32; + max_dimensions.0 = max_dimensions.0.max(width); max_dimensions.1 = max_dimensions.1.max(height); @@ -115,8 +119,8 @@ impl<'a, Message: Clone> Widget for Arrangemen display_area.1 = display_area.1.max(height as i32 + output.position.1); } - let width = (max_dimensions.0 as i32 * 3 + display_area.0) as f32 / UNIT_PIXELS; - let height = (max_dimensions.1 as i32 * 3 + display_area.1) as f32 / UNIT_PIXELS; + let width = (max_dimensions.0 as i32 * 2 + display_area.0) as f32 / UNIT_PIXELS; + let height = (max_dimensions.1 as i32 * 2 + display_area.1) as f32 / UNIT_PIXELS; let state = tree.state.downcast_mut::(); state.max_dimensions = ( @@ -382,8 +386,8 @@ fn display_regions<'a>( }; let (mut width, mut height) = ( - (mode.size.0 as f32) / UNIT_PIXELS, - (mode.size.1 as f32) / UNIT_PIXELS, + (mode.size.0 as f32 / output.scale as f32) / UNIT_PIXELS, + (mode.size.1 as f32 / output.scale as f32) / UNIT_PIXELS, ); (width, height) = if output.transform.map_or(true, is_landscape) { @@ -432,11 +436,6 @@ fn update_dragged_region( ) { let mut dragged_region = Rectangle { x, y, ..*region }; - // Prevent display from exceeding boundaries. - if !dragged_region.is_within_strict(bounds) { - return; - } - let mut nearest = f32::MAX; let mut nearest_region = Rectangle::default(); let mut nearest_side = NearestSide::East; @@ -537,11 +536,6 @@ fn update_dragged_region( dragged_region.y = nearest_region.y + nearest_region.height - dragged_region.height; } - // Prevent display from exceeding boundaries. - if !dragged_region.is_within_strict(bounds) { - return; - } - // Prevent display from overlapping with other displays. for (other_output, other_region) in display_regions(model, list, bounds, max_dimensions) { if other_output == output { diff --git a/app/src/pages/display/mod.rs b/app/src/pages/display/mod.rs index c34b6ea..b693a57 100644 --- a/app/src/pages/display/mod.rs +++ b/app/src/pages/display/mod.rs @@ -9,6 +9,7 @@ use crate::{app, pages}; use apply::Apply; use arrangement::Arrangement; use cosmic::iced::Length; +use cosmic::iced_core::Alignment; use cosmic::iced_widget::scrollable::{Direction, Properties}; use cosmic::widget::{ column, container, dropdown, list_column, segmented_button, toggler, view_switcher, @@ -371,10 +372,7 @@ impl Page { .on_placement(|id, x, y| pages::Message::Displays(Message::Position(id, x, y))) .apply(cosmic::widget::scrollable) .width(Length::Shrink) - .direction(Direction::Both { - horizontal: Properties::new(), - vertical: Properties::new(), - }) + .direction(Direction::Horizontal(Properties::new())) .apply(container) .center_x() .width(Length::Fill)