Skip to content

Commit

Permalink
wip: apply scale to lock surface
Browse files Browse the repository at this point in the history
  • Loading branch information
wash2 committed Aug 1, 2024
1 parent fa817c7 commit 0187214
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 1 deletion.
16 changes: 16 additions & 0 deletions sctk/src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

}
Expand All @@ -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);
}
}
_ => {}
}
}
Expand Down Expand Up @@ -2365,6 +2378,9 @@ where
SctkEvent::SessionLockSurfaceDone { surface } => {
&surface.id() == object_id
}
SctkEvent::SessionLockSurfaceScaleFactorChanged { surface, .. } => {
&surface.id() == object_id
}
SctkEvent::SessionUnlocked => false,
}
}
3 changes: 3 additions & 0 deletions sctk/src/event_loop/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,9 @@ where
| SctkEvent::WindowEvent {
variant: WindowEventVariant::ScaleFactorChanged(..),
..
}
| SctkEvent::SessionLockSurfaceScaleFactorChanged {
..
} => true,
// ignore other events that shouldn't be in this buffer
event => {
Expand Down
42 changes: 41 additions & 1 deletion sctk/src/event_loop/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -240,6 +240,9 @@ pub struct SctkLockSurface {
pub(crate) id: window::Id,
pub(crate) session_lock_surface: SessionLockSurface,
pub(crate) last_configure: Option<SessionLockSurfaceConfigure>,
pub(crate) scale_factor: Option<f64>,
pub(crate) wp_fractional_scale: Option<WpFractionalScaleV1>,
pub(crate) wp_viewport: Option<WpViewport>,
}

pub struct Dnd<T> {
Expand Down Expand Up @@ -460,6 +463,27 @@ impl<T> SctkState<T> {
});
}

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.
}
}
Expand Down Expand Up @@ -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 {
Expand Down
6 changes: 6 additions & 0 deletions sctk/src/sctk_event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,11 @@ pub enum SctkEvent {
SessionLockSurfaceDone {
surface: WlSurface,
},
SessionLockSurfaceScaleFactorChanged {
surface: WlSurface,
scale_factor: f64,
viewport: Option<WpViewport>,
},
SessionUnlocked,
}

Expand Down Expand Up @@ -988,6 +993,7 @@ impl SctkEvent {
.into_iter()
.collect()
}
SctkEvent::SessionLockSurfaceScaleFactorChanged { .. } => vec![],
}
}
}
Expand Down

0 comments on commit 0187214

Please sign in to comment.