static void drag_grab_focus (MetaWaylandPointerGrab *grab, MetaWaylandSurface *surface) { MetaWaylandDragGrab *drag_grab = (MetaWaylandDragGrab*) grab; MetaWaylandSeat *seat = drag_grab->seat; struct wl_client *client; struct wl_resource *data_device_resource, *offer = NULL; struct wl_display *display; guint32 serial; wl_fixed_t sx, sy; if (drag_grab->drag_focus == surface) return; if (drag_grab->drag_focus_data_device) { wl_data_device_send_leave (drag_grab->drag_focus_data_device); wl_list_remove (&drag_grab->drag_focus_listener.link); drag_grab->drag_focus_data_device = NULL; drag_grab->drag_focus = NULL; } if (!surface) return; if (!drag_grab->drag_data_source && wl_resource_get_client (surface->resource) != drag_grab->drag_client) return; client = wl_resource_get_client (surface->resource); data_device_resource = wl_resource_find_for_client (&seat->data_device.resource_list, client); if (!data_device_resource) return; display = wl_client_get_display (client); serial = wl_display_next_serial (display); if (drag_grab->drag_data_source) offer = meta_wayland_data_source_send_offer (drag_grab->drag_data_source, data_device_resource); meta_wayland_pointer_get_relative_coordinates (grab->pointer, surface, &sx, &sy); wl_data_device_send_enter (data_device_resource, serial, surface->resource, sx, sy, offer); drag_grab->drag_focus = surface; drag_grab->drag_focus_data_device = data_device_resource; drag_grab->drag_focus_listener.notify = destroy_drag_focus; wl_resource_add_destroy_listener (data_device_resource, &drag_grab->drag_focus_listener); }
static void weston_drag_set_focus(struct weston_drag *drag, struct weston_seat *seat, struct weston_view *view, wl_fixed_t sx, wl_fixed_t sy) { struct wl_resource *resource, *offer = NULL; struct wl_display *display = seat->compositor->wl_display; uint32_t serial; if (drag->focus && view && drag->focus->surface == view->surface) { drag->focus = view; return; } if (drag->focus_resource) { wl_data_device_send_leave(drag->focus_resource); wl_list_remove(&drag->focus_listener.link); drag->focus_resource = NULL; drag->focus = NULL; } if (!view || !view->surface->resource) return; if (!drag->data_source && wl_resource_get_client(view->surface->resource) != drag->client) return; resource = wl_resource_find_for_client(&seat->drag_resource_list, wl_resource_get_client(view->surface->resource)); if (!resource) return; serial = wl_display_next_serial(display); if (drag->data_source) { offer = weston_data_source_send_offer(drag->data_source, resource); if (offer == NULL) return; } wl_data_device_send_enter(resource, serial, view->surface->resource, sx, sy, offer); drag->focus = view; drag->focus_listener.notify = destroy_drag_focus; wl_resource_add_destroy_listener(resource, &drag->focus_listener); drag->focus_resource = resource; }
static void drag_grab_focus(struct wl_pointer_grab *grab, struct wl_surface *surface, wl_fixed_t x, wl_fixed_t y) { struct wl_seat *seat = container_of(grab, struct wl_seat, drag_grab); struct wl_resource *resource, *offer = NULL; struct wl_display *display; uint32_t serial; if (seat->drag_focus_resource) { wl_data_device_send_leave(seat->drag_focus_resource); wl_list_remove(&seat->drag_focus_listener.link); seat->drag_focus_resource = NULL; seat->drag_focus = NULL; } if (!surface) return; if (!seat->drag_data_source && surface->resource.client != seat->drag_client) return; resource = find_resource(&seat->drag_resource_list, surface->resource.client); if (!resource) return; display = wl_client_get_display(resource->client); serial = wl_display_next_serial(display); if (seat->drag_data_source) offer = wl_data_source_send_offer(seat->drag_data_source, resource); wl_data_device_send_enter(resource, serial, &surface->resource, x, y, offer); seat->drag_focus = surface; seat->drag_focus_listener.notify = destroy_drag_focus; wl_signal_add(&resource->destroy_signal, &seat->drag_focus_listener); seat->drag_focus_resource = resource; grab->focus = surface; }