Merge remote-tracking branch 'origin/craft/0.30.13' into fix/windows-alt-codes-rebased

# Conflicts:
#	PATCHES.md
This commit is contained in:
David Mann committed 2026-11-27 14:03:00 +01:00
commit bd5969e945
4 files changed
+181 -5

No files matched your search

+1
View File
@@ -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) |
| W30 | this commit | Linux: the first window created without an activation token takes the launcher's (`XDG_ACTIVATION_TOKEN` on Wayland, `DESKTOP_STARTUP_ID` on X11) and hands it back as one given through `with_activation_token` would be (`platform_impl/linux/startup_token.rs`), so GNOME drops the busy cursor and a Wayland window opens focused; later windows don't reuse the spent token, an empty or oversized (over 1,024 bytes) token is ignored, and the variable stays in the environment (changing it while other threads may read it is unsound) | none; to be proposed | upstream release that hands the launcher's token to the first window | pdfcraft vendor patch (14); cadcraft#2030 (`tests/winit_startup_token.rs`) |
| W36 | `924c77b4` | Windows: an Alt code (Alt+0181 for µ) types its character; Windows sends it in `WM_CHAR` after Alt's key-up, which the keyboard builder dropped as IME text. It goes on a press of an unidentified key (as `VK_PACKET` is reported) with a release after it | none found; to be proposed | upstream release with an equivalent | pdfcraft#5746 |
Conflict resolved by hand: `wayland/seat/mod.rs` `remove_seat` keeps all three cleanups — cancel a
+2 -2
View File
@@ -28,10 +28,10 @@ use crate::event_loop::{ActiveEventLoop, AsyncRequestSerial};
use crate::window::{ActivationToken, Window, WindowAttributes};
/// The variable which is used mostly on X11.
const X11_VAR: &str = "DESKTOP_STARTUP_ID";
pub(crate) const X11_VAR: &str = "DESKTOP_STARTUP_ID";
/// The variable which is used mostly on Wayland.
const WAYLAND_VAR: &str = "XDG_ACTIVATION_TOKEN";
pub(crate) const WAYLAND_VAR: &str = "XDG_ACTIVATION_TOKEN";
pub trait EventLoopExtStartupNotify {
/// Read the token from the environment.
+12 -3
View File
@@ -25,6 +25,7 @@ use crate::event_loop::{
use crate::icon::Icon;
use crate::keyboard::Key;
use crate::platform::pump_events::PumpStatus;
use crate::platform::startup_notify;
#[cfg(x11_platform)]
use crate::platform::x11::{WindowType as XWindowType, XlibErrorHook};
use crate::window::{
@@ -38,6 +39,7 @@ pub(crate) use crate::icon::RgbaIcon as PlatformIcon;
pub(crate) use crate::platform_impl::Fullscreen;
pub(crate) mod common;
mod startup_token;
#[cfg(wayland_platform)]
pub(crate) mod wayland;
#[cfg(x11_platform)]
@@ -290,16 +292,23 @@ impl Window {
#[inline]
pub(crate) fn new(
window_target: &ActiveEventLoop,
attribs: WindowAttributes,
mut attribs: WindowAttributes,
) -> Result<Self, RootOsError> {
let given = attribs.platform_specific.activation_token.take();
match *window_target {
#[cfg(wayland_platform)]
ActiveEventLoop::Wayland(ref window_target) => {
wayland::Window::new(window_target, attribs).map(Window::Wayland)
startup_token::with_token(given, startup_notify::WAYLAND_VAR, |token| {
attribs.platform_specific.activation_token = token;
wayland::Window::new(window_target, attribs).map(Window::Wayland)
})
},
#[cfg(x11_platform)]
ActiveEventLoop::X(ref window_target) => {
x11::Window::new(window_target, attribs).map(Window::X)
startup_token::with_token(given, startup_notify::X11_VAR, |token| {
attribs.platform_specific.activation_token = token;
x11::Window::new(window_target, attribs).map(Window::X)
})
},
}
}
+166
View File
@@ -0,0 +1,166 @@
//! The launcher's activation token for the first window (CADCraft patch, from PdfCraft).
//!
//! A launcher with `StartupNotify=true` passes an activation token in the environment
//! (`XDG_ACTIVATION_TOKEN` on Wayland, `DESKTOP_STARTUP_ID` on X11) and shows a busy cursor
//! until a window hands it back. winit hands back only a token given through
//! `WindowAttributesExtStartupNotify::with_activation_token`, and eframe never gives one, so
//! GNOME kept the busy cursor until its 15-second timeout and the window opened without focus.
//!
//! The first window the process creates without a token now takes the one in the environment.
//! Later windows never do: the token is spent once a window has been created with it. A window
//! that fails to be created leaves it unspent, so a retry still hands it back. The variable is
//! left in the environment, unlike `reset_activation_token_env`, because changing the
//! environment while other threads may read it is unsound, and an application can start
//! threads before its first window.
use std::sync::atomic::{AtomicBool, Ordering};
use crate::window::ActivationToken;
/// Longer tokens are ignored. Launchers make tokens of a few dozen bytes; on X11 the token is
/// written to a window property and sent to the window manager, and an oversized one would
/// fail window creation.
const MAX_TOKEN_LEN: usize = 1024;
static TAKEN: AtomicBool = AtomicBool::new(false);
/// Creates a window with `given` if there is one, else, for the process's first window, the
/// environment's value of `var`. The launcher's token is spent only when `create` succeeds.
pub(crate) fn with_token<T, E>(
given: Option<ActivationToken>,
var: &str,
create: impl FnOnce(Option<ActivationToken>) -> Result<T, E>,
) -> Result<T, E> {
create_with(given, &TAKEN, from_env(var), create)
}
/// Reads the launcher's token from the environment variable `var`.
fn from_env(var: &str) -> impl FnOnce() -> Option<String> + '_ {
move || std::env::var(var).ok()
}
fn create_with<T, E>(
given: Option<ActivationToken>,
taken: &AtomicBool,
read: impl FnOnce() -> Option<String>,
create: impl FnOnce(Option<ActivationToken>) -> Result<T, E>,
) -> Result<T, E> {
let first = !taken.load(Ordering::Relaxed);
let token = if given.is_some() || !first {
given
} else {
read()
.filter(|token| !token.is_empty() && token.len() <= MAX_TOKEN_LEN)
.map(ActivationToken::from_raw)
};
let window = create(token)?;
// The first window spends the launcher's token, whether or not it was given one.
taken.store(true, Ordering::Relaxed);
Ok(window)
}
#[cfg(test)]
mod tests {
use super::*;
fn token(raw: &str) -> Option<ActivationToken> {
Some(ActivationToken::from_raw(raw.to_owned()))
}
/// The token a successfully created window received.
fn choose(
given: Option<ActivationToken>,
taken: &AtomicBool,
read: impl FnOnce() -> Option<String>,
) -> Option<ActivationToken> {
create_with(given, taken, read, Ok::<_, ()>).ok().flatten()
}
#[test]
fn the_first_window_takes_the_launchers_token() {
let taken = AtomicBool::new(false);
assert_eq!(
choose(None, &taken, || Some("gnome-shell/PdfCraft/1234".into())),
token("gnome-shell/PdfCraft/1234")
);
}
#[test]
fn a_later_window_does_not_reuse_the_spent_token() {
let taken = AtomicBool::new(false);
assert!(choose(None, &taken, || Some("t".into())).is_some());
assert_eq!(choose(None, &taken, || Some("t".into())), None);
}
#[test]
fn a_given_token_wins_and_still_spends_the_launchers() {
let taken = AtomicBool::new(false);
assert_eq!(choose(token("mine"), &taken, || Some("env".into())), token("mine"));
assert_eq!(choose(None, &taken, || Some("env".into())), None);
assert_eq!(choose(token("again"), &taken, || Some("env".into())), token("again"));
}
#[test]
fn a_missing_empty_or_oversized_token_is_ignored() {
assert_eq!(choose(None, &AtomicBool::new(false), || None), None);
assert_eq!(choose(None, &AtomicBool::new(false), || Some(String::new())), None);
let long = "x".repeat(MAX_TOKEN_LEN + 1);
assert_eq!(choose(None, &AtomicBool::new(false), || Some(long)), None);
let limit = "x".repeat(MAX_TOKEN_LEN);
assert!(choose(None, &AtomicBool::new(false), || Some(limit)).is_some());
}
/// The variable the child below reads its token from.
const VAR: &str = "WINIT_W30_TEST_ACTIVATION_TOKEN";
/// Set only in the child: the token it must take, or empty for none.
const EXPECT: &str = "WINIT_W30_TEST_EXPECT";
#[test]
fn the_token_is_read_from_the_variable_when_set_and_not_when_cleared() {
// The environment is given to a child process rather than changed here: `set_var` while
// other test threads run is the unsoundness this module avoids by leaving the variable.
let name = concat!(module_path!(), "::the_first_window_reads_the_variable_in_a_child");
let name = name.split_once("::").unwrap().1;
for value in [Some("gnome-shell/CADCraft/42"), None] {
let mut child = std::process::Command::new(std::env::current_exe().unwrap());
child.args([name, "--exact", "--test-threads=1"]).env(EXPECT, value.unwrap_or(""));
match value {
Some(value) => child.env(VAR, value),
None => child.env_remove(VAR),
};
let out = child.output().unwrap();
let stdout = String::from_utf8_lossy(&out.stdout);
assert!(
out.status.success(),
"{value:?}: {stdout}{}",
String::from_utf8_lossy(&out.stderr)
);
assert!(stdout.contains("1 passed"), "{value:?}: the child ran no test: {stdout}");
}
}
#[test]
fn the_first_window_reads_the_variable_in_a_child() {
let Some(expect) = std::env::var_os(EXPECT) else { return };
let expect = Some(expect.into_string().unwrap()).filter(|e| !e.is_empty());
let received = choose(None, &AtomicBool::new(false), from_env(VAR));
assert_eq!(received, expect.as_deref().and_then(token));
}
#[test]
fn a_failed_window_leaves_the_token_for_a_retry() {
let taken = AtomicBool::new(false);
let failed = create_with(
None,
&taken,
|| Some("t".into()),
|received| {
assert_eq!(received, token("t"));
Err::<(), _>("no window")
},
);
assert_eq!(failed, Err("no window"));
assert_eq!(choose(None, &taken, || Some("t".into())), token("t"));
assert_eq!(choose(None, &taken, || Some("t".into())), None);
}
}