Lots of owork on a calculator example, transparency, etc.
This commit is contained in:
@@ -148,6 +148,7 @@ enum InternalBackendEvent {
|
||||
|
||||
struct State {
|
||||
running: bool,
|
||||
fixed_size_request: Option<(u32, u32)>,
|
||||
_connection: Connection,
|
||||
_compositor: wl_compositor::WlCompositor,
|
||||
_surface: wl_surface::WlSurface,
|
||||
@@ -232,6 +233,18 @@ impl State {
|
||||
}
|
||||
}
|
||||
|
||||
fn fixed_size_request_for_spec(spec: &WindowSpec) -> Option<(u32, u32)> {
|
||||
if spec.resizable {
|
||||
return None;
|
||||
}
|
||||
let size = spec
|
||||
.requested_inner_size
|
||||
.or(spec.min_inner_size)
|
||||
.or(spec.max_inner_size)
|
||||
.unwrap_or_else(|| UiSize::new(800.0, 500.0));
|
||||
Some((size.width.max(1.0).round() as u32, size.height.max(1.0).round() as u32))
|
||||
}
|
||||
|
||||
fn wayland_cursor_shape(icon: CursorIcon) -> wp_cursor_shape_device_v1::Shape {
|
||||
match icon {
|
||||
CursorIcon::Default => wp_cursor_shape_device_v1::Shape::Default,
|
||||
@@ -364,6 +377,7 @@ impl WaylandWindow {
|
||||
surface_target,
|
||||
state: State {
|
||||
running: true,
|
||||
fixed_size_request: fixed_size_request_for_spec(&spec),
|
||||
_connection: connection,
|
||||
_compositor: compositor,
|
||||
_surface: surface,
|
||||
@@ -697,6 +711,7 @@ impl WaylandWindow {
|
||||
}
|
||||
|
||||
pub fn apply_spec(&mut self, spec: &WindowSpec) -> Result<(), Box<dyn Error>> {
|
||||
self.state.fixed_size_request = fixed_size_request_for_spec(spec);
|
||||
self.state._toplevel.set_title(spec.title.clone());
|
||||
if let Some(app_id) = spec.app_id.as_ref() {
|
||||
self.state._toplevel.set_app_id(app_id.clone());
|
||||
@@ -732,6 +747,14 @@ impl WaylandWindow {
|
||||
}
|
||||
|
||||
if let Some((width, height)) = self.state.pending_size.take() {
|
||||
trace!(
|
||||
target: "ruin_ui_platform_wayland::resize",
|
||||
width,
|
||||
height,
|
||||
previous_width = self.state.current_size.0,
|
||||
previous_height = self.state.current_size.1,
|
||||
"prepare_frame observed pending size change"
|
||||
);
|
||||
self.state.current_size = (width, height);
|
||||
self.state.needs_redraw = false;
|
||||
return Some(FrameRequest {
|
||||
@@ -742,6 +765,12 @@ impl WaylandWindow {
|
||||
}
|
||||
|
||||
if self.state.needs_redraw {
|
||||
trace!(
|
||||
target: "ruin_ui_platform_wayland::resize",
|
||||
width = self.state.current_size.0,
|
||||
height = self.state.current_size.1,
|
||||
"prepare_frame servicing redraw without size change"
|
||||
);
|
||||
self.state.needs_redraw = false;
|
||||
return Some(FrameRequest {
|
||||
width: self.state.current_size.0,
|
||||
@@ -2101,6 +2130,14 @@ impl Dispatch<xdg_surface::XdgSurface, ()> for State {
|
||||
if let xdg_surface::Event::Configure { serial } = event {
|
||||
xdg_surface.ack_configure(serial);
|
||||
state.configured = true;
|
||||
trace!(
|
||||
target: "ruin_ui_platform_wayland::resize",
|
||||
serial,
|
||||
current_width = state.current_size.0,
|
||||
current_height = state.current_size.1,
|
||||
has_pending_size = state.pending_size.is_some(),
|
||||
"received xdg_surface configure"
|
||||
);
|
||||
state.request_redraw();
|
||||
}
|
||||
}
|
||||
@@ -2153,7 +2190,37 @@ impl Dispatch<xdg_toplevel::XdgToplevel, ()> for State {
|
||||
height,
|
||||
"received Wayland toplevel configure"
|
||||
);
|
||||
state.pending_size = Some((width, height));
|
||||
let next_size = (width, height);
|
||||
if let Some(expected_size) = state.fixed_size_request {
|
||||
if next_size != expected_size {
|
||||
trace!(
|
||||
target: "ruin_ui_platform_wayland::resize",
|
||||
width,
|
||||
height,
|
||||
expected_width = expected_size.0,
|
||||
expected_height = expected_size.1,
|
||||
"ignoring stale toplevel configure for fixed-size window"
|
||||
);
|
||||
state.request_redraw();
|
||||
return;
|
||||
}
|
||||
}
|
||||
let size_changed =
|
||||
next_size != state.current_size && state.pending_size != Some(next_size);
|
||||
trace!(
|
||||
target: "ruin_ui_platform_wayland::resize",
|
||||
width,
|
||||
height,
|
||||
current_width = state.current_size.0,
|
||||
current_height = state.current_size.1,
|
||||
pending_width = state.pending_size.map(|size| size.0),
|
||||
pending_height = state.pending_size.map(|size| size.1),
|
||||
size_changed,
|
||||
"processed Wayland toplevel configure"
|
||||
);
|
||||
if size_changed {
|
||||
state.pending_size = Some(next_size);
|
||||
}
|
||||
state.request_redraw();
|
||||
}
|
||||
_ => {}
|
||||
|
||||
Reference in New Issue
Block a user