diff --git a/Cargo.toml b/Cargo.toml index 1dde01de..243c0680 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,22 +8,22 @@ edition = "2024" license = "Apache-2.0" repository = "https://github.com/rust-windowing/winit" rust-version = "1.85" -version = "0.31.0-beta.2" +version = "0.31.0-beta.1" [workspace.dependencies] # Workspace dependencies. # `winit` has no version here to allow using it in dev deps for docs. winit = { path = "winit" } -winit-android = { version = "=0.31.0-beta.2", path = "winit-android" } -winit-appkit = { version = "=0.31.0-beta.2", path = "winit-appkit" } -winit-common = { version = "=0.31.0-beta.2", path = "winit-common" } -winit-core = { version = "=0.31.0-beta.2", path = "winit-core" } -winit-orbital = { version = "=0.31.0-beta.2", path = "winit-orbital" } -winit-uikit = { version = "=0.31.0-beta.2", path = "winit-uikit" } -winit-wayland = { version = "=0.31.0-beta.2", path = "winit-wayland", default-features = false } -winit-web = { version = "=0.31.0-beta.2", path = "winit-web" } -winit-win32 = { version = "=0.31.0-beta.2", path = "winit-win32" } -winit-x11 = { version = "=0.31.0-beta.2", path = "winit-x11" } +winit-android = { version = "=0.31.0-beta.1", path = "winit-android" } +winit-appkit = { version = "=0.31.0-beta.1", path = "winit-appkit" } +winit-common = { version = "=0.31.0-beta.1", path = "winit-common" } +winit-core = { version = "=0.31.0-beta.1", path = "winit-core" } +winit-orbital = { version = "=0.31.0-beta.1", path = "winit-orbital" } +winit-uikit = { version = "=0.31.0-beta.1", path = "winit-uikit" } +winit-wayland = { version = "=0.31.0-beta.1", path = "winit-wayland", default-features = false } +winit-web = { version = "=0.31.0-beta.1", path = "winit-web" } +winit-win32 = { version = "=0.31.0-beta.1", path = "winit-win32" } +winit-x11 = { version = "=0.31.0-beta.1", path = "winit-x11" } # Core dependencies. bitflags = "2" @@ -80,8 +80,7 @@ xkbcommon-dl = "0.4.2" # Orbital dependencies. orbclient = { version = "0.3.47", default-features = false } -redox_syscall = "0.7" -libredox = "0.1.12" +redox_syscall = "0.5.7" # Web dependencies. atomic-waker = "1" diff --git a/README.md b/README.md index ac7fa2ae..15ea7e90 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ ```toml [dependencies] -winit = "0.31.0-beta.2" +winit = "0.31.0-beta.1" ``` ## [Documentation](https://docs.rs/winit) diff --git a/src/platform_impl/linux/wayland/dnd.rs b/src/platform_impl/linux/wayland/dnd.rs deleted file mode 100644 index d4405650..00000000 --- a/src/platform_impl/linux/wayland/dnd.rs +++ /dev/null @@ -1,135 +0,0 @@ -use sctk::data_device_manager::{ - data_device::DataDeviceHandler, data_offer::DataOfferHandler, data_source::DataSourceHandler, -}; - -use crate::platform_impl::wayland::state::WinitState; - -impl DataDeviceHandler for WinitState { - fn enter( - &mut self, - conn: &wayland_client::Connection, - qh: &wayland_client::QueueHandle, - data_device: &wayland_client::protocol::wl_data_device::WlDataDevice, - x: f64, - y: f64, - wl_surface: &wayland_client::protocol::wl_surface::WlSurface, - ) { - todo!() - } - - fn leave( - &mut self, - conn: &wayland_client::Connection, - qh: &wayland_client::QueueHandle, - data_device: &wayland_client::protocol::wl_data_device::WlDataDevice, - ) { - todo!() - } - - fn motion( - &mut self, - conn: &wayland_client::Connection, - qh: &wayland_client::QueueHandle, - data_device: &wayland_client::protocol::wl_data_device::WlDataDevice, - x: f64, - y: f64, - ) { - todo!() - } - - fn selection( - &mut self, - conn: &wayland_client::Connection, - qh: &wayland_client::QueueHandle, - data_device: &wayland_client::protocol::wl_data_device::WlDataDevice, - ) { - todo!() - } - - fn drop_performed( - &mut self, - conn: &wayland_client::Connection, - qh: &wayland_client::QueueHandle, - data_device: &wayland_client::protocol::wl_data_device::WlDataDevice, - ) { - todo!() - } -} - -impl DataOfferHandler for WinitState { - fn source_actions( - &mut self, - conn: &wayland_client::Connection, - qh: &wayland_client::QueueHandle, - offer: &mut sctk::data_device_manager::data_offer::DragOffer, - actions: wayland_client::protocol::wl_data_device_manager::DndAction, - ) { - todo!() - } - - fn selected_action( - &mut self, - conn: &wayland_client::Connection, - qh: &wayland_client::QueueHandle, - offer: &mut sctk::data_device_manager::data_offer::DragOffer, - actions: wayland_client::protocol::wl_data_device_manager::DndAction, - ) { - todo!() - } -} - -impl DataSourceHandler for WinitState { - fn accept_mime( - &mut self, - conn: &wayland_client::Connection, - qh: &wayland_client::QueueHandle, - source: &wayland_client::protocol::wl_data_source::WlDataSource, - mime: Option, - ) { - } - - fn send_request( - &mut self, - conn: &wayland_client::Connection, - qh: &wayland_client::QueueHandle, - source: &wayland_client::protocol::wl_data_source::WlDataSource, - mime: String, - fd: sctk::data_device_manager::WritePipe, - ) { - } - - fn cancelled( - &mut self, - conn: &wayland_client::Connection, - qh: &wayland_client::QueueHandle, - source: &wayland_client::protocol::wl_data_source::WlDataSource, - ) { - } - - fn dnd_dropped( - &mut self, - conn: &wayland_client::Connection, - qh: &wayland_client::QueueHandle, - source: &wayland_client::protocol::wl_data_source::WlDataSource, - ) { - } - - fn dnd_finished( - &mut self, - conn: &wayland_client::Connection, - qh: &wayland_client::QueueHandle, - source: &wayland_client::protocol::wl_data_source::WlDataSource, - ) { - } - - fn action( - &mut self, - conn: &wayland_client::Connection, - qh: &wayland_client::QueueHandle, - source: &wayland_client::protocol::wl_data_source::WlDataSource, - action: wayland_client::protocol::wl_data_device_manager::DndAction, - ) { - } -} - -sctk::delegate_data_device!(WinitState); diff --git a/winit-android/src/lib.rs b/winit-android/src/lib.rs index 989c9716..abe97677 100644 --- a/winit-android/src/lib.rs +++ b/winit-android/src/lib.rs @@ -63,7 +63,7 @@ //! with `cargo apk`, then the minimal changes would be: //! 1. Remove `ndk-glue` from your `Cargo.toml` //! 2. Enable the `"android-native-activity"` feature for Winit: `winit = { version = -//! "0.31.0-beta.2", features = [ "android-native-activity" ] }` +//! "0.31.0-beta.1", features = [ "android-native-activity" ] }` //! 3. Add an `android_main` entrypoint (as above), instead of using the '`[ndk_glue::main]` proc //! macro from `ndk-macros` (optionally add a dependency on `android_logger` and initialize //! logging as above). diff --git a/winit-core/src/event.rs b/winit-core/src/event.rs index ade39acf..24a80990 100644 --- a/winit-core/src/event.rs +++ b/winit-core/src/event.rs @@ -368,18 +368,6 @@ pub enum WindowEvent { surface_size_writer: SurfaceSizeWriter, }, - /// The suggested bounds of the window's surface has changed. - /// - /// Contains the new bounds of the surface - /// - /// - **iOS / Android / Web / Orbital / Windows:** Unsupported. - SuggestedBounds(Option>), - - /// The window state has changed. - /// - /// - **iOS / Android / Web / Orbital / Windows:** Unsupported. - WindowStateChanged, - /// The system window theme has changed. /// /// Applications might wish to react to this to change the theme of the content of the window diff --git a/winit-core/src/window.rs b/winit-core/src/window.rs index f22f35e5..aa7f1710 100644 --- a/winit-core/src/window.rs +++ b/winit-core/src/window.rs @@ -881,8 +881,7 @@ pub trait Window: AsAny + Send + Sync + fmt::Debug { /// ## Platform-specific /// /// - **Android / iOS / X11 / Web / Windows:** Unsupported. - /// - **Wayland:** Only works with `org_kde_kwin_blur_manager` or - /// `ext_background_effect_manager_v1` protocol. + /// - **Wayland:** Only works with org_kde_kwin_blur_manager protocol. fn set_blur(&self, blur: bool); /// Modifies the window's visibility. diff --git a/winit-orbital/Cargo.toml b/winit-orbital/Cargo.toml index 330bd520..1d1e20a8 100644 --- a/winit-orbital/Cargo.toml +++ b/winit-orbital/Cargo.toml @@ -23,4 +23,3 @@ winit-core.workspace = true # Platform-specific orbclient.workspace = true redox_syscall.workspace = true -libredox.workspace = true diff --git a/winit-orbital/src/event_loop.rs b/winit-orbital/src/event_loop.rs index 7db55f14..8ef97156 100644 --- a/winit-orbital/src/event_loop.rs +++ b/winit-orbital/src/event_loop.rs @@ -639,13 +639,7 @@ impl EventLoop { // Wait for event if needed. let mut event = syscall::Event::default(); - loop { - match self.window_target.event_socket.read(&mut event) { - Ok(_) => break, - Err(syscall::Error { errno: syscall::EINTR }) => continue, - Err(err) => unreachable!("failed to read event: {}", err), - } - } + self.window_target.event_socket.read(&mut event).unwrap(); // TODO: handle spurious wakeups (redraw caused wakeup but redraw already handled) match requested_resume { diff --git a/winit-orbital/src/lib.rs b/winit-orbital/src/lib.rs index 0a41dd0e..71efc821 100644 --- a/winit-orbital/src/lib.rs +++ b/winit-orbital/src/lib.rs @@ -33,7 +33,7 @@ impl RedoxSocket { // example, the seek would change in a potentially unpredictable way if either read or write // were called at the same time by multiple threads. fn open_raw(path: &str) -> syscall::Result { - let fd = libredox::call::open(path, libredox::flag::O_RDWR | libredox::flag::O_CLOEXEC, 0)?; + let fd = syscall::open(path, syscall::O_RDWR | syscall::O_CLOEXEC)?; Ok(Self { fd }) } @@ -97,7 +97,7 @@ struct WindowProperties<'a> { impl<'a> WindowProperties<'a> { fn new(path: &'a str) -> Self { - // /scheme/orbital/flags/x/y/w/h/t + // orbital:flags/x/y/w/h/t let mut parts = path.splitn(6, '/'); let flags = parts.next().unwrap_or(""); let x = parts.next().map_or(0, |part| part.parse::().unwrap_or(0)); diff --git a/winit-wayland/src/event_loop/mod.rs b/winit-wayland/src/event_loop/mod.rs index 65c97412..3a6ca698 100644 --- a/winit-wayland/src/event_loop/mod.rs +++ b/winit-wayland/src/event_loop/mod.rs @@ -379,27 +379,6 @@ impl EventLoop { } } - if compositor_update.suggested_bounds { - let suggested_bounds = self.with_state(|state| { - let windows = state.windows.get_mut(); - let window = windows.get(&window_id).unwrap().lock().unwrap(); - - window - .last_configure - .as_ref() - .and_then(|c| c.suggested_bounds) - .map(|b| dpi::LogicalSize::new(b.0, b.1).to_physical(window.scale_factor())) - .clone() - }); - let event = WindowEvent::SuggestedBounds(suggested_bounds); - app.window_event(&self.active_event_loop, window_id, event); - } - - if compositor_update.xdg_window_state.take().is_some() { - let event = WindowEvent::WindowStateChanged; - app.window_event(&self.active_event_loop, window_id, event); - } - // NOTE: Rescale changed the physical size which winit operates in, thus we should // resize. if compositor_update.resized || compositor_update.scale_changed { diff --git a/winit-wayland/src/lib.rs b/winit-wayland/src/lib.rs index 937a7df7..b34dedad 100644 --- a/winit-wayland/src/lib.rs +++ b/winit-wayland/src/lib.rs @@ -14,16 +14,12 @@ //! * `wayland-csd-adwaita-crossfont`. //! * `wayland-csd-adwaita-notitle`. //! * `wayland-csd-adwaita-notitlebar`. -use std::any::Any; use std::ffi::c_void; -use std::marker::PhantomData; use std::ptr::NonNull; use dpi::{LogicalSize, PhysicalSize}; -use rwh_06::HandleError; use sctk::reexports::client::Proxy; use sctk::reexports::client::protocol::wl_surface::WlSurface; -use sctk::reexports::csd_frame::WindowState; use sctk::shm::slot::{Buffer, CreateBufferError, SlotPool}; use wayland_client::protocol::wl_shm::Format; use winit_core::event_loop::ActiveEventLoop as CoreActiveEventLoop; @@ -76,37 +72,12 @@ pub trait EventLoopBuilderExtWayland { fn with_any_thread(&mut self, any_thread: bool) -> &mut Self; } -pub struct XdgSurfaceHandle<'a> { - raw: NonNull, - _marker: PhantomData<&'a ()>, -} - -impl<'a> XdgSurfaceHandle<'a> { - /// Create a `XdgSurfaceHandle` from a [`NonNull`] - pub unsafe fn borrow_raw(raw: NonNull) -> Self { - Self { raw, _marker: PhantomData } - } - - /// Get the underlying raw xdg_surface handle. - pub fn as_raw(&self) -> NonNull { - self.raw - } -} - -pub trait HasXdgSurfaceHandle { - fn xdg_surface_handle(&self) -> Result, HandleError>; -} - /// Additional methods on [`Window`] that are specific to Wayland. /// /// [`Window`]: crate::window::Window pub trait WindowExtWayland { /// Returns `xdg_toplevel` of the window or [`None`] if the window is X11 window. fn xdg_toplevel(&self) -> Option>; - - fn xdg_surface_handle<'a>(&'a self) -> Option<&dyn HasXdgSurfaceHandle>; - - fn window_state(&self) -> Option; } impl WindowExtWayland for dyn CoreWindow + '_ { @@ -114,15 +85,6 @@ impl WindowExtWayland for dyn CoreWindow + '_ { fn xdg_toplevel(&self) -> Option> { self.cast_ref::()?.xdg_toplevel() } - - #[inline] - fn xdg_surface_handle(&self) -> Option<&dyn HasXdgSurfaceHandle> { - Some(self.cast_ref::()? as &dyn HasXdgSurfaceHandle) - } - - fn window_state(&self) -> Option { - self.cast_ref::()?.xdg_window_state() - } } #[derive(Debug, Clone, PartialEq, Eq)] diff --git a/winit-wayland/src/state.rs b/winit-wayland/src/state.rs index adf32e4b..d6090599 100644 --- a/winit-wayland/src/state.rs +++ b/winit-wayland/src/state.rs @@ -29,7 +29,7 @@ use crate::seat::{ PointerConstraintsState, PointerGesturesState, RelativePointerState, TextInputState, WinitPointerData, WinitPointerDataExt, WinitSeatState, }; -use crate::types::bgr_effects::BgrEffectManager; +use crate::types::kwin_blur::KWinBlurManager; use crate::types::wp_fractional_scaling::FractionalScalingManager; use crate::types::wp_tablet_input_v2::TabletManager; use crate::types::wp_viewporter::ViewporterState; @@ -116,8 +116,8 @@ pub struct WinitState { /// Fractional scaling manager. pub fractional_scaling_manager: Option, - /// Blur manager. - pub blur_manager: Option, + /// KWin blur manager. + pub kwin_blur_manager: Option, /// Loop handle to re-register event sources, such as keyboard repeat. pub loop_handle: LoopHandle<'static, Self>, @@ -192,7 +192,7 @@ impl WinitState { window_events_sink: Default::default(), viewporter_state, fractional_scaling_manager, - blur_manager: BgrEffectManager::new(globals, queue_handle).ok(), + kwin_blur_manager: KWinBlurManager::new(globals, queue_handle).ok(), seats, text_input_state: TextInputState::new(globals, queue_handle).ok(), @@ -301,24 +301,15 @@ impl WindowHandler for WinitState { self.window_compositor_updates.len() - 1 }; - let mut winit_window = self + // Populate the configure to the window. + self.window_compositor_updates[pos].resized |= self .windows .get_mut() .get_mut(&window_id) .expect("got configure for dead window.") .lock() - .unwrap(); - // Populate the configure to the window. - - self.window_compositor_updates[pos].suggested_bounds |= configure.suggested_bounds - != winit_window.last_configure.as_ref().and_then(|last| last.suggested_bounds); - - if winit_window.last_configure.as_ref().is_none_or(|last| last.state != configure.state) { - self.window_compositor_updates[pos].xdg_window_state = Some(configure.state); - } - - self.window_compositor_updates[pos].resized |= - winit_window.configure(configure, &self.shm, &self.subcompositor_state); + .unwrap() + .configure(configure, &self.shm, &self.subcompositor_state); // NOTE: configure demands wl_surface::commit, however winit doesn't commit on behalf of the // users, since it can break a lot of things, thus it'll ask users to redraw instead. @@ -446,24 +437,11 @@ pub struct WindowCompositorUpdate { /// Close the window. pub close_window: bool, - - /// New suggested bounds. - pub suggested_bounds: bool, - - /// New xdg window state. - pub xdg_window_state: Option, } impl WindowCompositorUpdate { fn new(window_id: WindowId) -> Self { - Self { - window_id, - resized: false, - scale_changed: false, - close_window: false, - suggested_bounds: false, - xdg_window_state: None, - } + Self { window_id, resized: false, scale_changed: false, close_window: false } } } diff --git a/winit-wayland/src/types/bgr_effects.rs b/winit-wayland/src/types/bgr_effects.rs deleted file mode 100644 index 0607d907..00000000 --- a/winit-wayland/src/types/bgr_effects.rs +++ /dev/null @@ -1,85 +0,0 @@ -use sctk::compositor::Region; -use sctk::reexports::client::QueueHandle; -use sctk::reexports::client::globals::{BindError, GlobalList}; -use sctk::reexports::client::protocol::wl_surface::WlSurface; -use sctk::reexports::protocols::ext::background_effect::v1::client::ext_background_effect_surface_v1::ExtBackgroundEffectSurfaceV1; -use wayland_protocols_plasma::blur::client::org_kde_kwin_blur::OrgKdeKwinBlur; - -use crate::state::WinitState; -use crate::types::ext_background_effect::ExtBackgroundEffectManager; -use crate::types::kwin_blur::KWinBlurManager; - -/// Wrapper around various background effects for [`WlSurface`]. -#[derive(Debug, Clone)] -pub enum BgrEffectManager { - Ext(ExtBackgroundEffectManager), - KWin(KWinBlurManager), -} - -impl BgrEffectManager { - pub fn new( - globals: &GlobalList, - queue_handle: &QueueHandle, - ) -> Result { - ExtBackgroundEffectManager::new(globals, queue_handle) - .map(Self::Ext) - .or_else(|_| KWinBlurManager::new(globals, queue_handle).map(Self::KWin)) - } - - /// Creates a new blur effect for the surface. - pub fn new_blur_effect( - &mut self, - surface: &WlSurface, - queue_handle: &QueueHandle, - ) -> SurfaceBlurEffect { - match self { - BgrEffectManager::Ext(mgr) => SurfaceBlurEffect::Ext(mgr.blur(surface, queue_handle)), - BgrEffectManager::KWin(mgr) => SurfaceBlurEffect::Kwin( - mgr.blur(surface, queue_handle), - mgr.clone(), - surface.clone(), - ), - } - } -} - -#[derive(Debug)] -pub enum SurfaceBlurEffect { - Ext(ExtBackgroundEffectSurfaceV1), - Kwin(OrgKdeKwinBlur, KWinBlurManager, WlSurface), -} - -impl SurfaceBlurEffect { - /// Returns `true` if the main surface commit is required. - /// - /// `None` clears the blur. - #[must_use] - pub fn set_blur(&self, region: Option<&Region>) -> bool { - let region = region.map(|region| region.wl_region()); - match self { - SurfaceBlurEffect::Ext(surface) => { - surface.set_blur_region(region); - true - }, - SurfaceBlurEffect::Kwin(blur, ..) => { - blur.set_region(region); - blur.commit(); - true - }, - } - } -} - -impl Drop for SurfaceBlurEffect { - fn drop(&mut self) { - match self { - SurfaceBlurEffect::Ext(surface) => surface.destroy(), - SurfaceBlurEffect::Kwin(blur, mgr, wl_surface) => { - blur.set_region(None); - blur.commit(); - blur.release(); - mgr.unset(wl_surface); - }, - } - } -} diff --git a/winit-wayland/src/types/ext_background_effect.rs b/winit-wayland/src/types/ext_background_effect.rs deleted file mode 100644 index 6ef1e27c..00000000 --- a/winit-wayland/src/types/ext_background_effect.rs +++ /dev/null @@ -1,59 +0,0 @@ -use sctk::globals::GlobalData; -use sctk::reexports::client::globals::{BindError, GlobalList}; -use sctk::reexports::client::protocol::wl_surface::WlSurface; -use sctk::reexports::client::{Connection, Dispatch, Proxy, QueueHandle, delegate_dispatch}; -use wayland_protocols::ext::background_effect::v1::client::ext_background_effect_manager_v1::ExtBackgroundEffectManagerV1; -use wayland_protocols::ext::background_effect::v1::client::ext_background_effect_surface_v1::ExtBackgroundEffectSurfaceV1; - -use crate::state::WinitState; - -#[derive(Debug, Clone)] -pub struct ExtBackgroundEffectManager { - manager: ExtBackgroundEffectManagerV1, -} - -impl ExtBackgroundEffectManager { - pub fn new( - globals: &GlobalList, - queue_handle: &QueueHandle, - ) -> Result { - let manager = globals.bind(queue_handle, 1..=1, GlobalData)?; - Ok(Self { manager }) - } - - pub fn blur( - &mut self, - surface: &WlSurface, - queue_handle: &QueueHandle, - ) -> ExtBackgroundEffectSurfaceV1 { - self.manager.get_background_effect(surface, queue_handle, ()) - } -} - -impl Dispatch for ExtBackgroundEffectManager { - fn event( - _: &mut WinitState, - _: &ExtBackgroundEffectManagerV1, - _: ::Event, - _: &GlobalData, - _: &Connection, - _: &QueueHandle, - ) { - } -} - -impl Dispatch for ExtBackgroundEffectManager { - fn event( - _: &mut WinitState, - _: &ExtBackgroundEffectSurfaceV1, - _: ::Event, - _: &(), - _: &Connection, - _: &QueueHandle, - ) { - // There is no event - } -} - -delegate_dispatch!(WinitState: [ExtBackgroundEffectManagerV1: GlobalData] => ExtBackgroundEffectManager); -delegate_dispatch!(WinitState: [ExtBackgroundEffectSurfaceV1: ()] => ExtBackgroundEffectManager); diff --git a/winit-wayland/src/types/mod.rs b/winit-wayland/src/types/mod.rs index 2758da43..03b31bf5 100644 --- a/winit-wayland/src/types/mod.rs +++ b/winit-wayland/src/types/mod.rs @@ -1,8 +1,6 @@ //! Wayland protocol implementation boilerplate. -pub mod bgr_effects; pub mod cursor; -pub mod ext_background_effect; pub mod kwin_blur; pub mod wp_fractional_scaling; pub mod wp_tablet_input_v2; diff --git a/winit-wayland/src/window/mod.rs b/winit-wayland/src/window/mod.rs index ad6b01d5..37021bb0 100644 --- a/winit-wayland/src/window/mod.rs +++ b/winit-wayland/src/window/mod.rs @@ -12,7 +12,6 @@ use sctk::reexports::client::protocol::wl_surface::WlSurface; use sctk::reexports::client::{Proxy, QueueHandle}; use sctk::reexports::protocols::xdg::activation::v1::client::xdg_activation_v1::XdgActivationV1; use sctk::shell::WaylandSurface; -use sctk::shell::xdg::XdgSurface; use sctk::shell::xdg::window::{Window as SctkWindow, WindowDecorations}; use tracing::warn; use winit_core::cursor::Cursor; @@ -31,7 +30,7 @@ use super::event_loop::sink::EventSink; use super::output::MonitorHandle; use super::state::WinitState; use super::types::xdg_activation::XdgActivationTokenData; -use crate::{HasXdgSurfaceHandle, WindowAttributesWayland, XdgSurfaceHandle, output}; +use crate::{WindowAttributesWayland, output}; pub(crate) mod state; @@ -128,8 +127,7 @@ impl Window { // Set transparency hint. window_state.set_transparent(attributes.transparent); - // Set blur. - let _ = window_state.set_blur(attributes.blur); + window_state.set_blur(attributes.blur); // Set the decorations hint. window_state.set_decorate(attributes.decorations); @@ -253,11 +251,6 @@ impl Window { pub fn surface(&self) -> &WlSurface { self.window.wl_surface() } - - #[inline] - pub fn xdg_window_state(&self) -> Option { - self.window_state.lock().unwrap().last_configure.as_ref().map(|c| c.state) - } } impl Drop for Window { @@ -492,9 +485,7 @@ impl CoreWindow for Window { #[inline] fn set_blur(&self, blur: bool) { - if self.window_state.lock().unwrap().set_blur(blur) { - self.request_redraw(); - } + self.window_state.lock().unwrap().set_blur(blur); } #[inline] @@ -664,17 +655,6 @@ impl CoreWindow for Window { } } -impl HasXdgSurfaceHandle for Window { - fn xdg_surface_handle(&self) -> Result, rwh_06::HandleError> { - let raw = { - let ptr = self.window.xdg_surface().id().as_ptr(); - std::ptr::NonNull::new(ptr as *mut _).expect("wl_surface will never be null") - }; - - unsafe { Ok(XdgSurfaceHandle::borrow_raw(raw)) } - } -} - /// The request from the window to the event loop. #[derive(Debug)] pub struct WindowRequests { diff --git a/winit-wayland/src/window/state.rs b/winit-wayland/src/window/state.rs index 4c072cd9..86711bdd 100644 --- a/winit-wayland/src/window/state.rs +++ b/winit-wayland/src/window/state.rs @@ -29,6 +29,7 @@ use sctk::shm::slot::SlotPool; use sctk::subcompositor::SubcompositorState; use tracing::{info, warn}; use wayland_protocols::xdg::toplevel_icon::v1::client::xdg_toplevel_icon_manager_v1::XdgToplevelIconManagerV1; +use wayland_protocols_plasma::blur::client::org_kde_kwin_blur::OrgKdeKwinBlur; use winit_core::cursor::{CursorIcon, CustomCursor as CoreCustomCursor}; use winit_core::error::{NotSupportedError, RequestError}; use winit_core::window::{ @@ -42,8 +43,8 @@ use crate::seat::{ ZwpTextInputV3Ext, }; use crate::state::{WindowCompositorUpdate, WinitState}; -use crate::types::bgr_effects::{BgrEffectManager, SurfaceBlurEffect}; use crate::types::cursor::{CustomCursor, SelectedCursor, WaylandCustomCursor}; +use crate::types::kwin_blur::KWinBlurManager; use crate::types::xdg_toplevel_icon_manager::ToplevelIcon; #[cfg(feature = "sctk-adwaita")] @@ -154,8 +155,8 @@ pub struct WindowState { viewport: Option, fractional_scale: Option, - blur: Option, - blur_manager: Option, + blur: Option, + blur_manager: Option, /// Whether the client side decorations have pending move operations. /// @@ -204,7 +205,7 @@ impl WindowState { toplevel_icon: None, xdg_toplevel_icon_manager, blur: None, - blur_manager: winit_state.blur_manager.clone(), + blur_manager: winit_state.kwin_blur_manager.clone(), compositor, handle, csd_fails: false, @@ -703,13 +704,6 @@ impl WindowState { // Set surface size without the borders. viewport.set_destination(self.size.width as _, self.size.height as _); } - - // Update blur region with new size. - if self.blur.is_some() { - // NOTE: either user resized or configure, in both cases - // the redraw scheduling is done on the caller side. - let _ = self.set_blur(true); - } } /// Get the scale factor of the window. @@ -1069,37 +1063,20 @@ impl WindowState { } } - /// Make window background blurred. - /// - /// Returns `true` if redraw is required. - #[must_use] - pub fn set_blur(&mut self, blurred: bool) -> bool { - if !blurred { - self.blur = None; - return true; - } - - let mgr = match self.blur_manager.as_mut() { - Some(mgr) => mgr, - None => { - info!("Blur manager unavailable, unable to change blur"); - return false; - }, - }; - - let blur = match self.blur.as_ref() { - Some(blur) => blur, - None => { - self.blur = Some(mgr.new_blur_effect(self.window.wl_surface(), &self.queue_handle)); - self.blur.as_ref().unwrap() - }, - }; - - if let Ok(region) = Region::new(&*self.compositor) { - region.add(0, 0, i32::MAX, i32::MAX); - blur.set_blur(Some(®ion)) - } else { - false + /// Make window background blurred + #[inline] + pub fn set_blur(&mut self, blurred: bool) { + if blurred && self.blur.is_none() { + if let Some(blur_manager) = self.blur_manager.as_ref() { + let blur = blur_manager.blur(self.window.wl_surface(), &self.queue_handle); + blur.commit(); + self.blur = Some(blur); + } else { + info!("Blur manager unavailable, unable to change blur") + } + } else if !blurred && self.blur.is_some() { + self.blur_manager.as_ref().unwrap().unset(self.window.wl_surface()); + self.blur.take().unwrap().release(); } } @@ -1197,6 +1174,10 @@ impl WindowState { impl Drop for WindowState { fn drop(&mut self) { + if let Some(blur) = self.blur.take() { + blur.release(); + } + if let Some(fs) = self.fractional_scale.take() { fs.destroy(); } diff --git a/winit/examples/application.rs b/winit/examples/application.rs index 573f228e..dc432bb0 100644 --- a/winit/examples/application.rs +++ b/winit/examples/application.rs @@ -557,9 +557,7 @@ impl ApplicationHandler for Application { | WindowEvent::DragDropped { .. } | WindowEvent::Destroyed | WindowEvent::Ime(_) - | WindowEvent::Moved(_) - | WindowEvent::SuggestedBounds(_) - | WindowEvent::WindowStateChanged => (), + | WindowEvent::Moved(_) => (), } } diff --git a/winit/src/changelog/unreleased.md b/winit/src/changelog/unreleased.md index f3a0f6d2..93491753 100644 --- a/winit/src/changelog/unreleased.md +++ b/winit/src/changelog/unreleased.md @@ -39,3 +39,18 @@ The migration guide could reference other migration examples in the current changelog entry. ## Unreleased + +### Added + +- Add `EventLoopExtRegister::register_app` for being explicit about how the event loop runs on Web. +- Add `EventLoopExtNeverReturn::run_app_never_return` for being explicit about how the event loop runs on iOS. + +### Changed + +- On Web, avoid throwing an exception in `EventLoop::run_app`, instead preferring to return to the caller. + This requires passing a `'static` application to ensure that the application state will live as long as necessary. +- On Web, the event loop can now always be re-created once it has finished running. + +### Fixed + +- Fixed panic when calling `Window::set_ime_allowed`. diff --git a/winit/src/changelog/v0.31.md b/winit/src/changelog/v0.31.md index f8eb99a2..109e23f1 100644 --- a/winit/src/changelog/v0.31.md +++ b/winit/src/changelog/v0.31.md @@ -1,20 +1,3 @@ -## 0.31.0-beta.2 - -### Added - -- Add `EventLoopExtRegister::register_app` for being explicit about how the event loop runs on Web. -- Add `EventLoopExtNeverReturn::run_app_never_return` for being explicit about how the event loop runs on iOS. - -### Changed - -- On Web, avoid throwing an exception in `EventLoop::run_app`, instead preferring to return to the caller. - This requires passing a `'static` application to ensure that the application state will live as long as necessary. -- On Web, the event loop can now always be re-created once it has finished running. - -### Fixed - -- Fixed panic when calling `Window::set_ime_allowed`. - ## 0.31.0-beta.1 ### Added