Holding Alt and typing a number on the number pad (Alt+0181 for µ) makes
Windows send the character in WM_CHAR after Alt's key-up. The keyboard
builder adds a WM_CHAR only to a pending key press, so after a release
it took the character for IME text and dropped it: Alt codes typed
nothing in any text field (storytold/pdfcraft#5746).
When Alt's release is followed by WM_CHAR or WM_SYSCHAR, the character
now goes on a press of its own, reported like a character injected with
VK_PACKET: an unidentified key whose text and logical key are the
character. A release follows the press at once, so the key isn't left
down. A character after any other key's release is still left to the
input method.
Tested with a message-only window: Alt's release then the queued µ give
the Alt release, then a press with text "µ" and its release; without
the fix the µ gives no event. A character after Enter's release still
gives none.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
b452532's test called set_var and remove_var while other test threads
ran, which is the unsoundness W30 avoids by leaving the launcher's
variable alone; a variable no other test reads doesn't make it sound,
since any thread reading any variable races the write. The test now runs
itself in a child process with the variable set, then removed, and
checks the child ran its one test; this process's environment never
changes.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The policy tests gave the token through a closure; this one reads it from
a real environment variable (one no other test uses, so setting it races
nothing): set, the first window takes it; cleared, it takes none. Also
rustfmt startup_token.rs, which had four lines over 100 columns.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
eframe never gives winit an activation token, so with StartupNotify=true
GNOME kept its busy cursor for 15 seconds after the window appeared, and a
Wayland window opened without focus. The first window created without a
token now takes the one the launcher put in the environment
(XDG_ACTIVATION_TOKEN on Wayland, DESKTOP_STARTUP_ID on X11) and hands it
back as a token given through with_activation_token would be. Later
windows don't reuse the spent token, and an empty or oversized (over 1,024
bytes) token is ignored. The variable is left in the environment, unlike
reset_activation_token_env: changing the environment while other threads
may read it is unsound.
Port of PdfCraft's vendored winit patch (14), from storytold/cadcraft#2030.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Each commit makes the compositor send done, and input-method-v2 compositors ignore input-method commits against an older serial, so an app calling it every frame could lose typed text.
The replacement range is applied only in the arms that deliver the text, so text dropped while IME isn't allowed doesn't remove text from ImeDocument that the app still shows.
The window procedure leaves Preedit before CPS_CANCEL, so WM_IME_ENDCOMPOSITION doesn't read GCS_RESULTSTR and commit it, and sends the empty preedit itself, as X11, Wayland and macOS do.
Input methods that correct the text around the cursor, such as
Vietnamese engines and predictive keyboards, need the field's text
(text-input-v3 `set_surrounding_text`) and a way to delete part of it
(`delete_surrounding_text`). winit master added both with new core types
and an `Ime::DeleteSurrounding` event; winit 0.30's `Ime` enum is
exhaustive, so they come here as a Wayland extension instead:
- `WindowExtWayland::set_ime_surrounding_text(text, cursor, anchor)`
clamps the byte offsets to character boundaries and cuts text over the
protocol's 4000 bytes around the cursor and selection. Enabling a text
input sends it again with the purpose and cursor area, which enabling
resets; disallowing IME forgets it.
- A deletion goes out with the `Ime::Commit` of the same input method
update, an empty one if the update has no commit.
`WindowExtWayland::take_ime_delete_surrounding` returns it while that
commit is handled, so the application deletes after removing the
preedit and before inserting the text, in text-input-v3's order.
Co-authored-by: DorotaC <43449960+dcz-self@users.noreply.github.com>
Replacement ranges were honoured by sending one Backspace per replaced
character. Toolkits delete a whole grapheme cluster per Backspace, so
replacing text after a combining accent, a flag or a ZWJ emoji deleted
text before the replaced range.
The deletion now goes with an Ime::Commit, as on Wayland:
WindowExtMacOS::take_ime_delete_surrounding returns it, in UTF-8 bytes,
while the app handles that commit. A replacement before a preedit, such
as press-and-hold marking the letter it accents, gets an empty commit.
Shortcuts such as Ctrl+C are defined by Latin letters, so on a Russian,
Greek, Arabic, Hebrew or Thai layout a toolkit can't match them from the
characters the keys type. GTK and Qt fall back to the first Latin layout
group for this.
The `KeyEventExtLatinLayout` extension reports, for a key event, what the
key types on the keymap's first Latin layout when the active layout isn't
Latin, letter or not, and whether the active layout is Latin. A toolkit
can then tell a key without a Latin letter (Dvorak's ' on the key that
types й on Russian) from a user without a Latin layout. A layout is Latin
when most of its 26 letter keys type Latin letters, so Dvorak and AZERTY
count as Latin and keep their own letters.
Toolkits need to drop the composition when the text cursor moves to
another field or the user clicks elsewhere in the text, without turning
IME off and on: otherwise the input method continues the composition in
the next field. `reset_ime` discards the composition without committing
it and sends an empty preedit if one was shown.
- X11: resets the window's input context with `XmbResetIC`. IME requests
are also handled before each X event, so a reset or allow request made
when focus moved reaches the input method before the next key does.
- Wayland: disables and enables text input in two commits, so the
compositor deactivates and reactivates the input method, then sends
the purpose and cursor area again.
- Windows: while a composition is in progress, cancels it with
`ImmNotifyIME(NI_COMPOSITIONSTR, CPS_CANCEL)`. The IME ends the
composition with its usual messages; the result string stays empty.
- macOS: the input context discards its marked text, and an empty
preedit is sent if the input method didn't send one.
- iOS, Android, Web and Orbital ignore it.
A key pressed with ⌘ was named by charactersIgnoringModifiers, which
ignores the layout's table for ⌘. On "Dvorak – QWERTY ⌘" the layout
types Dvorak letters but QWERTY ones with ⌘, so ⌘V was reported as ⌘K
and opened PdfCraft's command palette (storytold/pdfcraft#3655). With ⌘
held, the logical key is now UCKeyTranslate's character with cmdKey
(and shiftKey when Shift is held), falling back to the old rule when
the table has no character.
KeyEventExtMacOS::key_with_command reports the ⌘ table's character for
every key event, as key_without_modifiers does for the base table, so
shortcut matching and labels can use it without ⌘ held.
The view reports a caret to input methods: after the text inserted
since the caret last moved for another reason (a command key, a click,
a shortcut, IME toggled), with marked text after it (ImeDocument).
Dictation, which inserted nothing while selectedRange was NSNotFound
(rust-windowing/winit#4666), now has a place to insert. Replacement
ranges that reach the caret are honoured (#3617): the replaced text is
deleted with Backspace presses before the new preedit or commit, which
toolkits already handle. Press-and-hold then replaces the letter with
the accent picked instead of typing it after the letter. Reporting a
caret also makes held letters in text input open the accent menu
instead of repeating, as in other Mac apps; the repeats the input
method takes for the menu aren't typed.
Text an input method types without a composition during a key press is
committed when it isn't the key's own text, and the key's text isn't
sent: Chinese punctuation (,for ,) and the ideographic space arrived
as the key's ASCII character.
An input method calling the view while its window is torn down no
longer panics inside an Objective-C callback, which aborted: the
firstRectForCharacterRange guard is master's d6f7a28 (#4333), and
queued events and the input context are checked the same way.
Co-authored-by: Jeremiah S <46010924+HXavS@users.noreply.github.com>
Setting the IME spot is a synchronous XIM request, and it went out after
the next X event, often one carrying an input method's reply to a key.
Xlib handles the keys an input method forwards back while it waits for
the request's reply: it puts them back on the event queue in reverse
order and marks only the last one as forwarded, so the others are
filtered again. The input method gets its own keys back as new key
presses, and the app gets them after the text committed with them.
Vietnamese engines in fcitx5 that fix a word by forwarding BackSpaces and
committing the new tail garble the text this way
(rust-windowing/winit#4777, storytold/wordcraft#2932).
Input methods only send keys back in answer to keys the client gave
them. The latest spot for each window is now queued and sent once no X
event is queued and no event has gone to the input method for 100 ms;
the event loop wakes up to send it.
Disallowing IME destroyed the window's input context and allowing it
created a new one. Input methods keep their per-context state only while
the context lives, so each focus change between text fields reset it:
Vietnamese Telex turned off, and the new context stayed unfocused until
the window lost and regained the focus.
The window now keeps the context it was created with, in the preedit
style. Allowing IME focuses it; disallowing it resets the composition and
unfocuses it, and keys are no longer filtered through it.
While an IME uses a key, WM_KEYDOWN carries VK_PROCESSKEY. winit sent
it as a Process key press with the key's physical code, and apps that
fall back to the physical key (egui-winit does) took it as a press of
that key: Backspace, Enter or an arrow typed into a composition acted
both in the composition and in the app. Such a key-down is no longer
sent, unless the IME passes text on with it as WM_CHAR. The key-up still
arrives with the real virtual key.
Guarded in tests/ime_patches.rs. Part of storytold/craft-libs#198
(item I6).
Some IMEs place their composition and candidate windows at the system
caret (GetCaretPos, GetGUIThreadInfo) and ignore ImmSetCandidateWindow:
Sogou, and some Japanese IMEs. winit created no caret, so those windows
didn't follow the text. A window that has the keyboard focus and allows
IME now keeps a hidden caret the size of the last IME cursor area,
created on focus or when IME is allowed, moved with
set_ime_cursor_area, and destroyed before the window loses the focus
(Windows has one caret per thread).
The policy is plain Rust (ime_caret.rs), so its tests run on every
platform through tests/ime_patches.rs, with a guard on its callers.
Part of storytold/craft-libs#198 (item I6).
Most of these patches can only be exercised with a real input method or
compositor, so `tests/ime_patches.rs` and `tests/pointer_patches.rs`
check that each fix is still in the source and fail if a rebase drops
it. The Wayland scroll-phase policy (W13) is plain Rust, so its unit
tests run in `tests/pointer_patches.rs` too.
Use the reported axis source so wheel, wheel-tilt and continuous-source scroll events report
`TouchPhase::Moved` instead of starting a finger gesture that never ends; egui then follows modifier
release instead of keeping Ctrl zoom latched. Finger momentum is unchanged. The phase policy lives
in `seat/pointer/scroll.rs`. Taken from storytold/pdfcraft vendor/winit patch (13)
(storytold/pdfcraft#1569). No upstream winit PR yet.
Co-authored-by: Brandon Thomas <echelon@gmail.com>
With a transparent title bar over a full-size content view, AppKit asks the view under the pointer
whether a press can move the window, and NSView answers YES for a non-opaque view. winit's view did
not override it, so any drag starting in the title-bar band moved the window before the app saw it
(PdfCraft's tab reordering never got the drag). The view now answers with the window's
`movable_by_window_background` attribute (NO unless asked); apps still move the window through
`ViewportCommand::StartDrag`. Taken from storytold/pdfcraft vendor/winit patch (12)
(storytold/pdfcraft#2347). No upstream winit PR yet.
Hyprland (0.56.2) sends the selection and drags only to the first
wl_data_device a client binds for a seat (dataDeviceForClient in
src/protocols/core/DataDevice.cpp). Winit binds one for file drops, so a
toolkit clipboard such as smithay-clipboard, which binds a second device on the
same connection, never receives the selection and paste fails everywhere. A
client should keep one data device per seat, so winit now offers the clipboard
on its own device instead.
platform::wayland::Clipboard reads and writes text on the seat that last gave
the application input. It is found from the event loop with
ActiveEventLoopExtWayland::clipboard, or from a wl_display pointer with
Clipboard::for_display, for toolkits that only receive the display handle.
Keyboard enter, key and button events record the serial that setting the
selection needs. Reading another client's selection receives it through a pipe
without dispatching the event loop and gives up after two seconds of silence.
Our own selection carries a private marker type and is returned directly, so
pasting it never waits on the thread that would have to send it. The compositor
asks for our text through the data source, and a short-lived thread writes it.
Winit binds a wl_data_device for each seat and accepts drags that offer
text/uri-list with the copy action. The list is read without blocking as
soon as the drag enters a window, so the window receives HoveredFile for each
local file while the drag is over it, HoveredFileCancelled when it leaves, and
DroppedFile for each file once it is dropped.
The actions are set only on enter: setting them again on motion restarts the
negotiation and can turn a quick drop into a leave. Only file URIs naming this
machine become paths.
Add an opt-in macOS builder flag that cancels native termination and queues close requests on the ordinary event loop. Preserve default behavior and handle repeated requests, stale windows and completed exits.
Required by storytold/designcraft#544.
(cherry picked from commit 3d51077fd1)
Without Xft.dpi, use the X screen's configured DPI (its size in pixels and millimetres) before the RandR panel-physical fallback; WINIT_X11_SCALE_FACTOR still overrides. Taken from storytold/pdfcraft vendor/winit (storytold/pdfcraft#1150, replacing the launcher pin in #908); the same change is open as storytold/photocraft#3724, gridcraft#389, deckcraft#170 and wordcraft#721. No upstream winit PR yet.
Related to rust-windowing/winit#4478; PdfCraft patch, to be proposed upstream.
Originally "M15.1: suppress duplicate macOS Korean spaces" in storytold/wordcraft#787 (same change as storytold/pdfcraft vendor/winit).
Port of the emoji-picker part of rust-windowing/winit#4749 (0.30 backport of #4748).
Originally "M15.1: forward macOS emoji picker text" in storytold/wordcraft#787 (same change as storytold/pdfcraft vendor/winit).
Port of rust-windowing/winit#4650 (0.30 backport of #4651, merged on master).
Originally "M15.1: preserve macOS IME commits" in storytold/wordcraft#787 (same change as storytold/pdfcraft vendor/winit).
Port of rust-windowing/winit#4587 (focus-safe form of #4575).
Originally "M15.1: keep hidden maximized windows hidden" in storytold/wordcraft#787 (same change as storytold/pdfcraft vendor/winit).
The `text` field on `KeyEvent` was hardcoded to `None` on Android,
making it impossible for custom `NativeActivity` subclasses that
show the IME to receive functional text input using *for example* the
existing `winit-egui` crate which relies on this field being set.
Use `Key::to_text()` on press events to derive `text` from
`logical_key`, matching the convention used by the Windows and macOS
backends.
Supposedly that doesn't include all kinds of special virtual unicode
keys, but at least the basics work this way.