static void fill_states (struct wl_array *states, MetaWindow *window) { uint32_t *s; if (META_WINDOW_MAXIMIZED (window)) { s = wl_array_add (states, sizeof *s); *s = XDG_SURFACE_STATE_MAXIMIZED; } if (meta_window_is_fullscreen (window)) { s = wl_array_add (states, sizeof *s); *s = XDG_SURFACE_STATE_FULLSCREEN; } if (meta_grab_op_is_resizing (window->display->grab_op)) { s = wl_array_add (states, sizeof *s); *s = XDG_SURFACE_STATE_RESIZING; } if (meta_window_appears_focused (window)) { s = wl_array_add (states, sizeof *s); *s = XDG_SURFACE_STATE_ACTIVATED; } }
static int clipboard_source_data(int fd, uint32_t mask, void *data) { struct clipboard_source *source = data; struct clipboard *clipboard = source->clipboard; char *p; int len, size; if (source->contents.alloc - source->contents.size < 1024) { wl_array_add(&source->contents, 1024); source->contents.size -= 1024; } p = source->contents.data + source->contents.size; size = source->contents.alloc - source->contents.size; len = read(fd, p, size); if (len == 0) { wl_event_source_remove(source->event_source); close(fd); source->event_source = NULL; } else if (len < 0) { clipboard_source_unref(source); clipboard->source = NULL; } else { source->contents.size += len; } return 1; }
WL_EXPORT void wl_array_copy(struct wl_array *array, struct wl_array *source) { array->size = 0; wl_array_add(array, source->size); memcpy(array->data, source->data, source->size); }
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; }
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); }
WL_EXPORT void wlb_keyboard_key(struct wlb_keyboard *keyboard, uint32_t time, uint32_t key, enum wl_keyboard_key_state state) { struct wl_resource *resource; uint32_t serial, *k, *end; keyboard_ensure_focus(keyboard); end = keyboard->keys.data + keyboard->keys.size; for (k = keyboard->keys.data; k < end; k++) { if (*k == key) { /* Ignore server-generated repeats. */ if (state == WL_KEYBOARD_KEY_STATE_PRESSED) return; *k = *--end; } } keyboard->keys.size = (void *) end - keyboard->keys.data; if (state == WL_KEYBOARD_KEY_STATE_PRESSED) { k = wl_array_add(&keyboard->keys, sizeof *k); *k = key; } if (!keyboard->focus || wl_list_empty(&keyboard->resource_list)) return; serial = wl_display_next_serial(keyboard->seat->compositor->display); wl_resource_for_each(resource, &keyboard->resource_list) wl_keyboard_send_key(resource, serial, time, key, state); }
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; }
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); }
WL_EXPORT int wl_array_copy(struct wl_array *array, struct wl_array *source) { if (array->size < source->size) { if (!wl_array_add(array, source->size - array->size)) return -1; } else { array->size = source->size; } memcpy(array->data, source->data, source->size); return 0; }
static void selection_offer_offer(void *data, struct wl_selection_offer *selection_offer, const char *type) { struct selection_offer *offer = data; char **p; p = wl_array_add(&offer->types, sizeof *p); if (p) *p = strdup(type); };
static void data_source_offer (struct wl_client *client, struct wl_resource *resource, const char *type) { MetaWaylandDataSource *source = wl_resource_get_user_data (resource); char **p; p = wl_array_add (&source->mime_types, sizeof *p); if (p) *p = strdup (type); if (!p || !*p) wl_resource_post_no_memory (resource); }
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 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 wlegl_handle_add_fd(struct wl_client *client, struct wl_resource *resource, int32_t fd) { struct wlegl_handle *handle = wl_resource_get_user_data(resource); int *next_fd; if (handle->fds.size >= handle->num_fds * sizeof(int)) { wl_resource_post_error(handle->resource, ANDROID_WLEGL_HANDLE_ERROR_TOO_MANY_FDS, "too many file descriptors"); close(fd); return; } next_fd = wl_array_add(&handle->fds, sizeof(int)); if (!next_fd) { wl_resource_post_no_memory(resource); return; } *next_fd = fd; }
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); }
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 ssb_fd(void *data, android_wlegl_server_buffer_handle *, int fd) { ServerWaylandBuffer *wsb = static_cast<ServerWaylandBuffer *>(data); int *ptr = (int *)wl_array_add(&wsb->fds, sizeof(int)); *ptr = fd; }
static int weston_wm_read_data_source(int fd, uint32_t mask, void *data) { struct weston_wm *wm = data; int len, current, available; void *p; current = wm->source_data.size; if (wm->source_data.size < incr_chunk_size) p = wl_array_add(&wm->source_data, incr_chunk_size); else p = (char *) wm->source_data.data + wm->source_data.size; available = wm->source_data.alloc - current; len = read(fd, p, available); if (len == -1) { weston_log("read error from data source: %m\n"); weston_wm_send_selection_notify(wm, XCB_ATOM_NONE); wl_event_source_remove(wm->property_source); close(fd); wl_array_release(&wm->source_data); } weston_log("read %d (available %d, mask 0x%x) bytes: \"%.*s\"\n", len, available, mask, len, (char *) p); wm->source_data.size = current + len; if (wm->source_data.size >= incr_chunk_size) { if (!wm->incr) { weston_log("got %zu bytes, starting incr\n", wm->source_data.size); wm->incr = 1; xcb_change_property(wm->conn, XCB_PROP_MODE_REPLACE, wm->selection_request.requestor, wm->selection_request.property, wm->atom.incr, 32, /* format */ 1, &incr_chunk_size); wm->selection_property_set = 1; wm->flush_property_on_delete = 1; wl_event_source_remove(wm->property_source); weston_wm_send_selection_notify(wm, wm->selection_request.property); } else if (wm->selection_property_set) { weston_log("got %zu bytes, waiting for " "property delete\n", wm->source_data.size); wm->flush_property_on_delete = 1; wl_event_source_remove(wm->property_source); } else { weston_log("got %zu bytes, " "property deleted, seting new property\n", wm->source_data.size); weston_wm_flush_source_data(wm); } } else if (len == 0 && !wm->incr) { weston_log("non-incr transfer complete\n"); /* Non-incr transfer all done. */ weston_wm_flush_source_data(wm); weston_wm_send_selection_notify(wm, wm->selection_request.property); xcb_flush(wm->conn); wl_event_source_remove(wm->property_source); close(fd); wl_array_release(&wm->source_data); wm->selection_request.requestor = XCB_NONE; } else if (len == 0 && wm->incr) { weston_log("incr transfer complete\n"); wm->flush_property_on_delete = 1; if (wm->selection_property_set) { weston_log("got %zu bytes, waiting for " "property delete\n", wm->source_data.size); } else { weston_log("got %zu bytes, " "property deleted, seting new property\n", wm->source_data.size); weston_wm_flush_source_data(wm); } xcb_flush(wm->conn); wl_event_source_remove(wm->property_source); close(wm->data_source_fd); wm->data_source_fd = -1; close(fd); } else { weston_log("nothing happened, buffered the bytes\n"); } return 1; }
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); }