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.
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.
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.
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
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.
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.
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.
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.
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`.
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.
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 :)
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.