From 0ecdbe5e51b0d090739fdd0e33c2b7860047bf44 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sun, 22 Nov 2026 08:54:59 -0800 Subject: [PATCH] W42: Wayland: compile the KDE blur protocol only with wayland-kde-blur The `wayland` feature, which is on by default, enabled wayland-protocols-plasma for the org_kde_kwin_blur_manager protocol. That crate is MIT, but the blur protocol XML it turns into code is LGPL-2.1-or-later, so every Linux build compiled LGPL-derived bindings. The new `wayland-kde-blur` feature, off by default and not part of `wayland`, enables the dependency and the blur code. Without it, Window::set_blur and WindowAttributes::with_blur are ignored on Wayland and the window logs the request at info level. With it, blur works as before. CI gets a job that fails when the default features, or any feature other than `wayland-kde-blur`, bring in wayland-protocols-plasma, and a Linux row that builds, tests and lints with `wayland-kde-blur`. --- .github/workflows/ci.yml | 27 +++++++++++++++++++ Cargo.toml | 2 +- PATCHES.md | 1 + src/platform/wayland.rs | 6 +++++ src/platform_impl/linux/wayland/state.rs | 3 +++ src/platform_impl/linux/wayland/types/mod.rs | 1 + .../linux/wayland/window/state.rs | 17 ++++++++++++ src/window.rs | 3 ++- 8 files changed, 58 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index aa80f409..ebf5220b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -35,6 +35,32 @@ jobs: echo 'To check for a diff, run `typos`' echo 'You can find typos here: https://crates.io/crates/typos' + kde-blur-opt-in: + name: Check that the KDE blur protocol is opt-in + runs-on: ubuntu-latest + steps: + - uses: taiki-e/checkout-action@v1 + - uses: dtolnay/rust-toolchain@stable + - name: Only `wayland-kde-blur` brings in wayland-protocols-plasma + # The protocol XML in wayland-protocols-plasma is LGPL-2.1-or-later. + run: | + set -eu + plasma() { + tree=$(cargo tree -e normal,build --target x86_64-unknown-linux-gnu --prefix none "$@") \ + || { echo "cargo tree $* failed"; exit 2; } + printf '%s\n' "$tree" | grep -q '^wayland-protocols-plasma ' + } + others=$(cargo metadata --format-version 1 --no-deps \ + | jq -r '[.packages[] | select(.name == "winit") | .features | keys[] + | select(. != "default" and . != "wayland-kde-blur")] | join(",")') + if plasma; then echo 'the default features bring in wayland-protocols-plasma'; exit 1; fi + if plasma --features="$others"; then + echo "one of $others brings in wayland-protocols-plasma"; exit 1 + fi + if ! plasma --no-default-features --features=wayland-kde-blur; then + echo 'wayland-kde-blur does not bring in wayland-protocols-plasma'; exit 1 + fi + tests: name: Test ${{ matrix.toolchain }} ${{ matrix.platform.name }} runs-on: ${{ matrix.platform.os }} @@ -53,6 +79,7 @@ jobs: - { name: 'Linux 64bit', target: x86_64-unknown-linux-gnu, os: ubuntu-latest, } - { name: 'X11', target: x86_64-unknown-linux-gnu, os: ubuntu-latest, options: '--no-default-features --features=x11' } - { name: 'Wayland', target: x86_64-unknown-linux-gnu, os: ubuntu-latest, options: '--no-default-features --features=wayland,wayland-dlopen' } + - { name: 'Wayland KDE blur', target: x86_64-unknown-linux-gnu, os: ubuntu-latest, options: '--features=wayland-kde-blur' } - { name: 'Android', target: aarch64-linux-android, os: ubuntu-latest, options: '--package=winit --features=android-native-activity', cmd: 'apk --' } - { name: 'Redox OS', target: x86_64-unknown-redox, os: ubuntu-latest, } - { name: 'macOS', target: x86_64-apple-darwin, os: macos-latest, } diff --git a/Cargo.toml b/Cargo.toml index 72be2b0e..e8d0369e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -63,13 +63,13 @@ wayland = [ "wayland-client", "wayland-backend", "wayland-protocols", - "wayland-protocols-plasma", "sctk", "ahash", "memmap2", "percent-encoding", ] wayland-dlopen = ["wayland-backend/dlopen"] +wayland-kde-blur = ["wayland", "dep:wayland-protocols-plasma"] wayland-csd-adwaita = ["sctk-adwaita", "sctk-adwaita/ab_glyph"] wayland-csd-adwaita-crossfont = ["sctk-adwaita", "sctk-adwaita/crossfont"] wayland-csd-adwaita-notitle = ["sctk-adwaita"] diff --git a/PATCHES.md b/PATCHES.md index c100c83d..786365a0 100644 --- a/PATCHES.md +++ b/PATCHES.md @@ -34,6 +34,7 @@ input lives in `craft-tablet`). | W25 | `eb4007da` | X11/Wayland: `platform::latin_layout::KeyEventExtLatinLayout`, the key on the first Latin layout group for shortcuts on non-Latin layouts | none; to be proposed | upstream release with an equivalent | storytold/winit PR #5; craft-libs#198 (K2) | | W26 | `2b9cd1cf` | macOS: replaced text is deleted by UTF-8 byte count with the commit (`WindowExtMacOS::take_ime_delete_surrounding`, same shape as W27) | master: `Ime::DeleteSurrounding` (a new `Ime` variant breaks 0.30 matchers) | the egui → 0.31 move | storytold/winit PR #6 (`d103edae`) | | W27 | `f40c76a2` | Wayland: text-input-v3 surrounding text (`WindowExtWayland::set_ime_surrounding_text`, `set_ime_surrounding_text_with_change_cause`, `clear_ime_surrounding_text`), delete-surrounding attached to the commit (`take_ime_delete_surrounding` → `ImeDeleteSurrounding { before_bytes, after_bytes }`), per-seat preedit ownership and outgoing state waiting for a matching `done` (E21b) | master has both as core API (`Ime::DeleteSurrounding`) | the egui → 0.31 move | storytold/winit PR #7; craft-libs#198 (I7) | +| W42 | `fix/kde-blur-optional` | Wayland: the KDE blur protocol (`wayland-protocols-plasma`, whose protocol XML is LGPL-2.1-or-later) is compiled only with the new `wayland-kde-blur` feature, off by default and not part of `wayland`; without it `set_blur`/`with_blur` are ignored on Wayland (CI job `kde-blur-opt-in` checks the dependency graph; CI row `Wayland KDE blur` builds the blur code) | none; master enables `wayland-protocols-plasma` with `wayland` | keep while the suite ships no LGPL code | storytold/vectorcraft#9113 | Conflict resolved by hand: `wayland/seat/mod.rs` `remove_seat` keeps all three cleanups — cancel a file drag (W15), remove the seat from winit's clipboard (W15), destroy the seat's text input (W2). diff --git a/src/platform/wayland.rs b/src/platform/wayland.rs index 5e3fc81a..dc55984e 100644 --- a/src/platform/wayland.rs +++ b/src/platform/wayland.rs @@ -13,6 +13,12 @@ //! * `wayland-csd-adwaita` (default). //! * `wayland-csd-adwaita-crossfont`. //! * `wayland-csd-adwaita-notitle`. +//! +//! ## Window blur +//! +//! [`Window::set_blur`] uses the KDE `org_kde_kwin_blur_manager` protocol, which is compiled only +//! with the `wayland-kde-blur` cargo feature (off by default). Without it, blur requests are +//! ignored. use std::ffi::c_void; use std::ptr::NonNull; diff --git a/src/platform_impl/linux/wayland/state.rs b/src/platform_impl/linux/wayland/state.rs index 74c44574..46f4fd73 100644 --- a/src/platform_impl/linux/wayland/state.rs +++ b/src/platform_impl/linux/wayland/state.rs @@ -34,6 +34,7 @@ use crate::platform_impl::wayland::seat::{ PointerConstraintsState, RelativePointerState, TextInputState, WinitPointerData, WinitPointerDataExt, WinitSeatState, }; +#[cfg(feature = "wayland-kde-blur")] use crate::platform_impl::wayland::types::kwin_blur::KWinBlurManager; use crate::platform_impl::wayland::types::wp_fractional_scaling::FractionalScalingManager; use crate::platform_impl::wayland::types::wp_viewporter::ViewporterState; @@ -125,6 +126,7 @@ pub struct WinitState { pub fractional_scaling_manager: Option, /// KWin blur manager. + #[cfg(feature = "wayland-kde-blur")] pub kwin_blur_manager: Option, /// Loop handle to re-register event sources, such as keyboard repeat. @@ -250,6 +252,7 @@ impl WinitState { window_events_sink: Default::default(), viewporter_state, fractional_scaling_manager, + #[cfg(feature = "wayland-kde-blur")] kwin_blur_manager: KWinBlurManager::new(globals, queue_handle).ok(), seats, diff --git a/src/platform_impl/linux/wayland/types/mod.rs b/src/platform_impl/linux/wayland/types/mod.rs index 77e67f48..ca0bc661 100644 --- a/src/platform_impl/linux/wayland/types/mod.rs +++ b/src/platform_impl/linux/wayland/types/mod.rs @@ -1,6 +1,7 @@ //! Wayland protocol implementation boilerplate. pub mod cursor; +#[cfg(feature = "wayland-kde-blur")] pub mod kwin_blur; pub mod wp_fractional_scaling; pub mod wp_viewporter; diff --git a/src/platform_impl/linux/wayland/window/state.rs b/src/platform_impl/linux/wayland/window/state.rs index 79e60ccd..067c0aac 100644 --- a/src/platform_impl/linux/wayland/window/state.rs +++ b/src/platform_impl/linux/wayland/window/state.rs @@ -28,6 +28,7 @@ use sctk::shell::WaylandSurface; use sctk::shm::slot::SlotPool; use sctk::shm::Shm; use sctk::subcompositor::SubcompositorState; +#[cfg(feature = "wayland-kde-blur")] use wayland_protocols_plasma::blur::client::org_kde_kwin_blur::OrgKdeKwinBlur; use crate::cursor::CustomCursor as RootCustomCursor; @@ -35,6 +36,7 @@ use crate::dpi::{LogicalPosition, LogicalSize, PhysicalPosition, PhysicalSize, S use crate::error::{ExternalError, NotSupportedError}; use crate::platform_impl::wayland::logical_to_physical_rounded; use crate::platform_impl::wayland::types::cursor::{CustomCursor, SelectedCursor}; +#[cfg(feature = "wayland-kde-blur")] use crate::platform_impl::wayland::types::kwin_blur::KWinBlurManager; use crate::platform_impl::{PlatformCustomCursor, WindowId}; use crate::window::{CursorGrabMode, CursorIcon, ImePurpose, ResizeDirection, Theme}; @@ -263,7 +265,9 @@ pub struct WindowState { viewport: Option, fractional_scale: Option, + #[cfg(feature = "wayland-kde-blur")] blur: Option, + #[cfg(feature = "wayland-kde-blur")] blur_manager: Option, /// Whether the client side decorations have pending move operations. @@ -304,7 +308,9 @@ impl WindowState { .map(|fsm| fsm.fractional_scaling(window.wl_surface(), queue_handle)); Self { + #[cfg(feature = "wayland-kde-blur")] blur: None, + #[cfg(feature = "wayland-kde-blur")] blur_manager: winit_state.kwin_blur_manager.clone(), compositor, connection, @@ -1444,6 +1450,7 @@ impl WindowState { } /// Make window background blurred + #[cfg(feature = "wayland-kde-blur")] #[inline] pub fn set_blur(&mut self, blurred: bool) { if blurred && self.blur.is_none() { @@ -1460,6 +1467,15 @@ impl WindowState { } } + /// Without the `wayland-kde-blur` feature, blur requests are ignored. + #[cfg(not(feature = "wayland-kde-blur"))] + #[inline] + pub fn set_blur(&mut self, blurred: bool) { + if blurred { + info!("Blur needs the `wayland-kde-blur` feature, unable to change blur") + } + } + /// Set the window title to a new value. /// /// This will automatically truncate the title to something meaningful. @@ -1547,6 +1563,7 @@ impl WindowState { impl Drop for WindowState { fn drop(&mut self) { + #[cfg(feature = "wayland-kde-blur")] if let Some(blur) = self.blur.take() { blur.release(); } diff --git a/src/window.rs b/src/window.rs index 4602943a..dfaaa0d2 100644 --- a/src/window.rs +++ b/src/window.rs @@ -954,7 +954,8 @@ impl Window { /// ## Platform-specific /// /// - **Android / iOS / X11 / Web / Windows:** Unsupported. - /// - **Wayland:** Only works with org_kde_kwin_blur_manager protocol. + /// - **Wayland:** Only works with org_kde_kwin_blur_manager protocol, and only when the + /// `wayland-kde-blur` cargo feature is enabled. Without it, the request is ignored. #[inline] pub fn set_blur(&self, blur: bool) { let _span = tracing::debug_span!("winit::Window::set_blur", blur).entered();