X11 Display/Inputs driver(X11显示/输入驱动程序)

Overview(概览)

显示原文
The X11 display/input driver offers support for simulating the LVGL display and keyboard/mouse inputs in an X11 desktop window.
It is an alternative to Wayland, XCB, SDL or Qt.

The main purpose for this driver is for testing/debugging the LVGL application in a Linux simulation window.


X11 显示/输入 driver 程序提供对在X11桌面窗口中模拟LVGL显示和键盘/鼠标输入的支持。它是 Wayland、XCB、SDL或Qt 的备选方案。

该驱动程序的主要目的是在 Linux 模拟窗口中进行LVGL应用程序的测试和调试。

Prerequisites(先决条件)

显示原文

The X11 driver uses XLib to access the linux window manager.

  1. Install XLib: sudo apt-get install libx11-6 (should be installed already)

  2. Install XLib development package: sudo apt-get install libx11-dev


X11驱动程序使用XLib来访问Linux窗口管理器。

  1. 安装XLib: sudo apt-get install libx11-6 (应该已经安装)

  2. 安装XLib开发包: sudo apt-get install libx11-dev

Configure X11 driver(配置X11驱动程序)

显示原文
  1. Enable the X11 driver support in lv_conf.h, by cmake compiler define or by KConfig
    #define LV_USE_X11  1
    
  2. Optional configuration options:
    • Direct Exit
      #define LV_X11_DIRECT_EXIT  1 /* preferred default - ends the application automatically if last window has been closed */
      // or
      #define LV_X11_DIRECT_EXIT  0 /* application is responsible for ending the application (e.g. by own LV_EVENT_DELETE handler */
      
    • Double buffering
      #define LV_X11_DOUBLE_BUFFER  1 /* preferred default */
      // or
      #define LV_X11_DOUBLE_BUFFER  0 /* not recommended */
      
    • Render mode
      #define LV_X11_RENDER_MODE_PARTIAL 1  /* LV_DISPLAY_RENDER_MODE_PARTIAL, preferred default */
      // or
      #define LV_X11_RENDER_MODE_DIRECT  1  /* LV_DISPLAY_RENDER_MODE_DIRECT, not recommended for X11 driver */
      // or
      #define LV_X11_RENDER_MODE_DULL    1  /* LV_DISPLAY_RENDER_MODE_FULL, not recommended for X11 driver */
      

  1. lv_conf.h 中启用 X11 驱动支持,可以通过 CMake 编译器定义或 KConfig 配置实现:

#define LV_USE_X11  1
  1. 可选配置选项:

  • 直接退出

#define LV_X11_DIRECT_EXIT  1 /* 推荐默认设置 - 如果最后一个窗口被关闭,应用程序自动结束 */
// 或
#define LV_X11_DIRECT_EXIT  0 /* 应用程序负责结束,例如通过自定义 LV_EVENT_DELETE 事件处理程序 */
  • 双缓冲

#define LV_X11_DOUBLE_BUFFER  1 /* 推荐默认设置 */
// 或
#define LV_X11_DOUBLE_BUFFER  0 /* 不推荐 */
  • 渲染模式

#define LV_X11_RENDER_MODE_PARTIAL 1  /* LV_DISPLAY_RENDER_MODE_PARTIAL,推荐默认设置 */
// 或
#define LV_X11_RENDER_MODE_DIRECT  1  /* LV_DISPLAY_RENDER_MODE_DIRECT,不推荐用于 X11 驱动 */
// 或
#define LV_X11_RENDER_MODE_DULL    1  /* LV_DISPLAY_RENDER_MODE_FULL,不推荐用于 X11 驱动 */

Usage(用法)

显示原文
The minimal initialisation opening a window and enabling keyboard/mouse support
(e.g. in main.c, LV_X11_DIRECT_EXIT must be 1):
int main(int argc, char ** argv)
{
    ...

    /* initialize X11 display driver */
    lv_display_t * disp = lv_x11_window_create("LVGL X11 Simulation", monitor_hor_res, monitor_ver_res);

    /* initialize X11 input drivers (for keyboard, mouse & mousewheel) */
    lv_x11_inputs_create(disp, NULL);

    ...

    while(true)
    {
        ...

        /* Periodically call the lv_timer handler */
        lv_timer_handler();
    }
}
Full initialisation with mouse pointer symbol and own application exit handling
(dependent on LV_X11_DIRECT_EXIT (can be 1 or 0))
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 */
    lv_display_t * disp = lv_x11_window_create("LVGL X11 Simulation", monitor_hor_res, monitor_ver_res);
    lv_display_add_event_cb(disp, on_close_cb, LV_EVENT_DELETE, disp);

    /* initialize X11 input drivers (for keyboard, mouse & mousewheel) */
    LV_IMAGE_DECLARE(my_mouse_cursor_icon);
    lv_x11_inputs_create(disp, &my_mouse_cursor_icon);

    #if !LV_X11_DIRECT_EXIT
    /* set optional window close callback to enable application cleanup and exit */
    lv_x11_window_set_close_cb(disp, on_close_cb, disp);
    #endif

    ...

    while(!terminated)
    {
        ...

        /* Periodically call the lv_timer handler */
        lv_timer_handler();
    }
}

最小化的初始化,打开一个窗口并启用键盘/鼠标支持(例如,在main.c中,LV_X11_DIRECT_EXIT必须为1):

int main(int argc, char ** argv)
{
    ...

    /* initialize X11 display driver */
    lv_display_t * disp = lv_x11_window_create("LVGL X11 Simulation", monitor_hor_res, monitor_ver_res);

    /* initialize X11 input drivers (for keyboard, mouse & mousewheel) */
    lv_x11_inputs_create(disp, NULL);

    ...

    while(true)
    {
        ...

        /* Periodically call the lv_task handler */
        lv_task_handler();
    }
}

完整的初始化,带有鼠标指针符号和自定义应用程序退出处理(取决于LV_X11_DIRECT_EXIT(可以为1或0)):

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 */
    lv_display_t * disp = lv_x11_window_create("LVGL X11 Simulation", monitor_hor_res, monitor_ver_res);
    lv_display_add_event_cb(disp, on_close_cb, LV_EVENT_DELETE, disp);

    /* initialize X11 input drivers (for keyboard, mouse & mousewheel) */
    LV_IMG_DECLARE(my_mouse_cursor_icon);
    lv_x11_inputs_create(disp, &my_mouse_cursor_icon);

    #if !LV_X11_DIRECT_EXIT
    /* set optional window close callback to enable application cleanup and exit */
    lv_x11_window_set_close_cb(disp, on_close_cb, disp);
    #endif

    ...

    while(!terminated)
    {
        ...

        /* Periodically call the lv_task handler */
        lv_task_handler();
    }
}