iced-yoda/winit/src/platform_specific/mod.rs
Votre Nom e424487704
Some checks are pending
Audit / vulnerabilities (push) Waiting to run
Check / wasm (push) Waiting to run
Check / widget (push) Waiting to run
Document / all (push) Waiting to run
Format / all (push) Waiting to run
Lint / all (push) Waiting to run
Test / all (macOS-latest, 1.88) (push) Waiting to run
Test / all (macOS-latest, beta) (push) Waiting to run
Test / all (macOS-latest, stable) (push) Waiting to run
Test / all (ubuntu-latest, 1.88) (push) Waiting to run
Test / all (ubuntu-latest, beta) (push) Waiting to run
Test / all (ubuntu-latest, stable) (push) Waiting to run
Test / all (windows-latest, 1.88) (push) Waiting to run
Test / all (windows-latest, beta) (push) Waiting to run
Test / all (windows-latest, stable) (push) Waiting to run
yoda: iced_winit dead-code purge (29→0 warnings)
Removed code paths inherited from past refactors that no longer have any
reader:

- ViewFn type alias (window.rs)
- a11y_enabled flag and resized flag (lib.rs) — assigned but never read
- BootConfig.fonts/graphics_settings/is_wayland — already passed to
  run_instance(...) directly; the BootConfig copies were never read
- Runner.system_theme oneshot::Sender — stored but no producer ever
  wired; receiver side already falls back to default
- event_loop/control_flow.rs — local ControlFlow enum, all callers use
  winit::event_loop::ControlFlow
- event_loop/proxy.rs — Proxy<Message> never constructed
- Error::Connect(ConnectError) variant — never constructed
- Common.has_focus / ime_pos / ime_size — never read after assignment
- SctkPopupData.grab — replicated settings.grab, never read back
- SubsurfaceEventVariant::Created.surface field — destructure does
  `surface: _` everywhere, the value is unused

Visibility tightening:
- a11y.rs WinitActivationHandler / WinitActionHandler /
  WinitDeactivationHandler: pub proxy → pub(crate) proxy
- conversion::touch_event: pub → private (no external callers)
- proxy::Proxy:🆕 pub → pub(crate)

Allow attributes (intentional, not warning-suppression):
- conversion::RawImage: #[allow(dead_code)] — fields kept for
  IconProvider downcast-via-AsAny on winit's side
- event_loop::Error: #[allow(dead_code)] — variant payloads kept for
  Debug, never inspected programmatically
- lib.rs Event<Message>: #[allow(hidden_glob_reexports)] — intentional
  shadow of winit::event::Event coming from `pub use winit`
- window.rs/lib.rs: #[allow(deprecated)] on enable_ime/disable_ime/
  process_event with TODOs for set_ime_* → request_ime_update and
  try_next → try_recv migrations

Five orphan imports also removed (Hash/Hasher, BorrowMut, 3× Compositor).

Leyoda 2026 – GPLv3
2026-05-05 18:26:08 +02:00

213 lines
5.9 KiB
Rust

