Commit Graph
65 Commits
Author SHA1 Message Date
8b18693e25 Combine Wayland pinch and rotation on the Craft 0.30 branch
Adapt rotation polarity and lifecycle from storytold/winit#21; retain the pinch and teardown behavior of #20.

Co-authored-by: Leonid <leonidofsparta@users.noreply.github.com>
Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-29 07:18:00 +00:00
David MannandClaude Opus 5.5 3698a67bb7 CI: fix the doc, 1.70.0 and Windows test failures on craft/0.30.13
With the lockfile step fixed, CI reaches steps that were never green on
this branch:

- rustdoc -D warnings: escape `*` inside <kbd> (invalid_html_tags) and
  wrap a bare URL in dark_mode.rs (nightly's bare_urls).
- docs.rs check (nightly, every platform): platform::wayland is built
  under docsrs on all platforms, but its clipboard API names
  platform_impl::wayland, which only exists with wayland_platform. The
  clipboard items are now gated on wayland_platform.
- Rust 1.70.0 on Windows: update_system_caret is pub but takes the
  pub(crate) CaretChange (E0446); it is pub(crate) now.
- ime_patches/pointer_patches read sources with CRLF on a Windows
  checkout (* text=auto) and missed patterns that span lines; source()
  normalizes to LF.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-27 14:27:56 +01:00
tomasmark79 6c23e53b22 wayland: deliver native touchpad pinch gestures on the Craft 0.30 branch
Port the pinch input path from storytold/pdfcraft#1580 to the resolved winit fork, preserving newer drag and IME seat teardown. Test cumulative scales, cancellation, invalid input and unsupported surfaces.
2026-10-31 08:56:47 +01:00
skylartaylor a517b3846e Preserve input order across requested IME resets 2026-10-24 13:32:33 +02:00
skylartaylor ae48c756a3 Integrate bounded Wayland clipboard and IME lifecycle repairs 2026-10-24 05:07:08 +02:00
aiongg e592e35d80 W27: Wayland set_ime_surrounding_text sends nothing when unchanged
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.
2026-10-23 05:29:11 +00:00
aiongg 063cfe9e54 W22: macOS insertText leaves the IME document alone when it drops the 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.
2026-10-23 05:29:11 +00:00
aiongg 953f5e9b97 W24: Windows reset_ime drops the preedit without committing
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.
2026-10-23 05:29:03 +00:00
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 2b9cd1cf47 W26: macOS: delete replaced text by byte count with the commit
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.
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 c8cd8aa149 W23: macOS: name keys pressed with ⌘ by the layout's ⌘ table
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.
2026-10-21 18:07:40 +00:00
aionggandJeremiah S 0816871e62 W22: macOS: replacement ranges, text typed without a composition, teardown
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>
2026-10-21 18:07:40 +00:00
aiongg 23bb19a7a9 W21: X11: send the IME spot once the input method is quiet
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.
2026-10-21 18:07:40 +00:00
aiongg 019c95f115 W20: X11: keep one input context per window
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.
2026-10-21 18:07:40 +00:00
aiongg fa2e1b3d76 W19: Windows: don't send keys the IME takes as key presses
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).
2026-10-21 18:07:40 +00:00
aiongg 894bf2d733 W18: Windows: keep a hidden system caret at the IME cursor area
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).
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
skylartaylor c488d2e9a7 W14: fix(macos): route opted-in application termination to close requests
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)
2026-10-21 18:16:39 +02: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 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
Mads Marquartanddaxpedda 31f8b816bd Make EventLoopProxy Sync
Co-authored-by: daxpedda <daxpedda@gmail.com>
Closes: #3448
2024-02-19 08:47:32 +04:00
daxpedda 2c15de7cf9 Allow custom cursor caching (#3276) 2023-12-22 22:20:41 +01:00
af93167237 feat(all): Custom cursor images for all desktop platforms
There seems to be many PRs relating to this issue, but they don't include all
platforms and for some reason lost steam. This PR again tries to make this
feature happen, and does it for all desktop platforms (x11, wayland, macos,
windows, web).

I think the best user of this feature and the reason I'm doing this is Bevy and
game engines in general. There non laggy hardware cursors with custom images are
very important. Game devs also like their PNGs so supporting platform native
cursor files is not that important, but I guess could be added too.

Co-authored-by: daxpedda <daxpedda@gmail.com>
Co-authored-by: Mads Marquart <mads@marquart.dk>
Co-authored-by: Kirill Chibisov <contact@kchibisov.com>
2023-12-16 12:02:17 -08:00
Diggory HardyandKirill Chibisov acfeff5327 Revise Key and KeyCode enums
Split `Key` into clear categories, like `Named`, `Dead`, Character`, `Unidentified`
removing the `#[non_exhaustive]` from the `Key` itself.

Similar action was done for the `KeyCode`.

Fixes: #2995
Co-authored-by: Kirill Chibisov <contact@kchibisov.com>
2023-10-19 18:27:49 +04:00
Kirill Chibisov 801fddbfcf Make WindowBuilder Send + Sync
Window builder is always accessed by winit on the thread event loop
is on, thus it's safe to mark the data it gets as `Send + Sync`.
Each unsafe object is marked individually as `Send + Sync` instead
of just implementing `Send` and `Sync` for the whole builder.
2023-10-17 04:54:12 +04:00
daxpedda 8f7f3efc0d On Web, implement Send and Sync where appropriate (#2834) 2023-06-05 02:44:54 +02:00
918430979f Overhaul the Keyboard API
Overhaul the keyboard API in winit to mimic the W3C specification
to achieve better crossplatform parity. The `KeyboardInput` event
is now uses `KeyEvent` which consists of:

  - `physical_key` - a cross platform way to refer to scancodes;
  - `logical_key`  - keysym value, which shows your key respecting the
                     layout;
  - `text`         - the text produced by this keypress;
  - `location`     - the location of the key on the keyboard;
  - `repeat`       - whether the key was produced by the repeat.

And also a `platform_specific` field which encapsulates extra
information on desktop platforms, like key without modifiers
and text with all modifiers.

The `Modifiers` were also slightly reworked as in, the information
whether the left or right modifier is pressed is now also exposed
on platforms where it could be queried reliably. The support was
also added for the web and orbital platforms finishing the API
change.

This change made the `OptionAsAlt` API on macOS redundant thus it
was removed all together.

Co-authored-by: Artúr Kovács <kovacs.artur.barnabas@gmail.com>
Co-authored-by: Kirill Chibisov <contact@kchibisov.com>
Co-authored-by: daxpedda <daxpedda@gmail.com>
Fixes: #2631.
Fixes: #2055.
Fixes: #2032.
Fixes: #1904.
Fixes: #1810.
Fixes: #1700.
Fixes: #1443.
Fixes: #1343.
Fixes: #1208.
Fixes: #1151.
Fixes: #812.
Fixes: #600.
Fixes: #361.
Fixes: #343.
2023-05-28 21:02:59 +03:00
Amr BashirandMads Marquart 5e77d70245 Use cfg aliases throught the code base
Co-authored-by: Mads Marquart <mads@marquart.dk>
2022-12-25 10:57:27 +03:00
Osspial 3a1e694c2f Make size/position types generic over pixel type (#1277)
* Begin implementing DPI generics

* Fix multithreaded example

* Format

* Fix serde test

* hopefully fix most of the errors

* Fix dpi module errors

* More error fixings

* Format

* fix macos errors

* Another error pass

* Replace bad type signatures

* more fixins
2020-01-05 14:15:11 -05:00
Héctor Ramón 7b23d190b1 Fix web errors (#1040)
* Fix old `use` declarations

* Fix hidden lifetime parameter

* Fix missing methods in `web::Monitor`.

Originally fixed by @ryanisaacg in 94387c4bf5bca35f4e24562ce89a4f4badd53aa8.

* Disable some tests and examples on `wasm32`
2019-07-10 18:54:54 -04:00
Osspial e2c84725de Format everything and add rustfmt to travis (#951)
* Format everything and add rustfmt to travis

* Remove extern crate winit from examples and add force_multiline_blocks

* Format the code properly

* Fix inconsistent period in PULL_REQUEST_TEMPLATE.md

* Only run rustfmt on nightly

* Travis fixings
2019-06-21 11:33:15 -04:00
Felix Rabe c56a66cb90 Fix warnings (#929)
* Fix warnings

* Bring back derivatives crate for Windows
2019-06-19 15:12:01 -04:00
CrLF0710 f879bca21c Migrate to 2018 edition. (#924)
* Migrate to 2018 edition.

* Use impl Iterator at one site.

* Fix more rust 2018 idioms.
2019-06-17 14:27:00 -04:00
Osspial 0df436901a Refine function names and type signatures (#886)
* First name consistency pass. More to come!

* Remove multitouch variable (hopefully this compiles!)

* Remove CreationError::NotSupported

* Add new error handling types

* Remove `get_` prefix from getters.

This is as per the Rust naming conventions recommended in
https://rust-lang-nursery.github.io/api-guidelines/naming.html#getter-names-follow-rust-convention-c-getter

* Make changes to Window position and size function signatures

* Remove CreationError in favor of OsError

* Begin updating iOS backend

* Change MonitorHandle::outer_position to just position

* Fix build on Windows and Linux

* Add Display and Error implementations to Error types

* Attempt to fix iOS build.

I can't actually check that this works since I can't cross-compile to
iOS on a Windows machine (thanks apple :/) but this should be one of
several commits to get it working.

* Attempt to fix iOS errors, and muck up Travis to make debugging easier

* More iOS fixins

* Add Debug and Display impls to OsError

* Fix Display impl

* Fix unused code warnings and travis

* Rename set_ime_spot to set_ime_position

* Add CHANGELOG entry

* Rename set_cursor to set_cursor_icon and MouseCursor to CursorIcon

* Organize Window functions into multiple, categorized impls

* Improve clarity of function ordering and docs in EventLoop
2019-05-29 21:29:54 -04:00
Victor Berger 6513351e0c Wayland's eventloop 2.0 (#790)
* match unix common API to evl 2.0

* wayland: eventloop2.0

* make EventLoopProxy require T: 'static

* Fix linux build and tests

* wayland: update sctk & small fixes
2019-02-21 10:51:43 +01:00
Osspial 9602716ed2 Event Loop 2.0 API and Windows implementation (#638)
* Rename EventsLoop and associated types to EventLoop

* Rename WindowEvent::Refresh to WindowEvent::Redraw

* Remove second thread from win32 backend

* Update run_forever to hijack thread

* Replace windows Mutex with parking_lot Mutex

* Implement new ControlFlow and associated events

* Add StartCause::Init support, timer example

* Add ability to send custom user events

* Fully invert windows control flow so win32 calls into winit's callback

* Add request_redraw

* Rename platform to platform_impl

* Rename os to platform, add Ext trait postfixes

* Add platform::desktop module with EventLoopExt::run_return

* Re-organize into module structure

* Improve documentation

* Small changes to examples

* Improve docs for run and run_return

* Change instances of "events_loop" to "event_loop"

* Rename MonitorId to MonitorHandle

* Add CHANGELOG entry

* Improve WaitUntil timer precision

* When SendEvent is called during event closure, buffer events

* Fix resize lag when waiting in some situations

* Update send test and errors that broke some examples/APIs

* Improve clarity/fix typos in docs

* Fix unreachable panic after setting ControlFlow to Poll during some RedrawRequested events.

* Fix crash when running in release mode

* Remove crossbeam dependency and make drop events work again

* Remove serde implementations from ControlFlow

* Fix 1.24.1 build

* Fix freeze when setting decorations

* Replace &EventLoop in callback with &EventLoopWindowTarget

* Document and implement Debug for EventLoopWindowTarget

* Fix some deadlocks that could occur when changing window state

* Fix thread executor not executing closure when called from non-loop thread

* Fix buffered events not getting dispatched

* Fix crash with runner refcell not getting dropped

* Address review feedback

* Fix CHANGELOG typo

* Catch panics in user callback
2019-02-05 10:30:33 -05:00
Osspial 6bec912961 Add optional Serde implementations and missing derivable traits (#652)
* Add optional serde feature

* Document features in README

* Add changelog entry

* Implement some missing derivable traits

* Add changelog entry for std derives

* Remove extraneous space on serde doc comments

* Add period to end of serde line in readme

* Remove serde impls from WindowAttributes

* Add serde impls for TouchPhase

* Add serde test file

* Add feature lines to testing CIs

* Remove WindowAttributes from changelog
2018-11-01 04:24:56 -04:00
Francesca Frangipane 42f0671531 x11: Windows are Sync again (#474)
* x11: Windows are Sync again

Fixes #472

* Add test ensuring that Window is Sync

Window must be Sync for Vulkano's Arc<FramebufferAbstract> to be usable.
2018-04-21 11:53:57 -04:00
Victor Berger 229029f2da Formalize thread-safety guarantees (#322) 2017-10-18 20:40:21 +02:00
mitchmindtree c8e791b402 Add a test that checks that EventsLoopProxy impls Send 2017-05-25 23:18:56 +10:00
mitchmindtree 06a5ec35b3 [WIP] Remove Sync and Clone from EventsLoop. Add EventsLoopProxy.
This commit only updates the top-level API to get some early feedback.
None of the platform-specific code has been updated yet. I'm hoping to
get around to this over the next couple days however if someone more
familiar with the windows backend would like to do a PR against this
fork that would be a great help.

Closes #187.
2017-05-25 20:13:54 +10:00
Victor Berger e6e96ab6f4 tests: don't instanciate an event loop to check EventsLoop: Send+Sync 2017-03-04 09:09:09 +01:00
mitchmindtree 3ce7904e01 Wrap the temporarily stored user callback in a type to enforce
invariants

This also removes the need for "box"ing the callback in favour of
storing a raw `*mut` pointer. We can do this by ensuring that we never
store the pointer for longer than the lifetime of the user callback,
which is the duration of a call to `poll_events` or `run_forever`.

Also removes old commented out event code from the window module.
2017-02-05 12:51:09 +11:00
Pierre Krieger 007ad0f911 Fix the test and the examples 2016-03-26 18:10:19 +01:00
Pierre Krieger 10bb03c5f0 Remove most OpenGL stuff and make it compile on win32 2016-02-23 12:56:23 +01:00
Fredrik Noren 2a66d1cffc Construct cocoa headless context based on args 2016-01-18 13:12:40 -05:00
Fredrik Noren db074dc32f Use GLES 2016-01-18 12:45:55 -05:00
Fredrik Noren a5de084856 Only run headless test on osx for now 2016-01-09 14:31:56 -05:00