Wayland入门14:窗口操作

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

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

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

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);
//wl_shell_suface_add_listener(shell_surface,&shell_surface_listener,NULL);

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

而surface窗口在shell之下。

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

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函数用于处理窗口弹出结束

编译运行

初始状态为

default

鼠标点击之后

clicked

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

完整代码在Wayland_Frashman中的14.surface、14.surface_EGL下

本文首发于:Wayland入门14:窗口操作

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

幽迷狂

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值