diff --git a/iced_layershell/src/application.rs b/iced_layershell/src/application.rs index cbf8633..bca3863 100644 --- a/iced_layershell/src/application.rs +++ b/iced_layershell/src/application.rs @@ -368,8 +368,12 @@ async fn run_instance( while let Some(event) = event_receiver.next().await { match event { - IcedLayerEvent::RequestRefresh { width, height } => { - state.update_view_port(width, height); + IcedLayerEvent::RequestRefresh { + width, + height, + fractal_scale, + } => { + state.update_view_port(width, height, fractal_scale); let ps = state.physical_size(); let width = ps.width; let height = ps.height; diff --git a/iced_layershell/src/application/state.rs b/iced_layershell/src/application/state.rs index 7199a5e..f025596 100644 --- a/iced_layershell/src/application/state.rs +++ b/iced_layershell/src/application/state.rs @@ -58,7 +58,8 @@ where self.window_scale_factor } - pub fn update_view_port(&mut self, width: u32, height: u32) { + pub fn update_view_port(&mut self, width: u32, height: u32, scale: f64) { + self.window_scale_factor = scale; self.viewport = Viewport::with_physical_size( iced::Size::new(width, height), self.current_wayland_scale() * self.scale_factor, diff --git a/iced_layershell/src/event.rs b/iced_layershell/src/event.rs index 1d8dfec..789c010 100644 --- a/iced_layershell/src/event.rs +++ b/iced_layershell/src/event.rs @@ -98,6 +98,7 @@ pub enum IcedLayerEvent { RequestRefreshWithWrapper { width: u32, height: u32, + fractal_scale: f64, wrapper: WindowWrapper, is_created: bool, info: Option, @@ -105,6 +106,7 @@ pub enum IcedLayerEvent { RequestRefresh { width: u32, height: u32, + fractal_scale: f64, }, Window(WindowEvent), NormalUpdate, @@ -131,12 +133,16 @@ impl From<(Option, IcedLayerEvent From<&DispatchMessage> for IcedLayerEvent { fn from(value: &DispatchMessage) -> Self { match value { - DispatchMessage::RequestRefresh { width, height, .. } => { - IcedLayerEvent::RequestRefresh { - width: *width, - height: *height, - } - } + DispatchMessage::RequestRefresh { + width, + height, + scale_float, + .. + } => IcedLayerEvent::RequestRefresh { + width: *width, + height: *height, + fractal_scale: *scale_float, + }, DispatchMessage::MouseEnter { surface_x: x, surface_y: y, diff --git a/iced_layershell/src/multi_window.rs b/iced_layershell/src/multi_window.rs index 82e19a6..d697952 100644 --- a/iced_layershell/src/multi_window.rs +++ b/iced_layershell/src/multi_window.rs @@ -256,6 +256,7 @@ where DispatchMessage::RequestRefresh { width, height, + scale_float, is_created, .. } => { @@ -268,6 +269,7 @@ where IcedLayerEvent::RequestRefreshWithWrapper { width: *width, height: *height, + fractal_scale: *scale_float, wrapper: unit.gen_wrapper(), is_created: *is_created, info: unit.get_binding().cloned(), @@ -502,6 +504,7 @@ async fn run_instance( IcedLayerEvent::RequestRefreshWithWrapper { width, height, + fractal_scale, wrapper, is_created, info, @@ -515,6 +518,7 @@ async fn run_instance( let window = window_manager.insert( id, (width, height), + fractal_scale, Arc::new(wrapper), &application, &mut compositor, diff --git a/iced_layershell/src/multi_window/state.rs b/iced_layershell/src/multi_window/state.rs index f60fada..53c0506 100644 --- a/iced_layershell/src/multi_window/state.rs +++ b/iced_layershell/src/multi_window/state.rs @@ -26,12 +26,16 @@ impl State where A::Theme: DefaultStyle, { - pub fn new(id: window::Id, application: &A, (width, height): (u32, u32)) -> Self { + pub fn new( + id: window::Id, + application: &A, + (width, height): (u32, u32), + wayland_scale_factor: f64, + ) -> Self { let scale_factor = application.scale_factor(id); let theme = application.theme(); let appearance = application.style(&theme); - let wayland_scale_factor = 1.0; let viewport = Viewport::with_physical_size( iced_core::Size::new(width, height), wayland_scale_factor * scale_factor, diff --git a/iced_layershell/src/multi_window/window_manager.rs b/iced_layershell/src/multi_window/window_manager.rs index fa2a9a5..85cfec7 100644 --- a/iced_layershell/src/multi_window/window_manager.rs +++ b/iced_layershell/src/multi_window/window_manager.rs @@ -74,12 +74,13 @@ where &mut self, id: IcedId, size: (u32, u32), + fractal_scale: f64, window: Arc, application: &A, compositor: &mut C, ) -> &mut Window { let layerid = window.id(); - let state = State::new(id, application, size); + let state = State::new(id, application, size, fractal_scale); let physical_size = state.physical_size(); let surface = compositor.create_surface(window, physical_size.width, physical_size.height); let renderer = compositor.create_renderer(); diff --git a/layershellev/src/events.rs b/layershellev/src/events.rs index e39f116..f395f1d 100644 --- a/layershellev/src/events.rs +++ b/layershellev/src/events.rs @@ -239,8 +239,8 @@ pub(crate) enum DispatchMessageInner { RequestRefresh { width: u32, height: u32, - is_created: bool, scale_float: f64, + is_created: bool, }, PreferredScale { scale_u32: u32, @@ -323,8 +323,8 @@ pub enum DispatchMessage { RequestRefresh { width: u32, height: u32, - is_created: bool, scale_float: f64, + is_created: bool, }, /// fractal scale handle PreferredScale { scale_u32: u32, scale_float: f64 }, @@ -401,13 +401,13 @@ impl From for DispatchMessage { DispatchMessageInner::RequestRefresh { width, height, - is_created, scale_float, + is_created, } => DispatchMessage::RequestRefresh { width, height, - is_created, scale_float, + is_created, }, DispatchMessageInner::Axis { time, diff --git a/layershellev/src/lib.rs b/layershellev/src/lib.rs index 79458b2..0509cde 100644 --- a/layershellev/src/lib.rs +++ b/layershellev/src/lib.rs @@ -1656,20 +1656,16 @@ impl Dispatch for WindowStat _qhandle: &QueueHandle, ) { if let wp_fractional_scale_v1::Event::PreferredScale { scale } = event { - let Some(id) = state - .units - .iter() - .find(|info| { - info.fractional_scale - .as_ref() - .is_some_and(|fractional_scale| fractional_scale == proxy) - }) - .map(|unit| unit.id) - else { + let Some(unit) = state.units.iter_mut().find(|info| { + info.fractional_scale + .as_ref() + .is_some_and(|fractional_scale| fractional_scale == proxy) + }) else { return; }; + unit.scale = scale; state.message.push(( - Some(id), + Some(unit.id), DispatchMessageInner::PreferredScale { scale_u32: scale, scale_float: scale as f64 / 120., @@ -2422,7 +2418,6 @@ impl WindowState { becreated: true, wl_output: None, binding: info, - scale: 120, }); }