Commit graph

283 commits

Author SHA1 Message Date
Simon Hausmann
ab051680e5 janitor: Rename GLWindow to WinitWindowAdapter
It's no more an "OpenGL Window", it's the type that adapts winit to our windowing
system abstraction.
2023-04-05 11:04:19 +02:00
Simon Hausmann
43234dafc5 Fix loading of demos in SlintPad
Add a data attribute hack to force auto-resizing to the preferred size
in SlintPad. Otherwise the initial size of the hello world will remain
in effect when loading other demos.
2023-03-31 15:23:55 +02:00
Simon Hausmann
3b9c2ec7f1 Fix wasm build 2023-03-30 09:28:37 +02:00
Simon Hausmann
d6c9ddd27a Qt: Avoid setting 0x0 as maximum size on a window
Centralize the code to ensure that we only set a maximum size if > 0 into corelib.
2023-03-30 08:43:48 +02:00
Simon Hausmann
528f428c60 Unify the code to compute the optional min/max window size into a helper function 2023-03-30 08:43:48 +02:00
Simon Hausmann
71253ef52e Share logic for determining if winit window is resizable
In show() use the same logic as in apply_geometry_constraint.
2023-03-30 08:43:48 +02:00
Simon Hausmann
a7043a3a36 Apply a maximum size to a window only if it's non-zero
A window with zero width or height doesn't make sense.
2023-03-30 08:43:48 +02:00
Simon Hausmann
84b3e8f78a Cleanup
When modifying the window builder in show(), don't mix shadowing and variable re-assignment.
In this case, just use assignment.
2023-03-30 08:43:48 +02:00
Simon Hausmann
ab5f6101fa When applying geometry constraints, make the window resizable only when an min/max is set on the window
(also removed redundant set_resizable(true) call)
2023-03-30 08:43:48 +02:00
Olivier Goffart
e8f21035ff Fix the slide_puzzle canvas size on wasm
Since winit can't handle resize from the CSS or JS, work it around in
the demo by calling set_size on the slint window.

Also fix slint_size panicking not working on wasm as the map_state was
mutably borrowed by the set_size, and this may recurse into other
functions (eg, draw) causing a panic. So don't keep the state borrowed
when calling winit.

Another fix is fixing the initialization size of the window item when
the initial size is set with set_size

Fixes #547
2023-03-29 15:41:07 +02:00
Simon Hausmann
09f269b6ff Minor cleanup
Use the new winit_handle() function to remove one level of indentation.
2023-03-28 11:52:33 +02:00
Simon Hausmann
5879e1ec71 Fix touch events not working for wasm builds
Work around a winit bug for WASM builds by pinning to the exact winit
version and making the coordinates relative again.

cc #2424
2023-03-28 11:52:33 +02:00
Simon Hausmann
b38df20d9a Add a feature to enable system fonts with the software renderer
If we have a file system, then we can allow users of the software
renderer to support text rendering by from fonts served by the file
system.

cc #2100
2023-03-28 11:33:44 +02:00
Simon Hausmann
a45421b425 Speed up Linux builds
Remove the dark-light dependency, as it significantly slows down the
build on Linux. On Windows/Mac/Web it's not needed. On Linux Desktop,
folks are likely going to have Qt installed - where this works - and on
Embedded Linux the assumption is that it's not running as Linux Desktop.

On Linux the number of dependencies for `-p slint` goes down from 418 to
328. Build time on my machine goes from 1 minute down to ~50 seconds.
2023-03-28 11:32:59 +02:00
Simon Hausmann
278d650d7d Fix error messages when supplying invalid sizes to Skia and FemtoVG
Apply the same error message as for
https://github.com/slint-ui/slint/pull/2402#discussion_r1146657846
2023-03-27 12:47:31 +02:00
Simon Hausmann
029c91d577 Fix missing window title when using Slint on Wayland
Winit defaults to sctk-adwaita with ab_glyph rendering. Pick the same
default when the wayland feature is enabled on our end.

This is a stop-gap. In the future we should try to implement the window
decoration rendering ourselves.

