Commit graph

3542 commits

Author SHA1 Message Date
Mads Marquart
8db4a9cc61
macOS: Close windows automatically when exiting (#4154)
This disallows carrying over open windows between calls of `run_app_on_demand`
(which wasn't intended to be supported anyhow).
2025-03-17 11:29:53 +01:00
Kirill Chibisov
a4ab7dc64c
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-03-17 13:20:17 +03:00
Mads Marquart
afb731bb52
Drop application handler on run loop exit (#4149)
Calling the `Drop` impl of the user's `ApplicationHandler` is important on
iOS and Web, since they don't return from `EventLoop::run_app`.

And now that we reliably call `Drop`, the `ApplicationHandler::exited`
event/callback is unnecessary; using `Drop` composes much better (open files
etc. stored in the app state will be automatically flushed), and prevents
weirdness like attempting to create a new window while exiting.
2025-03-17 10:56:00 +01:00
aloucks
ef37b1d5dd
macOS: Make set_simple_fullscreen honor set_borderless_game (#4164)
* Prevent panic when calling set_simple_fullscreen(false) on macos

Calling `set_simple_fullscreen(false)` to restore the window after
a previous call to `set_simple_fullscreen(true)` panics with
`view must be installed in a window` in the call to `set_style_mask`
with the old style.

Moving the `set_style_mask` call after the frame has been resized
fixes the issue.

* Hide the doc and menubar on macos when using set_borderless_game
with set_simple_fullscreen
2025-03-17 02:58:47 +01:00
aloucks
2b4e8ef916
Fix a pause in the event loop when clicking the title bar on windows (#4136)
* Fix a pause in the event loop when clicking the title bar on windows

When clicking the title bar on Windows, to drag the window, there is
a noticible pause in continuous redraw requests. This was fixed
in #839 and then regressed in #1852. The cursor blinks in both
cases and is unrelated. The regression made the blink happen after
the pause instead of immediately.

* Update the event loop pause note on the WM_NCLBUTTONDOWN handler

The application example was also updated to optionally animate the fill color
in order to demonstrate continuous redraw without pauses in the event
loop.
2025-03-17 02:27:27 +01:00
Kirill Chibisov
ae28eea406
cursor: refactor CustomCursor to be dyn
cursor: refactor `CustomCursor` to be `dyn`

Same as for `MonitorHandle`, the source was changed to support
all kinds of sources.
2025-03-13 17:18:37 +03:00
Aaron Muir Hamilton
a0464ae83b
x11: implement true cursor area with XNArea attribute 2025-03-11 21:04:50 +03:00
Mads Marquart
16d5f46db1
utils: add cast_* methods to allow more type-safe casting
Relying on just `as_any` was error prone and will become redundant in
the future, once upcasting will be stable, we also won't to impose a
restriction on to which concrete type we're casting, since casting
to a type that doesn't implement a base trait doesn't make much
sense.

Co-authored-by: Kirill Chibisov <contact@kchibisov.com>
2025-03-11 16:35:25 +03:00
Kirill Chibisov
5cada36ae8
x11: move x11 specific code to x11 from linux/mod.rs 2025-03-08 10:14:08 +03:00
Kirill Chibisov
b3dcfa1275 docs: don't build platform docs for docsrs
Due to casts and use of platform specific crates in those modules
it's not really feasible to build docs for them.

After separating crates, thus should become way easier to navigate,
since backends information would be publicly available.
2025-03-07 19:22:12 +03:00
Kirill Chibisov
f1c5afd84e monitor: refactor MonitorHandle to store dyn object
This also alters `VideoMode` to be a regular object and not reference
the `MonitorHandle`, since it's a static data.

Given that `VideoMode` set may change during runtime keeping the
reference as a some sort of validity may not be idea and propagating
errors when changing video mode could be more reliable.
2025-03-07 19:22:12 +03:00
Mads Marquart
be1baf164c
Properly implement Debug for Window and EventLoop types (#3297)
For EventLoop, EventLoopBuilder, EventLoopProxy and by requiring it as
a supertrait of Window and ActiveEventLoop.

It is especially useful for user to be able to know that Window is Debug.
2025-03-03 08:40:04 +01:00
Mads Marquart
39c0862198
apple: Implement wake-ups using system mechanisms (#4146)
Do the wake-up inside the perform callback on `CFRunLoopSource`.
2025-03-01 20:18:28 +01:00
Mads Marquart
aa8ebdc795
Remove top-level Event enum (#4153) 2025-03-01 13:16:39 +01:00
Mads Marquart
ea68916055
macOS: Parse more key codes into named keys (#4148) 2025-03-01 12:41:46 +01:00
Mads Marquart
e26b831f23
Windows: Use ApplicationHandler (#4141)
* Make ActiveEventLoop a thin wrapper over EventLoopRunner
* Use ApplicationHandler instead of Event
2025-03-01 12:09:59 +01:00
Mads Marquart
8c3e69c08b
macOS: Fix crash when reconnecting monitors (#4151)
CFArrayGetValueAtIndex does not return a retained value, so we must
retain ourselves.
2025-02-28 17:32:24 +01:00
rctlmk
46879429ed
Windows: add IconExtWindows::from_resource_name (#4137) 2025-02-26 22:02:32 +01:00
Mads Marquart
0c89ea7386
Merge KeyEventExtra into KeyEvent (#4029)
To make the fields easier to use, and to allow constructing KeyEvent in
user test code.
2025-02-26 17:51:49 +01:00
dependabot[bot]
6c0e3c3b15
Remove @types/eslint__js (#4133)
It is deprecated.
2025-02-24 20:17:44 +01:00
Mads Marquart
675582bd46
Swizzle sendEvent: instead of subclassing NSApplication (#4036)
This is done to avoid order-dependent behavior that you'd otherwise
encounter where `EventLoop::new` had to be called at the beginning of
`fn main` to ensure that Winit's application was the one being
registered as the main application by calling `sharedApplication`.

Fixes https://github.com/rust-windowing/winit/issues/3772.

This should also make it (more) possible to use multiple versions of
Winit in the same application (though that's still untested).

Finally, it should allow the user to override `NSApplication` themselves
if they need to do that for some reason.
2025-02-24 10:38:10 +01:00
Mads Marquart
4d6fe7e35c
web: Avoid top-level Event 2025-02-24 11:21:55 +03:00
Mads Marquart
f9912baf09
x11: Call ApplicationHandler directly
Instead of going through the Event enum.
2025-02-24 11:13:25 +03:00
Mads Marquart
f290619dce
wayland: use custom Event enum for buffered events 2025-02-24 10:56:11 +03:00
valadaptive
23011c6b0a
Update to windows-sys 0.59 (#4098) 2025-02-24 04:40:11 +01:00
Kirill Chibisov
3a39a6ddb0
examples: make default example simple
The old example is in application for more sophisticated use of winit
and for maintainers to test things, since it does pretty much
everything.
2025-02-21 20:35:22 +03:00
Kirill Chibisov
90cf9a3398 docs: remove dead doc link 2025-02-20 22:03:03 +03:00
Kirill Chibisov
05d8fa0b91 chore: fix clippy lints 2025-02-20 22:03:03 +03:00
Kirill Chibisov
d7d20507ed ci: disable 32-bit windows gnu on nightly 2025-02-20 22:03:03 +03:00
Bruce Mitchener
f6e66a71f8
doc: remove spurious derive directive
This was unintentionally added in eccd9e415.
2025-02-18 14:53:16 +03:00
Kirill Chibisov
c09160d1a8
Bump version on master
This commit does not represent a release and only synchronizes CHANGELOG
from the latest release.

This also includes 0.30.8 sync, since it was forgotten.
2025-02-06 13:26:30 +03:00
Mads Marquart
2230e71093
ios: fix timers
Fixes #4074.
Fixes #3816.
2025-02-06 12:56:10 +03:00
Kirill Chibisov
5e6350d142
x11: fix modifiers replay
The serial was not unique, thus leading to issues and replay being
triggered for normal input. Track modifiers based on they keycodes
instead, since it's more unique.

Links: https://github.com/alacritty/alacritty/issues/8461
2025-02-05 09:04:09 +03:00
Kirill Chibisov
a6998af997
x11: fix crash with uim
Let's just not forward events to the IME once the user requested that
it should be disabled, though, still try to change its state explicitly.

Fixes #4082.
2025-02-03 20:43:43 +03:00
Mads Marquart
5c48ec7977
Document that we require cargo +nightly fmt (#4105) 2025-01-31 18:24:33 +01:00
Mads Marquart
953d9b4268
Update to objc2 v0.6 (#4092)
* Use available! macro
* Use objc2-core-foundation and objc2-core-graphics
* Use MainThreadBound instead of StaticMainThreadBound hack
2025-01-28 21:31:14 +01:00
valadaptive
f5dcd2aabe
Rework Drag-And-Drop API (#4079)
* Add cursor position drag and drop events.
* Reword drag events to match pointer ones.
* appkit: Use `convertPoint_fromView` for coordinate conversion.
* appkit: use ProtocolObject<dyn NSDraggingInfo>.
* x11: store dnd.position as pair of i16

  It's what translate_coords takes anyway, so the extra precision is
  misleading if we're going to cast it to i16 everywhere it's used.

  We can also simplify the "unpacking" from the XdndPosition message--we
  can and should use the value of 16 as the shift instead of
  size_of::<c_short> * 2 or something like that, because the specification
  gives us the constant 16.
* x11: store translated DnD coords.
* x11: don't emit DragLeave without DragEnter.
* windows: only emit DragEnter if valid.
* windows: in DnD, always set pdwEffect.

  It appears other apps (like Chromium) set pdwEffect on Drop too:
  61a391b86b/ui/base/dragdrop/drop_target_win.cc
* docs: make it clearer that drag events are for dragged *files*.
* examples/dnd: handle RedrawRequested event.

Co-authored-by: amrbashir <amr.bashir2015@gmail.com>
2025-01-28 21:10:40 +01:00
Tom Churchman
77f1c73f06
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-01-17 19:29:10 +03:00
Pascal Hertleif
24c226416e
Use wrapper type for CFUUID (#4032)
This no longer exposes `CGDisplayCreateUUIDFromDisplayID` and instead
uses `CFUUID` to avoid a leak.

Monitor comparisons should also be more stable now.
2025-01-17 12:38:42 +01:00
Sl-L
69382fda9a
examples/child_window: use distinct color/position for children
This should help with understanding how they work.
2025-01-10 18:07:17 +03:00
Kirill Chibisov
ee245c569d
api: make VideoModeHandle into VideoMode
The video mode is generally a static data and not a reference to some
video mode. This changes the exclusive fullscreen API to match that an
accept a monitor now.
2025-01-02 03:29:42 +03:00
Kirill Chibisov
5462f27dda
api: add ActivationToken::{from,into}_raw
This is needed when passing and getting token from the IPC to activate
the window.
2024-12-31 06:08:18 +03:00
Kirill Chibisov
927deb030f
x11: fix cursor grab mode tracking on error
Fixes #4064.
2024-12-31 05:52:12 +03:00
Kirill Chibisov
5ea81efc74 x11: add workaround for disabling IME on gnome
GNOME doesn't list that there's a _NONE_ style at all, but it still
works if you use it.
2024-12-28 14:25:56 -08:00
Matt Campbell
6896de5b73
windows: fix the event loop not waking on accessibility requests
Fixes #4055.
2024-12-24 00:23:44 +03:00
Kirill Chibisov
d736763216
Bump version on master
This commit does not represent a release and only synchronizes CHANGELOG
from the latest release.
2024-12-22 23:13:25 +03:00
Kirill Chibisov
e316a89847
x11: fix KeyboardInput delivered twice with IME
The filtered events were still processed even though they shouldn't once
we know that they're filtered.

Fixes #4048.
2024-12-22 17:51:44 +03:00
Kirill Chibisov
f0d8689039
Bump version on master
This commit does not represent a release and only synchronizes CHANGELOG
from the latest release.
2024-12-21 09:39:09 +03:00
Exidex
4d5e68c6e2
Implement ability to make non-activating window on macOS (#4035)
Fixes #3894
2024-12-13 00:56:39 +01:00
Skip R.
5835c9102e
macOS: Fix checking for undocumented cursors (#4033)
`AnyClass::responds_to` delegates to `class_respondsToSelector`, a
function provided by the Objective-C runtime. However, at some point,
this began to return `false` for selectors referring to undocumented
cursors, despite the cursors remaining accessible via said selectors.
That this check fails prevents the cursors from being used.

We can instead send `respondsToSelector:` to the `NSCursor` class
itself. As an instance method, this is nominally impossible; however,
Apple grants an exemption[1] that permits class objects to perform
instance methods defined in the root class.

Checking for the undocumented cursors in this way gets them working
again, at least on macOS Sequoia 15.1.1.

[1]: https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/ObjectiveC/Chapters/ocObjectsClasses.html#//apple_ref/doc/uid/TP30001163-CH11-TPXREF120
2024-12-08 22:01:57 +01:00