diff --git a/winit/src/platform_specific/mod.rs b/winit/src/platform_specific/mod.rs index 608ca389ec..5f1727620d 100644 --- a/winit/src/platform_specific/mod.rs +++ b/winit/src/platform_specific/mod.rs @@ -59,13 +59,6 @@ impl PlatformSpecific { } } - pub(crate) fn send_ready(&mut self) { - #[cfg(all(feature = "wayland", target_os = "linux"))] - { - self.send_wayland(wayland::Action::Ready); - } - } - pub(crate) fn update_subsurfaces( &mut self, id: window::Id, diff --git a/winit/src/platform_specific/wayland/event_loop/mod.rs b/winit/src/platform_specific/wayland/event_loop/mod.rs index 74b3cb0c62..06961a1cd2 100644 --- a/winit/src/platform_specific/wayland/event_loop/mod.rs +++ b/winit/src/platform_specific/wayland/event_loop/mod.rs @@ -103,50 +103,49 @@ impl SctkEventLoop { _ = loop_handle .insert_source(action_rx, |event, _, state| { match event { - calloop::channel::Event::Msg(e) => match e { - crate::platform_specific::Action::Action(a) => { - if let Err(err) = state.handle_action(a) { - log::warn!("{err:?}"); + calloop::channel::Event::Msg(e) => match e { + crate::platform_specific::Action::Action(a) => { + if let Err(err) = state.handle_action(a) { + log::warn!("{err:?}"); + } } - } - crate::platform_specific::Action::TrackWindow( - window, - id, - ) => { - state.windows.push(SctkWindow { window, id }); - } - crate::Action::RemoveWindow(id) => { - // TODO clean up popups matching the window. - state.windows.retain(|window| id != window.id); - } - crate::platform_specific::Action::SetCursor(icon) => { - if let Some(seat) = state.seats.get_mut(0) { - seat.icon = Some(icon); - seat.set_cursor(&state.connection, icon); + crate::platform_specific::Action::TrackWindow( + window, + id, + ) => { + state.windows.push(SctkWindow { window, id }); } - } - crate::platform_specific::Action::RequestRedraw(id) => { - let e = state.frame_status.entry(id).or_insert(FrameStatus::RequestedRedraw); - if matches!(e, FrameStatus::Received) { - *e = FrameStatus::Ready; + crate::Action::RemoveWindow(id) => { + // TODO clean up popups matching the window. + state.windows.retain(|window| id != window.id); } + crate::platform_specific::Action::SetCursor( + icon, + ) => { + if let Some(seat) = state.seats.get_mut(0) { + seat.icon = Some(icon); + seat.set_cursor(&state.connection, icon); + } + } + crate::platform_specific::Action::RequestRedraw( + id, + ) => { + let e = state + .frame_status + .entry(id) + .or_insert(FrameStatus::RequestedRedraw); + if matches!(e, FrameStatus::Received) { + *e = FrameStatus::Ready; + } + } + crate::Action::Dropped(id) => { + _ = state.destroyed.remove(&id.inner()); + } + }, + calloop::channel::Event::Closed => { + log::info!("Calloop channel closed."); } - crate::platform_specific::Action::PrePresentNotify( - _, - ) => { - // TODO - } - crate::platform_specific::Action::Ready => { - state.ready = true; - } - crate::Action::Dropped(id) => { - _ = state.destroyed.remove(&id.inner()); - } - }, - calloop::channel::Event::Closed => { - log::info!("Calloop channel closed."); } - } }) .unwrap(); let wayland_source = @@ -227,7 +226,6 @@ impl SctkEventLoop { proxy, id_map: Default::default(), to_commit: HashMap::new(), - ready: true, destroyed: HashSet::new(), pending_popup: Default::default(), activation_token_ctr: 0, @@ -305,9 +303,6 @@ impl SctkEventLoop { } } } - if !state.state.ready { - continue; - } if let Err(err) = state.event_loop.dispatch(None, &mut state.state) @@ -370,7 +365,6 @@ impl SctkEventLoop { ); } } - if wake_up { state.state.proxy.wake_up(); } diff --git a/winit/src/platform_specific/wayland/event_loop/state.rs b/winit/src/platform_specific/wayland/event_loop/state.rs index 2e90516ee6..09589c6cbc 100644 --- a/winit/src/platform_specific/wayland/event_loop/state.rs +++ b/winit/src/platform_specific/wayland/event_loop/state.rs @@ -378,7 +378,6 @@ pub struct SctkState { pub(crate) id_map: HashMap, pub(crate) to_commit: HashMap, pub(crate) destroyed: HashSet, - pub(crate) ready: bool, pub(crate) pending_popup: Option<(SctkPopupSettings, usize)>, pub(crate) activation_token_ctr: u32, diff --git a/winit/src/platform_specific/wayland/mod.rs b/winit/src/platform_specific/wayland/mod.rs index 445b1b67be..e4fcfd9d16 100644 --- a/winit/src/platform_specific/wayland/mod.rs +++ b/winit/src/platform_specific/wayland/mod.rs @@ -28,11 +28,9 @@ pub(crate) enum Action { Action(iced_runtime::platform_specific::wayland::Action), SetCursor(CursorIcon), RequestRedraw(ObjectId), - PrePresentNotify(ObjectId), TrackWindow(Arc, window::Id), RemoveWindow(window::Id), Dropped(SurfaceIdWrapper), - Ready, } impl std::fmt::Debug for Action { @@ -45,16 +43,12 @@ impl std::fmt::Debug for Action { Self::RequestRedraw(arg0) => { f.debug_tuple("RequestRedraw").field(arg0).finish() } - Self::PrePresentNotify(arg0) => { - f.debug_tuple("PrePresentNotify").field(arg0).finish() - } Self::TrackWindow(_arg0, arg1) => { f.debug_tuple("TrackWindow").field(arg1).finish() } Self::RemoveWindow(arg0) => { f.debug_tuple("RemoveWindow").field(arg0).finish() } - Self::Ready => write!(f, "Ready"), Self::Dropped(_surface_id_wrapper) => write!(f, "Dropped"), } } diff --git a/winit/src/platform_specific/wayland/winit_window.rs b/winit/src/platform_specific/wayland/winit_window.rs index 0ca4ceeb57..36b2d5efd6 100644 --- a/winit/src/platform_specific/wayland/winit_window.rs +++ b/winit/src/platform_specific/wayland/winit_window.rs @@ -2,10 +2,7 @@ use crate::platform_specific::wayland::Action; use raw_window_handle::HandleError; use sctk::reexports::{ calloop::channel, - client::{ - protocol::{wl_display::WlDisplay, wl_surface::WlSurface}, - Proxy, QueueHandle, - }, + client::{protocol::wl_display::WlDisplay, Proxy, QueueHandle}, }; use std::sync::{Arc, Mutex}; use winit::{ @@ -16,19 +13,7 @@ use winit::{ use crate::platform_specific::SurfaceIdWrapper; -use super::event_loop::state::{ - Common, CommonSurface, SctkLayerSurface, SctkLockSurface, SctkPopup, - SctkState, TOKEN_CTR, -}; - -#[derive(Debug)] -pub(crate) enum Surface { - Popup(SctkPopup), - Layer(SctkLayerSurface), - Lock(SctkLockSurface), -} - -impl Surface {} +use super::event_loop::state::{Common, CommonSurface, SctkState, TOKEN_CTR}; pub struct SctkWinitWindow { tx: channel::Sender, @@ -37,7 +22,6 @@ pub struct SctkWinitWindow { common: Arc>, display: WlDisplay, pub(crate) queue_handle: QueueHandle, - wait_redraw: bool, } impl Drop for SctkWinitWindow { @@ -62,7 +46,6 @@ impl SctkWinitWindow { surface, display, queue_handle, - wait_redraw: false, }) } } @@ -87,9 +70,6 @@ impl winit::window::Window for SctkWinitWindow { fn pre_present_notify(&self) { let surface = self.surface.wl_surface(); _ = surface.frame(&self.queue_handle, surface.clone()); - _ = self - .tx - .send(Action::PrePresentNotify(self.surface.wl_surface().id())); } fn set_cursor(&self, cursor: winit::window::Cursor) { diff --git a/winit/src/program.rs b/winit/src/program.rs index 4f2566bdf8..70b00f0c54 100644 --- a/winit/src/program.rs +++ b/winit/src/program.rs @@ -795,7 +795,6 @@ async fn run_instance<'a, P, C>( let event = if let Ok(event) = event_receiver.try_next() { event } else { - platform_specific_handler.send_ready(); event_receiver.next().await }; @@ -1135,6 +1134,8 @@ async fn run_instance<'a, P, C>( continue; }; + window.redraw_requested = false; + // TODO: Avoid redrawing all the time by forcing widgets to // request redraws on state changes // diff --git a/winit/src/program/window_manager.rs b/winit/src/program/window_manager.rs index 5ffc5ea5c1..85d7254ff0 100644 --- a/winit/src/program/window_manager.rs +++ b/winit/src/program/window_manager.rs @@ -71,6 +71,7 @@ where mouse_interaction: mouse::Interaction::None, prev_dnd_destination_rectangles_count: 0, resize_enabled: false, + redraw_requested: false, }, ); @@ -167,6 +168,7 @@ where pub surface: C::Surface, pub renderer: P::Renderer, pub resize_enabled: bool, + pub(crate) redraw_requested: bool, } impl Window @@ -193,6 +195,9 @@ where } pub fn request_redraw(&mut self) { - self.raw.request_redraw(); + if !self.redraw_requested { + self.redraw_requested = true; + self.raw.request_redraw(); + } } }