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
};


你可能感兴趣的:(linux,Wayland)