Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

apply scale to lock surface #164

Merged
merged 1 commit into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions sctk/src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -824,6 +824,15 @@ 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()))
{
state.wp_viewport = viewport;
state.set_scale_factor(scale_factor);
}
}
_ => {}
}
}
Expand Down Expand Up @@ -2365,6 +2374,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
Loading