//! Wayland specific shell
//!
use std::collections::HashMap;
use iced_graphics::compositor;
use iced_runtime::{
core::{Vector, window}, user_interface,
};
use winit::raw_window_handle::HasWindowHandle;
#[cfg(all(feature = "cctk", target_os = "linux"))]
pub mod wayland;
#[cfg(all(feature = "cctk", target_os = "linux"))]
pub use wayland::*;
use crate::{CreateCompositor, Program, WindowManager};
pub type UserInterfaces<'a, P> = HashMap<
window::Id,
user_interface::UserInterface<
'a,
<P as Program>::Message,
<P as Program>::Theme,
<P as Program>::Renderer,
>,
rustc_hash::FxBuildHasher,
>;
#[derive(Debug)]
pub enum Event {
#[cfg(all(feature = "cctk", target_os = "linux"))]
Wayland(sctk_event::SctkEvent),
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum SurfaceIdWrapper {
LayerSurface(window::Id),
Window(window::Id),
Popup(window::Id),
SessionLock(window::Id),
Subsurface(window::Id),
}
impl SurfaceIdWrapper {
pub fn inner(&self) -> window::Id {
match self {
SurfaceIdWrapper::LayerSurface(id) => *id,
SurfaceIdWrapper::Window(id) => *id,
SurfaceIdWrapper::Popup(id) => *id,
SurfaceIdWrapper::SessionLock(id) => *id,
SurfaceIdWrapper::Subsurface(id) => *id,
}
}
}
#[derive(Debug, Default)]
pub struct PlatformSpecific {
#[cfg(all(feature = "cctk", target_os = "linux"))]
wayland: WaylandSpecific,
}
impl PlatformSpecific {
pub(crate) fn send_action(
&mut self,
action: iced_runtime::platform_specific::Action,
) {
match action {
#[cfg(all(feature = "cctk", target_os = "linux"))]
iced_runtime::platform_specific::Action::Wayland(a) => {
self.send_wayland(wayland::Action::Action(a));
}
}
}
pub(crate) fn retain_subsurfaces<F: Fn(window::Id) -> bool>(
&mut self,
keep: F,
) {
#[cfg(all(feature = "cctk", target_os = "linux"))]
{
self.wayland.retain_subsurfaces(keep);
}
}
pub(crate) fn clear_subsurface_list(&mut self) {
#[cfg(all(feature = "cctk", target_os = "linux"))]
{
self.wayland.clear_subsurface_list();
}
}
pub(crate) fn update_subsurfaces(
&mut self,
id: window::Id,
window: &dyn HasWindowHandle,
) {
#[cfg(all(feature = "cctk", target_os = "linux"))]
{
use cctk::sctk::reexports::client::{
Proxy, protocol::wl_surface::WlSurface,
};
use wayland_backend::client::ObjectId;
let Some(conn) = self.wayland.conn() else {
log::info!("No Wayland conn");
return;
};
let Ok(raw) = window.window_handle() else {
log::error!("Invalid window handle {id:?}");
return;
};
let wl_surface = match raw.as_raw() {
raw_window_handle::RawWindowHandle::Wayland(
wayland_window_handle,
) => {
let res = unsafe {
ObjectId::from_ptr(
WlSurface::interface(),
wayland_window_handle.surface.as_ptr().cast(),
)
};
let Ok(id) = res else {
log::error!(
"Could not create WlSurface Id from window"
);
return;
};
let Ok(surface) = WlSurface::from_id(&conn, id) else {
log::error!("Could not create WlSurface from Id");
return;
};
surface
}
_ => {
log::error!("Unexpected window handle type");
return;
}
};
self.wayland.update_subsurfaces(id, &wl_surface);
}
}
pub(crate) fn create_surface(
&mut self,
) -> Option<Box<dyn HasWindowHandle + Send + Sync + 'static>> {
#[cfg(all(feature = "cctk", target_os = "linux"))]
{
self.wayland.create_surface()
}
#[cfg(not(all(feature = "cctk", target_os = "linux")))]
{
None
}
}
pub(crate) fn update_surface_shm(
&mut self,
surface: &dyn HasWindowHandle,
width: u32,
height: u32,
scale: f64,
data: &[u8],
offset: Vector,
) {
#[cfg(all(feature = "cctk", target_os = "linux"))]
{
return self.wayland.update_surface_shm(
surface, width, height, scale, data, offset,
);
}
}
}
pub(crate) async fn handle_event<'a, 'b, P>(
e: Event,
events: &mut Vec<(Option<window::Id>, iced_runtime::core::Event)>,
platform_specific: &mut PlatformSpecific,
program: &'a crate::program::Instance<P>,
compositor: &mut Option<
<<P as Program>::Renderer as compositor::Default>::Compositor,
>,
window_manager: &mut WindowManager<
P,
<<P as Program>::Renderer as compositor::Default>::Compositor,
>,
user_interfaces: &mut UserInterfaces<'a, P>,
clipboard: &mut crate::Clipboard,
create_compositor: CreateCompositor<'b, P>,
) where
P: Program,
{
match e {
#[cfg(all(feature = "cctk", target_os = "linux"))]
Event::Wayland(e) => {
platform_specific
.wayland
.handle_event(
e,
events,
program,
compositor,
window_manager,
user_interfaces,
clipboard,
create_compositor,
)
.await;
}
}
}