Fixes #2188
2023-03-27 10:33:47 +02:00
Simon Hausmann
8ffb5131c7
Introduce error handling in the FemtoVG and Skia renderers (#2402)
Avoid unwrap() and expect() and instead propagate errors all the way
down to run_event_loop(), show(), and hide() in the Slint AIP.
2023-03-24 14:18:11 +01:00
Simon Hausmann
ef07da4893 Add comment about resizing tweak on macOS 2023-03-23 15:36:42 +01:00
Simon Hausmann
c54e1cba43 Fix support on GLX displays with FemtoVG
In order for GLX support to work, we need to create the X11 window with
the same visual as in the GLX configuration. That requires delaying
the creation of the window.

This is done in four parts:

- The window builder is re-introduced in the winit backend create
  internal renderer interface.
- The glcontext helper code for wasm was moved into a separate function
  (less indentation).
- The loop over different display preferences was replaced with a
  preference to the "window system native GL interface" over EGL,
  which should achieve the same as the fix for #2162. Upstream glutin
  defaults to this and so do various downstream projects.
- Use glutin-winit for the actual display selection.

This covers the FemtoVG bits of #2269
2023-03-23 15:36:42 +01:00
Olivier Goffart
82e23a114b Wasm: don't print fake keys in input box
We should only forward keys that are a single character. Other ones are
just virtual keys that should't be processed.

This regressed in commit 32d2ba7

Fix #2327
2023-03-09 10:46:03 +01:00
Tobias Hunger
3ac01c3f07 clippy: Fix clippy warnings 2023-03-09 09:35:29 +01:00
Olivier Goffart
04eacbb526 Don't panic twice when the rendering panics 2023-03-06 17:13:33 +01:00
Simon Hausmann
9fcce74b2f Fix build with RUST_FONTCONFIG_DLOPEN
Since the fontconfig ffi code moved to the femtovg renderer create, we
need to build the build.rs feature setting.
2023-03-06 16:40:26 +01:00
Simon Hausmann
aac74a6271 Fix build without x11 2023-03-06 14:02:18 +01:00
Simon Hausmann
6d968aa329 Extract the FemtoVG renderer into a separate crate
This will be needed for a future experiment. Unlike the Skia renderer,
which operates on raw window handles, the FemtoVG renderer exposes a
different interface where it assumes that the caller takes care of the
OpenGL context state. This means more boilerplate remains in the winit
backend, including the glutin dependency. The upside is that it will
allow using the FemtoVG renderer in environments without glutin.

In order to work in an environment without fontconfig or memmap, the
crate has two features:

  - fontconfig (set when we anticipate fontconfig to be available at
    run-time and libloading being available at compile time).
  - diskfonts (set when we want to be able to load fonts from disk)

The winit crate enables fontconfig on "Linux" and diskfonts on !wasm.
2023-03-06 11:45:28 +01:00
Simon Hausmann
fb06cd8d51 winit: Fix rendering when moving windows between monitors with different scale factor
Adjust the size of the underlying graphics surface to avoid rendering
artefacts.

Fixes #2282
2023-03-03 15:22:56 +01:00
Simon Hausmann
fdb719a65e femtovg: Fix panic when rendering colorized image with transparent global alpha
This is reproducible in the energy monitor when scrolling down in the
settings page.

In the helper function to colorize an image, we did not expect
brush_to_paint() to fail. The condition of a transparent colorize color
was handled earlier, but it turns out that brush_to_paint() also checked
the global state as an optimization.

This optimization is wrong, as the cached colorized image should not
depend on the untracked global transparency.

So this patch adds a graceful handling of brush_to_paint returning None
for defensive measures, but also moves the early return on an global
transparent alpha to the call sites where it makes sense.
2023-03-03 15:22:28 +01:00
Simon Hausmann
1473637ce3 Remove dark-light dependency on the web
winit 0.28.2 was released today, which supports `Window::theme()` on the
web.
2023-03-02 18:53:55 +01:00
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
c3c98d928c Fix panic when minimizing window on Windows with winit
Fixes #2197
2023-02-17 15:59:02 +01:00
Olivier Goffart
ed51f6b7b6 Femtovg backend: fix text_input_cursor_rect_for_byte_offset for the last glyph
It was on the wrong line if not a \n, and on the wrong position if a \n
2023-02-17 15:51:14 +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
Simon Hausmann
59e0723793 Improved fix for panic when using OpenGL with the winit backend on Linux
Replace the patch with use of the glutin API as advised upstream (and
also implemented in glutin-winit).

Closes #2215
2023-02-09 16:16:36 +01:00
Simon Hausmann
476300ded7 Prospective fix for preview panicing on Linux v2
Avoid unwrap in the display/context selection try function.
2023-02-09 14:24:20 +01:00
Simon Hausmann
e8439061e8 Prospective fix for vscode extension preview not working on Linux
The CI build vsix panics on line 84 in glcontext.rs. There's no unwrap()
there but there's one nearby. I wasn't able to reproduce this with a
local build, so this is a prospective attempt, assuming that this is due
to the attempt of glx-over-egl display configuration finding.
2023-02-09 09:45:54 +01:00
Olivier Goffart
a19efc30db
Replace the MAX_BUFFER_AGE const generic with a runtime enum
Having a const generic for that didn't turn to be a good API.
Also made the C++ side more difficult

(Also renamed buffer_stride to pixel_stride)

Closes #2135
2023-02-08 14:44:01 +01:00
Simon Hausmann
860f318f7c
Bump femtovg, rustybuzz, ttf-parser, and fontdb dependencies (#2191)
Mostly bugfix changes upstream with some minor API changes. FemtoVG is
no more limited to 24 gradient stops for the paint.
2023-02-08 09:56:53 +01:00
Simon Hausmann
ed8ea3c85c Prospective fix for Linux systems that don't support EGL with X11
As the surface creation may fail with Egl later, then display preference
EglThenGlx is not sufficient and we need to completely re-do the glutin
initialization and try with GLX.

cc #2162
2023-02-03 17:12:59 +01:00
Olivier Goffart
33dc95f165 Update winit 2023-02-03 13:36:36 +01:00
ogoffart
e7f48512ee Bump version number to 1.0.0 2023-02-03 11:07:15 +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
Simon Hausmann
04ceb63433 Update to FemtoVG 4.0
Not big changes, just API and Cargo feature cleanups
2023-01-27 12:03:33 +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
Simon Hausmann
52fb1ab9fe Fix signature of get_proc_address in Rust GraphicsAPI
Use a CStr instead of str, to avoid an extra CString allocation. The underlying operating system API for
this expects a zero terminated C String.

Fixes #1943
2023-01-26 11:55:10 +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
5ff0278185 Simplify path event extraction
Return the path events for rendering as an Option, so that if the path is empty,
we simply return.

This avoids a double property dependency in the (likely) event the path is not empty.
2023-01-21 13:10:19 +01:00