From ba8084b9485e7dd90c9fdc59260508c5d59d770f Mon Sep 17 00:00:00 2001 From: ShootingStarDragons Date: Sat, 5 Oct 2024 00:03:27 +0900 Subject: [PATCH] fix: set scale at the beginning --- iced_layershell/src/application.rs | 8 ++++++-- iced_layershell/src/application/state.rs | 3 ++- iced_layershell/src/event.rs | 18 ++++++++++++------ iced_layershell/src/multi_window.rs | 4 ++++ iced_layershell/src/multi_window/state.rs | 8 ++++++-- .../src/multi_window/window_manager.rs | 3 ++- layershellev/src/events.rs | 8 ++++---- layershellev/src/lib.rs | 1 - 8 files changed, 36 insertions(+), 17 deletions(-) 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 5e997fb..924755f 100644 --- a/layershellev/src/lib.rs +++ b/layershellev/src/lib.rs @@ -2463,7 +2463,6 @@ impl WindowState { becreated: true, wl_output: None, binding: info, - scale: 120, }); }