Skip to content

Commit

Permalink
fix(displays): reduce height of display arrangement widget
Browse files Browse the repository at this point in the history
  • Loading branch information
mmstick committed Oct 22, 2024
1 parent 2a76db4 commit 3c4742b
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions cosmic-settings/src/pages/display/arrangement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ use cosmic_randr_shell::{self as randr, OutputKey};
use randr::Transform;

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 OnSelectFunc<Message> = Box<dyn Fn(segmented_button::Entity) -> Message>;
Expand Down Expand Up @@ -100,6 +102,7 @@ impl<'a, Message: Clone> Widget<Message, cosmic::Theme, Renderer> for Arrangemen
limits: &layout::Limits,
) -> layout::Node {
// Determine the max display dimensions, and the total display area utilized.
let mut total_height = 0;
let mut max_dimensions = (0, 0);
let mut display_area = (0, 0);

Expand Down Expand Up @@ -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.1 = display_area.1.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;
total_height = total_height.max(height as i32 + output.position.1);
}

let state = tree.state.downcast_mut::<State>();

state.max_dimensions = (
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
.width(Length::Fixed(width))
.height(Length::Fixed(height));
Expand Down Expand Up @@ -240,7 +246,10 @@ impl<'a, Message: Clone> Widget<Message, cosmic::Theme, Renderer> for Arrangemen
shell.publish(on_placement(
output_key,
((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,
));
}

Expand Down Expand Up @@ -429,7 +438,9 @@ fn display_regions<'a>(
width,
height,
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,
},
))
})
Expand Down

0 comments on commit 3c4742b

Please sign in to comment.