Skip to content

Commit

Permalink
fix: convert sctk configure events to Opened and Resized
Browse files Browse the repository at this point in the history
  • Loading branch information
wash2 committed Dec 2, 2024
1 parent 8e63228 commit 5a38039
Showing 1 changed file with 87 additions and 6 deletions.
93 changes: 87 additions & 6 deletions winit/src/platform_specific/wayland/sctk_event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use iced_futures::{
},
PlatformSpecific,
},
Clipboard as _,
Clipboard as _, Size,
},
event,
futures::channel::mpsc,
Expand Down Expand Up @@ -838,9 +838,12 @@ impl SctkEvent {
surface,
first,
) => {
if let Some(w) = surface_ids
.get(&surface.id())
.and_then(|id| window_manager.get_mut(id.inner()))
if let Some((id, w)) =
surface_ids.get(&surface.id()).and_then(|id| {
window_manager
.get_mut(id.inner())
.map(|v| (id.inner(), v))
})
{
let scale = w.state.scale_factor();
let p_w = (configure.new_size.0.max(1) as f64 * scale)
Expand All @@ -854,6 +857,26 @@ impl SctkEvent {
)),
debug,
);
if first {
events.push((
Some(id),
iced_runtime::core::Event::Window(
window::Event::Resized(
w.state.logical_size(),
),
),
))
} else {
events.push((
Some(id),
iced_runtime::core::Event::Window(
window::Event::Opened {
size: w.state.logical_size(),
position: Default::default(),
},
),
))
}
}
}
},
Expand Down Expand Up @@ -1044,7 +1067,34 @@ impl SctkEvent {

let _ = user_interfaces.insert(surface_id, ui);
}
PopupEventVariant::Configure(_, _, _) => {} // TODO
PopupEventVariant::Configure(configure, surface, first) => {
let size = Size::new(
configure.width as f32,
configure.height as f32,
);
if let Some(id) =
surface_ids.get(&surface.id()).map(|id| id.inner())
{
if first {
events.push((
Some(id),
iced_runtime::core::Event::Window(
window::Event::Resized(size),
),
))
} else {
events.push((
Some(id),
iced_runtime::core::Event::Window(
window::Event::Opened {
size: size,
position: Default::default(),
},
),
))
}
}
} // TODO
PopupEventVariant::RepositionionedPopup { token: _ } => {}
PopupEventVariant::Size(_, _) => {}
PopupEventVariant::ScaleFactorChanged(..) => {}
Expand Down Expand Up @@ -1190,7 +1240,38 @@ impl SctkEvent {
),
);
}
SctkEvent::SessionLockSurfaceConfigure { .. } => {}
SctkEvent::SessionLockSurfaceConfigure {
surface,
configure,
first,
} => {
let size = Size::new(
configure.new_size.0 as f32,
configure.new_size.1 as f32,
);
if let Some(id) =
surface_ids.get(&surface.id()).map(|id| id.inner())
{
if first {
events.push((
Some(id),
iced_runtime::core::Event::Window(
window::Event::Resized(size),
),
))
} else {
events.push((
Some(id),
iced_runtime::core::Event::Window(
window::Event::Opened {
size: size,
position: Default::default(),
},
),
))
}
}
}
SctkEvent::SessionLockSurfaceDone { surface } => {
if let Some(id) = surface_ids.remove(&surface.id()) {
_ = window_manager.remove(id.inner());
Expand Down

0 comments on commit 5a38039

Please sign in to comment.