Wayland入门教程08.10:输入设备管理器

系列索引地址:Wayland入门教程索引

上一篇:Wayland入门教程08.09:第一个窗口

Wayland入门教程08.06:获取全局对象中我们介绍了Wayland全局对象:

  • wl_display:表示与服务器的连接。
  • wl_registry:全局对象注册表,全局对象需要通过它获取。
  • wl_compositor:窗口合成器,也是服务器。
  • wl_shm:内存管理器,与窗口合成器共享内存用。
  • wl_shell:支持窗口操作功能。
  • wl_seat:输入设备管理器。
  • wl_pointer:代表鼠标设备。
  • wl_keyboard:代表键盘设备。

可以看出鼠标、键盘是输入的一种。

本文我们来获取开发平台所支持的设备。

方法和流程和Wayland入门教程08.06:获取全局对象中一样。

关键在于wl_seat_listener的回调函数的写法。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
static void
seat_handle_capabilities(void *data, struct wl_seat *seat,
enum wl_seat_capability caps)
{
if (caps & WL_SEAT_CAPABILITY_POINTER)
{
printf("Display has a pointer\n");
}

if (caps & WL_SEAT_CAPABILITY_KEYBOARD)
{
printf("Display has a keyboard\n");
}

if (caps & WL_SEAT_CAPABILITY_TOUCH)
{
printf("Display has a touch screen\n");
}
}

编译执行输出为:

1
2
3
4
5
hyper@ubuntu:~/Nutstore Files/Nutstore/Wayland_Freshman/10.seat$ ./seat
connected to display
Display has a pointer
Display has a keyboard
disconnected from display

完整代码在Wayland_Freshman08.10.seat中。

下一篇:Wayland入门教程08.11:鼠标操作


Wayland入门教程08.10:输入设备管理器
https://feater.top/wayland/wayland-input-device-manager/
作者
JackeyLea
发布于
2021年9月30日
许可协议