Commit Graph
209 Commits
Author SHA1 Message Date
daxpedda 28a811bbba Remove extern crate statements (#3310) 2023-12-25 09:25:09 +01:00
daxpedda be4a660011 Merge Window::set_cursor_icon() and Window::set_custom_cursor() (#3308) 2023-12-25 07:20:52 +01:00
daxpedda e5310ade08 Custom cursor improvements (#3292) 2023-12-23 16:12:29 +01:00
daxpedda 37946e0a3a Use std::cell::OnceCell (#3290) 2023-12-22 23:49:25 +01:00
daxpedda 8cd3aaa8a2 On Web, use the new WebCanvasWindowHandle (#3270) 2023-12-22 22:33:50 +01:00
daxpedda 2c15de7cf9 Allow custom cursor caching (#3276) 2023-12-22 22:20:41 +01:00
daxpedda 4f669ebbd2 On Web, fix context menu not being disabled (#3282) 2023-12-22 00:11:36 +01:00
daxpedda cc33212479 On Web, fix setting cursor icon overriding cursor visibility (#3269) 2023-12-17 18:49:45 +01:00
daxpedda f2c5127f27 Web: remove queuing fullscreen request (#3242) 2023-12-17 13:31:48 +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
daxpedda eab982c402 Web: forbid additional functions in favor of caching them (#3219) 2023-11-10 22:46:51 +01: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 48f6582eb4 Web Async Rework (#3082) 2023-10-16 15:50:22 +02:00
John NunleyandTornaxO7 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
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
daxpedda fac6110cb6 Web: fix ControlFlow::WaitUntil to never wake up **before** the given time (#3133) 2023-10-09 12:31:02 +02:00
Dmitry Sharshakov 0363be4776 Add Window::set_blur
Allow clients to request blur behind their window, implemented on
Wayland for now.
2023-10-08 23:53:15 +04:00
daxpedda f5dd1c008c Web: remove unnecessary usage of once_cell::unsync::Lazy (#3134) 2023-10-08 02:00:51 +02:00
daxpedda 0caba93b51 Rename PollType to PollStrategy (#3089) 2023-09-08 18:39:23 +02:00
daxpedda 83950acd5a Add Window.requestIdleCallback() support (#3084) 2023-09-07 12:12:35 +02:00
daxpedda e648169861 Move ControlFlow to EventLoopWindowTarget
Fixes #3042.
2023-09-07 10:25:04 +04:00
daxpeddaandnerditation 7a2a2341c2 Remove T from EventLoopTargetWindow (#3081)
Co-authored-by: nerditation <12248559+nerditation@users.noreply.github.com>
2023-09-03 02:26:53 +02:00
Mads Marquart a06ea45c0f Slightly reduce number of cfgs (#3071)
* Make Linux platforms less dependent on the root monitor handle

* Add various functions to the Wayland platform to reduce cfgs

* Don't use a cfg in listen_device_events

* Don't use a cfg in set_content_protected

* Fix instance of a target_os cfg
2023-09-01 23:14:16 +02:00
daxpedda 0c8cf94a70 Web: Fullscreen Overhaul (#3063) 2023-08-29 09:28:30 +02:00
daxpedda 1dfca5a395 Enable event propagation (#3062) 2023-08-28 19:18:10 +02:00
daxpedda 67d3fd28f7 Move Event::RedrawRequested to WindowEvent (#3049) 2023-08-27 16:15:09 +02:00
daxpedda a3cba838ea On Web, never return a MonitorHandle (#3051) 2023-08-26 18:56:44 +02:00
daxpedda 48abf52aac Use setTimeout() trick instead of Window.requestIdleCallback() (#3044) 2023-08-25 21:40:21 +02:00
Mads Marquartanddaxpedda af6c343d0e Improve macOS/iOS/Web thread safety
Co-authored-by: daxpedda <daxpedda@gmail.com>
2023-08-14 23:19:57 +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
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 Chibisovanddaxpedda 8100a6a584 Remove 'static requirement on run
There's no need to force the static on the users, given that internally
some backends were not using static in the first place.

Co-authored-by: daxpedda <daxpedda@gmail.com>
2023-08-06 01:56:56 +04:00
dAxpeDDa 57fad2ce15 On Web, use requestAnimationFrame for RedrawRequested 2023-08-04 14:23:44 +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
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 935146d299 Rename LoopDestroyed to LoopExiting
Considering the possibility of re-running an event loop via run_ondemand
then it's more correct to say that the loop is about to exit without
assuming it's going to be destroyed.
2023-07-28 20:19:53 +04:00
daxpedda b63164645b On Web, add WindowBuilderExtWebSys::with_append() (#2953) 2023-07-12 17:11:52 +02:00
daxpedda 5379d60e4d On Web, remove Window::is_dark_mode() (#2951) 2023-07-11 18:26:32 +02:00
daxpedda 3b2d1a7643 On Web, implement and fix missing methods on Window(Builder) (#2949) 2023-07-11 13:14:40 +02:00
daxpedda 50b17a3907 Add Fullscreen API compatibility for Safari (#2948) 2023-07-11 00:34:02 +02:00
daxpedda af26f01b95 On Web, cache commonly used values (#2947) 2023-07-11 00:11:06 +02:00
daxpedda c4d70d75c1 Increase accuracy of various Web APIs (#2946) 2023-07-10 23:55:43 +02:00
Kirill Chibisov ff0ce9d065 Rename Window::set_inner_size to Window::request_inner_size
Some systems could resize the window immediately and we'd rather
inform the users right away if that was the case, so they could
create e.g. EGLSurface without waiting for resize, which is really
important for Wayland.

Fixes #2868.
2023-07-10 04:02:26 +00:00
daxpedda 42e492cde8 Fix touch location accuracy (#2944) 2023-07-10 02:17:36 +02:00
daxpedda 5e0e1e96bc On Web, implement WindowEvent::Occluded (#2940) 2023-07-10 02:02:38 +02:00
daxpedda 4652d48105 Don't unnecessarily clone canvas on Web (#2934) 2023-07-08 17:05:05 +02:00
dAxpeDDa b0106898f7 Don't allow event loops to run in parallel 2023-06-29 15:53:58 +02:00