系列索引地址:Wayland开发入门教程索引
上一篇:Wayland开发入门教程15:个性化鼠标
在上一篇文章中,我们介绍的鼠标的基本操作,但是会发现已实现的操作只能捕获鼠标的位置和进入离开窗口状态,本文来实现捕获鼠标的点击状态。
先把第9篇的基本窗口的代码拿过来,因为只是实现功能,那么其他的功能没有最好。
在main()函数中,可以发现
1 2 3 4 5 6 7 8 9 10
| shell_surface = wl_shell_get_shell_surface(shell, surface); if (shell_surface == NULL) { fprintf(stderr, "Can't create shell surface\n"); exit(1); }else{ fprintf(stderr, "Created shell surface\n"); } wl_shell_surface_set_toplevel(shell_surface);
|
捕获窗口事件的是surface,原意指表面,延时为窗口。在OpenGL中和纹理Texture是同一种东西,但是纹理可以使用硬件加速。
而surface窗口在shell之下。
将wl_shell_surface_add_listener的注释去掉。当然,要想使用它还得实现其回调函数。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| static void handle_ping(void *data, struct wl_shell_surface *shell_surface, uint32_t serial) { wl_shell_surface_pong(shell_surface, serial); fprintf(stderr, "Pinged and ponged\n"); }
static void handle_configure(void *data, struct wl_shell_surface *shell_surface, uint32_t edges, int32_t width, int32_t height) {}
static void handle_popup_done(void *data, struct wl_shell_surface *shell_surface) {}
struct wl_shell_surface_listener shell_surface_listener = { handle_ping, handle_configure, handle_popup_done };
|
窗口处理包含三个回调函数,不管需不需要都要实现,哪怕是空的。
- ping函数用于发送客户端窗口请求
- configure函数用于处理客户端窗口尺寸变化
- popup_done函数用于处理窗口弹出结束
编译运行
初始状态为

鼠标点击之后

EGL版本只是替换了窗口显示部分,其他的代码一样。
完整代码在Wayland_Freshman中的16.surface
、16.surface_EGL
下。
下一篇:Wayland开发入门教程17:窗口背景