From 0187214803afe83bb53183fdf6dafd8ac3f5c072 Mon Sep 17 00:00:00 2001 From: Ashley Wulber Date: Thu, 1 Aug 2024 17:00:09 -0400 Subject: [PATCH] wip: apply scale to lock surface --- sctk/src/application.rs | 16 ++++++++++++++ sctk/src/event_loop/mod.rs | 3 +++ sctk/src/event_loop/state.rs | 42 +++++++++++++++++++++++++++++++++++- sctk/src/sctk_event.rs | 6 ++++++ 4 files changed, 66 insertions(+), 1 deletion(-) diff --git a/sctk/src/application.rs b/sctk/src/application.rs index dadb47a65d..e5863d001b 100644 --- a/sctk/src/application.rs +++ b/sctk/src/application.rs @@ -810,6 +810,7 @@ where } state.set_logical_size(configure.new_size.0 as f32 , configure.new_size.1 as f32); + state.frame_pending = false; } } @@ -824,6 +825,18 @@ where destroyed_surface_ids.insert(surface.id(), surface_id); } } + SctkEvent::SessionLockSurfaceScaleFactorChanged { surface, scale_factor, viewport } => { + if let Some(state) = surface_ids + .get(&surface.id()) + .and_then(|id| states.get_mut(&id.inner())) + { + // XXX we need to wait for the next configure event to redraw + state.frame_pending = true; + + state.wp_viewport = viewport; + state.set_scale_factor(scale_factor); + } + } _ => {} } } @@ -2365,6 +2378,9 @@ where SctkEvent::SessionLockSurfaceDone { surface } => { &surface.id() == object_id } + SctkEvent::SessionLockSurfaceScaleFactorChanged { surface, .. } => { + &surface.id() == object_id + } SctkEvent::SessionUnlocked => false, } } diff --git a/sctk/src/event_loop/mod.rs b/sctk/src/event_loop/mod.rs index c89689a4e5..f9994d0656 100644 --- a/sctk/src/event_loop/mod.rs +++ b/sctk/src/event_loop/mod.rs @@ -516,6 +516,9 @@ where | SctkEvent::WindowEvent { variant: WindowEventVariant::ScaleFactorChanged(..), .. + } + | SctkEvent::SessionLockSurfaceScaleFactorChanged { + .. } => true, // ignore other events that shouldn't be in this buffer event => { diff --git a/sctk/src/event_loop/state.rs b/sctk/src/event_loop/state.rs index 5623f7e0b8..b86eacab2c 100644 --- a/sctk/src/event_loop/state.rs +++ b/sctk/src/event_loop/state.rs @@ -8,7 +8,7 @@ use crate::{ application::Event, dpi::LogicalSize, handlers::{ - wp_fractional_scaling::FractionalScalingManager, + shell::layer, wp_fractional_scaling::FractionalScalingManager, wp_viewporter::ViewporterState, }, sctk_event::{ @@ -240,6 +240,9 @@ pub struct SctkLockSurface { pub(crate) id: window::Id, pub(crate) session_lock_surface: SessionLockSurface, pub(crate) last_configure: Option, + pub(crate) scale_factor: Option, + pub(crate) wp_fractional_scale: Option, + pub(crate) wp_viewport: Option, } pub struct Dnd { @@ -460,6 +463,27 @@ impl SctkState { }); } + if let Some(l) = self + .lock_surfaces + .iter_mut() + .find(|l| l.session_lock_surface.wl_surface() == surface) + { + if legacy && self.fractional_scaling_manager.is_some() { + return; + } + l.scale_factor = Some(scale_factor); + let wl_surface = l.session_lock_surface.wl_surface(); + if legacy { + let _ = wl_surface.set_buffer_scale(scale_factor as i32); + } + self.compositor_updates.push( + SctkEvent::SessionLockSurfaceScaleFactorChanged { + surface: wl_surface.clone(), + scale_factor, + viewport: l.wp_viewport.clone(), + }, + ); + } // TODO winit sets cursor size after handling the change for the window, so maybe that should be done as well. } } @@ -864,10 +888,26 @@ where output, &self.queue_handle, ); + let wp_viewport = self.viewporter_state.as_ref().map(|state| { + state.get_viewport( + session_lock_surface.wl_surface(), + &self.queue_handle, + ) + }); + let wp_fractional_scale = + self.fractional_scaling_manager.as_ref().map(|fsm| { + fsm.fractional_scaling( + session_lock_surface.wl_surface(), + &self.queue_handle, + ) + }); self.lock_surfaces.push(SctkLockSurface { id, session_lock_surface, last_configure: None, + wp_viewport, + wp_fractional_scale, + scale_factor: None, }); Some(wl_surface) } else { diff --git a/sctk/src/sctk_event.rs b/sctk/src/sctk_event.rs index 5c9ac61b39..0d89347596 100755 --- a/sctk/src/sctk_event.rs +++ b/sctk/src/sctk_event.rs @@ -215,6 +215,11 @@ pub enum SctkEvent { SessionLockSurfaceDone { surface: WlSurface, }, + SessionLockSurfaceScaleFactorChanged { + surface: WlSurface, + scale_factor: f64, + viewport: Option, + }, SessionUnlocked, } @@ -988,6 +993,7 @@ impl SctkEvent { .into_iter() .collect() } + SctkEvent::SessionLockSurfaceScaleFactorChanged { .. } => vec![], } } }