Commit graph

49 commits

Author SHA1 Message Date
Simon Hausmann
155b1443e2 Add support for reacting to dark/light mode theme changes with winit
On macOS and Windows, use winit's `Window::theme()` instead of
dark-light, to detect the theme.

Always react to WindowEvent::ThemeChange. It's delivered on macOS,
Windows, and the web.
2023-02-17 16:11:44 +01:00
Simon Hausmann
3c686047cd Silence debug output on macOS and Windows when selecting text
Use a truly silent no-op clipboard context.
2023-02-17 15:27:12 +01:00
Olivier Goffart
fb8a7fb1e5 winit backend: fix compilation with wayland but not x11 2023-02-10 11:18:05 +01:00
Olivier Goffart
6889dfa5f5 Rust: Make new(), run() and show() report errors from the backend
Fixes #2198
2023-02-10 05:00:03 +01:00
Olivier Goffart
33dc95f165 Update winit 2023-02-03 13:36:36 +01:00
Olivier Goffart
f34b1bda2e Add primary keyboard support on unix (selection copy, middle click paste)
Closes #2146
2023-01-31 16:39:22 +01:00
Simon Hausmann
32d2ba70ca
Change WindowEvent::KeyPressed/Released to use a SharedString instead of a char (#2148)
Also, `WindowEvent` is not `Copy` anymore.

Closes #1749
2023-01-31 15:44:54 +01:00
Florian Blasius
d84de623b4
TextEdit select text with double and dribble click (#2088)
* Select word in `TextEdit` by double click
* Select paragraph in `TextEdit` by dribble click
2023-01-31 15:04:19 +01:00
Olivier Goffart
ae20ec59c8 Rename PointerEventButton::None to PointerEventButton::Other
And mark the enum non_exhaustive

closes #1903
2023-01-26 13:36:54 +01:00
Olivier Goffart
f4fca41173 Compile the winit backend's with RUSTFLAGS='--cfg slint_int_coord'
(at least the swrenderer part)
2023-01-24 15:52:49 +01:00
Simon Hausmann
247772104a Move WindowEvent, PointerEventButton and Key to the platform module
For `Key` this is a move, as it is a new type. For `WindowEvent` and `PointerEventButton` deprecated aliases
are provided.
2022-11-24 11:34:28 +01:00
Simon Hausmann
0f25000610 internal: Replace calls to the internal process_key_input with the public dispatch_event API
This can be done for key press and release events, for composition we
need to extend the API first.
2022-11-16 09:47:54 +01:00
Florian Blasius
61c39b5fa1 Add support for dispatching key events through the public platform API
This change adds `KeyPress` and `KeyRelease` variants to the
`WindowEvent` enum, along with the new `slint::Key` enum, that allows
encoding keys.
2022-11-15 10:34:17 +01:00
Simon Hausmann
38a55f87a4 Change internal MouseEvent to use logical points 2022-10-13 17:02:18 +02:00
Simon Hausmann
299325370d Change generated accessor functions for Property<Coord> getters to return LogicalLength 2022-10-13 17:02:18 +02:00
Simon Hausmann
dc8bc5690b Fix C++ build with changed KeyEvent
cbindgen does not support Option.
2022-10-07 11:16:36 +02:00
Simon Hausmann
8cba0622f5 Initial input method support for the winit backend and the FemtoVG/Skia renderers
Known caveats:

- winit doesn't forward mouse events to the IME, so clicking
  with the mouse while composing results in funny effects such
  as the pre-edit text following the cursor.
- With FemtoVG there's no text decoration support, thus no underlining
  of the preedit area.
2022-10-07 11:16:36 +02:00
Simon Hausmann
ea73253d16 Fix panic in online editor when resizing the preview widget
A resize of the HTML canvas element would trigger our own resize
handler, which tried to do a special dance to trigger a redraw.

As it turns out, this breaks with current winit as the event loop target
is gone, so calling with_window_target() panics.

See also commit 8b728df021

Instead, this patch reverts to the simpler method of calling
invoke_from_event_loop, has workarounds for how to properly wake up the
event loop and return poll. In there we can just call request_redraw()
on the winit window directly to trigger a draw.
2022-09-20 10:12:39 +02:00
Olivier Goffart
e17d07fbc8 winit: Set the icon from the builder
Also simplify the code that sets the property to the builder
2022-09-13 13:39:09 +02:00
Olivier Goffart
8aeea6d8df
Winit: fix entering of character containing dead key (#1628)
The regression happened when upgrading winit as they added support for IME
2022-09-13 13:38:41 +02:00
Simon Hausmann
22f21f16a4 Move the trick to return Poll when request_redraw() is called during draw() straight into the event loop handler 2022-09-08 11:35:34 +02:00
Simon Hausmann
372e6b0ffc winit: Work around request_redraw() not always resulting in a Event::RedrawRequested
The old workaround doesn't work anymore (commit
575665994a removed the
redraw_all_windows() but that was correct as well). Instead we take an
approach that is hopefully more idiomatic to winit:

The winit documention suggests two methods: For continuously repainting
windows, we can just draw in MainEventsCleared. Otherwise call
request_redraw() and wait for Event::RedrawRequested(id).

In practice sometimes a call to request_redraw() from within the input
event processing results right away in a Event::RedrawRequested
(observed on Windows). Sometimes a request_redraw() results in waking up
with NewEvents() but no Event::RedrawRequested, and then in the next
iteration a new request_redraw() is included (observed on Windows).

We will continue to issue request_redraw() but for any windows that
haven't received Event::RedrawRequested() we will just draw. This still
allows the windowing system to compress / combine paint events.

If during draw() request_redraw() is called, we assume that the
application wants to redraw ASAP and we fall back to Poll. This was
previously the workaround in corelib that's now only in the winit code.

Fixes #1574
2022-09-08 11:35:34 +02:00
Simon Hausmann
4095622303 Clean up internal WinitWindow trait
Since event_loop.rs is not shared anymore between the winit backend and
the "mcu" backend, we can reduce the WinitWindow trait to the features
that are needed for the event loop code to store it as trait object.
2022-09-08 08:56:17 +02:00
Olivier Goffart
6ede77436b api: Return an error from invoke_from_event_loop and quit_event_loop 2022-09-07 10:13:58 +02:00
Simon Hausmann
7967bf1ab0 Replace the internal WindowHandleAccess trait with a helper function on WindowInner
The reversal of ownership removes the need for the glue trait in the
publicly visible API.
2022-09-06 16:17:06 +02:00
Simon Hausmann
7e5de3d5d3 Remove use of euclid types and tags for logical/physical position and size in the public API
Instead provide our own types.
2022-09-02 11:05:53 +02:00
Simon Hausmann
85461d380d Remove euclid from the public re-export of the Slint crate 2022-09-02 11:05:53 +02:00
Olivier Goffart
fcca38e0f6 Rename set_event_loop_quit_on_last_window_closed to remove EventLoopQuitBehavior
For the winit backend, also make the function work after a call to run()
2022-09-01 12:08:05 +02:00
Tobias Hunger
1e6ffeaa0f API cleanup: Rename PlatformWindow to WindowAdapter 2022-08-29 16:53:47 +02:00
Simon Hausmann
e24ceb490f winit: Fix panic when shutting down event loop
If we (or the user) ends up calling hide() on a window after returning from the event loop, our
attempt at posting an event would panic in winit as we
try to create a new event loop instances.

Since Winit 0.27 a panic is raised when creating an event loop instance a second time.
2022-08-25 16:49:59 +02:00
Simon Hausmann
be7947a321 Update winit and glutin 2022-08-25 16:49:59 +02:00
Olivier Goffart
2e5ab86bea Rename backend module to platform
and the Backend trait into PlatfromAbstraction trait
2022-08-23 19:39:49 +02:00
Olivier Goffart
4edd0b27c1 Janitor: Some code reformating 2022-08-22 14:41:50 +02:00
Olivier Goffart
ecd80059c3 Use new timer api in winit backend 2022-08-22 14:41:50 +02:00
Olivier Goffart
00e9fcc9dd backend API: polish and move the timer functions to the backend module 2022-08-22 14:41:50 +02:00
Simon Hausmann
af86f36157 Invert slint:🪟:WindowInner and PlatformWindow ownership
Previously: Window is an Rc<WindowInner>, which has an Rc<dyn
PLatformWindow> - and weak references the other way around.

Now: Rc<dyn PlatformWindow> is the root of window ownership. The impl
PlatformWindow has a slint::api::Window, which just holds a WindowInner.

This change is incomplete on a few levels, mainly that neither of the
code generators nor the interpreter is ported.
2022-08-19 15:07:27 +02:00
Simon Hausmann
f88b688fbf Simplify PlatformWindow receivers
For hide() we don't really need Rc<Self>, and for show() we had Rc<Self> because
for example for winit we need a Weak<Self> for the thread-local mapping of
window id to window.

However that can be encapsulated in the PlatformWindow impl using Rc::new_cyclic,
there's no need to expose this in the trait.
2022-08-19 15:07:27 +02:00
Simon Hausmann
8e84faa2c5 Prepare PlatformWindow API for exposing and (in the future) owning the Window
Move the self_weak of WindowInner into the impl of PlatformWindow. Most implementations already have it anyway.

While right now the method returns a `WindowRc`, at the end of the series
it should return a `&Window`.

From that `&Window` we can get to `&WindowInner` and all receivers there
are `&self`.
2022-08-19 15:07:27 +02:00
Simon Hausmann
262c96af8c Simplify receiver for WindowInner
Use &self consistently, instead of Rc<Self>, so that in the future we can
replace Window(Rc<WindowInner>) with Window(WindowInner).
2022-08-19 15:07:27 +02:00
Olivier Goffart
c900b2f604 winit backend: use the Window::set_size form the resize event 2022-08-18 09:39:25 +02:00
Olivier Goffart
02c60e5389 Refactor the way the backend sets the window size 2022-08-18 09:39:25 +02:00
Olivier Goffart
a62a5cbd19 Rename MouseEvent pos to position 2022-08-17 18:28:12 +02:00
Olivier Goffart
61739dcb81 Remove the Mouse prefix from enum value of the MouseEvent enum 2022-08-17 18:28:12 +02:00
Simon Hausmann
7314fa0953 Attempt to clarify the reasoning behind windows_with_pending_property_updates 2022-08-10 11:34:30 +02:00
Simon Hausmann
6209af1c9a Remove unnecessary into_iter() call on the Vec's drain 2022-08-10 11:34:30 +02:00
Simon Hausmann
6446a28fd6 winit: fix jitter on macos again when resizing windows
Commit 0ee361d994 regressed on
https://github.com/slint-ui/slint/issues/1269 as the inner_size()
returned at the time during event processing is already the future
value, that will change again when processing the resize event.

Instead of storing the last received value, process the event at the
appropriate MainEventsCleared stage.
2022-08-10 11:34:30 +02:00
Simon Hausmann
f4ddfa5ef6 winit: separate rendering from surface resizing
Resize the glutin context when we receive a resize event from winit.
This is the approach recommended by glutin/winit's documentation.

This approach also avoids jitter when rendering with metal (not
implemented yet, but tested locally :)
2022-08-09 16:20:53 +02:00
Simon Hausmann
0ee361d994 winit: Remove unused existing_size field
This field duplicates the winit window's inner size. It is set on a
WindowEvent::Resized(), after which
`winit:🪟:Window::inner_size()` returns the same value.
2022-08-09 13:16:52 +02:00
Simon Hausmann
27bf9348e6 Rename the backend-gl crate into backend-winit 2022-07-26 17:43:51 +02:00
Renamed from internal/backends/gl/event_loop.rs (Browse further)