Skip to content

Commit

Permalink
refactor: apply requested size for surface after creation
Browse files Browse the repository at this point in the history
This should help popups start as the correct size, and also layer surfaces
  • Loading branch information
wash2 committed Oct 23, 2024
1 parent 29ff72b commit 4f9a86b
Show file tree
Hide file tree
Showing 2 changed files with 123 additions and 27 deletions.
4 changes: 1 addition & 3 deletions winit/src/platform_specific/wayland/event_loop/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ use crate::{
};

use raw_window_handle::HasDisplayHandle;
use sctk::reexports::{
calloop_wayland_source::WaylandSource, client::protocol::wl_subcompositor,
};
use sctk::reexports::calloop_wayland_source::WaylandSource;
use sctk::{
activation::ActivationState,
compositor::CompositorState,
Expand Down
146 changes: 122 additions & 24 deletions winit/src/platform_specific/wayland/sctk_event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -741,20 +741,66 @@ impl SctkEvent {
);
}

let _ = user_interfaces.insert(
let mut ui = crate::program::build_user_interface(
program,
user_interface::Cache::default(),
&mut window.renderer,
logical_size,
debug,
surface_id,
crate::program::build_user_interface(
program,
user_interface::Cache::default(),
&mut window.renderer,
logical_size,
debug,
surface_id,
window.raw.clone(),
window.prev_dnd_destination_rectangles_count,
clipboard,
),
window.raw.clone(),
window.prev_dnd_destination_rectangles_count,
clipboard,
);

_ = ui.update(
&vec![iced_runtime::core::Event::PlatformSpecific(
iced_runtime::core::event::PlatformSpecific::Wayland(
iced_runtime::core::event::wayland::Event::RequestResize,
),
)],
window.state.cursor(),
&mut window.renderer,
clipboard,
&mut Vec::new(),
);

if let Some(requested_size) =
clipboard.requested_logical_size.lock().unwrap().take()
{
let requested_physical_size =
winit::dpi::PhysicalSize::new(
(requested_size.width as f64
* window.state.scale_factor())
.ceil() as u32,
(requested_size.height as f64
* window.state.scale_factor())
.ceil() as u32,
);
let physical_size = window.state.physical_size();
if requested_physical_size.width != physical_size.width
|| requested_physical_size.height
!= physical_size.height
{
// FIXME what to do when we are stuck in a configure event/resize request loop
// We don't have control over how winit handles this.
window.resize_enabled = true;

let s = winit::dpi::Size::Physical(
requested_physical_size,
);
_ = window.raw.request_surface_size(s);
window.raw.set_min_surface_size(Some(s));
window.raw.set_max_surface_size(Some(s));
window.state.synchronize(
&program,
surface_id,
window.raw.as_ref(),
);
}
}

let _ = user_interfaces.insert(surface_id, ui);
}
LayerSurfaceEventVariant::ScaleFactorChanged(..) => {}
LayerSurfaceEventVariant::Configure(
Expand Down Expand Up @@ -901,20 +947,72 @@ impl SctkEvent {
);
let logical_size = window.size();

let _ = user_interfaces.insert(
let mut ui = crate::program::build_user_interface(
program,
user_interface::Cache::default(),
&mut window.renderer,
logical_size,
debug,
surface_id,
crate::program::build_user_interface(
program,
user_interface::Cache::default(),
&mut window.renderer,
logical_size,
debug,
surface_id,
window.raw.clone(),
window.prev_dnd_destination_rectangles_count,
clipboard,
),
window.raw.clone(),
window.prev_dnd_destination_rectangles_count,
clipboard,
);

_ = ui.update(
&vec![iced_runtime::core::Event::PlatformSpecific(
iced_runtime::core::event::PlatformSpecific::Wayland(
iced_runtime::core::event::wayland::Event::RequestResize,
),
)],
window.state.cursor(),
&mut window.renderer,
clipboard,
&mut Vec::new(),
);

if let Some(requested_size) = clipboard
.requested_logical_size
.lock()
.unwrap()
.take()
{
let requested_physical_size =
winit::dpi::PhysicalSize::new(
(requested_size.width as f64
* window.state.scale_factor())
.ceil()
as u32,
(requested_size.height as f64
* window.state.scale_factor())
.ceil()
as u32,
);
let physical_size = window.state.physical_size();
if requested_physical_size.width
!= physical_size.width
|| requested_physical_size.height
!= physical_size.height
{
// FIXME what to do when we are stuck in a configure event/resize request loop
// We don't have control over how winit handles this.
window.resize_enabled = true;

let s = winit::dpi::Size::Physical(
requested_physical_size,
);
_ = window.raw.request_surface_size(s);
window.raw.set_min_surface_size(Some(s));
window.raw.set_max_surface_size(Some(s));
window.state.synchronize(
&program,
surface_id,
window.raw.as_ref(),
);
}
}

let _ = user_interfaces.insert(surface_id, ui);
}
PopupEventVariant::Configure(_, _, _) => {} // TODO
PopupEventVariant::RepositionionedPopup { token: _ } => {}
Expand Down

0 comments on commit 4f9a86b

Please sign in to comment.