chore: cleanup platform specific code

This commit is contained in:
Ashley Wulber 2026-03-30 15:19:39 -04:00 committed by Ashley Wulber
parent a11b828280
commit 3b7f0bec0e
18 changed files with 109 additions and 101 deletions

View file

@ -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<Box<dyn HasWindowHandle + Send + Sync + 'static>> {
#[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;