# Wayland display and input driver
Wayland display and input driver, with support for keyboard, pointer (i.e. mouse) and touchscreen.
Keyboard support is based on libxkbcommon.
Following shell are supported:
* wl_shell (deprecated)
* xdg_shell
> xdg_shell requires an extra build step; see section _Generate protocols_ below.
Basic client-side window decorations (simple title bar, minimize and close buttons)
are supported, while integration with desktop environments is not.
## Install headers and libraries
### Ubuntu
```
sudo apt-get install libwayland-dev libxkbcommon-dev libwayland-bin wayland-protocols
```
### Fedora
```
sudo dnf install wayland-devel libxkbcommon-devel wayland-utils wayland-protocols-devel
```
## Generate protocols
Support for non-basic shells (i.e. other than _wl_shell_) requires additional
source files to be generated before the first build of the project. To do so,
navigate to the _wayland_ folder (the one which includes this file) and issue
the following commands:
```
cmake .
make
```
## Build configuration under Eclipse
In "Project properties > C/C++ Build > Settings" set the followings:
- "Cross GCC Compiler > Command line pattern"
- Add ` ${wayland-cflags}` and ` ${xkbcommon-cflags}` to the end (add a space between the last command and this)
- "Cross GCC Linker > Command line pattern"
- Add ` ${wayland-libs}` and ` ${xkbcommon-libs}` to the end (add a space between the last command and this)
- In "C/C++ Build > Build variables"
- Configuration: [All Configuration]
- Add
- Variable name: `wayland-cflags`
- Type: `String`
- Value: `pkg-config --cflags wayland-client`
- Variable name: `wayland-libs`
- Type: `String`
- Value: `pkg-config --libs wayland-client`
- Variable name: `xkbcommon-cflags`
- Type: `String`
- Value: `pkg-config --cflags xkbcommon`
- Variable name: `xkbcommon-libs`
- Type: `String`
- Value: `pkg-config --libs xkbcommon`
## Init Wayland in LVGL
1. In `main.c` `#incude "lv_drivers/wayland/wayland.h"`
2. Enable the Wayland driver in `lv_drv_conf.h` with `USE_WAYLAND 1` and
configure its features below, enabling at least support for one shell.
3. `LV_COLOR_DEPTH` should be set either to `32` or `16` in `lv_conf.h`;
support for `8` and `1` depends on target platform.
4. After `lv_init()` call `lv_wayland_init()`.
5. Add a display (or more than one) using `lv_wayland_create_window()`,
possibly with a close callback to track the status of each display:
```c
#define H_RES (800)
#define V_RES (480)
/* Create a display */
lv_disp_t * disp = lv_wayland_create_window(H_RES, V_RES, "Window Title", close_cb);
```
As part of the above call, the Wayland driver will register four input devices
for each display:
- a KEYPAD connected to Wayland keyboard events
- a POINTER connected to Wayland touch events
- a POINTER connected to Wayland pointer events
- a ENCODER connected to Wayland pointer axis events
Handles for input devices of each display can be get using respectively
`lv_wayland_get_indev_keyboard()`, `lv_wayland_get_indev_touchscreen()`,
`lv_wayland_get_indev_pointer()` and `lv_wayland_get_indev_pointeraxis()`, using
`disp` as argument.
5. After `lv_deinit()` (if used), or in any case during de-initialization, call
`lv_wayland_deinit()`.
### Fullscreen mode
In order to set one window as fullscreen or restore it as a normal one,
call the `lv_wayland_window_set_fullscreen()` function respectively with `true`
or `false` as `fullscreen` argument.
### Disable window client-side decoration at runtime
Even when client-side decorations are enabled at compile time, they can be
disabled at runtime setting the `LV_WAYLAND_DISABLE_WINDOWDECORATION`
environment variable to `1`.
### Event-driven timer handler
Set `LV_WAYLAND_TIMER_HANDLER` in `lv_drv_conf.h` and call `lv_wayland_timer_handler()`
in your timer loop (in place of `lv_timer_handler()`).
You can now sleep/wait until the next timer/event is ready, e.g.:
```
/* [After initialization and display creation] */
#include <limits.h>
#include <errno.h>
#include <poll.h>
struct pollfd pfd;
uint32_t time_till_next;
int sleep;
pfd.fd = lv_wayland_get_fd();
pfd.events = POLLIN;
while (1) {
/* Handle any Wayland/LVGL timers/events */
time_till_next = lv_wayland_timer_handler();
/* Run until the last window closes */
if (!lv_wayland_window_is_open(NULL)) {
break;
}
/* Wait for something interesting to happen */
if (time_till_next == LV_NO_TIMER_READY) {
sleep = -1;
} else if (time_till_next > INT_MAX) {
sleep = INT_MAX;
} else {
sleep = time_till_next;
}
while ((poll(&pfd, 1, sleep) < 0) && (errno == EINTR));
}
```
lvgl-小项目源码-通过按钮切换窗口的设计
需积分: 0 129 浏览量
更新于2025-06-12
收藏 3.42MB ZIP 举报
lvgl作为一款开源的嵌入式图形库,已经在嵌入式软件开发领域内广泛应用。该图形库以轻量级,可配置性强,占用资源少而著称,非常适合于资源有限的单片机系统。在进行嵌入式软件开发时,lvgl的掌握已经成为很多开发者必走的学习路线之一,尤其在设计用户界面时,lvgl可以提供丰富的控件和功能,让开发者能够方便快捷地设计出美观实用的界面。
在本次分享的小项目源码中,我们将深入探讨如何利用lvgl实现一个通过按钮切换窗口的功能。这个功能在很多具有多窗口显示需求的应用中十分常见,比如一些嵌入式设备中可能会用到的仪表盘,车载娱乐系统等。通过按钮切换窗口的设计不仅能够使得人机交互更加友好,同时也能在有限的显示面积上展示更多的信息内容。
项目源码的核心内容主要包含以下几个方面:
项目中会涉及到lvgl库的基本使用,包括如何初始化lvgl,创建基本的控件以及如何组织这些控件形成窗口。用户界面的构建通常从一个主窗口开始,然后根据需要创建其他的子窗口。每一个窗口都可以视为一个独立的lvgl对象,这些对象在lvgl内部是通过各种数据结构组织起来的。
项目中会详细展示如何通过按钮控件响应用户操作,从而触发窗口切换的逻辑。在lvgl中,按钮是最基本的交互控件之一,可以绑定回调函数来实现特定的功能。当按钮被用户按下时,系统会调用事先定义好的回调函数来响应这一操作。在本项目中,按钮的回调函数会涉及到对当前窗口状态的检查以及窗口切换的处理。
接着,项目中还会涉及到窗口的显示与隐藏逻辑。lvgl提供了非常灵活的方式来控制窗口的显示状态。开发者可以通过设置窗口的可见性属性来决定是否将窗口渲染到屏幕上。隐藏窗口通常是为了节省宝贵的屏幕资源,或者是为了在切换到其他窗口之前清除当前窗口的内容。
项目还将介绍如何在不同的窗口之间传递数据和信息。例如,在一个窗口中收集了用户输入的信息后,如何将这些信息展示到另一个窗口,或者如何将一个窗口中的处理结果反馈到主窗口。lvgl提供了一定的机制来支持这种跨窗口的数据交互,但开发者往往需要根据自己的应用需求进行相应的封装和实现。
通过本项目的学习,开发者不仅能够掌握通过按钮切换窗口的基本技能,还能够加深对lvgl图形库的理解和使用,为以后开发更加复杂的应用打下坚实的基础。

不上500不改名272
- 粉丝: 71
最新资源
- 网络安全(PPT36页)(1).ppt
- 论借助sniffer诊断Linux网络故障.docx
- 商务英语教学中网络的地位.doc
- 在市打击治理电信网络新型违法犯罪联席会议上表态发言三篇.doc
- 2023年大学计算机基础期末考试知识点.doc
- 系统安全预测技术.pptx
- 企业信息化建设的重要性和状况.docx
- 遥感数字图像处理考题整理.doc
- 高校师生同上一堂网络安全课观后感心得感悟5篇.docx
- 企业集团财务结算中心与计算机系统设计与会计操作.doc
- 电话网络系统方案.doc
- 九上下册物理第三节:广播-电视和移动通信公开课教案教学设计课件测试卷练习卷课时同步训练练习公开课教案.ppt
- 图像处理:十一表示描述.ppt
- 什么网站工作总结写的比较好.docx
- 项目管理与招标采购培训重点课程.doc
- 有关信息化银行对账问题的探讨【会计实务操作教程】.pptx