Merge remote-tracking branch 'upstream/master' into yoda-wayland-only

# Conflicts:
#	Cargo.lock
#	Cargo.toml
#	wgpu/Cargo.toml
#	wgpu/src/window/compositor.rs
This commit is contained in:
Lionel DARNIS 2026-08-19 21:44:35 +02:00
commit d24bcd0272
36 changed files with 475 additions and 209 deletions

View file

@ -14,7 +14,18 @@ keywords.workspace = true
workspace = true
[features]
wayland = ["winit/wayland", "wayland-csd-adwaita"]
wayland = [
"winit/wayland",
"wayland-csd-adwaita",
"wayland-protocols",
"raw-window-handle",
"iced_runtime/wayland",
"wayland-backend",
"xkbcommon",
"xkbcommon-dl",
"xkeysym",
"dep:cctk",
]
default = ["x11", "wayland-dlopen"]
debug = ["iced_debug/enable"]
sysinfo = ["dep:sysinfo"]
@ -26,17 +37,6 @@ 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",
]
# Prevents multiple separate process instances.
single-instance = []
@ -64,7 +64,8 @@ iced_debug.workspace = true
iced_program.workspace = true
[target.'cfg(target_os = "linux")'.dependencies]
[target.'cfg(all(unix, not(any(target_os = "redox", target_family = "wasm", target_os = "android", target_vendor = "apple"))))'.dependencies]
mundy.workspace = true
mundy.optional = true
@ -89,3 +90,6 @@ winapi.workspace = true
web-sys.workspace = true
web-sys.features = ["Document", "Window", "HtmlCanvasElement"]
wasm-bindgen-futures.workspace = true
[build-dependencies]
build_helpers = { path = "../build_helpers" }

3
winit/build.rs Normal file
View file

@ -0,0 +1,3 @@
fn main() {
build_helpers::cfg_aliases_setup();
}

View file

