Commit Graph
240 Commits
Author SHA1 Message Date
aionggandDorotaC f40c76a238 W27: Wayland: IME surrounding text and delete-surrounding
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>
2026-10-21 18:07:40 +00:00
aiongg 4b5bc5a03a W24: Add Window::reset_ime (X11, Wayland, Windows, macOS)
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.
2026-10-21 18:07:40 +00:00
aiongg 2be273826c W17: regression tests for W2, W3, W5–W10, W12 and W13
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.
2026-10-21 18:02:42 +00:00
tomasmark79andBrandon Thomas 5506b1a95e W13: Wayland: pixel-only wheel, wheel-tilt and continuous scrolls report Moved
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>
2026-10-21 18:16:39 +02:00
Carmine Paolino b05ce12933 On Wayland, offer the clipboard through winit's data device
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.
2026-10-21 18:16:39 +02:00
Carmine Paolino cf73a29ce8 On Wayland, report dropped files through the data device
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.
2026-10-21 18:16:39 +02:00
cyfung1031 13ca693b1e W2: Wayland: destroy the seat text input only when the seat is removed
Port of rust-windowing/winit#4747 (merged on master).

Originally "M15.1: preserve Wayland winit text input" in storytold/wordcraft#787 (same change as storytold/pdfcraft vendor/winit).
2026-10-21 18:16:38 +02:00
Kirill Chibisov efb5b37fff chore: fix ci 2026-03-02 22:49:04 +09:00
Pedro Macedo 6bb43fd130 wayland: implement resize increments 2026-03-02 22:49:04 +09:00
Kirill Chibisov c0a8bedee2 chore: fix typos from updated typos tool 2025-07-27 21:59:42 +09:00
Kirill Chibisov f7ac8127e3 wayland: fix pump events's loop drop deadlock 2025-05-21 17:50:00 +09:00
Bruce Mitchener 17b5737972 Fix typos from updated typos tool (#4213) 2025-05-21 17:50:00 +09:00
jpy794 7672fd5657 wayland: support fractional scale for custom cursor 2025-04-30 20:46:44 +09:00
Putta Khunchalee 847511672a wayland: add WindowExtWayland::xdg_toplevel
Fixes #4068.
2025-04-30 20:46:44 +09:00
Kirill Chibisov 53bbe6c273 wayland: ensure external loop is notified with pump_events
Spawn a thread when pump_events is used, so the external thread will
get woken-up correctly. This only happens when timeout was given.

Fixes #4183.
2025-04-30 20:46:44 +09:00
Kirill Chibisov 114599c2da wayland/fix: crash due consequent calls to set_cursor_grab
Only mark that the grab was applied when it actually got applied.
Previously there was an issue with grab being marked as applied without
a pointer over the window, when in reality it wasn't.

Fixes #4073.
2025-04-30 20:46:44 +09:00
Kirill Chibisov c6cfa048b0 x11:wayland: fix pump_events blocking with Wait
Using `Duration::Zero` with `Wait` polling mode was still blocking until
the event was actually delivered. Thus when `pump_events` API is used,
ensure that it's not happening.

Fixes #4130.
2025-04-30 20:46:44 +09:00
Tom Churchman abfe90bddb wayland: clear IME preedit only when necessary
When all we'll be doing is setting a new preedit, the preedit doesn't
have to be explicitly cleared first. This change is perhaps debatable.

The direct reason for this is to make it easier to work around
quirks/bugs: in Masonry we've found IBus appears to resend
the IME preedit in response to `Window::set_ime_cursor_area`
(`zwp_text_input_v3::set_cursor_rectangle`). Because currently the
preedit is first cleared, a new IME cursor area is sent, which again
causes IBus to resend the preedit. This can loop for a while.

The Wayland protocol is mechanically quite prescriptive,
it says for zwp_text_input_v3:event:done.

> 1. Replace existing preedit string with the cursor.
> 2. Delete requested surrounding text.
> 3. Insert commit string with the cursor at its end.
> 4. Calculate surrounding text to send.
> 5. Insert new preedit text in cursor position.
> 6. Place cursor inside preedit text.

Winit currently doesn't do surrounding text, so 2. and 4. can be
ignored. In Winit's IME model, without a commit, sending just the
`Ime::Preedit` event without explicitly clearing is arguably still
equivalent to doing 1., 5., and 6.
2025-02-06 13:13:19 +03:00
Kirill Chibisov d7710f7264 api: add ActivationToken::{from,into}_raw
This is needed when passing and getting token from the IPC to activate
the window.
2025-01-04 08:45:12 +03:00
Kirill Chibisov ba188376d1 wayland: bump dependencies
Update SCTK as a follow-up to 1170554dbd (ignore events to dead
objects) fixing it for wl_output.
2024-07-16 21:04:25 +03:00
daxpedda 6509f8a18b Make DeviceId/WindowId::dummy() safe (#3784) 2024-07-16 21:04:25 +03:00
Kirill Chibisov ec24c3efd3 wayland: ignore events for dead objects
Nothing wrong will happen if we ignore events when compositor is at
wrong, at least crashing because compositor is just _wrong_ probably is
not a great option.

Links: https://github.com/alacritty/alacritty/issues/8065
2024-07-16 21:04:25 +03:00
Kirill Chibisov 96388f4f6b chore: address 1.79 clippy lints 2024-06-15 20:00:04 +03:00
growfrow 61bd8172bd chore: fix some typos in comments (#3635)
Signed-off-by: growfrow <growfrow@outlook.com>
2024-04-27 19:00:38 +04:00
Kirill Chibisov 7b0c7b6cb2 chore(rustfmt): use nightly (#2325)
Stable rustfmt lacks a lot of features resulting in worse formatted
code, thus use nightly formatter.
2024-04-26 17:11:44 +02:00
Kirill Chibisov 9ab4c03e89 wayland: fix CSD decorations glitch when closing
In rare cases destroying subsurfaces before the main surface could
result in a frame where the window is still shown, but decorations
got hidden, right before the window itself disappears.
2024-04-19 14:40:00 +04:00
John Nunley 7b0ef160fc chore: silence clippy
It appears that clippy's dead code detection has gotten better. This
commit fixes winit's code to match.

Signed-off-by: John Nunley <dev@notgull.net>
2024-03-27 12:20:21 +04:00
Kirill Chibisov fc8a008b25 chore(wayland): don't reapply same cursor grab
Some compositors break when re-taking the same grab.

Closes: https://github.com/rust-windowing/winit/issues/3566
2024-03-05 15:38:08 +04:00
John Nunley 944347696a Replace log with tracing
Tracing is a modern replacement for the log crate that allows for
annotating log messages with the function that they come from.

Signed-off-by: John Nunley <dev@notgull.net>
Closes: #3482
2024-03-01 20:45:31 +04:00
Kirill Chibisov 7abd427216 Create custom cursor with directly with event loop
Replace the `CustomCursorBuilder` with the `CustomCursorSource` and
perform the loading of the cursor via the
`EventLoop::create_custom_cursor` instead of passing it to the builder
itself.

This follows the `EventLoop::create_window` API.
2024-02-21 14:44:29 +04:00
Kirill Chibisov 3fb93b4f83 Deprecate window creation with stale event loop
Creating window when event loop is not running generally doesn't work,
since a bunch of events and sync OS requests can't be processed. This
is also an issue on e.g. Android, since window can't be created outside
event loop easily.

Thus deprecate the window creation when event loop is not running,
as well as other resource creation to running event loop.

Given that all the examples use the bad pattern of creating the window
when event loop is not running and also most example existence is
questionable, since they show single thing and the majority of their
code is window/event loop initialization, they wore merged into
a single example 'window.rs' example that showcases very simple
application using winit.

Fixes #3399.
2024-02-21 14:44:29 +04:00
Andriy 19190a95a0 On Wayland, send DeviceEvent::Motion 2024-02-20 13:34:05 +04:00
Bruce Mitchener c4310af83c Fix various typos
Mainly fix typos in comments, but also some minor code changes:

* Rename `apply_on_poiner` to `apply_on_pointer`.
* Rename `ImeState::Commited` to `ImeState::Committed`
* Correct `cfg_attr` usage: `wayland_platfrom` -> `wayland_platform`.
2024-02-19 08:58:44 +04:00
Kirill Chibisov 542d1938ce Fix warnings with latest nightly 2024-02-19 08:47:32 +04:00
Kirill Chibisov e61a7320a2 On X11, use events modifiers to detect state
While there's a separate event to deliver modifiers for keyboard,
unfortunately, it's not even remotely reflects the modifiers state.

Thus use events along side regular modifier updates to correctly
detect the state. Also, apply the modifiers from the regular
key event by converting their state to xkb modifiers state.

Links: https://github.com/alacritty/alacritty/issues/7549
Closes: #3388
2024-02-18 01:39:42 +04:00
Kirill Chibisov 385c4b3c88 On Wayland, update title from AboutToWait
Fixes #3472.
2024-02-14 00:48:52 +04:00
Kirill Chibisov 4d4d6e5052 On Wayland, fix min/max inner size setting
The size is only applied on the next `wl_surface::commit` thus we
must trigger the redraw.
2024-02-01 00:11:31 +04:00
Kirill Chibisov 21df84b7f4 On Wayland, pre-multiply alpha for custom cursor
Fixes: #3360
2024-01-30 21:31:17 +04:00
Kirill Chibisov dd13ccda4c On Wayland, send Focused(false) once seats left
Given that we merge all the seats, we should consider that window
is not focused once all seats wl_keyboards are no longer present.

We use seats instead of keyboards to track focus to protect against
wl_keyboard::leave not being delivered when removing the seat
(usually it's not the case though).

Fixes: #3376
2024-01-30 18:28:13 +04:00
Kirill Chibisov ff731197dc On Wayland, disable Occluded handling
Change in state requires a redraw, however drawing when getting
`Occluded` with vsync will block indefinitely, thus the event in
it's current state is rather useless.

To solve this issue winit needs a way to determine whether the user
paused/continued their render loop, so it can commit on their behalf.

This commit also forces redraw when getting configure.

Links: https://github.com/rust-windowing/winit/issues/3442
2024-01-30 13:00:10 +04:00
Mads Marquart f526a47152 Remove EventLoopError::AlreadyRunning
This is already prevented by the type-system, and as such it doesn't
make sense to have an error case for this.
2024-01-29 22:06:03 +04:00
daxpedda d7c7ba1d6c Move PlatformSpecificWindowBuilderAttributes (#3318) 2024-01-17 23:37:28 +01:00
daxpedda d1717b6a01 X11: cache custom cursors (#3366) 2024-01-17 18:17:49 +01:00
Mads Marquart 22311802b5 Remove generic parameter T from EventLoopWindowTarget (#3298) 2024-01-13 21:36:53 +01:00
Kirill Chibisov 8b3de7cedf Issue resize due to scale change on Wayland
This is a regression from 8f6de4ef.

Links: https://github.com/alacritty/alacritty/issues/7559
2024-01-03 21:49:11 +04:00
Kirill Chibisov 8f6de4ef4b On Wayland, fix Window::request_inner_size during resize
The user may change the size during the on-going resize, meaning that
the size will desync with winit's internal loop which breaks viewporter
setup with fractional scaling.

Links: https://github.com/alacritty/alacritty/issues/7474
2023-12-29 21:28:06 +04:00
daxpedda 658f49b014 Rename VideoMode to VideoModeHandle (#3328) 2023-12-26 22:12:33 +01:00
daxpedda 34e42ff94d Remove unsound SendSyncWrapper (#3303) 2023-12-26 20:13:02 +01:00
daxpedda ba654bb61e Add WindowBuilder::with_cursor() (#3319) 2023-12-26 19:50:58 +01:00
daxpedda 28a811bbba Remove extern crate statements (#3310) 2023-12-25 09:25:09 +01:00