wayland helloworld (二) 之Wayland鼠标消息

Wayland鼠标消息

    Wayland只提供了wl_pointer_listener,要想获取鼠标相关的消息需要首先设置监听器。

    wl_pointer的消息有:

enter 进入窗口范围

leave 离开窗口范围

motion 鼠标移动

button 鼠标点击,鼠标按键id定义位于文件<linux/input.h>中,例如BTN_LEFT表示鼠标左键。


    初始化wl_pointer_listener对象:

void pointer_enter(void *data, HPOINTER wl_pointer, uint32_t serial, HSURFACE surface, wl_fixed_t surface_x, wl_fixed_t surface_y)
{
	wlGetRegistry()->s_pointer_surface = surface;
}

void pointer_leave(void *data, HPOINTER wl_pointer, uint32_t serial, HSURFACE surface)
{
	wlGetRegistry()->s_pointer_surface = NULL;
}

void pointer_motion(void *data, HPOINTER wl_pointer, uint32_t time, wl_fixed_t surface_x, wl_fixed_t surface_y)
{
}

void pointer_button(void *data, HPOINTER wl_pointer, uint32_t serial, uint32_t time, uint32_t button, uint32_t state)
{
	if (wlGetRegistry()->s_pointer_surface == NULL)
		return;

	if (BTN_LEFT == button && state == WL_POINTER_BUTTON_STATE_PRESSED)
	{
		HSHELLSURFACE shell_surface = _wlGetSurfacePrivate(wlGetRegistry()->s_pointer_surface)->shell_surface;
		wl_shell_surface_move(shell_surface, wlGetRegistry()->s_seat, serial);
		return;
	}
}

void pointer_axis(void *data, struct wl_pointer *wl_pointer, uint32_t time, uint32_t axis, wl_fixed_t value)
{
}

struct wl_pointer_listener pointer_listener = 
{
	.enter = pointer_enter,
	.leave = pointer_leave,
	.motion = pointer_motion,
	.button = pointer_button,
	.axis = pointer_axis
};


转载于:https://my.oschina.net/txl/blog/266928

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值