fix(displays): reduce height of display arrangement widget

This commit is contained in:
Michael Aaron Murphy 2024-10-08 17:20:15 +02:00 committed by Michael Murphy
parent 2a76db48e2
commit 3c4742b7f6

View file

@ -15,6 +15,8 @@ use cosmic_randr_shell::{self as randr, OutputKey};
use randr::Transform; use randr::Transform;
const UNIT_PIXELS: f32 = 12.0; const UNIT_PIXELS: f32 = 12.0;
const VERTICAL_OVERHEAD: f32 = 1.5;
const VERTICAL_DISPLAY_OVERHEAD: f32 = 4.0;
pub type OnPlacementFunc<Message> = Box<dyn Fn(OutputKey, i32, i32) -> Message>; pub type OnPlacementFunc<Message> = Box<dyn Fn(OutputKey, i32, i32) -> Message>;
pub type OnSelectFunc<Message> = Box<dyn Fn(segmented_button::Entity) -> Message>; pub type OnSelectFunc<Message> = Box<dyn Fn(segmented_button::Entity) -> Message>;
@ -100,6 +102,7 @@ impl<'a, Message: Clone> Widget<Message, cosmic::Theme, Renderer> for Arrangemen
limits: &layout::Limits, limits: &layout::Limits,
) -> layout::Node { ) -> layout::Node {
// Determine the max display dimensions, and the total display area utilized. // Determine the max display dimensions, and the total display area utilized.
let mut total_height = 0;
let mut max_dimensions = (0, 0); let mut max_dimensions = (0, 0);
let mut display_area = (0, 0); let mut display_area = (0, 0);
@ -131,17 +134,20 @@ impl<'a, Message: Clone> Widget<Message, cosmic::Theme, Renderer> for Arrangemen
display_area.0 = display_area.0.max(width as i32 + output.position.0); display_area.0 = display_area.0.max(width as i32 + output.position.0);
display_area.1 = display_area.1.max(height as i32 + output.position.1); display_area.1 = display_area.1.max(height as i32 + output.position.1);
total_height = total_height.max(height as i32 + output.position.1);
} }
let width = ((max_dimensions.0 as f32 * 2.0) as i32 + display_area.0) as f32 / UNIT_PIXELS;
let height = ((max_dimensions.1 as f32 * 2.0) as i32 + display_area.1) as f32 / UNIT_PIXELS;
let state = tree.state.downcast_mut::<State>(); let state = tree.state.downcast_mut::<State>();
state.max_dimensions = ( state.max_dimensions = (
max_dimensions.0 as f32 / UNIT_PIXELS, max_dimensions.0 as f32 / UNIT_PIXELS,
max_dimensions.1 as f32 / UNIT_PIXELS, total_height as f32 / UNIT_PIXELS,
); );
let width = ((max_dimensions.0 as f32 * 2.0) as i32 + display_area.0) as f32 / UNIT_PIXELS;
let height = total_height as f32 * VERTICAL_OVERHEAD / UNIT_PIXELS;
let limits = limits let limits = limits
.width(Length::Fixed(width)) .width(Length::Fixed(width))
.height(Length::Fixed(height)); .height(Length::Fixed(height));
@ -240,7 +246,10 @@ impl<'a, Message: Clone> Widget<Message, cosmic::Theme, Renderer> for Arrangemen
shell.publish(on_placement( shell.publish(on_placement(
output_key, output_key,
((region.x - state.max_dimensions.0 - bounds.x) * UNIT_PIXELS) as i32, ((region.x - state.max_dimensions.0 - bounds.x) * UNIT_PIXELS) as i32,
((region.y - state.max_dimensions.1 - bounds.y) * UNIT_PIXELS) as i32, ((region.y
- (state.max_dimensions.1 / VERTICAL_DISPLAY_OVERHEAD)
- bounds.y)
* UNIT_PIXELS) as i32,
)); ));
} }
@ -429,7 +438,9 @@ fn display_regions<'a>(
width, width,
height, height,
x: max_dimensions.0 + bounds.x + (output.position.0 as f32) / UNIT_PIXELS, x: max_dimensions.0 + bounds.x + (output.position.0 as f32) / UNIT_PIXELS,
y: max_dimensions.1 + bounds.y + (output.position.1 as f32) / UNIT_PIXELS, y: (max_dimensions.1 / VERTICAL_DISPLAY_OVERHEAD)
+ bounds.y
+ (output.position.1 as f32) / UNIT_PIXELS,
}, },
)) ))
}) })