@ -49,7 +49,10 @@ pub fn event_func(
position,
..
} => {
if !window.is_decorated() {
let resizable = !window.is_decorated()
&& !window.is_maximized()
&& window.fullscreen().is_none();
if resizable {
let location = cursor_resize_direction(
window.surface_size(),
*position,

View file

@ -92,7 +92,7 @@ impl Clipboard {
})
.unwrap_or(State::Unavailable);
#[cfg(target_os = "linux")]
#[cfg(wayland_platform)]
if let State::Connected { clipboard, .. } = &state {
clipboard.init_dnd(Box::new(sender));
}

View file

@ -23,6 +23,33 @@ use winit::event::Force;
use winit::icon::IconProvider;
use winit::keyboard::SmolStr;
/// Returns the activation token provided by the compositor, if any.
///
/// The token is single-use, so it is only ever handed out to the first window.
#[cfg(target_os = "linux")]
fn take_activation_token() -> Option<winit::window::ActivationToken> {
use std::sync::Mutex;
use std::sync::OnceLock;
use winit::platform::startup_notify::reset_activation_token_env;
static TOKEN: OnceLock<Mutex<Option<winit::window::ActivationToken>>> =
OnceLock::new();
TOKEN
.get_or_init(|| {
let token = std::env::var("XDG_ACTIVATION_TOKEN")
.ok()
.map(winit::window::ActivationToken::from_raw);
reset_activation_token_env();
Mutex::new(token)
})
.lock()
.ok()
.and_then(|mut token| token.take())
}
/// Converts some [`window::Settings`] into some `WindowAttributes` from `winit`.
pub fn window_attributes(
settings: window::Settings,
@ -182,12 +209,19 @@ pub fn window_attributes(
{
use winit::platform::wayland::WindowAttributesWayland;
attributes = attributes.with_platform_attributes(Box::new(
WindowAttributesWayland::default().with_name(
let mut wayland_attributes = WindowAttributesWayland::default()
.with_name(
&settings.platform_specific.application_id,
&settings.platform_specific.application_id,
),
));
);
if let Some(token) = take_activation_token() {
wayland_attributes =
wayland_attributes.with_activation_token(token);
}
attributes = attributes
.with_platform_attributes(Box::new(wayland_attributes));
}
}
@ -424,7 +458,7 @@ pub fn window_event(
WindowEvent::ScaleFactorChanged { scale_factor, .. } => {
Some(Event::Window(window::Event::Rescaled(scale_factor as f32)))
}
#[cfg(all(feature = "cctk", target_os = "linux"))]
#[cfg(wayland_platform)]
WindowEvent::SuggestedBounds(bounds) => {
let size = bounds.map(|bounds| {
let size = bounds.to_logical(scale_factor);
@ -437,7 +471,7 @@ pub fn window_event(
),
)))
}
#[cfg(all(feature = "cctk", target_os = "linux"))]
#[cfg(wayland_platform)]
WindowEvent::WindowStateChanged => {
use cctk::sctk::reexports::csd_frame::WindowState;
use winit::platform::wayland::WindowExtWayland;
@ -1491,7 +1525,7 @@ pub fn winit_key_code(
})
}
#[cfg(all(feature = "cctk", target_os = "linux"))]
#[cfg(wayland_platform)]
fn winit_native_key_code(
keycode: keyboard::key::NativeCode,
) -> winit::keyboard::NativeKeyCode {
@ -1515,7 +1549,7 @@ fn winit_native_key_code(
}
/// Reconstruct the raw keycode
#[cfg(all(feature = "cctk", target_os = "linux"))]
#[cfg(wayland_platform)]
pub fn physical_to_scancode(physical: keyboard::key::Physical) -> Option<u32> {
let Some(physical_key) = (match physical {
keyboard::key::Physical::Code(code) => {

View file

@ -47,7 +47,6 @@ mod window;
pub use clipboard::Clipboard;
pub use error::Error;
pub use proxy::Proxy;
use winit::dpi::LogicalSize;
use winit::dpi::PhysicalPosition;
use winit::dpi::PhysicalSize;
@ -92,10 +91,10 @@ where
let event_loop = EventLoop::new().expect("Create event loop");
#[cfg(all(feature = "cctk", target_os = "linux"))]
#[cfg(wayland_platform)]
let is_wayland =
winit::platform::wayland::EventLoopExtWayland::is_wayland(&event_loop);
#[cfg(not(all(feature = "cctk", target_os = "linux")))]
#[cfg(not(wayland_platform))]
let is_wayland = false;
// TODO this is new..
@ -262,7 +261,7 @@ where
| winit::event::WindowEvent::Moved(_)
);
#[cfg(all(feature = "cctk", target_os = "linux"))]
#[cfg(wayland_platform)]
{
if matches!(event, WindowEvent::RedrawRequested) {
for id in
@ -577,10 +576,7 @@ where
.expect("Send event");
}
Control::Winit(id, e) => {
#[cfg(all(
feature = "cctk",
target_os = "linux"
))]
#[cfg(wayland_platform)]
{
if matches!(e, WindowEvent::RedrawRequested)
{
@ -776,7 +772,7 @@ async fn run_instance<P>(
let mut platform_specific_handler =
crate::platform_specific::PlatformSpecific::default();
#[cfg(all(feature = "cctk", target_os = "linux"))]
#[cfg(wayland_platform)]
if is_wayland {
platform_specific_handler = platform_specific_handler.with_wayland(
control_sender.clone(),
@ -861,6 +857,8 @@ async fn run_instance<P>(
&mut is_window_opening,
&mut system_theme,
&mut platform_specific_handler,
&mut dnd_surface,
&mut dnd_surface_id,
is_daemon,
)
};
@ -887,7 +885,7 @@ async fn run_instance<P>(
on_open,
resize_border,
} => {
#[cfg(all(feature = "cctk", target_os = "linux"))]
#[cfg(wayland_platform)]
platform_specific_handler.send_wayland(
platform_specific::Action::TrackWindow(window.clone(), id),
);
@ -1056,7 +1054,7 @@ async fn run_instance<P>(
continue;
}
// XX must force update to corner radius before the surface is committed.
#[cfg(all(feature = "cctk", target_os = "linux"))]
#[cfg(wayland_platform)]
if (window.surface_version != window.state.surface_version()
|| window.logical_size() != window.state.logical_size())
&& !crate::subsurface_widget::is_subsurface(window_id)
@ -1395,8 +1393,7 @@ async fn run_instance<P>(
true
}
});
let no_window_events = window_events.is_empty();
#[cfg(all(feature = "cctk", target_os = "linux"))]
#[cfg(wayland_platform)]
window_events.push(core::Event::PlatformSpecific(
core::event::PlatformSpecific::Wayland(
core::event::wayland::Event::RequestResize,
@ -1413,8 +1410,7 @@ async fn run_instance<P>(
&mut clipboard,
&mut messages,
);
let mut needs_redraw =
!no_window_events || !messages.is_empty();
let mut needs_redraw = !messages.is_empty();
if let Some(requested_size) =
clipboard.requested_logical_size.lock().unwrap().take()
{
@ -1470,8 +1466,17 @@ async fn run_instance<P>(
mouse_interaction,
..
} => {
let mouse_changed =
window.mouse_interaction != mouse_interaction;
window.update_mouse(mouse_interaction);
if mouse_changed {
window.request_redraw(
core::window::RedrawRequest::NextFrame,
);
}
#[cfg(not(feature = "unconditional-rendering"))]
window.request_redraw(_redraw_request);
}
@ -2074,6 +2079,10 @@ fn run_action<'a, P, C>(
is_window_opening: &mut bool,
system_theme: &mut theme::Mode,
platform_specific: &mut crate::platform_specific::PlatformSpecific,
dnd_surface: &mut Option<
Arc<Box<dyn HasWindowHandle + Send + Sync + 'static>>,
>,
dnd_surface_id: &mut Option<window::Id>,
is_daemon: bool,
) -> bool
where
@ -2128,7 +2137,7 @@ where
_ = control_sender.start_send(Control::Cleanup(id)).ok();
}
let proxy = clipboard.proxy();
#[cfg(all(feature = "cctk", target_os = "linux"))]
#[cfg(wayland_platform)]
platform_specific
.send_wayland(platform_specific::Action::RemoveWindow(id));
if let Some(window) = window_manager.remove(id) {
@ -2589,6 +2598,10 @@ where
}
iced_runtime::dnd::DndAction::EndDnd => {
clipboard.end_dnd();
*dnd_surface = None;
if let Some(id) = dnd_surface_id.take() {
platform_specific.retain_subsurfaces(|other| other != id);
}
}
iced_runtime::dnd::DndAction::PeekDnd(m, channel) => {
let data = clipboard.peek_dnd(m);

View file

@ -1,24 +1,20 @@
//! Wayland specific shell
//!
use std::{borrow::Cow, collections::HashMap, sync::Arc};
use std::collections::HashMap;
#[cfg(all(feature = "cctk", target_os = "linux"))]
use cctk::sctk::reexports::client::Connection;
use iced_graphics::{Compositor, compositor};
use iced_graphics::compositor;
use iced_runtime::{
core::{Vector, window},
platform_specific, user_interface,
user_interface,
};
use winit::raw_window_handle::HasWindowHandle;
#[cfg(all(feature = "cctk", target_os = "linux"))]
#[cfg(wayland_platform)]
pub mod wayland;
#[cfg(all(feature = "cctk", target_os = "linux"))]
#[cfg(wayland_platform)]
pub use wayland::*;
#[cfg(all(feature = "cctk", target_os = "linux"))]
use wayland_backend::client::Backend;
use crate::{CreateCompositor, Program, WindowManager};
@ -35,7 +31,7 @@ pub type UserInterfaces<'a, P> = HashMap<
#[derive(Debug)]
pub enum Event {
#[cfg(all(feature = "cctk", target_os = "linux"))]
#[cfg(wayland_platform)]
Wayland(sctk_event::SctkEvent),
}
@ -61,7 +57,7 @@ impl SurfaceIdWrapper {
#[derive(Debug, Default)]
pub struct PlatformSpecific {
#[cfg(all(feature = "cctk", target_os = "linux"))]
#[cfg(wayland_platform)]
wayland: WaylandSpecific,
}
@ -71,7 +67,7 @@ impl PlatformSpecific {
action: iced_runtime::platform_specific::Action,
) {
match action {
#[cfg(all(feature = "cctk", target_os = "linux"))]
#[cfg(wayland_platform)]
iced_runtime::platform_specific::Action::Wayland(a) => {
self.send_wayland(wayland::Action::Action(a));
}
@ -82,14 +78,14 @@ impl PlatformSpecific {
&mut self,
keep: F,
) {
#[cfg(all(feature = "cctk", target_os = "linux"))]
#[cfg(wayland_platform)]
{
self.wayland.retain_subsurfaces(keep);
}
}
pub(crate) fn clear_subsurface_list(&mut self) {
#[cfg(all(feature = "cctk", target_os = "linux"))]
#[cfg(wayland_platform)]
{
self.wayland.clear_subsurface_list();
}
@ -100,7 +96,7 @@ impl PlatformSpecific {
id: window::Id,
window: &dyn HasWindowHandle,
) {
#[cfg(all(feature = "cctk", target_os = "linux"))]
#[cfg(wayland_platform)]
{
use cctk::sctk::reexports::client::{
Proxy, protocol::wl_surface::WlSurface,
@ -151,7 +147,7 @@ impl PlatformSpecific {
pub(crate) fn create_surface(
&mut self,
) -> Option<Box<dyn HasWindowHandle + Send + Sync + 'static>> {
#[cfg(all(feature = "cctk", target_os = "linux"))]
#[cfg(wayland_platform)]
{
self.wayland.create_surface()
}
@ -170,7 +166,7 @@ impl PlatformSpecific {
data: &[u8],
offset: Vector,
) {
#[cfg(all(feature = "cctk", target_os = "linux"))]
#[cfg(wayland_platform)]
{
return self.wayland.update_surface_shm(
surface, width, height, scale, data, offset,
@ -198,7 +194,7 @@ pub(crate) async fn handle_event<'a, 'b, P>(
P: Program,
{
match e {
#[cfg(all(feature = "cctk", target_os = "linux"))]
#[cfg(wayland_platform)]
Event::Wayland(e) => {
platform_specific
.wayland

View file

@ -874,6 +874,11 @@ impl SctkState {
_ = wl_surface.frame(&self.queue_handle, wl_surface.clone());
if let Some(old) = self.blur_surfaces.remove(&settings.id) {
old.destroy();
}
_ = self.corner_radii.remove(&settings.id);
if let Some(blur) = self.pending_blur.remove(&settings.id) {
self.apply_blur(settings.id, Some(blur), &wl_surface);
}
@ -1011,6 +1016,12 @@ impl SctkState {
layer_surface.set_input_region(Some(&region));
region.destroy();
}
if let Some(old) = self.blur_surfaces.remove(&id) {
old.destroy();
}
_ = self.corner_radii.remove(&id);
if let Some(blur) = self.pending_blur.remove(&id) {
self.apply_blur(id, Some(blur), &wl_surface);
}
@ -1268,11 +1279,11 @@ impl SctkState {
|| self.layer_surfaces.iter().any(|l| l.id == settings.parent && p.data.parent.wl_surface() == l.surface.wl_surface()))
) {
let existing = &mut self.popups[existing];
let size = if settings.positioner.size.is_none() {
log::info!("No configured popup size");
(1, 1)
let size = if let Some(size) = settings.positioner.size {
size
} else {
settings.positioner.size.unwrap()
let guard = existing.common.lock().unwrap();
(guard.size.width, guard.size.height)
};
let Ok(positioner) = XdgPositioner::new(&self.xdg_shell_state)
.map_err(PopupCreationError::PositionerCreationFailed) else {
@ -1392,7 +1403,7 @@ impl SctkState {
},
};
let mut to_destroy = vec![sctk_popup];
// TODO optionally destroy parents if they request to be destroyed with children
while let Some(popup_to_destroy_last) = to_destroy.last().and_then(|popup| self
.popups
.iter()
@ -1839,6 +1850,7 @@ impl SctkState {
s: &WlSurface,
) {
let existing_blur = self.blur_surfaces.entry(id);
match (existing_blur, rectangles) {
(Entry::Occupied(occupied_entry), None) => {
let blur_surface = occupied_entry.remove();
@ -2021,6 +2033,11 @@ impl SctkState {
region.destroy();
}
if let Some(old) = self.blur_surfaces.remove(&settings.id) {
old.destroy();
}
_ = self.corner_radii.remove(&settings.id);
if let Some(blur) = self.pending_blur.remove(&settings.id) {
_ = self.apply_blur(settings.id, Some(blur), &wl_surface);
}

View file

@ -1,8 +1,5 @@
use crate::{
event_loop::state::FrameStatus,
platform_specific::wayland::{
event_loop::state::SctkState, sctk_event::SctkEvent,
},
use crate::platform_specific::wayland::{
event_loop::state::SctkState, sctk_event::SctkEvent,
};
use cctk::sctk::{
delegate_pointer,
@ -50,14 +47,6 @@ impl PointerHandler for SctkState {
continue;
}
let entry = self
.frame_status
.entry(e.surface.id())
.or_insert(FrameStatus::RequestedRedraw);
if matches!(entry, FrameStatus::Received) {
*entry = FrameStatus::Ready;
}
self.sctk_events.push(SctkEvent::PointerEvent {
variant: PointerEvent {
surface: e.surface.clone(),

View file

@ -27,6 +27,15 @@ impl LayerShellHandler for SctkState {
None => return,
};
if let Some(id) = self.id_map.remove(&layer.surface.wl_surface().id()) {
if let Some(blurred) = self.blur_surfaces.remove(&id) {
blurred.destroy();
}
_ = self.corner_radii.remove(&id);
_ = self.destroyed.insert(id);
}
self.sctk_events.push(SctkEvent::LayerSurfaceEvent {
variant: LayerSurfaceEventVariant::Done,
id: layer.surface.wl_surface().clone(),

View file

@ -84,6 +84,11 @@ impl PopupHandler for SctkState {
for popup in to_destroy.into_iter().rev() {
if let Some(id) = self.id_map.remove(&popup.popup.wl_surface().id())
{
if let Some(blurred) = self.blur_surfaces.remove(&id) {
blurred.destroy();
}
_ = self.corner_radii.remove(&id);
_ = self.destroyed.insert(id);
}