From 5265fa24642392213e2acf6847e3047ac2e36417 Mon Sep 17 00:00:00 2001 From: ShootingStarDragons Date: Mon, 7 Oct 2024 00:58:25 +0900 Subject: [PATCH] chore: try set viewport --- iced_layershell/src/actions.rs | 1 + iced_layershell/src/application.rs | 17 ++++++++++++----- iced_layershell/src/application/state.rs | 8 +++++++- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/iced_layershell/src/actions.rs b/iced_layershell/src/actions.rs index 80698a8..8ef200e 100644 --- a/iced_layershell/src/actions.rs +++ b/iced_layershell/src/actions.rs @@ -13,6 +13,7 @@ pub(crate) enum LayerShellActions { RedrawAll, RedrawWindow(LayerId), // maybe one day it is useful, but now useless NewMenu((IcedNewPopupSettings, INFO)), + SingleLayerViewportDestintion { width: i32, height: i32 }, } #[derive(Debug, PartialEq, Eq, Clone, Copy)] diff --git a/iced_layershell/src/application.rs b/iced_layershell/src/application.rs index bca3863..8c230e6 100644 --- a/iced_layershell/src/application.rs +++ b/iced_layershell/src/application.rs @@ -308,6 +308,9 @@ where LayerShellActions::RedrawWindow(index) => { ev.append_return_data(ReturnData::RedrawIndexRequest(index)); } + LayerShellActions::SingleLayerViewportDestintion { width, height } => { + ev.main_window().try_set_viewport_destination(width, height); + } _ => {} } def_returndata @@ -374,10 +377,14 @@ async fn run_instance( fractal_scale, } => { state.update_view_port(width, height, fractal_scale); - let ps = state.physical_size(); - let width = ps.width; - let height = ps.height; - //state.update_view_port(width, height); + let physical_size = state.physical_size(); + let width = physical_size.width; + let height = physical_size.height; + let logical_size = state.logical_size(); + custom_actions.push(LayerShellActions::SingleLayerViewportDestintion { + width: logical_size.width.ceil() as i32, + height: logical_size.height.ceil() as i32, + }); debug.layout_started(); user_interface = ManuallyDrop::new(ManuallyDrop::into_inner(user_interface).relayout( @@ -470,7 +477,7 @@ async fn run_instance( } } IcedLayerEvent::Window(event) => { - state.update(&event); + state.update(&event, &mut custom_actions); if let Some(event) = conversion::window_event(&event, state.scale_factor(), state.modifiers()) diff --git a/iced_layershell/src/application/state.rs b/iced_layershell/src/application/state.rs index f025596..dba6403 100644 --- a/iced_layershell/src/application/state.rs +++ b/iced_layershell/src/application/state.rs @@ -1,3 +1,4 @@ +use crate::actions::LayerShellActions; use crate::application::Application; use crate::{Appearance, DefaultStyle}; use iced_core::{mouse as IcedMouse, Color, Point, Size}; @@ -101,7 +102,7 @@ where .unwrap_or(IcedMouse::Cursor::Unavailable) } - pub fn update(&mut self, event: &WindowEvent) { + pub fn update(&mut self, event: &WindowEvent, custom_actions: &mut Vec>) { match event { WindowEvent::CursorLeft => { self.mouse_position = None; @@ -121,6 +122,11 @@ where self.viewport_version = self.viewport_version.wrapping_add(1); self.window_scale_factor = *scale_float; + let logical_size = self.logical_size(); + custom_actions.push(LayerShellActions::SingleLayerViewportDestintion { + width: logical_size.width.ceil() as i32, + height: logical_size.height.ceil() as i32, + }); } _ => {} }