2023-11-18 08:46:43 +01:00
=========================
X11 Display/Inputs driver
=========================
2023-11-15 14:08:03 +01:00
Overview
2024-05-11 18:17:15 +02:00
--------
2023-11-15 14:08:03 +01:00
2024-01-18 14:29:39 +01:00
| The **X11** display/input `driver <https://github.com/lvgl/lvgl/src/drivers/x11> `__ offers support for simulating the LVGL display and keyboard/mouse inputs in an X11 desktop window.
2023-11-18 08:46:43 +01:00
| It is an alternative to **Wayland** , **XCB** , **SDL** or **Qt** .
2023-11-15 14:08:03 +01:00
2023-11-18 08:46:43 +01:00
The main purpose for this driver is for testing/debugging the LVGL application in a **Linux** simulation window.
2023-11-15 14:08:03 +01:00
Prerequisites
-------------
2023-11-18 08:46:43 +01:00
The X11 driver uses XLib to access the linux window manager.
2023-11-15 14:08:03 +01:00
1. Install XLib: `` sudo apt-get install libx11-6 `` (should be installed already)
2. Install XLib development package: `` sudo apt-get install libx11-dev ``
2023-11-18 08:46:43 +01:00
Configure X11 driver
--------------------
2023-11-15 14:08:03 +01:00
2023-11-18 08:46:43 +01:00
1. Enable the X11 driver support in lv_conf.h, by cmake compiler define or by KConfig
2024-09-30 06:57:22 -06:00
.. code-block :: c
2023-11-15 14:08:03 +01:00
#define LV_USE_X11 1
2. Optional configuration options:
- Direct Exit
2024-09-30 06:57:22 -06:00
.. code-block :: c
2023-11-15 14:08:03 +01:00
2024-10-23 12:53:33 -06:00
#define LV_X11_DIRECT_EXIT 1 /* preferred default - ends the application automatically if last window has been closed * /
2023-11-15 14:08:03 +01:00
// or
2024-10-23 12:53:33 -06:00
#define LV_X11_DIRECT_EXIT 0 /* application is responsible for ending the application (e.g. by own LV_EVENT_DELETE handler * /
2023-11-15 14:08:03 +01:00
- Double buffering
2024-09-30 06:57:22 -06:00
.. code-block :: c
2023-11-15 14:08:03 +01:00
2024-10-23 12:53:33 -06:00
#define LV_X11_DOUBLE_BUFFER 1 /* preferred default * /
2023-11-15 14:08:03 +01:00
// or
2024-10-23 12:53:33 -06:00
#define LV_X11_DOUBLE_BUFFER 0 /* not recommended * /
2023-11-15 14:08:03 +01:00
- Render mode
2024-09-30 06:57:22 -06:00
.. code-block :: c
2023-11-15 14:08:03 +01:00
2024-10-23 12:53:33 -06:00
#define LV_X11_RENDER_MODE_PARTIAL 1 /* LV_DISPLAY_RENDER_MODE_PARTIAL, preferred default * /
2023-11-15 14:08:03 +01:00
// or
2024-10-23 12:53:33 -06:00
#define LV_X11_RENDER_MODE_DIRECT 1 /* LV_DISPLAY_RENDER_MODE_DIRECT, not recommended for X11 driver * /
2023-11-15 14:08:03 +01:00
// or
2024-10-23 12:53:33 -06:00
#define LV_X11_RENDER_MODE_DULL 1 /* LV_DISPLAY_RENDER_MODE_FULL, not recommended for X11 driver * /
2023-11-15 14:08:03 +01:00
Usage
-----
2023-11-18 08:46:43 +01:00
| The minimal initialisation opening a window and enabling keyboard/mouse support
| (e.g. in main.c, LV_X11_DIRECT_EXIT must be 1):
2023-11-15 14:08:03 +01:00
2024-09-30 06:57:22 -06:00
.. code-block :: c
2023-11-15 14:08:03 +01:00
int main(int argc, char ** argv)
{
...
/* initialize X11 display driver * /
2024-01-25 18:38:26 +01:00
lv_display_t * disp = lv_x11_window_create("LVGL X11 Simulation", monitor_hor_res, monitor_ver_res);
2023-11-15 14:08:03 +01:00
/* initialize X11 input drivers (for keyboard, mouse & mousewheel) * /
lv_x11_inputs_create(disp, NULL);
...
while(true)
{
...
2024-04-10 15:17:44 +08:00
/* Periodically call the lv_timer handler * /
lv_timer_handler();
2023-11-15 14:08:03 +01:00
}
}
2023-11-18 08:46:43 +01:00
| Full initialisation with mouse pointer symbol and own application exit handling
| (dependent on LV_X11_DIRECT_EXIT (can be 1 or 0))
2023-11-15 14:08:03 +01:00
2024-09-30 06:57:22 -06:00
.. code-block :: c
2023-11-15 14:08:03 +01:00
bool terminated = false;
#if !LV_X11_DIRECT_EXIT
static void on_close_cb(lv_event_t * e)
{
...
terminate = true;
}
#endif
int main(int argc, char ** argv)
{
...
/* initialize X11 display driver * /
2024-01-25 18:38:26 +01:00
lv_display_t * disp = lv_x11_window_create("LVGL X11 Simulation", monitor_hor_res, monitor_ver_res);
2023-11-28 15:36:51 +01:00
lv_display_add_event_cb(disp, on_close_cb, LV_EVENT_DELETE, disp);
2023-11-15 14:08:03 +01:00
/* initialize X11 input drivers (for keyboard, mouse & mousewheel) * /
2024-04-10 15:17:44 +08:00
LV_IMAGE_DECLARE(my_mouse_cursor_icon);
2023-11-15 14:08:03 +01:00
lv_x11_inputs_create(disp, &my_mouse_cursor_icon);
#if !LV_X11_DIRECT_EXIT
2023-11-27 03:41:09 +08:00
/* set optional window close callback to enable application cleanup and exit * /
2023-11-15 14:08:03 +01:00
lv_x11_window_set_close_cb(disp, on_close_cb, disp);
#endif
...
while(!terminated)
{
...
2024-04-10 15:17:44 +08:00
/* Periodically call the lv_timer handler * /
lv_timer_handler();
2023-11-15 14:08:03 +01:00
}
}