static void get_data_device(struct wl_client * client, struct wl_resource * resource, uint32_t id, struct wl_resource * seat_resource) { data_device_bind(swc.seat->data_device, client, wl_resource_get_version(resource), id); }
static void create_prime_buffer(struct wl_client * client, struct wl_resource * resource, uint32_t id, int32_t fd, int32_t width, int32_t height, uint32_t format, int32_t offset0, int32_t stride0, int32_t offset1, int32_t stride1, int32_t offset2, int32_t stride2) { struct wld_buffer * buffer; struct wl_resource * buffer_resource; union wld_object object = { .i = fd }; buffer = wld_import_buffer(swc.drm->context, WLD_DRM_OBJECT_PRIME_FD, object, width, height, format, stride0); close(fd); if (!buffer) goto error0; buffer_resource = swc_wayland_buffer_create_resource (client, wl_resource_get_version(resource), id, buffer); if (!buffer_resource) goto error1; return; error1: wld_buffer_unreference(buffer); error0: wl_resource_post_no_memory(resource); }
static void wp_viewporter_get_viewport (struct wl_client *client, struct wl_resource *resource, uint32_t viewport_id, struct wl_resource *surface_resource) { MetaWaylandSurface *surface; struct wl_resource *viewport_resource; surface = wl_resource_get_user_data (surface_resource); if (surface->viewport.resource) { wl_resource_post_error (resource, WP_VIEWPORTER_ERROR_VIEWPORT_EXISTS, "viewport already exists on surface"); return; } viewport_resource = wl_resource_create (client, &wp_viewport_interface, wl_resource_get_version (resource), viewport_id); wl_resource_set_implementation (viewport_resource, &meta_wayland_viewport_interface, surface, wp_viewport_destructor); surface->viewport.resource = viewport_resource; surface->viewport.destroy_handler_id = g_signal_connect (surface, "destroy", G_CALLBACK (on_surface_destroyed), NULL); }
/// Wayland protocol: Create new region. /// @see wayland-region.h void noia_wayland_create_region(struct wl_client* client, struct wl_resource* resource, uint32_t id) { NoiaItemId new_rid = noia_wayland_facade_create_region(); int32_t version = wl_resource_get_version(resource); noia_wayland_region_bind(client, (void*) new_rid, version, id); }
/// Wayland protocol: create new surface. void noia_wayland_create_surface(struct wl_client* client, struct wl_resource* resource, uint32_t id) { NoiaSurfaceId new_sid = noia_wayland_facade_create_surface(); int32_t version = wl_resource_get_version(resource); noia_wayland_surface_bind(client, (void*) new_sid, version, id); }
void SurfaceExtensionGlobal::surface_extension_get_extended_surface(Resource *resource, uint32_t id, struct wl_resource *surface_resource) { QWaylandSurface *surface = QWaylandSurface::fromResource(surface_resource); ExtendedSurface *extSurface = new ExtendedSurface(resource->client(),id, wl_resource_get_version(resource->handle), surface); emit extendedSurfaceReady(extSurface, surface); }
static void create_panel(struct wl_client * client, struct wl_resource * resource, uint32_t id, struct wl_resource * surface_resource) { struct swc_surface * surface = wl_resource_get_user_data(surface_resource); if (!panel_new(client, wl_resource_get_version(resource), id, surface)) wl_client_post_no_memory(client); }
static void create_data_source(struct wl_client * client, struct wl_resource * resource, uint32_t id) { struct wl_resource * data_source; data_source = data_source_new(client, wl_resource_get_version(resource), id); if (!data_source) wl_resource_post_no_memory(resource); }
void CompositorInterface::Private::createRegion(wl_client *client, wl_resource *resource, uint32_t id) { RegionInterface *region = new RegionInterface(q, resource); region->create(display->getConnection(client), wl_resource_get_version(resource), id); if (!region->resource()) { wl_resource_post_no_memory(resource); delete region; return; } emit q->regionCreated(region); }
void CompositorInterface::Private::createSurface(wl_client *client, wl_resource *resource, uint32_t id) { SurfaceInterface *surface = new SurfaceInterface(q, resource); surface->create(display->getConnection(client), wl_resource_get_version(resource), id); if (!surface->resource()) { wl_resource_post_no_memory(resource); delete surface; return; } emit q->surfaceCreated(surface); }
static void create_data_source (struct wl_client *client, struct wl_resource *resource, guint32 id) { MetaWaylandDataSource *source = g_slice_new0 (MetaWaylandDataSource); source->resource = wl_resource_create (client, &wl_data_source_interface, wl_resource_get_version (resource), id); wl_resource_set_implementation (source->resource, &data_source_interface, source, destroy_data_source); wl_array_init (&source->mime_types); }
static void get_xdg_surface(struct wl_client *client, struct wl_resource *resource, uint32_t id, struct wl_resource *surface_resource) { struct surface *surface = wl_resource_get_user_data(surface_resource); struct xdg_surface *xdg_surface; xdg_surface = xdg_surface_new(client, wl_resource_get_version(resource), id, surface); if (!xdg_surface) wl_resource_post_no_memory(resource); }
static void wl_compositor_create_region (struct wl_client *client, struct wl_resource *compositor_resource, uint32_t id) { MetaWaylandRegion *region = g_slice_new0 (MetaWaylandRegion); region->resource = wl_resource_create (client, &wl_region_interface, wl_resource_get_version (compositor_resource), id); wl_resource_set_implementation (region->resource, &meta_wayland_region_interface, region, meta_wayland_region_resource_destroy_cb); region->region = cairo_region_create (); }
void KeyboardInterface::repeatInfo(qint32 charactersPerSecond, qint32 delay) { Q_D(); if (!d->resource) { return; } if (wl_resource_get_version(d->resource) < WL_KEYBOARD_REPEAT_INFO_SINCE_VERSION) { // only supported since version 4 return; } wl_keyboard_send_repeat_info(d->resource, charactersPerSecond, delay); }
static void get_data_device (struct wl_client *client, struct wl_resource *manager_resource, guint32 id, struct wl_resource *seat_resource) { MetaWaylandSeat *seat = wl_resource_get_user_data (seat_resource); struct wl_resource *cr; cr = wl_resource_create (client, &wl_data_device_interface, wl_resource_get_version (manager_resource), id); wl_resource_set_implementation (cr, &data_device_interface, &seat->data_device, unbind_resource); wl_list_insert (&seat->data_device.resource_list, wl_resource_get_link (cr)); }
static void get_xdg_popup(struct wl_client *client, struct wl_resource *resource, uint32_t id, struct wl_resource *surface_resource, struct wl_resource *parent_resource, struct wl_resource *seat_resource, uint32_t serial, int32_t x, int32_t y) { struct surface *surface = wl_resource_get_user_data(surface_resource); struct surface *parent = wl_resource_get_user_data(parent_resource); struct xdg_popup *popup; popup = xdg_popup_new(client, wl_resource_get_version(resource), id, surface, parent, x, y); if (!popup) wl_resource_post_no_memory(resource); }
static void create_buffer(struct wl_client * client, struct wl_resource * resource, uint32_t id, int32_t offset, int32_t width, int32_t height, int32_t stride, uint32_t format) { struct pool * pool = wl_resource_get_user_data(resource); struct pool_reference * reference; struct wld_buffer * buffer; struct wl_resource * buffer_resource; union wld_object object; if (offset > pool->size || offset < 0) { wl_resource_post_error(resource, WL_SHM_ERROR_INVALID_STRIDE, "offset is too big or negative"); return; } object.ptr = (void *)((uintptr_t) pool->data + offset); buffer = wld_import_buffer(swc.shm->context, WLD_OBJECT_DATA, object, width, height, format_shm_to_wld(format), stride); if (!buffer) goto error0; buffer_resource = wayland_buffer_create_resource (client, wl_resource_get_version(resource), id, buffer); if (!buffer_resource) goto error1; if (!(reference = malloc(sizeof *reference))) goto error2; reference->pool = pool; reference->destructor.destroy = &handle_buffer_destroy; wld_buffer_add_destructor(buffer, &reference->destructor); ++pool->references; return; error2: wl_resource_destroy(buffer_resource); error1: wld_buffer_unreference(buffer); error0: wl_resource_post_no_memory(resource); }
void GammaControlManager::getGammaControl(wl_client *client, wl_resource *res, uint32_t id, wl_resource *outputRes) { Output *output = Output::fromResource(outputRes); class GammaControl { public: GammaControl(Output *o) : output(o) { } void destroy(wl_client *c, wl_resource *r) { wl_resource_destroy(r); } void setGamma(wl_client *c, wl_resource *res, wl_array *red, wl_array *green, wl_array *blue) { if (red->size != green->size || red->size != blue->size) { wl_resource_post_error(res, GAMMA_CONTROL_ERROR_INVALID_GAMMA, "The gamma ramps don't have the same size"); return; } uint16_t *r = (uint16_t *)red->data; uint16_t *g = (uint16_t *)green->data; uint16_t *b = (uint16_t *)blue->data; output->setGamma(red->size / sizeof(uint16_t), r, g, b); } void resetGamma(wl_client *c, wl_resource *res) { } Output *output; }; static const struct gamma_control_interface implementation = { wrapExtInterface(&GammaControl::destroy), wrapExtInterface(&GammaControl::setGamma), wrapExtInterface(&GammaControl::resetGamma) }; GammaControl *gc = new GammaControl(output); wl_resource *resource = wl_resource_create(client, &gamma_control_interface, wl_resource_get_version(res), id); wl_resource_set_implementation(resource, &implementation, gc, [](wl_resource *r) { delete static_cast<GammaControl *>(wl_resource_get_user_data(r)); }); gamma_control_send_gamma_size(resource, output->gammaSize()); }
static bool subcomp_defer_handler( struct surface_request* req, struct arcan_shmif_cont* con) { if (!con){ trace(TRACE_SHELL, "reqfail"); wl_resource_post_no_memory(req->target); return false; } struct wl_resource* subsurf = wl_resource_create(req->client->client, &wl_subsurface_interface, wl_resource_get_version(req->target), req->id); if (!subsurf){ trace(TRACE_SHELL, "reqfail"); wl_resource_post_no_memory(req->target); return false; } struct comp_surf* surf = wl_resource_get_user_data(req->target); wl_resource_set_implementation(subsurf, &subsurf_if, surf, NULL); if (!surf){ trace(TRACE_SHELL, "reqfail"); wl_resource_post_no_memory(req->target); return false; } surf->acon = *con; surf->cookie = 0xfeedface; surf->shell_res = subsurf; surf->dispatch = subsurf_shmifev_handler; surf->sub_parent_res = req->parent; snprintf(surf->tracetag, SURF_TAGLEN, "subsurf"); if (req->parent){ struct comp_surf* psurf = wl_resource_get_user_data(req->parent); if (!psurf->acon.addr){ trace(TRACE_ALLOC, "bad subsurface, broken parent"); return false; } surf->viewport.ext.kind = ARCAN_EVENT(VIEWPORT); surf->viewport.ext.viewport.parent = psurf->acon.segment_token; arcan_shmif_enqueue(&surf->acon, &surf->viewport); } trace(TRACE_ALLOC, "subsurface"); return true; }
MetaWaylandRegion * meta_wayland_region_create (MetaWaylandCompositor *compositor, struct wl_client *client, struct wl_resource *compositor_resource, guint32 id) { MetaWaylandRegion *region = g_slice_new0 (MetaWaylandRegion); region->resource = wl_resource_create (client, &wl_region_interface, wl_resource_get_version (compositor_resource), id); wl_resource_set_implementation (region->resource, &meta_wayland_wl_region_interface, region, wl_region_destructor); region->region = cairo_region_create (); return region; }
void DpmsManagerInterface::Private::getDpmsCallback(wl_client *client, wl_resource *resource, uint32_t id, wl_resource *output) { auto p = Private::cast(resource); auto c = p->display->getConnection(client); OutputInterface *o = OutputInterface::get(output); DpmsInterface *dpms = new DpmsInterface(o, resource, p->q); dpms->create(c, wl_resource_get_version(resource), id); if (!dpms->resource()) { wl_resource_post_no_memory(resource); return; } dpms->sendSupported(); dpms->sendMode(); dpms->sendDone(); }
static void xdg_shell_get_xdg_surface (struct wl_client *client, struct wl_resource *resource, guint32 id, struct wl_resource *surface_resource) { MetaWaylandSurface *surface = wl_resource_get_user_data (surface_resource); MetaWaylandXdgSurface *xdg_surface; MetaWindow *window; if (META_IS_WAYLAND_XDG_SURFACE (surface->role) && META_WAYLAND_XDG_SURFACE (surface->role)->resource) { wl_resource_post_error (surface_resource, WL_DISPLAY_ERROR_INVALID_OBJECT, "xdg_shell::get_xdg_surface already requested"); return; } if (!meta_wayland_surface_assign_role (surface, META_TYPE_WAYLAND_XDG_SURFACE)) { wl_resource_post_error (resource, XDG_SHELL_ERROR_ROLE, "wl_surface@%d already has a different role", wl_resource_get_id (surface->resource)); return; } xdg_surface = META_WAYLAND_XDG_SURFACE (surface->role); xdg_surface->resource = wl_resource_create (client, &xdg_surface_interface, wl_resource_get_version (resource), id); wl_resource_set_implementation (xdg_surface->resource, &meta_wayland_xdg_surface_interface, xdg_surface, xdg_surface_destructor); xdg_surface->xdg_shell_resource = resource; window = meta_window_wayland_new (meta_get_display (), surface); meta_wayland_surface_set_window (surface, window); }
static void create_pool(struct wl_client * client, struct wl_resource * resource, uint32_t id, int32_t fd, int32_t size) { struct pool * pool; if (!(pool = malloc(sizeof *pool))) { wl_resource_post_no_memory(resource); return; } pool->resource = wl_resource_create(client, &wl_shm_pool_interface, wl_resource_get_version(resource), id); if (!pool->resource) { wl_resource_post_no_memory(resource); goto error0; } wl_resource_set_implementation(pool->resource, &shm_pool_implementation, pool, &destroy_pool_resource); pool->data = mmap(NULL, size, PROT_READ, MAP_SHARED, fd, 0); if (pool->data == MAP_FAILED) { wl_resource_post_error(resource, WL_SHM_ERROR_INVALID_FD, "mmap failed: %s", strerror(errno)); goto error1; } pool->size = size; pool->references = 1; return; error1: wl_resource_destroy(pool->resource); error0: free(pool); }
static void wl_shell_get_shell_surface (struct wl_client *client, struct wl_resource *resource, uint32_t id, struct wl_resource *surface_resource) { MetaWaylandSurface *surface = wl_resource_get_user_data (surface_resource); MetaWaylandWlShellSurface *wl_shell_surface; if (META_IS_WAYLAND_WL_SHELL_SURFACE (surface->role) && META_WAYLAND_WL_SHELL_SURFACE (surface->role)->resource) { wl_resource_post_error (surface_resource, WL_DISPLAY_ERROR_INVALID_OBJECT, "wl_shell::get_shell_surface already requested"); return; } if (!meta_wayland_surface_assign_role (surface, META_TYPE_WAYLAND_WL_SHELL_SURFACE, NULL)) { wl_resource_post_error (resource, WL_SHELL_ERROR_ROLE, "wl_surface@%d already has a different role", wl_resource_get_id (surface->resource)); return; } wl_shell_surface = META_WAYLAND_WL_SHELL_SURFACE (surface->role); wl_shell_surface->resource = wl_resource_create (client, &wl_shell_surface_interface, wl_resource_get_version (resource), id); wl_resource_set_implementation (wl_shell_surface->resource, &meta_wayland_wl_shell_surface_interface, wl_shell_surface, wl_shell_surface_destructor); create_wl_shell_surface_window (surface); }
static void linux_dmabuf_create_params(struct wl_client *client, struct wl_resource *linux_dmabuf_resource, uint32_t params_id) { struct weston_compositor *compositor; struct linux_dmabuf_buffer *buffer; uint32_t version; int i; version = wl_resource_get_version(linux_dmabuf_resource); compositor = wl_resource_get_user_data(linux_dmabuf_resource); buffer = zalloc(sizeof *buffer); if (!buffer) goto err_out; for (i = 0; i < MAX_DMABUF_PLANES; i++) buffer->attributes.fd[i] = -1; buffer->compositor = compositor; buffer->params_resource = wl_resource_create(client, &zwp_linux_buffer_params_v1_interface, version, params_id); if (!buffer->params_resource) goto err_dealloc; wl_resource_set_implementation(buffer->params_resource, &zwp_linux_buffer_params_implementation, buffer, destroy_params); return; err_dealloc: free(buffer); err_out: wl_resource_post_no_memory(linux_dmabuf_resource); }
static void server_wlegl_get_server_buffer_handle(wl_client *client, wl_resource *res, uint32_t id, int32_t width, int32_t height, int32_t format, int32_t usage) { if (width == 0 || height == 0) { wl_resource_post_error(res, 0, "invalid buffer size: %u,%u\n", width, height); return; } server_wlegl *wlegl = server_wlegl_from(res); wl_resource *resource = wl_resource_create(client, &android_wlegl_server_buffer_handle_interface, wl_resource_get_version(res), id); buffer_handle_t _handle; int _stride; usage |= GRALLOC_USAGE_HW_COMPOSER; int r = hybris_gralloc_allocate(width, height, format, usage, &_handle, (uint32_t*)&_stride); if (r) { HYBRIS_ERROR_LOG(SERVER_WLEGL, "failed to allocate buffer\n"); } server_wlegl_buffer *buffer = server_wlegl_buffer_create_server(client, width, height, _stride, format, usage, _handle, wlegl); struct wl_array ints; int *ints_data; wl_array_init(&ints); ints_data = (int*) wl_array_add(&ints, _handle->numInts * sizeof(int)); memcpy(ints_data, _handle->data + _handle->numFds, _handle->numInts * sizeof(int)); android_wlegl_server_buffer_handle_send_buffer_ints(resource, &ints); wl_array_release(&ints); for (int i = 0; i < _handle->numFds; i++) { android_wlegl_server_buffer_handle_send_buffer_fd(resource, _handle->data[i]); } android_wlegl_server_buffer_handle_send_buffer(resource, buffer->resource, format, _stride); wl_resource_destroy(resource); }
static void xdg_shell_get_xdg_popup (struct wl_client *client, struct wl_resource *resource, uint32_t id, struct wl_resource *surface_resource, struct wl_resource *parent_resource, struct wl_resource *seat_resource, uint32_t serial, int32_t x, int32_t y) { MetaWaylandSurface *surface = wl_resource_get_user_data (surface_resource); MetaWaylandPopupSurface *popup_surface; MetaWaylandSurface *parent_surf = wl_resource_get_user_data (parent_resource); MetaWaylandSurface *top_popup; MetaWaylandSeat *seat = wl_resource_get_user_data (seat_resource); MetaWindow *window; MetaDisplay *display = meta_get_display (); MetaWaylandXdgPopup *xdg_popup; MetaWaylandPopup *popup; if (META_IS_WAYLAND_XDG_POPUP (surface->role) && META_WAYLAND_XDG_POPUP (surface->role)->resource) { wl_resource_post_error (surface_resource, WL_DISPLAY_ERROR_INVALID_OBJECT, "xdg_shell::get_xdg_popup already requested"); return; } if (!meta_wayland_surface_assign_role (surface, META_TYPE_WAYLAND_XDG_POPUP)) { wl_resource_post_error (resource, XDG_SHELL_ERROR_ROLE, "wl_surface@%d already has a different role", wl_resource_get_id (surface->resource)); return; } if (parent_surf == NULL || parent_surf->window == NULL || (!META_IS_WAYLAND_XDG_POPUP (parent_surf->role) && !META_IS_WAYLAND_XDG_SURFACE (parent_surf->role))) { wl_resource_post_error (resource, XDG_SHELL_ERROR_INVALID_POPUP_PARENT, "invalid parent surface"); return; } top_popup = meta_wayland_pointer_get_top_popup (&seat->pointer); if ((top_popup == NULL && !META_IS_WAYLAND_XDG_SURFACE (parent_surf->role)) || (top_popup != NULL && parent_surf != top_popup)) { wl_resource_post_error (resource, XDG_SHELL_ERROR_NOT_THE_TOPMOST_POPUP, "parent not top most surface"); return; } xdg_popup = META_WAYLAND_XDG_POPUP (surface->role); xdg_popup->resource = wl_resource_create (client, &xdg_popup_interface, wl_resource_get_version (resource), id); wl_resource_set_implementation (xdg_popup->resource, &meta_wayland_xdg_popup_interface, xdg_popup, xdg_popup_destructor); xdg_popup->xdg_shell_resource = resource; if (!meta_wayland_seat_can_popup (seat, serial)) { xdg_popup_send_popup_done (xdg_popup->resource); return; } xdg_popup->parent_surface = parent_surf; xdg_popup->parent_destroy_listener.notify = handle_popup_parent_destroyed; wl_resource_add_destroy_listener (parent_surf->resource, &xdg_popup->parent_destroy_listener); window = meta_window_wayland_new (display, surface); meta_window_wayland_place_relative_to (window, parent_surf->window, x, y); window->showing_for_first_time = FALSE; meta_wayland_surface_set_window (surface, window); meta_window_focus (window, meta_display_get_current_time (display)); popup_surface = META_WAYLAND_POPUP_SURFACE (surface->role); popup = meta_wayland_pointer_start_popup_grab (&seat->pointer, popup_surface); if (popup == NULL) { xdg_popup_send_popup_done (xdg_popup->resource); meta_wayland_surface_destroy_window (surface); return; } xdg_popup->popup = popup; }
static void wl_cb_shell_get_shell_surface(struct wl_client *client, struct wl_resource *resource, uint32_t id, struct wl_resource *surface_resource) { struct wlc_shell *shell; struct wlc_surface *surface; if (!(shell = wl_resource_get_user_data(resource)) || !(surface = convert_from_wl_resource(surface_resource, "surface"))) return; wlc_resource r; if (!(r = wlc_resource_create(&shell->surfaces, client, &wl_shell_surface_interface, wl_resource_get_version(resource), 1, id))) return; wlc_resource_implement(r, &wl_shell_surface_implementation, NULL); struct wlc_surface_event ev = { .attach = { .type = WLC_SHELL_SURFACE, .shell_surface = r }, .surface = surface, .type = WLC_SURFACE_EVENT_REQUEST_VIEW_ATTACH };
static void compositor_create_surface(wl_client *client, wl_resource *compositorResource, uint32_t id) { Compositor *compositor = static_cast<Compositor *>(compositorResource->data); compositor->addSurface(new Surface(client, id, wl_resource_get_version(compositorResource), compositor)); }
static struct wl_resource * meta_wayland_data_source_send_offer (MetaWaylandDataSource *source, struct wl_resource *target) { MetaWaylandDataOffer *offer = g_slice_new0 (MetaWaylandDataOffer); char **p; offer->source = source; offer->source_destroy_listener.notify = destroy_offer_data_source; offer->resource = wl_resource_create (wl_resource_get_client (target), &wl_data_offer_interface, wl_resource_get_version (target), 0); wl_resource_set_implementation (offer->resource, &data_offer_interface, offer, destroy_data_offer); wl_resource_add_destroy_listener (source->resource, &offer->source_destroy_listener); wl_data_device_send_data_offer (target, offer->resource); wl_array_for_each (p, &source->mime_types) wl_data_offer_send_offer (offer->resource, *p); return offer->resource; }