From 525c635124d8d6dbc6b1869223665e39e5b04a43 Mon Sep 17 00:00:00 2001 From: Ashley Wulber Date: Tue, 29 Apr 2025 18:12:56 -0400 Subject: [PATCH] fix: avoid Fill for the left element this will allow the left element to expand if it needs more space, but half otherwise. Setting both left and right to Fill will make them both use half of the available space. --- src/greeter.rs | 12 +++++++++--- src/locker.rs | 28 +++++++++++++++++++++++----- 2 files changed, 32 insertions(+), 8 deletions(-) diff --git a/src/greeter.rs b/src/greeter.rs index 550701c..5c9ee6e 100644 --- a/src/greeter.rs +++ b/src/greeter.rs @@ -451,6 +451,12 @@ pub struct App { impl App { fn menu(&self, id: SurfaceId) -> Element { + let window_width = self.window_size.get(&id).map(|s| s.width).unwrap_or(800.); + let menu_width = if window_width > 800. { + 800. + } else { + window_width + }; let left_element = { let military_time = self .selected_username @@ -624,12 +630,11 @@ impl App { widget::container(iced::widget::column![ date_time_column, - widget::divider::horizontal::default(), + widget::divider::horizontal::default().width(Length::Fixed(menu_width / 2. - 16.)), status_row, - widget::divider::horizontal::default(), + widget::divider::horizontal::default().width(Length::Fixed(menu_width / 2. - 16.)), button_row, ]) - .width(Length::Fill) .align_x(alignment::Horizontal::Left) }; @@ -1175,6 +1180,7 @@ impl cosmic::Application for App { match self.surface_ids.remove(&output) { Some(surface_id) => { self.surface_images.remove(&surface_id); + self.window_size.remove(&surface_id); if let Some(n) = self.surface_names.remove(&surface_id) { self.text_input_ids.remove(&n); } diff --git a/src/locker.rs b/src/locker.rs index d524646..52ff444 100644 --- a/src/locker.rs +++ b/src/locker.rs @@ -35,7 +35,7 @@ use std::{ process, sync::Arc, }; -use tokio::{sync::mpsc, task, time}; +use tokio::{sync::mpsc, task}; use wayland_client::{Proxy, protocol::wl_output::WlOutput}; fn lockfile_opt() -> Option { @@ -276,10 +276,21 @@ pub struct App { prompt_opt: Option<(String, bool, Option)>, error_opt: Option, time: crate::time::Time, + window_size: HashMap, } impl App { fn menu(&self, surface_id: SurfaceId) -> Element { + let window_width = self + .window_size + .get(&surface_id) + .map(|s| s.width) + .unwrap_or(800.); + let menu_width = if window_width > 800. { + 800. + } else { + window_width + }; let left_element = { // TODO how should we get user preference for military time here? let military_time = false; @@ -320,12 +331,11 @@ impl App { widget::container(iced::widget::column![ date_time_column, - widget::divider::horizontal::default(), + widget::divider::horizontal::default().width(Length::Fixed(menu_width / 2. - 16.)), status_row, - widget::divider::horizontal::default(), + widget::divider::horizontal::default().width(Length::Fixed(menu_width / 2. - 16.)), button_row, ]) - .width(Length::Fill) .align_x(alignment::Horizontal::Left) }; @@ -543,6 +553,7 @@ impl cosmic::Application for App { prompt_opt: None, error_opt: None, time: crate::time::Time::new(), + window_size: HashMap::new(), }; let task = if cfg!(feature = "logind") { @@ -641,6 +652,11 @@ impl cosmic::Application for App { Size::new(unwrapped_size.0 as f32, unwrapped_size.1 as f32 - 32.), ) }; + self.window_size.insert( + surface_id, + Size::new(unwrapped_size.0 as f32, unwrapped_size.1 as f32), + ); + self.subsurface_rects .insert(output.clone(), Rectangle::new(loc, sub_size)); @@ -676,6 +692,7 @@ impl cosmic::Application for App { Some(surface_id) => { self.surface_images.remove(&surface_id); self.surface_names.remove(&surface_id); + self.window_size.remove(&surface_id); if let Some(n) = self.surface_names.remove(&surface_id) { self.text_input_ids.remove(&n); } @@ -844,7 +861,7 @@ impl cosmic::Application for App { let mut commands = Vec::new(); for (_output, surface_id) in self.surface_ids.iter() { self.surface_names.remove(surface_id); - + self.window_size.remove(surface_id); commands.push(destroy_lock_surface(*surface_id)); } if cfg!(feature = "logind") { @@ -971,6 +988,7 @@ impl cosmic::Application for App { for (_output, surface_id) in self.surface_ids.iter() { self.surface_names.remove(surface_id); + self.window_size.remove(&surface_id); commands.push(destroy_lock_surface(*surface_id)); }