wayland应用程序中touch事件的实现

最近在做有关wayland的相关东西。

wayland是新一代的显示协议,和X11相比有很多优点。wayland协议的具体内容大家可以去wayland官网上查阅。

我在最近的项目中用到了wayland,并在要实现一个wayland窗口,并使这个窗口可以实现接收touch事件。

1、首先我们先要声明一个display的结构,这个结构体里面有wayland窗口显示必要的一些元素。

例:

        struct  w {
struct display *display;
    };

   然后在主函数调用display_create(),返回display结构体。最后调用display_run( );

来生成窗口显示窗口,当然我这里只是说的wayland的方法。

另外,我们们还要有touch事件,

关于wayland的touch事件是这样实现的:

1、我们要声明一个

struct seat {
struct touch *touch;
struct wl_seat *seat;
struct wl_touch *wl_touch;
};

2、我们要写以下几个函数:

touch_handle_down,touch_handle_up,touch_handle_motion,touch_handle_cancel,touch_handle_frame这几种方法。

然后我我们用wl_touch_listener touch_listener来监听这几个回调函数,当事件发生时wayland会回调这些函数。

 3、我们实现一些回调函数

static void  seat_handle_capabilities(void *data, struct wl_seat *wl_seat,enum wl_seat_capability caps)
{
struct seat *seat = data;
struct touch *touch = seat->touch;
if ((caps & WL_SEAT_CAPABILITY_TOUCH) && !seat->wl_touch) {
seat->wl_touch = wl_seat_get_touch(wl_seat);
wl_touch_set_user_data(seat->wl_touch, touch);
wl_touch_add_listener(seat->wl_touch, &touch_listener, touch);
} else if (!(caps & WL_SEAT_CAPABILITY_TOUCH) && seat->wl_touch) {
wl_touch_destroy(seat->wl_touch);
seat->wl_touch = NULL;
}
}

我们来监听 seat_handle_capabilities
static const struct wl_seat_listener seat_listener = {
seat_handle_capabilities,
};

static void  add_seat(struct touch *touch, uint32_t name, uint32_t version)
{
struct seat *seat;
        seat = malloc(sizeof *seat);
assert(seat);
        seat->touch = touch;
seat->wl_touch = NULL;
seat->seat = wl_registry_bind(touch->registry, name, &wl_seat_interface, 1);
wl_seat_add_listener(seat->seat, &seat_listener, seat);
}

最后我们来实现下一个回调:

static void handle_global(void *data, struct wl_registry *registry,uint32_t name, const char *interface, uint32_t version)
{
struct touch *touch = data;
       if (strcmp(interface, "wl_compositor") == 0)

         {
touch->compositor =wl_registry_bind(registry, name,
&wl_compositor_interface, 1);

      if (strcmp(interface, "wl_seat") == 0) {
add_seat(touch, name, version);
}
}

static const struct wl_registry_listener registry_listener = {
handle_global,
};//临听handle_global

最后调用

touch->registry = wl_display_get_registry(touch->display);

wl_registry_add_listener(touch->registry, &registry_listener, touch);

总体说来我们是这样实现一个touch事件的wl_registry_add_listener-》调用handle_global这样我们依次调用下来

当事件发生时就可以接收事件了.具体实现请见weston里的例子!

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值