compositor: Handle disappearing surfaces and input devices for touch
This commit is contained in:
+56
-14
@@ -1454,6 +1454,28 @@ find_resource_for_surface(struct wl_list *list, struct wl_surface *surface)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
lose_touch_focus_resource(struct wl_listener *listener,
|
||||||
|
struct wl_resource *resource, uint32_t time)
|
||||||
|
{
|
||||||
|
struct wlsc_input_device *device =
|
||||||
|
container_of(listener, struct wlsc_input_device,
|
||||||
|
touch_focus_resource_listener);
|
||||||
|
|
||||||
|
device->touch_focus_resource = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
lose_touch_focus(struct wl_listener *listener,
|
||||||
|
struct wl_resource *resource, uint32_t time)
|
||||||
|
{
|
||||||
|
struct wlsc_input_device *device =
|
||||||
|
container_of(listener, struct wlsc_input_device,
|
||||||
|
touch_focus_listener);
|
||||||
|
|
||||||
|
device->touch_focus = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
touch_set_focus(struct wlsc_input_device *device,
|
touch_set_focus(struct wlsc_input_device *device,
|
||||||
struct wl_surface *surface, uint32_t time)
|
struct wl_surface *surface, uint32_t time)
|
||||||
@@ -1464,15 +1486,33 @@ touch_set_focus(struct wlsc_input_device *device,
|
|||||||
if (device->touch_focus == surface)
|
if (device->touch_focus == surface)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
resource = find_resource_for_surface(&input_device->resource_list,
|
if (surface) {
|
||||||
surface);
|
resource =
|
||||||
if (!resource) {
|
find_resource_for_surface(&input_device->resource_list,
|
||||||
fprintf(stderr, "couldn't find resource\n");
|
surface);
|
||||||
return;
|
if (!resource) {
|
||||||
}
|
fprintf(stderr, "couldn't find resource\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
device->touch_focus = surface;
|
device->touch_focus_resource_listener.func =
|
||||||
device->touch_focus_resource = resource;
|
lose_touch_focus_resource;
|
||||||
|
wl_list_insert(resource->destroy_listener_list.prev,
|
||||||
|
&device->touch_focus_resource_listener.link);
|
||||||
|
device->touch_focus_listener.func = lose_touch_focus;
|
||||||
|
wl_list_insert(surface->resource.destroy_listener_list.prev,
|
||||||
|
&device->touch_focus_listener.link);
|
||||||
|
|
||||||
|
device->touch_focus = surface;
|
||||||
|
device->touch_focus_resource = resource;
|
||||||
|
} else {
|
||||||
|
if (device->touch_focus)
|
||||||
|
wl_list_remove(&device->touch_focus_listener.link);
|
||||||
|
if (device->touch_focus_resource)
|
||||||
|
wl_list_remove(&device->touch_focus_resource_listener.link);
|
||||||
|
device->touch_focus = NULL;
|
||||||
|
device->touch_focus_resource = NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1504,11 +1544,12 @@ notify_touch(struct wl_input_device *device, uint32_t time, int touch_id,
|
|||||||
if (wd->num_tp == 1) {
|
if (wd->num_tp == 1) {
|
||||||
es = wlsc_compositor_pick_surface(ec, x, y, &sx, &sy);
|
es = wlsc_compositor_pick_surface(ec, x, y, &sx, &sy);
|
||||||
touch_set_focus(wd, &es->surface, time);
|
touch_set_focus(wd, &es->surface, time);
|
||||||
} else {
|
} else if (wd->touch_focus) {
|
||||||
es = (struct wlsc_surface *) wd->touch_focus;
|
es = (struct wlsc_surface *) wd->touch_focus;
|
||||||
wlsc_surface_transform(es, x, y, &sx, &sy);
|
wlsc_surface_transform(es, x, y, &sx, &sy);
|
||||||
}
|
}
|
||||||
if (wd->touch_focus_resource)
|
|
||||||
|
if (wd->touch_focus_resource && wd->touch_focus)
|
||||||
wl_resource_post_event(wd->touch_focus_resource,
|
wl_resource_post_event(wd->touch_focus_resource,
|
||||||
touch_type, time,
|
touch_type, time,
|
||||||
wd->touch_focus,
|
wd->touch_focus,
|
||||||
@@ -1516,6 +1557,9 @@ notify_touch(struct wl_input_device *device, uint32_t time, int touch_id,
|
|||||||
break;
|
break;
|
||||||
case WL_INPUT_DEVICE_TOUCH_MOTION:
|
case WL_INPUT_DEVICE_TOUCH_MOTION:
|
||||||
es = (struct wlsc_surface *) wd->touch_focus;
|
es = (struct wlsc_surface *) wd->touch_focus;
|
||||||
|
if (!es)
|
||||||
|
break;
|
||||||
|
|
||||||
wlsc_surface_transform(es, x, y, &sx, &sy);
|
wlsc_surface_transform(es, x, y, &sx, &sy);
|
||||||
if (wd->touch_focus_resource)
|
if (wd->touch_focus_resource)
|
||||||
wl_resource_post_event(wd->touch_focus_resource,
|
wl_resource_post_event(wd->touch_focus_resource,
|
||||||
@@ -1529,10 +1573,8 @@ notify_touch(struct wl_input_device *device, uint32_t time, int touch_id,
|
|||||||
if (wd->touch_focus_resource)
|
if (wd->touch_focus_resource)
|
||||||
wl_resource_post_event(wd->touch_focus_resource,
|
wl_resource_post_event(wd->touch_focus_resource,
|
||||||
touch_type, time, touch_id);
|
touch_type, time, touch_id);
|
||||||
if (wd->num_tp == 0) {
|
if (wd->num_tp == 0)
|
||||||
wd->touch_focus = NULL;
|
touch_set_focus(wd, NULL, time);
|
||||||
wd->touch_focus_resource = NULL;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -117,7 +117,9 @@ struct wlsc_input_device {
|
|||||||
|
|
||||||
uint32_t num_tp;
|
uint32_t num_tp;
|
||||||
struct wl_surface *touch_focus;
|
struct wl_surface *touch_focus;
|
||||||
|
struct wl_listener touch_focus_listener;
|
||||||
struct wl_resource *touch_focus_resource;
|
struct wl_resource *touch_focus_resource;
|
||||||
|
struct wl_listener touch_focus_resource_listener;
|
||||||
};
|
};
|
||||||
|
|
||||||
enum wlsc_visual {
|
enum wlsc_visual {
|
||||||
|
|||||||
Reference in New Issue
Block a user