static struct clipboard_source * clipboard_source_create(struct clipboard *clipboard, const char *mime_type, uint32_t serial, int fd) { struct wl_display *display = clipboard->seat->compositor->wl_display; struct wl_event_loop *loop = wl_display_get_event_loop(display); struct clipboard_source *source; char **s; source = malloc(sizeof *source); wl_array_init(&source->contents); wl_array_init(&source->base.mime_types); source->base.accept = clipboard_source_accept; source->base.send = clipboard_source_send; source->base.cancel = clipboard_source_cancel; source->base.resource.data = &source->base; wl_signal_init(&source->base.resource.destroy_signal); source->refcount = 1; source->clipboard = clipboard; source->serial = serial; s = wl_array_add(&source->base.mime_types, sizeof *s); *s = strdup(mime_type); source->event_source = wl_event_loop_add_fd(loop, fd, WL_EVENT_READABLE, clipboard_source_data, source); return source; }
struct wlegl_handle * wlegl_handle_create(struct wl_resource *parent, uint32_t id, int32_t num_fds, struct wl_array *ints) { struct wlegl_handle *handle; handle = malloc(sizeof *handle); if (!handle) { wl_resource_post_no_memory(parent); return; } memset(handle, 0, sizeof *handle); handle->resource = wl_resource_create(wl_resource_get_client(parent), &android_wlegl_handle_interface, 1, id); if (!handle->resource) { wl_resource_post_no_memory(parent); free(handle); return; } wl_resource_set_implementation(handle->resource, &wlegl_handle_implementation, handle, destroy_wlegl_handle); wl_array_init(&handle->ints); wl_array_init(&handle->fds); wl_array_copy(&handle->ints, ints); handle->num_fds = num_fds; handle->num_ints = ints->size / sizeof(int); }
static void weston_wm_send_data(struct weston_wm *wm, xcb_atom_t target, const char *mime_type) { struct weston_data_source *source; struct weston_seat *seat = weston_wm_pick_seat(wm); int p[2]; if (pipe2(p, O_CLOEXEC | O_NONBLOCK) == -1) { weston_log("pipe2 failed: %m\n"); weston_wm_send_selection_notify(wm, XCB_ATOM_NONE); return; } wl_array_init(&wm->source_data); wm->selection_target = target; wm->data_source_fd = p[0]; wm->property_source = wl_event_loop_add_fd(wm->server->loop, wm->data_source_fd, WL_EVENT_READABLE, weston_wm_read_data_source, wm); source = seat->selection_data_source; source->send(source, mime_type, p[1]); close(p[1]); }
static void create_data_source(struct wl_client *client, struct wl_resource *resource, uint32_t id) { struct wl_data_source *source; source = malloc(sizeof *source); if (source == NULL) { wl_resource_post_no_memory(resource); return; } source->resource.destroy = destroy_data_source; source->resource.object.id = id; source->resource.object.interface = &wl_data_source_interface; source->resource.object.implementation = (void (**)(void)) &data_source_interface; source->resource.data = source; wl_list_init(&source->resource.destroy_listener_list); source->offer_interface = &data_offer_interface; source->cancel = data_source_cancel; wl_array_init(&source->mime_types); wl_client_add_resource(client, &source->resource); }
void WaylandNativeWindowBuffer::wlbuffer_from_native_handle(struct android_wlegl *android_wlegl, struct wl_display *display, struct wl_event_queue *queue) { struct wl_array ints; int *ints_data; struct android_wlegl_handle *wlegl_handle; 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)); wlegl_handle = android_wlegl_create_handle(android_wlegl, handle->numFds, &ints); wl_array_release(&ints); for (int i = 0; i < handle->numFds; i++) { android_wlegl_handle_add_fd(wlegl_handle, handle->data[i]); } wlbuffer = android_wlegl_create_buffer(android_wlegl, width, height, stride, format, usage, wlegl_handle); android_wlegl_handle_destroy(wlegl_handle); creation_callback = wl_display_sync(display); wl_callback_add_listener(creation_callback, &buffer_create_sync_listener, &creation_callback); wl_proxy_set_queue((struct wl_proxy *)creation_callback, queue); }
ServerWaylandBuffer::ServerWaylandBuffer(unsigned int w, unsigned int h, int f, int u, gralloc_module_t *gralloc, android_wlegl *android_wlegl, struct wl_event_queue *queue) : WaylandNativeWindowBuffer() , m_buf(0) { ANativeWindowBuffer::width = w; ANativeWindowBuffer::height = h; m_gralloc = gralloc; usage = u; wl_array_init(&ints); wl_array_init(&fds); android_wlegl_server_buffer_handle *ssb = android_wlegl_get_server_buffer_handle(android_wlegl, width, height, f, u); wl_proxy_set_queue((struct wl_proxy *) ssb, queue); android_wlegl_server_buffer_handle_add_listener(ssb, &server_handle_listener, this); }
static void weston_wm_get_selection_targets(struct weston_wm *wm) { struct x11_data_source *source; struct weston_compositor *compositor; struct weston_seat *seat = weston_wm_pick_seat(wm); xcb_get_property_cookie_t cookie; xcb_get_property_reply_t *reply; xcb_atom_t *value; char **p; uint32_t i; cookie = xcb_get_property(wm->conn, 1, /* delete */ wm->selection_window, wm->atom.wl_selection, XCB_GET_PROPERTY_TYPE_ANY, 0, /* offset */ 4096 /* length */); reply = xcb_get_property_reply(wm->conn, cookie, NULL); if (reply == NULL) return; dump_property(wm, wm->atom.wl_selection, reply); if (reply->type != XCB_ATOM_ATOM) { free(reply); return; } source = zalloc(sizeof *source); if (source == NULL) { free(reply); return; } wl_signal_init(&source->base.destroy_signal); source->base.accept = data_source_accept; source->base.send = data_source_send; source->base.cancel = data_source_cancel; source->wm = wm; wl_array_init(&source->base.mime_types); value = xcb_get_property_value(reply); for (i = 0; i < reply->value_len; i++) { if (value[i] == wm->atom.utf8_string) { p = wl_array_add(&source->base.mime_types, sizeof *p); if (p) *p = strdup("text/plain;charset=utf-8"); } } compositor = wm->server->compositor; weston_seat_set_selection(seat, &source->base, wl_display_next_serial(compositor->wl_display)); free(reply); }
int WaylandNativeWindow::queueBuffer(BaseNativeWindowBuffer* buffer, int fenceFd){ WaylandNativeWindowBuffer *backbuf = (WaylandNativeWindowBuffer *) buffer; int ret = 0; lock(); backbuf->busy = 2; unlock(); while (this->frame_callback && ret != -1) ret = wl_display_dispatch_queue(m_display, this->wl_queue); if (ret < 0) return ret; lock(); this->frame_callback = wl_surface_frame(m_window->surface); wl_callback_add_listener(this->frame_callback, &frame_listener, this); wl_proxy_set_queue((struct wl_proxy *) this->frame_callback, this->wl_queue); if (backbuf->wlbuffer == NULL) { struct wl_array ints; int *ints_data; struct android_wlegl_handle *wlegl_handle; buffer_handle_t handle; handle = backbuf->handle; 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)); wlegl_handle = android_wlegl_create_handle(m_android_wlegl, handle->numFds, &ints); wl_array_release(&ints); for (int i = 0; i < handle->numFds; i++) { android_wlegl_handle_add_fd(wlegl_handle, handle->data[i]); } backbuf->wlbuffer = android_wlegl_create_buffer(m_android_wlegl, backbuf->width, backbuf->height, backbuf->stride, backbuf->format, backbuf->usage, wlegl_handle); android_wlegl_handle_destroy(wlegl_handle); backbuf->common.incRef(&backbuf->common); TRACE("Add listener for %p with %p inside", backbuf, backbuf->wlbuffer); wl_buffer_add_listener(backbuf->wlbuffer, &wl_buffer_listener, this); wl_proxy_set_queue((struct wl_proxy *) backbuf->wlbuffer, this->wl_queue); } wl_surface_attach(m_window->surface, backbuf->wlbuffer, 0, 0); wl_surface_damage(m_window->surface, 0, 0, backbuf->width, backbuf->height); wl_surface_commit(m_window->surface); fronted.push_back(backbuf); unlock(); return NO_ERROR; }
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); }
TouchExtensionGlobal::TouchExtensionGlobal(Compositor *compositor) : m_compositor(compositor), m_flags(0) { wl_array_init(&m_rawdata_array); m_rawdata_ptr = static_cast<float *>(wl_array_add(&m_rawdata_array, maxRawPos * sizeof(float) * 2)); wl_display_add_global(compositor->wl_display(), &qt_touch_extension_interface, this, TouchExtensionGlobal::bind_func); }
static void input_method_activate(void *data, struct wl_input_method *input_method, struct wl_input_method_context *context) { struct virtual_keyboard *keyboard = data; struct wl_array modifiers_map; const struct layout *layout; keyboard->keyboard->state = keyboardstate_default; if (keyboard->context) wl_input_method_context_destroy(keyboard->context); if (keyboard->preedit_string) free(keyboard->preedit_string); keyboard->preedit_string = strdup(""); keyboard->content_hint = 0; keyboard->content_purpose = 0; free(keyboard->preferred_language); keyboard->preferred_language = NULL; free(keyboard->surrounding_text); keyboard->surrounding_text = NULL; keyboard->serial = 0; keyboard->context = context; wl_input_method_context_add_listener(context, &input_method_context_listener, keyboard); wl_array_init(&modifiers_map); keysym_modifiers_add(&modifiers_map, "Shift"); keysym_modifiers_add(&modifiers_map, "Control"); keysym_modifiers_add(&modifiers_map, "Mod1"); wl_input_method_context_modifiers_map(context, &modifiers_map); keyboard->keysym.shift_mask = keysym_modifiers_get_mask(&modifiers_map, "Shift"); wl_array_release(&modifiers_map); layout = get_current_layout(keyboard); window_schedule_resize(keyboard->keyboard->window, layout->columns * key_width, layout->rows * key_height); wl_input_method_context_language(context, keyboard->serial, layout->language); wl_input_method_context_text_direction(context, keyboard->serial, layout->text_direction); widget_schedule_redraw(keyboard->keyboard->widget); }
void KeyboardInterface::Private::sendEnter(SurfaceInterface *surface, quint32 serial) { wl_array keys; wl_array_init(&keys); const auto states = seat->pressedKeys(); for (auto it = states.begin(); it != states.end(); ++it) { uint32_t *k = reinterpret_cast<uint32_t*>(wl_array_add(&keys, sizeof(uint32_t))); *k = *it; } wl_keyboard_send_enter(resource, serial, surface->resource(), &keys); wl_array_release(&keys); sendModifiers(); }
static void add_selection_offer(struct display *d, uint32_t id) { struct selection_offer *offer; offer = malloc(sizeof *offer); if (offer == NULL) return; offer->offer = wl_selection_offer_create(d->display, id); offer->display = d; wl_array_init(&offer->types); offer->input = NULL; wl_selection_offer_add_listener(offer->offer, &selection_offer_listener, offer); }
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); }
QWaylandBrcmBuffer(QWaylandDisplay *display, struct qt_brcm *brcm, const QSize &size, EGLint *data, int count) : m_size(size) , m_released(true) , m_display(display) { wl_array_init(&m_array); m_data = static_cast<EGLint *>(wl_array_add(&m_array, count * sizeof(EGLint))); for (int i = 0; i < count; ++i) m_data[i] = data[i]; mBuffer = qt_brcm_create_buffer(brcm, size.width(), size.height(), &m_array); static const struct wl_buffer_listener buffer_listener = { QWaylandBrcmBuffer::buffer_release }; wl_buffer_add_listener(mBuffer, &buffer_listener, this); }
/* local functions */ void _ecore_wl_input_add(Ecore_Wl_Display *ewd, unsigned int id) { Ecore_Wl_Input *input; LOGFN(__FILE__, __LINE__, __FUNCTION__); if (!(input = malloc(sizeof(Ecore_Wl_Input)))) return; memset(input, 0, sizeof(Ecore_Wl_Input)); input->display = ewd; input->pointer_focus = NULL; input->keyboard_focus = NULL; input->touch_focus = NULL; input->seat = wl_registry_bind(ewd->wl.registry, id, &wl_seat_interface, 1); ewd->inputs = eina_inlist_append(ewd->inputs, EINA_INLIST_GET(input)); wl_seat_add_listener(input->seat, &_ecore_wl_seat_listener, input); wl_seat_set_user_data(input->seat, input); wl_array_init(&input->data_types); if (ewd->wl.data_device_manager) { input->data_device = wl_data_device_manager_get_data_device(ewd->wl.data_device_manager, input->seat); wl_data_device_add_listener(input->data_device, &_ecore_wl_data_listener, input); } ewd->input = input; }
WL_EXPORT struct wlb_keyboard * wlb_keyboard_create(struct wlb_seat *seat) { struct wlb_keyboard *keyboard; if (seat->keyboard) return NULL; keyboard = zalloc(sizeof *keyboard); if (!keyboard) return NULL; keyboard->seat = seat; wl_list_init(&keyboard->resource_list); wl_array_init(&keyboard->keys); keyboard->keymap.fd = -1; keyboard->surface_destroy_listener.notify = keyboard_surface_destroyed; seat->keyboard = keyboard; return keyboard; }
static void create_data_source(struct wl_client *client, struct wl_resource *resource, uint32_t id) { struct weston_data_source *source; source = malloc(sizeof *source); if (source == NULL) { wl_resource_post_no_memory(resource); return; } wl_signal_init(&source->destroy_signal); source->accept = client_source_accept; source->send = client_source_send; source->cancel = client_source_cancel; wl_array_init(&source->mime_types); source->resource = wl_resource_create(client, &wl_data_source_interface, 1, id); wl_resource_set_implementation(source->resource, &data_source_interface, source, destroy_data_source); }
static void xdg_surface_role_configure (MetaWaylandSurfaceRoleShellSurface *shell_surface_role, int new_width, int new_height, MetaWaylandSerial *sent_serial) { MetaWaylandXdgSurface *xdg_surface = META_WAYLAND_XDG_SURFACE (shell_surface_role); MetaWaylandSurfaceRole *surface_role = META_WAYLAND_SURFACE_ROLE (shell_surface_role); MetaWaylandSurface *surface = meta_wayland_surface_role_get_surface (surface_role); struct wl_client *client = wl_resource_get_client (xdg_surface->resource); struct wl_display *display = wl_client_get_display (client); uint32_t serial = wl_display_next_serial (display); struct wl_array states; if (!xdg_surface->resource) return; wl_array_init (&states); fill_states (&states, surface->window); xdg_surface_send_configure (xdg_surface->resource, new_width, new_height, &states, serial); wl_array_release (&states); if (sent_serial) { sent_serial->set = TRUE; sent_serial->value = serial; } }
void WaylandNativeWindowBuffer::wlbuffer_from_native_handle(struct android_wlegl *android_wlegl) { struct wl_array ints; int *ints_data; struct android_wlegl_handle *wlegl_handle; 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)); wlegl_handle = android_wlegl_create_handle(android_wlegl, handle->numFds, &ints); wl_array_release(&ints); for (int i = 0; i < handle->numFds; i++) { android_wlegl_handle_add_fd(wlegl_handle, handle->data[i]); } wlbuffer = android_wlegl_create_buffer(android_wlegl, width, height, stride, format, usage, wlegl_handle); android_wlegl_handle_destroy(wlegl_handle); }
static void handle_enter(struct weston_wm *wm, xcb_client_message_event_t *client_message) { struct dnd_data_source *source; struct weston_seat *seat = weston_wm_pick_seat(wm); char **p; const char *name; uint32_t *types; int i, length, has_text; xcb_get_property_cookie_t cookie; xcb_get_property_reply_t *reply; source = malloc(sizeof *source); if (source == NULL) return; wl_signal_init(&source->base.destroy_signal); source->base.accept = data_source_accept; source->base.send = data_source_send; source->base.cancel = data_source_cancel; source->wm = wm; source->window = client_message->data.data32[0]; source->version = client_message->data.data32[1] >> 24; if (client_message->data.data32[1] & 1) { cookie = xcb_get_property(wm->conn, 0, /* delete */ source->window, wm->atom.xdnd_type_list, XCB_ATOM_ANY, 0, 2048); reply = xcb_get_property_reply(wm->conn, cookie, NULL); types = xcb_get_property_value(reply); length = reply->value_len; } else { reply = NULL; types = &client_message->data.data32[2]; length = 3; } wl_array_init(&source->base.mime_types); has_text = 0; for (i = 0; i < length; i++) { if (types[i] == XCB_ATOM_NONE) continue; name = get_atom_name(wm->conn, types[i]); if (types[i] == wm->atom.utf8_string || types[i] == wm->atom.text_plain_utf8 || types[i] == wm->atom.text_plain) { if (has_text) continue; has_text = 1; p = wl_array_add(&source->base.mime_types, sizeof *p); if (p) *p = strdup("text/plain;charset=utf-8"); } else if (strchr(name, '/')) { p = wl_array_add(&source->base.mime_types, sizeof *p); if (p) *p = strdup(name); } } free(reply); weston_seat_start_drag(seat, &source->base, NULL, NULL); }