diff --git a/Cargo.toml b/Cargo.toml index 6e9c6927..49b4b5d7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -118,8 +118,9 @@ winit = [ "iced_accessibility?/accesskit_winit", "iced_program/winit", ] +wayland = ["iced_renderer/wayland", "iced_winit/wayland"] +cctk = ["iced_winit/cctk", "iced_widget/cctk", "iced_core/cctk", "wayland"] # Enables the sctk shell. -wayland = ["iced_widget/wayland", "iced_core/wayland", "iced_winit/wayland"] [dependencies] diff --git a/core/Cargo.toml b/core/Cargo.toml index 936eed6f..e64a5c37 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -19,7 +19,6 @@ crisp = [] basic-shaping = [] advanced-shaping = [] a11y = ["iced_accessibility"] -wayland = ["cctk"] [dependencies] palette = "0.7" diff --git a/core/src/event.rs b/core/src/event.rs index e5ed162a..1aaf4ff4 100644 --- a/core/src/event.rs +++ b/core/src/event.rs @@ -7,7 +7,7 @@ use crate::keyboard; use crate::mouse; use crate::touch; use crate::window; -#[cfg(feature = "wayland")] +#[cfg(all(feature = "cctk", target_os = "linux"))] /// A platform specific event for wayland pub mod wayland; /// A user interface event. @@ -49,7 +49,7 @@ pub enum Event { /// A platform specific event #[derive(Debug, Clone, PartialEq)] pub enum PlatformSpecific { - #[cfg(feature = "wayland")] + #[cfg(all(feature = "cctk", target_os = "linux"))] /// A Wayland specific event Wayland(wayland::Event), } diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml index 90ce50eb..ea4741d1 100644 --- a/runtime/Cargo.toml +++ b/runtime/Cargo.toml @@ -17,7 +17,7 @@ workspace = true debug = [] selector = ["dep:iced_selector"] a11y = ["iced_accessibility", "iced_core/a11y"] -wayland = ["iced_core/wayland", "cctk"] +cctk = ["iced_core/cctk", "dep:cctk"] [dependencies] bytes.workspace = true diff --git a/runtime/src/platform_specific/mod.rs b/runtime/src/platform_specific/mod.rs index 572288b3..a25b5fc6 100644 --- a/runtime/src/platform_specific/mod.rs +++ b/runtime/src/platform_specific/mod.rs @@ -2,21 +2,21 @@ use std::fmt; -#[cfg(feature = "wayland")] +#[cfg(all(feature = "cctk", target_os = "linux"))] /// Platform specific actions defined for wayland pub mod wayland; /// Platform specific actions defined for wayland pub enum Action { /// Wayland Specific Actions - #[cfg(feature = "wayland")] + #[cfg(all(feature = "cctk", target_os = "linux"))] Wayland(wayland::Action), } impl fmt::Debug for Action { fn fmt(&self, _f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { - #[cfg(feature = "wayland")] + #[cfg(all(feature = "cctk", target_os = "linux"))] Action::Wayland(action) => action.fmt(_f), #[cfg(not(feature = "wayland"))] _ => Ok(()), diff --git a/runtime/src/window.rs b/runtime/src/window.rs index 62156e8a..4d2f5650 100644 --- a/runtime/src/window.rs +++ b/runtime/src/window.rs @@ -222,7 +222,7 @@ pub fn frames() -> Subscription<(Id, Instant)> { _ => None, }) } -#[cfg(feature = "wayland")] +#[cfg(all(feature = "cctk", target_os = "linux"))] /// Subscribes to the frames of the window of the running application. /// /// The resulting [`Subscription`] will produce items at a rate equal to the diff --git a/src/lib.rs b/src/lib.rs index fbc6bac2..8d408969 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -606,7 +606,7 @@ pub mod font { pub mod event { //! Handle events of a user interface. pub use crate::core::event::PlatformSpecific; - #[cfg(feature = "wayland")] + #[cfg(all(feature = "cctk", target_os = "linux"))] pub use crate::core::event::wayland; pub use crate::core::event::{Event, Status}; pub use iced_futures::event::{listen, listen_raw, listen_with}; diff --git a/wgpu/Cargo.toml b/wgpu/Cargo.toml index e4b01598..944fdb3e 100644 --- a/wgpu/Cargo.toml +++ b/wgpu/Cargo.toml @@ -52,6 +52,7 @@ resvg.optional = true rustix = { version = "0.38" } raw-window-handle.workspace = true cctk.workspace = true +cctk.optional = true wayland-protocols.workspace = true wayland-backend = { version = "0.3.3", features = ["client_system"] } wayland-client = { version = "0.31.2" } diff --git a/wgpu/src/window.rs b/wgpu/src/window.rs index 011f60e5..b9ec54bd 100644 --- a/wgpu/src/window.rs +++ b/wgpu/src/window.rs @@ -1,6 +1,11 @@ //! Display rendering results on windows. pub mod compositor; -#[cfg(all(unix, not(target_os = "macos"), not(target_os = "redox")))] +#[cfg(all( + unix, + feature = "cctk", + not(target_os = "macos"), + not(target_os = "redox") +))] mod wayland; #[cfg(all(unix, not(target_os = "macos"), not(target_os = "redox")))] mod x11; diff --git a/wgpu/src/window/compositor.rs b/wgpu/src/window/compositor.rs index f72dde70..833a642e 100644 --- a/wgpu/src/window/compositor.rs +++ b/wgpu/src/window/compositor.rs @@ -9,7 +9,12 @@ use crate::graphics::{self, Shell, Viewport}; use crate::settings::{self, Settings}; use crate::{Engine, Renderer}; -#[cfg(all(unix, not(target_os = "macos"), not(target_os = "redox")))] +#[cfg(all( + unix, + feature = "cctk", + not(target_os = "macos"), + not(target_os = "redox") +))] use super::wayland::get_wayland_device_ids; #[cfg(all(unix, not(target_os = "macos"), not(target_os = "redox")))] use super::x11::get_x11_device_ids; @@ -60,7 +65,12 @@ impl Compositor { compatible_window: Option, shell: Shell, ) -> Result { - #[cfg(all(unix, not(target_os = "macos"), not(target_os = "redox")))] + #[cfg(all( + unix, + feature = "cctk", + not(target_os = "macos"), + not(target_os = "redox") + ))] let ids = compatible_window.as_ref().and_then(|window| { get_wayland_device_ids(window) .or_else(|| get_x11_device_ids(window)) @@ -72,7 +82,12 @@ impl Compositor { // 3. and the user didn't set an adapter name, // 4. and the user didn't request the high power pref // => don't load the nvidia icd, as it might power on the gpu in hybrid setups causing severe delays - #[cfg(all(unix, not(target_os = "macos"), not(target_os = "redox")))] + #[cfg(all( + unix, + feature = "cctk", + not(target_os = "macos"), + not(target_os = "redox") + ))] if !matches!(ids, Some((0x10de, _))) && std::env::var_os("__NV_PRIME_RENDER_OFFLOAD") .is_none_or(|var| var == "0") @@ -133,6 +148,7 @@ impl Compositor { if std::env::var_os("WGPU_ADAPTER_NAME").is_none() { #[cfg(all( unix, + feature = "cctk", not(target_os = "macos"), not(target_os = "redox") ))] diff --git a/wgpu/src/window/wayland.rs b/wgpu/src/window/wayland.rs index 031b8b2f..48e00def 100644 --- a/wgpu/src/window/wayland.rs +++ b/wgpu/src/window/wayland.rs @@ -6,8 +6,8 @@ use cctk::sctk::{ }; use raw_window_handle::{RawDisplayHandle, WaylandDisplayHandle}; use wayland_client::{ - backend::Backend, globals::registry_queue_init, protocol::wl_buffer, - Connection, QueueHandle, + Connection, QueueHandle, backend::Backend, globals::registry_queue_init, + protocol::wl_buffer, }; use wayland_protocols::wp::linux_dmabuf::zv1::client::{ zwp_linux_buffer_params_v1, zwp_linux_dmabuf_feedback_v1, diff --git a/widget/Cargo.toml b/widget/Cargo.toml index e3c4796d..ab34819b 100644 --- a/widget/Cargo.toml +++ b/widget/Cargo.toml @@ -29,7 +29,7 @@ highlighter = ["dep:iced_highlighter"] advanced = [] crisp = [] a11y = ["iced_accessibility"] -wayland = ["cctk", "iced_runtime/wayland"] +cctk = ["iced_runtime/cctk", "dep:cctk"] [dependencies] iced_renderer.workspace = true diff --git a/winit/Cargo.toml b/winit/Cargo.toml index c6e32e94..1208cc17 100644 --- a/winit/Cargo.toml +++ b/winit/Cargo.toml @@ -14,18 +14,7 @@ keywords.workspace = true workspace = true [features] -wayland = [ - "winit/wayland", - "cctk", - "wayland-protocols", - "raw-window-handle", - "iced_runtime/wayland", - "wayland-backend", - "xkbcommon", - "xkbcommon-dl", - "xkeysym", - "wayland-csd-adwaita", -] +wayland = ["winit/wayland", "wayland-csd-adwaita"] default = ["x11", "wayland-dlopen"] debug = ["iced_debug/enable"] sysinfo = ["dep:sysinfo"] @@ -37,6 +26,17 @@ program = [] wayland-dlopen = ["winit/wayland-dlopen"] wayland-csd-adwaita = ["winit/wayland-csd-adwaita"] a11y = ["iced_accessibility", "iced_runtime/a11y"] +cctk = [ + "wayland", + "wayland-protocols", + "raw-window-handle", + "iced_runtime/cctk", + "wayland-backend", + "xkbcommon", + "xkbcommon-dl", + "xkeysym", + "dep:cctk", +] [dependencies] diff --git a/winit/src/conversion.rs b/winit/src/conversion.rs index 0c609d37..fcb73c39 100644 --- a/winit/src/conversion.rs +++ b/winit/src/conversion.rs @@ -178,7 +178,7 @@ pub fn window_attributes( ), )); } - #[cfg(feature = "wayland")] + #[cfg(all(feature = "cctk", target_os = "linux"))] { use winit::platform::wayland::WindowAttributesWayland; @@ -424,7 +424,7 @@ pub fn window_event( WindowEvent::ScaleFactorChanged { scale_factor, .. } => { Some(Event::Window(window::Event::Rescaled(scale_factor as f32))) } - #[cfg(feature = "wayland")] + #[cfg(all(feature = "cctk", target_os = "linux"))] WindowEvent::SuggestedBounds(bounds) => { let size = bounds.map(|bounds| { let size = bounds.to_logical(scale_factor); @@ -437,7 +437,7 @@ pub fn window_event( ), ))) } - #[cfg(feature = "wayland")] + #[cfg(all(feature = "cctk", target_os = "linux"))] WindowEvent::WindowStateChanged => { use cctk::sctk::reexports::csd_frame::WindowState; use winit::platform::wayland::WindowExtWayland; @@ -1491,7 +1491,7 @@ pub fn winit_key_code( }) } -#[cfg(feature = "wayland")] +#[cfg(all(feature = "cctk", target_os = "linux"))] fn winit_native_key_code( keycode: keyboard::key::NativeCode, ) -> winit::keyboard::NativeKeyCode { @@ -1515,7 +1515,7 @@ fn winit_native_key_code( } /// Reconstruct the raw keycode -#[cfg(feature = "wayland")] +#[cfg(all(feature = "cctk", target_os = "linux"))] pub fn physical_to_scancode(physical: keyboard::key::Physical) -> Option { let Some(physical_key) = (match physical { keyboard::key::Physical::Code(code) => { diff --git a/winit/src/lib.rs b/winit/src/lib.rs index 52bc9d5e..a4ef66d4 100644 --- a/winit/src/lib.rs +++ b/winit/src/lib.rs @@ -98,10 +98,10 @@ where let event_loop = EventLoop::new().expect("Create event loop"); - #[cfg(feature = "wayland")] + #[cfg(all(feature = "cctk", target_os = "linux"))] let is_wayland = winit::platform::wayland::EventLoopExtWayland::is_wayland(&event_loop); - #[cfg(not(feature = "wayland"))] + #[cfg(not(all(feature = "cctk", target_os = "linux")))] let is_wayland = false; // TODO this is new.. @@ -193,7 +193,10 @@ where error: Option, system_theme: Option>, control_sender: mpsc::UnboundedSender, - + + #[cfg(feature = "a11y")] + adapters: std::collections::HashMap, + #[cfg(target_arch = "wasm32")] is_booted: std::rc::Rc>, #[cfg(target_arch = "wasm32")] @@ -216,6 +219,9 @@ where error: None, system_theme: Some(system_theme_sender), + #[cfg(feature = "a11y")] + adapters: Default::default(), + #[cfg(target_arch = "wasm32")] canvas: None, }; @@ -257,7 +263,7 @@ where | winit::event::WindowEvent::Moved(_) ); - #[cfg(feature = "wayland")] + #[cfg(all(feature = "cctk", target_os = "linux"))] { if matches!(event, WindowEvent::RedrawRequested) { for id in @@ -558,7 +564,7 @@ where .expect("Send event"); } Control::Winit(id, e) => { - #[cfg(feature = "wayland")] + #[cfg(all(feature = "cctk", target_os = "linux"))] { if matches!(e, WindowEvent::RedrawRequested) { @@ -621,22 +627,23 @@ where proxy: self.control_sender.clone(), }; - self.sender - .start_send(Event::A11yAdapter( - id, - ( - node_id, - Adapter::with_direct_handlers( - event_loop, - window.as_ref(), - activation_handler, - action_handler, - deactivation_handler, - ), + _ = self.adapters.insert( + id, + ( + node_id, + Adapter::with_direct_handlers( + event_loop, + window.as_ref(), + activation_handler, + action_handler, + deactivation_handler, ), - )) - .expect("send event"); + ), + ); } + Control::Cleanup(id) => { + _ = self.adapters.remove(&id); + }, }, _ => { break; @@ -680,11 +687,11 @@ enum Event { Accessibility(window::Id, iced_accessibility::accesskit::ActionRequest), #[cfg(feature = "a11y")] AccessibilityEnabled(bool), - #[cfg(feature = "a11y")] - A11yAdapter( - window::Id, - (u64, iced_accessibility::accesskit_winit::Adapter), - ), + // #[cfg(feature = "a11y")] + // A11yAdapter( + // window::Id, + // (u64, iced_accessibility::accesskit_winit::Adapter), + // ), Winit(winit::window::WindowId, winit::event::WindowEvent), AboutToWait, UserEvent(Action), @@ -697,6 +704,7 @@ enum Control { ChangeFlow(winit::event_loop::ControlFlow), Exit, Crash(Error), + Cleanup(window::Id), CreateWindow { id: window::Id, settings: window::Settings, @@ -743,7 +751,7 @@ async fn run_instance

