|
| 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 | + |
0 commit comments