Wayland入门教程08.13:窗口操作

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

上一篇:Wayland入门教程08.12:个性化鼠标

在上一篇文章中,我们介绍的鼠标的基本操作,但是会发现已实现的操作只能捕获鼠标的位置和进入离开窗口状态,本文来实现捕获鼠标的点击状态。

先把第9篇的基本窗口的代码拿过来,因为只是实现功能,那么其他的功能没有最好。

在main()函数中,可以发现

1
2
3
4
5
6
7
8
9
10
11
12
13
shell_surface = xdg_wm_base_get_xdg_surface(xdg_shell, surface);
if (shell_surface == NULL)
{
fprintf(stderr, "Can't create shell surface\n");
exit(1);
}
else
{
fprintf(stderr, "Created shell surface\n");
}
// 窗口处理
toplevel = xdg_surface_get_toplevel(shell_surface);
xdg_surface_add_listener(shell_surface, &surface_listener, NULL);

捕获窗口事件的是surface,原意指表面,延时为窗口。在OpenGL中和纹理Texture是同一种东西,但是纹理可以使用硬件加速。

而surface窗口在shell之下。

将xdg_surface_add_listener的注释去掉。当然,要想使用它还得实现其回调函数。

1
2
3
4
5
6
7
static void handle_configure(void *data, struct xdg_surface *surface, uint32_t serial)
{
xdg_surface_ack_configure(surface, serial);
}

static const struct xdg_surface_listener surface_listener = {
.configure = handle_configure};

窗口处理包含一个回调函数,不管需不需要都要实现,哪怕是空的。

  • ping函数用于发送客户端窗口请求

编译运行

初始状态为

default

鼠标点击之后

clicked

EGL版本只是替换了窗口显示部分,其他的代码一样。

完整代码在Wayland_Freshman中的08.13.surface下。

下一篇:Wayland开发入门教程08.14:窗口背景


Wayland入门教程08.13:窗口操作
https://feater.top/wayland/wayland-input-shell-surface/
作者
JackeyLea
发布于
2021年11月6日
许可协议