( let mut platform_specific_handler = crate::platform_specific::PlatformSpecific::default(); - #[cfg(all(feature = "wayland", target_os = "linux"))] + #[cfg(all(feature = "cctk", target_os = "linux"))] if is_wayland { platform_specific_handler = platform_specific_handler.with_wayland( control_sender.clone(), @@ -774,7 +782,7 @@ async fn run_instance

( let mut dnd_surface_id: Option = None; #[cfg(feature = "a11y")] - let (mut adapters, mut a11y_enabled) = (Default::default(), false); + let mut a11y_enabled = false; #[cfg(all(feature = "linux-theme-detection", target_os = "linux"))] let mut system_theme = { @@ -836,7 +844,7 @@ async fn run_instance

( control_sender .start_send(Control::InitAdapter(id, window.clone())) .expect("Send control message"); - #[cfg(feature = "wayland")] + #[cfg(all(feature = "cctk", target_os = "linux"))] platform_specific_handler.send_wayland( platform_specific::Action::TrackWindow(window.clone(), id), ); @@ -1012,7 +1020,7 @@ async fn run_instance

( continue; } // XX must force update to corner radius before the surface is committed. - #[cfg(feature = "wayland")] + #[cfg(all(feature = "cctk", target_os = "linux"))] if (window.surface_version != window.state.surface_version() || window.logical_size() != window.state.logical_size() ) && !crate::subsurface_widget::is_subsurface(window_id) @@ -1382,7 +1390,7 @@ async fn run_instance

( } }); let no_window_events = window_events.is_empty(); - #[cfg(feature = "wayland")] + #[cfg(all(feature = "cctk", target_os = "linux"))] window_events.push(core::Event::PlatformSpecific( core::event::PlatformSpecific::Wayland( core::event::wayland::Event::RequestResize, @@ -1646,8 +1654,6 @@ async fn run_instance

( &mut window_manager, &mut user_interfaces, &mut clipboard, - #[cfg(feature = "a11y")] - &mut adapters, CreateCompositor { proxy: &proxy, display_handle: &display_handle, @@ -1884,10 +1890,6 @@ async fn run_instance

( } } } - #[cfg(feature = "a11y")] - Event::A11yAdapter(id, adapter) => { - _ = adapters.insert(id, adapter); - } _ => {} } } @@ -2124,8 +2126,9 @@ where window::Action::Close(id) => { let _ = ui_caches.remove(&id); let _ = interfaces.remove(&id); + _ = control_sender.start_send(Control::Cleanup(id)).ok(); let proxy = clipboard.proxy(); - #[cfg(feature = "wayland")] + #[cfg(all(feature = "cctk", target_os = "linux"))] platform_specific .send_wayland(platform_specific::Action::RemoveWindow(id)); if let Some(window) = window_manager.remove(id) { diff --git a/winit/src/platform_specific/mod.rs b/winit/src/platform_specific/mod.rs index 3f02b08f..9b74ee9c 100644 --- a/winit/src/platform_specific/mod.rs +++ b/winit/src/platform_specific/mod.rs @@ -3,7 +3,7 @@ use std::{borrow::Cow, collections::HashMap, sync::Arc}; -#[cfg(all(feature = "wayland", target_os = "linux"))] +#[cfg(all(feature = "cctk", target_os = "linux"))] use cctk::sctk::reexports::client::Connection; use iced_graphics::{Compositor, compositor}; use iced_runtime::{ @@ -12,12 +12,12 @@ use iced_runtime::{ }; use winit::raw_window_handle::HasWindowHandle; -#[cfg(all(feature = "wayland", target_os = "linux"))] +#[cfg(all(feature = "cctk", target_os = "linux"))] pub mod wayland; -#[cfg(all(feature = "wayland", target_os = "linux"))] +#[cfg(all(feature = "cctk", target_os = "linux"))] pub use wayland::*; -#[cfg(all(feature = "wayland", target_os = "linux"))] +#[cfg(all(feature = "cctk", target_os = "linux"))] use wayland_backend::client::Backend; use crate::{CreateCompositor, Program, WindowManager}; @@ -35,7 +35,7 @@ pub type UserInterfaces<'a, P> = HashMap< #[derive(Debug)] pub enum Event { - #[cfg(all(feature = "wayland", target_os = "linux"))] + #[cfg(all(feature = "cctk", target_os = "linux"))] Wayland(sctk_event::SctkEvent), } @@ -61,7 +61,7 @@ impl SurfaceIdWrapper { #[derive(Debug, Default)] pub struct PlatformSpecific { - #[cfg(all(feature = "wayland", target_os = "linux"))] + #[cfg(all(feature = "cctk", target_os = "linux"))] wayland: WaylandSpecific, } @@ -71,7 +71,7 @@ impl PlatformSpecific { action: iced_runtime::platform_specific::Action, ) { match action { - #[cfg(all(feature = "wayland", target_os = "linux"))] + #[cfg(all(feature = "cctk", target_os = "linux"))] iced_runtime::platform_specific::Action::Wayland(a) => { self.send_wayland(wayland::Action::Action(a)); } @@ -82,14 +82,14 @@ impl PlatformSpecific { &mut self, keep: F, ) { - #[cfg(all(feature = "wayland", target_os = "linux"))] + #[cfg(all(feature = "cctk", target_os = "linux"))] { self.wayland.retain_subsurfaces(keep); } } pub(crate) fn clear_subsurface_list(&mut self) { - #[cfg(all(feature = "wayland", target_os = "linux"))] + #[cfg(all(feature = "cctk", target_os = "linux"))] { self.wayland.clear_subsurface_list(); } @@ -100,7 +100,7 @@ impl PlatformSpecific { id: window::Id, window: &dyn HasWindowHandle, ) { - #[cfg(all(feature = "wayland", target_os = "linux"))] + #[cfg(all(feature = "cctk", target_os = "linux"))] { use cctk::sctk::reexports::client::{ Proxy, protocol::wl_surface::WlSurface, @@ -151,7 +151,7 @@ impl PlatformSpecific { pub(crate) fn create_surface( &mut self, ) -> Option> { - #[cfg(all(feature = "wayland", target_os = "linux"))] + #[cfg(all(feature = "cctk", target_os = "linux"))] { return self.wayland.create_surface(); } @@ -167,7 +167,7 @@ impl PlatformSpecific { data: &[u8], offset: Vector, ) { - #[cfg(all(feature = "wayland", target_os = "linux"))] + #[cfg(all(feature = "cctk", target_os = "linux"))] { return self.wayland.update_surface_shm( surface, width, height, scale, data, offset, @@ -190,16 +190,12 @@ pub(crate) async fn handle_event<'a, 'b, P>( >, user_interfaces: &mut UserInterfaces<'a, P>, clipboard: &mut crate::Clipboard, - #[cfg(feature = "a11y")] adapters: &mut std::collections::HashMap< - window::Id, - (u64, iced_accessibility::accesskit_winit::Adapter), - >, create_compositor: CreateCompositor<'b, P>, ) where P: Program, { match e { - #[cfg(all(feature = "wayland", target_os = "linux"))] + #[cfg(all(feature = "cctk", target_os = "linux"))] Event::Wayland(e) => { platform_specific .wayland @@ -211,8 +207,6 @@ pub(crate) async fn handle_event<'a, 'b, P>( window_manager, user_interfaces, clipboard, - #[cfg(feature = "a11y")] - adapters, create_compositor, ) .await; diff --git a/winit/src/platform_specific/wayland/mod.rs b/winit/src/platform_specific/wayland/mod.rs index 2361ecb0..7ae0db68 100644 --- a/winit/src/platform_specific/wayland/mod.rs +++ b/winit/src/platform_specific/wayland/mod.rs @@ -164,10 +164,6 @@ impl WaylandSpecific { >, user_interfaces: &mut UserInterfaces<'a, P>, clipboard: &mut crate::Clipboard, - #[cfg(feature = "a11y")] adapters: &mut HashMap< - window::Id, - (u64, iced_accessibility::accesskit_winit::Adapter), - >, create_compositor: CreateCompositor<'b, P>, ) where P: Program, @@ -213,8 +209,6 @@ impl WaylandSpecific { events, clipboard, subsurface_state, - #[cfg(feature = "a11y")] - adapters, create_compositor, ) .await; diff --git a/winit/src/platform_specific/wayland/sctk_event.rs b/winit/src/platform_specific/wayland/sctk_event.rs index 2ced88e5..04cad329 100755 --- a/winit/src/platform_specific/wayland/sctk_event.rs +++ b/winit/src/platform_specific/wayland/sctk_event.rs @@ -361,10 +361,6 @@ impl SctkEvent { events: &mut Vec<(Option, iced_runtime::core::Event)>, clipboard: &mut Clipboard, subsurface_state: &mut Option, - #[cfg(feature = "a11y")] adapters: &mut HashMap< - window::Id, - (u64, iced_accessibility::accesskit_winit::Adapter), - >, create_compositor_data: CreateCompositor<'b, P>, ) where P: Program, @@ -472,8 +468,7 @@ impl SctkEvent { x: -horizontal.value120 as f32 / 120., y: -vertical.value120 as f32 / 120., } - } else if horizontal.discrete != 0 - || vertical.discrete != 0 + } else if horizontal.discrete != 0 || vertical.discrete != 0 { mouse::ScrollDelta::Lines { x: -horizontal.discrete as f32,