Skip to content

Commit e186b4c

Browse files
authored
feat(driver): import Wayland driver from v8 (lvgl#6549)
1 parent aebb4d3 commit e186b4c

File tree

15 files changed

+4069
-1
lines changed

15 files changed

+4069
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ test_screenshot_error.h
2424
build/
2525
tests/build_*/
2626
tests/report/
27+
tests/wayland_protocols/
2728
.DS_Store
2829
.vscode
2930
.idea

Kconfig

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1562,6 +1562,18 @@ menu "LVGL configuration"
15621562
With 2 buffers in flush_cb only and address change is required.
15631563
endchoice
15641564

1565+
config LV_USE_WAYLAND
1566+
bool "Use the wayland client to open a window and handle inputs on Linux or BSD"
1567+
default n
1568+
config LV_WAYLAND_WINDOW_DECORATIONS
1569+
bool "Draw client side window decorations, only necessary on Mutter (GNOME)"
1570+
depends on LV_USE_WAYLAND
1571+
default n
1572+
config LV_WAYLAND_WL_SHELL
1573+
bool "Support the legacy wl_shell instead of the default XDG Shell protocol"
1574+
depends on LV_USE_WAYLAND
1575+
default n
1576+
15651577
config LV_USE_LINUX_FBDEV
15661578
bool "Use Linux framebuffer device"
15671579
default n

docs/integration/driver/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ Drivers
1111
X11
1212
windows
1313
opengles
14+
wayland

docs/integration/driver/wayland.rst

Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
=============================
2+
Wayland Display/Inputs driver
3+
=============================
4+
5+
Overview
6+
--------
7+
8+
| The **Wayland** `driver <https://github.com/lvgl/lvgl/tree/master/src/drivers/wayland>`__ offers support for simulating the LVGL display and keyboard/mouse inputs in a desktop window.
9+
| It is an alternative to **X11** or **SDL2**
10+
11+
The main purpose for this driver is for testing/debugging the LVGL application, it can also be used to run applications in 'kiosk mode'
12+
13+
Dependencies
14+
------------
15+
16+
The wayland driver requires some dependencies.
17+
18+
On Ubuntu
19+
20+
.. code:: bash
21+
22+
sudo apt-get install libwayland-dev libxkbcommon-dev libwayland-bin wayland-protocols
23+
24+
On Fedora
25+
26+
.. code:: bash
27+
28+
sudo dnf install wayland-devel libxkbcommon-devel wayland-utils wayland-protocols-devel
29+
30+
31+
Configuring the wayland driver
32+
------------------------------
33+
34+
1. Enable the wayland driver in ``lv_conf.h``
35+
36+
.. code:: c
37+
38+
#define LV_USE_WAYLAND 1
39+
40+
2. Optional configuration options:
41+
42+
- Enable window decorations, only required on GNOME because out of all the available wayland compositors
43+
**only** Mutter/GNOME enforces the use of client side decorations
44+
45+
.. code:: c
46+
47+
#define LV_WAYLAND_WINDOW_DECORATIONS 1
48+
49+
- Enable support for the deprecated 'wl_shell', Only useful when the BSP on the target has weston ``9.x``
50+
51+
.. code:: c
52+
53+
#define LV_WAYLAND_WL_SHELL 1
54+
55+
Example
56+
-------
57+
58+
An example simulator is available in this `repo <https://github.com/lvgl/lv_port_linux/>`__
59+
60+
Usage
61+
-----
62+
63+
#. In ``main.c`` ``#incude "lv_drivers/wayland/wayland.h"``
64+
#. Enable the Wayland driver in ``lv_conf.h`` with ``LV_USE_WAYLAND 1``
65+
66+
#. ``LV_COLOR_DEPTH`` should be set either to ``32`` or ``16`` in ``lv_conf.h``
67+
68+
#. Add a display using ``lv_wayland_window_create()``,
69+
possibly with a close callback to track the status of each display:
70+
71+
.. code:: c
72+
73+
#define H_RES (800)
74+
#define V_RES (480)
75+
76+
/* Create a display */
77+
lv_disp_t * disp = lv_wayland_create_window(H_RES, V_RES, "Window Title", close_cb);
78+
79+
80+
As part of the above call, the Wayland driver will register four input devices
81+
for each display:
82+
83+
* a KEYPAD connected to Wayland keyboard events
84+
* a POINTER connected to Wayland touch events
85+
* a POINTER connected to Wayland pointer events
86+
* an ENCODER connected to Wayland pointer axis events
87+
88+
Handles for input devices of each display can be obtained using
89+
``lv_wayland_get_indev_keyboard()``, ``lv_wayland_get_indev_touchscreen()``,
90+
``lv_wayland_get_indev_pointer()`` and ``lv_wayland_get_indev_pointeraxis()`` respectively.
91+
92+
Fullscreen mode
93+
^^^^^^^^^^^^^^^
94+
95+
To programmatically fullscreen the window,
96+
use the ``lv_wayland_window_set_fullscreen()`` function respectively with ``true``
97+
or ``false`` for the ``fullscreen`` argument.
98+
99+
Maximized mode
100+
^^^^^^^^^^^^^^
101+
102+
To programmatically maximize the window,
103+
use the ``lv_wayland_window_set_maximized()`` function respectively with ``true``
104+
or ``false`` for the ``maximized`` argument.
105+
106+
107+
Custom timer handler
108+
^^^^^^^^^^^^^^^^^^^^
109+
110+
Always call ``lv_wayland_timer_handler()`` in your timer loop instead of the regular ``lv_timer_handler()``.
111+
112+
**Note:** ``lv_wayland_timer_handler()`` internally calls ``lv_timer_handler()``
113+
114+
This allows the wayland client to work on well on weston, resizing shared memory buffers during
115+
a commit does not work well on weston.
116+
117+
Wrapping the call to ``lv_timer_hander()`` is a necessity to have more control over
118+
when the LVGL flush callback is called.
119+
120+
The custom timer handler returns ``false`` if the frame from previous cycle is not rendered.
121+
When this happens, it usually means that the application is minimized or hidden behind another window.
122+
Causing the driver to wait until the arrival of any message on the wayland socket, the process is in interruptible sleep.
123+
124+
Building the wayland driver
125+
---------------------------
126+
127+
An example simulator is available in this `repo <https://github.com/lvgl/lv_port_linux/>`__
128+
129+
If there is a need to use driver with another build system. The source and header files for the XDG shell
130+
must be generated from the definitions for the XDG shell protocol.
131+
132+
In the example Cmake is used to perform the operation by invoking the ``wayland-scanner`` utility
133+
134+
To achieve this manually,
135+
136+
Make sure the dependencies listed at the start of the article are installed.
137+
138+
The wayland protocol is defined using XML files which are present in ``/usr/share/wayland-protocols``
139+
140+
To generate the required files run the following commands:
141+
142+
.. code-block:: sh
143+
144+
wayland-scanner client-header </usr/share/wayland-protocols/stable/xdg-shell/xdg-shell.xml > wayland_xdg_shell.h
145+
wayland-scanner private-code </usr/share/wayland-protocols/stable/xdg-shell/xdg-shell.xml > wayland_xdg_shell.c
146+
147+
The resulting files can then be integrated into the project, it's better to re-run ``wayland-scanner`` on
148+
each build to ensure that the correct versions are generated, they must match the version of the ``wayland-client``
149+
dynamically linked library installed on the system.
150+
151+
152+
Current state and objectives
153+
----------------------------
154+
155+
* Add direct rendering mode
156+
* Refactor the shell integrations to avoid excessive conditional compilation
157+
* Technically, the wayland driver allows to create multiple windows - but this feature is experimental.
158+
* Eventually add enhanced support for XDG shell to allow the creation of desktop apps on Unix-like platforms,
159+
similar to what the win32 driver does.
160+
* Add a support for Mesa, currently wl_shm is used and it's not the most effective technique.
161+
162+
163+
Bug reports
164+
-----------
165+
166+
The wayland driver is currently under construction, bug reports, contributions and feedback is always welcome.
167+
168+
It is however important to create detailed issues when a problem is encountered, logs and screenshots of the problem are of great help.
169+
170+
Please enable ``LV_USE_LOG`` and launch the simulator executable like so
171+
172+
.. code::
173+
174+
WAYLAND_DEBUG=1 ./path/to/simulator_executable > /tmp/debug 2>&1
175+
176+
This will create a log file called ``debug`` in the ``/tmp`` directory, copy-paste the content of the file in the github issue.
177+
The log file contains LVGL logs and the wayland messages.
178+
179+
Be sure to replicate the problem quickly otherwise the logs become too big
180+

lv_conf_template.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -955,6 +955,13 @@
955955
#define LV_X11_RENDER_MODE_FULL 0 /*Full render mode*/
956956
#endif
957957

958+
/*Use Wayland to open a window and handle input on Linux or BSD desktops */
959+
#define LV_USE_WAYLAND 0
960+
#if LV_USE_WAYLAND
961+
#define LV_WAYLAND_WINDOW_DECORATIONS 0 /*Draw client side window decorations only necessary on Mutter/GNOME*/
962+
#define LV_WAYLAND_WL_SHELL 0 /*Use the legacy wl_shell protocol instead of the default XDG shell*/
963+
#endif
964+
958965
/*Driver for /dev/fb*/
959966
#define LV_USE_LINUX_FBDEV 0
960967
#if LV_USE_LINUX_FBDEV

scripts/install-prerequisites.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,7 @@ sudo apt install gcc gcc-multilib g++-multilib ninja-build \
1111
libpng-dev libjpeg-turbo8-dev libfreetype6-dev \
1212
libglew-dev libglfw3-dev libsdl2-dev libsdl2-image-dev \
1313
libpng-dev:i386 libjpeg-dev:i386 libfreetype6-dev:i386 \
14-
ruby-full gcovr cmake python3 pngquant libinput-dev libxkbcommon-dev libdrm-dev pkg-config
14+
ruby-full gcovr cmake python3 pngquant libinput-dev libxkbcommon-dev \
15+
libdrm-dev pkg-config wayland-protocols libwayland-dev libwayland-bin \
16+
libwayland-dev:i386 libxkbcommon-dev:i386
1517
pip3 install pypng lz4

src/drivers/lv_drivers.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ extern "C" {
4343

4444
#include "qnx/lv_qnx.h"
4545

46+
#include "wayland/lv_wayland.h"
47+
4648
/*********************
4749
* DEFINES
4850
*********************/

0 commit comments

Comments
 (0)