Commit graph

282 commits

Author SHA1 Message Date
Mads Marquart
db2c97a995
macOS: set the theme on the NSWindow, instead of application-wide
This new implementation uses:
- The NSAppearanceCustomization protocol for retrieving the appearance
  of the window, instead of using the application-wide
  `-[NSApplication effectiveAppearance]`.
- Key-Value observing for observing the `effectiveAppearance` to compute
  the `ThemeChanged` event, instead of using the undocumented
  `AppleInterfaceThemeChangedNotification` notification.

This also fixes `WindowBuilder::with_theme` not having any effect, and
the conversion between `Theme` and `NSAppearance` is made a bit more
robust.
2024-06-20 17:05:34 +03:00
Kirill Chibisov
3e8fa41073
event_loop: remove deprecated run APIs
The APIs are not well suited for the `&dyn ApplicationHandler` model and
`Box<dyn EventLoop>` structure, thus remove them.
2024-05-20 20:27:36 +04:00
Joshua Pedrick
fd477986de
Add UIGestureRecognizerDelegate and PanGestureRecogniser (#3597)
- Allow all gestures simultaneously recognized.
- Add PanGestureRecogniser with min/max number of touches.
- Fix sending delta values relative to Update instead to match macOS.
- Fix rotation gesture units from iOS to be in degrees instead of radians.

Co-authored-by: Mads Marquart <mads@marquart.dk>
2024-04-27 15:55:04 +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
daxpedda
4f47a4e793
Update dev-dependencies (#3641) 2024-04-18 21:52:38 +02:00
daxpedda
c15fa6e433
Re-introduce Web examples (#3637) 2024-04-18 19:43:39 +02:00
Bruce Mitchener
7dd7dc1fc8
example: Fix typo: "fosus" -> "focus" (#3629) 2024-04-15 23:59:58 +02:00
Colin Kinloch
44aabdddcc
example: add an example of request_inner_size
Add the shortcut "Alt + R" to swap the size of the window axes in
window example.
2024-03-28 23:39:19 +04:00
AmeKnite
b2f9fad654 ci: add typos-cli
Given that typos are frequent and may appear in the public API spell
check code on CI.
2024-03-07 18:03:38 +04:00
Kirill Chibisov
d123cd2f8e api: add ApplicationHandler and matching run APIs
Add a simple `ApplicationHandler` trait since winit is moving towards
trait based API. Add `run_app` group of APIs to accept `&mut impl
ApplicationHandler` deprecating the old `run` APIs.

Part-of: https://github.com/rust-windowing/winit/issues/3432
2024-03-05 16:13:14 +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
daxpedda
010787a430
Fix nightly CI (#3526) 2024-02-26 09:46:12 +01: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
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
21df84b7f4 On Wayland, pre-multiply alpha for custom cursor
Fixes: #3360
2024-01-30 21:31:17 +04:00
John Nunley
3830b492c4 Update new builders for latest master
Signed-off-by: John Nunley <dev@notgull.net>
2024-01-27 10:16:52 -08:00
Mads Marquart
8862ce0163 Add EventLoop::builder, which replaces EventLoopBuilder::new
Similarly for EventLoop::with_user_event and EventLoopBuilder::with_user_event
2024-01-27 10:16:52 -08:00
Mads Marquart
569c44a632 Add Window::builder, which replaces WindowBuilder::new 2024-01-27 10:16:52 -08:00
François
6b29253797
Support pinch, double tap and rotation gestures on iOS (#3130)
This is off by default on iOS. Note that pinch delta may be NaN.

Co-authored-by: Mads Marquart <mads@marquart.dk>
2024-01-16 21:31:18 +01:00
daxpedda
16d860736b
Platform is called Web not Wasm (#3393) 2024-01-14 18:54:52 +01:00
Mads Marquart
22311802b5
Remove generic parameter T from EventLoopWindowTarget (#3298) 2024-01-13 21:36:53 +01:00
daxpedda
169cd39f93
Web: improve custom cursor handling and add animated cursors (#3384) 2024-01-12 11:51:19 +01:00
daxpedda
be4a660011
Merge Window::set_cursor_icon() and Window::set_custom_cursor() (#3308) 2023-12-25 07:20:52 +01:00
Kirill Chibisov
8cc5cb9d9b Fix run_on_demand exiting on consequent call
Fixes #3284.
2023-12-24 22:21:45 +04:00
Mads Marquart
4f6fd44c6c
macOS: Clean up coordinate system calculations (#3302)
* Clean up macOS and iOS monitor code a bit

* Clean up window size methods

Use `setContentSize`, `setContentMinSize`, `setContentMaxSize` and `contentRectForFrameRect` to let the windowing system figure out the required scaling, instead of us doing it manually.

* Use a flipped NSView coordinate system

* Clean up window position methods
2023-12-24 10:12:09 +01:00
daxpedda
2c15de7cf9
Allow custom cursor caching (#3276) 2023-12-22 22:20:41 +01:00
Eero Lehtinen
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
John Nunley
da947992ac
bugfix(x11): Use the right atom type in focus_window()
Closes #3248 by removing an Xlibism I forgot about

Signed-off-by: John Nunley <dev@notgull.net>
2023-11-28 16:20:36 -08:00
Linda_pp
d333dd8664
Fix crash when minimizing example on Windows 2023-10-31 19:21:36 +04:00
Diggory Hardy
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
John Nunley
e41fac825c
Update to new raw-window-handle strategy
Signed-off-by: John Nunley <dev@notgull.net>
Co-authored-by: TornaxO7 <tornax@proton.me>
2023-10-15 06:07:39 +04:00
YouKnow
1ea41a2ee2
Add Window::show_window_menu
Add a method to request a system menu. The implementation
is provided only on Windows for now.

Co-authored-by: daxpedda <daxpedda@gmail.com>
Co-authored-by: Kirill Chibisov <contact@kchibisov.com>
2023-10-11 01:46:16 +04:00
epimeletes
ee0db52ac4
Rename run_ondemand to run_on_demand 2023-10-04 01:24:42 +04:00
daxpedda
878d832d24
Make ControlFlow::Wait the default (#3106) 2023-09-22 21:27:11 +02:00
daxpedda
e648169861
Move ControlFlow to EventLoopWindowTarget
Fixes #3042.
2023-09-07 10:25:04 +04:00
daxpedda
0c8cf94a70
Web: Fullscreen Overhaul (#3063) 2023-08-29 09:28:30 +02:00
daxpedda
67d3fd28f7
Move Event::RedrawRequested to WindowEvent (#3049) 2023-08-27 16:15:09 +02:00
Kirill Chibisov
f801c4a00b
Reexport raw-window-handle in window module
We use raw-window-handle extensive in the public API as well as we
force the users to use it to get some essential data for interop, thus
reexport it.

Fixes: #2913.
2023-08-14 11:24:45 +04:00
Kirill Chibisov
f9758528f6
Propagate error from EventLoop creation
Inner panics could make it hard to trouble shoot the issues and for some
users it's not desirable.

The inner panics were left only when they are used to `assert!` during
development.

This reverts commit 9f91bc413fe20618bd7090829832bb074aab15c3 which
reverted the original patch which was merged without a proper review.

Fixes: #500.
2023-08-13 23:20:09 +04:00
John Nunley
dc973883c9
Add a way to embed the X11 window into another
Signed-off-by: John Nunley <dev@notgull.net>
Tested-by: Kirill Chibisov <contact@kchibisov.com>
2023-08-11 13:30:55 +04:00
Kirill Chibisov
793c535b01
Revert "Propagate error from EventLoop creation" (#3010)
This reverts commit ed26dd58fd.
The patched was merged with a review by accident.
2023-08-06 06:07:01 +04:00
Kirill Chibisov
ed26dd58fd
Propagate error from EventLoop creation
Inner panics could make it hard to trouble shoot the issues and for some
users ints not desirable.

The inner panics were left only when they are used to `assert!` during
development.
2023-08-06 06:03:54 +04:00
Kirill Chibisov
38f28d5836 Add Window::on_present_notify to ack about drawing
That's a way to communicate to winit that you'll present to the window.
While it's a no-op for now, it'll be used to throttle drawing.
2023-08-04 14:23:44 +04:00
Kirill Chibisov
9ac3259a79
Remove lifetime from the Event
Lifetimes don't work nicely when dealing with multithreaded environments
in the current design of the existing winit's event handling model, so
remove it in favor of `InnerSizeWriter` fences passed to client, so they
could try to update the size.

Fixes #1387.
2023-07-31 00:39:01 +04:00
Tobias Hunger
2b2dd6b65d
On Windows, keep window maximized when setting size bounds (#2899) 2023-07-29 16:22:28 +02:00
Robert Bragg
ae7497e18f
Remove RedrawEventsCleared + MainEventsCleared, and added AboutToWait
The idea that redraw events are dispatched with a specific ordering
that makes it possible to specifically report when we have finished
dispatching redraw events isn't portable and the way in which we
dispatched RedrawEventsCleared was inconsistent across backends.

More generally speaking, there is no inherent relationship between
redrawing and event loop iterations. An event loop may wake up at any
frequency depending on what sources of input events are being listened
to but redrawing is generally throttled and in some way synchronized
with the display frequency.

Similarly there's no inherent relationship between a single event loop
iteration and the dispatching of any specific kind of "main" event.

An event loop wakes up when there are events to read (e.g. input
events or responses from a display server / compositor) and goes back
to waiting when there's nothing else to read.

There isn't really a special kind of "main" event that is dispatched
in order with respect to other events.

What we can do more portably is emit an event when the event loop
is about to block and wait for new events.

In practice this is very similar to how MainEventsCleared was
implemented except it wasn't the very last event previously since
redraw events could be dispatched afterwards.

The main backend where we don't strictly know when we're going to
wait for events is Web (since the real event loop is internal to
the browser). For now we emulate AboutToWait on Web similar to how
MainEventsCleared was dispatched.

In practice most applications almost certainly shouldn't care about
AboutToWait because the frequency of event loop iterations is
essentially arbitrary and usually irrelevant.
2023-07-28 20:37:56 +04:00
Robert Bragg
ae9b02e097 Add timeout argument to pump_events
This renames all internal implementations of pump_events_with_timeout
to pump_events and makes them public.

Since all platforms that support pump_events support timeouts there's
no need to have a separate API.
2023-07-28 03:04:32 +04:00
Robert Bragg
e5eb253698 window_ondemand: wait for Destroyed event before exiting app
Considering the strict requirement that applications can't keep windows
across run_ondemand calls, this tries to make the window_ondemand example
explicitly wait for its Window to be destroyed before exiting each
run_ondemand iteration.

This updates the example to only `.set_exit()` after it gets a
`Destroyed` event after the Window has been dropped.

On Windows this works to ensure the Window is destroyed before the
example waits for 5 seconds.

Unfortunately though:
1. The Wayland backend doesn't emit `Destroyed` events for windows
2. The macOS backend emits `Destroyed` events before the window is
   really destroyed.

and so the example isn't currently portable.
2023-07-28 03:04:32 +04:00