static int headless_compositor_create_output(struct headless_compositor *c, struct headless_parameters *param) { struct headless_output *output; struct wl_event_loop *loop; output = zalloc(sizeof *output); if (output == NULL) return -1; output->mode.flags = WL_OUTPUT_MODE_CURRENT | WL_OUTPUT_MODE_PREFERRED; output->mode.width = param->width; output->mode.height = param->height; output->mode.refresh = 60000; wl_list_init(&output->base.mode_list); wl_list_insert(&output->base.mode_list, &output->mode.link); output->base.current_mode = &output->mode; weston_output_init(&output->base, &c->base, 0, 0, param->width, param->height, param->transform, 1); output->base.make = "weston"; output->base.model = "headless"; loop = wl_display_get_event_loop(c->base.wl_display); output->finish_frame_timer = wl_event_loop_add_timer(loop, finish_frame_handler, output); output->base.start_repaint_loop = headless_output_start_repaint_loop; output->base.repaint = headless_output_repaint; output->base.destroy = headless_output_destroy; output->base.assign_planes = NULL; output->base.set_backlight = NULL; output->base.set_dpms = NULL; output->base.switch_mode = NULL; if (c->use_pixman) { output->image_buf = malloc(param->width * param->height * 4); if (!output->image_buf) return -1; output->image = pixman_image_create_bits(PIXMAN_x8r8g8b8, param->width, param->height, output->image_buf, param->width * 4); if (pixman_renderer_output_create(&output->base) < 0) return -1; pixman_renderer_output_set_buffer(&output->base, output->image); } wl_list_insert(c->base.output_list.prev, &output->base.link); return 0; }
struct tag * tag_new(unsigned index, const char * name) { struct tag * tag; if (!(tag = malloc(sizeof *tag))) goto error0; if (!(tag->name = strdup(name))) goto error1; tag->mask = TAG_MASK(index); tag->screen = NULL; tag->global = wl_global_create(velox.display, &velox_tag_interface, 1, tag, &bind_tag); if (!tag->global) goto error2; tag->config.group.name = strdup(tag->name); tag->config.group.type = CONFIG_NODE_TYPE_GROUP; wl_list_init(&tag->config.group.group); wl_list_insert(&tag_group.group, &tag->config.group.link); tag->config.name.name = "name"; tag->config.name.type = CONFIG_NODE_TYPE_PROPERTY; tag->config.name.property.set = &set_name; wl_list_insert(&tag->config.group.group, &tag->config.name.link); tag->config.activate.name = "activate"; tag->config.activate.type = CONFIG_NODE_TYPE_ACTION; tag->config.activate.action.run = &activate; wl_list_insert(&tag->config.group.group, &tag->config.activate.link); tag->config.toggle.name = "toggle"; tag->config.toggle.type = CONFIG_NODE_TYPE_ACTION; tag->config.toggle.action.run = &toggle; wl_list_insert(&tag->config.group.group, &tag->config.toggle.link); tag->config.apply.name = "apply"; tag->config.apply.type = CONFIG_NODE_TYPE_ACTION; tag->config.apply.action.run = &apply; wl_list_insert(&tag->config.group.group, &tag->config.apply.link); wl_list_init(&tag->resources); return tag; error2: free(tag->name); error1: free(tag); error0: return NULL; }
void window_add_config_nodes() { wl_list_insert(&window_group.group, &border_width_property.link); wl_list_insert(&window_group.group, &border_color_active_property.link); wl_list_insert(&window_group.group, &border_color_inactive_property.link); wl_list_insert(&window_group.group, &begin_move_action.link); wl_list_insert(&window_group.group, &end_move_action.link); wl_list_insert(&window_group.group, &begin_resize_action.link); wl_list_insert(&window_group.group, &end_resize_action.link); wl_list_insert(&window_group.group, &switch_layer_action.link); wl_list_insert(&window_group.group, &close_action.link); wl_list_insert(config_root, &window_group.link); }
void wlb_keyboard_create_resource(struct wlb_keyboard *keyboard, struct wl_client *client, uint32_t id) { struct wl_resource *resource; int null_fd; resource = wl_resource_create(client, &wl_keyboard_interface, 1, id); if (!resource) { wl_client_post_no_memory(client); return; } wl_resource_set_implementation(resource, &keyboard_interface, NULL, unlink_resource); wl_list_insert(&keyboard->resource_list, wl_resource_get_link(resource)); if (keyboard->keymap.data) { wl_keyboard_send_keymap(resource, keyboard->keymap.format, keyboard->keymap.fd, keyboard->keymap.size); } else { null_fd = open("/dev/null", O_RDONLY); wl_keyboard_send_keymap(resource, WL_KEYBOARD_KEYMAP_FORMAT_NO_KEYMAP, null_fd, 0); close(null_fd); } }
struct window * window_create(struct display *display, const char *title, int32_t width, int32_t height) { struct window *window; window = malloc(sizeof *window); if (window == NULL) return NULL; memset(window, 0, sizeof *window); window->display = display; window->title = strdup(title); window->surface = wl_compositor_create_surface(display->compositor); window->allocation.x = 0; window->allocation.y = 0; window->allocation.width = width; window->allocation.height = height; window->saved_allocation = window->allocation; window->margin = 16; window->decoration = 1; if (display->drm) window->buffer_type = WINDOW_BUFFER_TYPE_DRM; else window->buffer_type = WINDOW_BUFFER_TYPE_SHM; wl_surface_set_user_data(window->surface, window); wl_list_insert(display->window_list.prev, &window->link); return window; }
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->input_device = wl_display_bind(ewd->wl.display, id, &wl_input_device_interface); wl_list_insert(ewd->inputs.prev, &input->link); wl_input_device_add_listener(input->input_device, &_ecore_wl_input_listener, input); wl_input_device_set_user_data(input->input_device, input); input->data_device = wl_data_device_manager_get_data_device(ewd->wl.data_device_manager, input->input_device); wl_data_device_add_listener(input->data_device, &_ecore_wl_data_listener, input); ewd->input = input; }
static void seat_get_pointer (struct wl_client *client, struct wl_resource *resource, uint32_t id) { ClaylandSeat *seat = wl_resource_get_user_data (resource); struct wl_resource *cr; cr = wl_client_add_object (client, &wl_pointer_interface, &pointer_interface, id, seat); wl_list_insert (&seat->pointer.resource_list, wl_resource_get_link (cr)); wl_resource_set_destructor (cr, unbind_resource); if (seat->pointer.focus && wl_resource_get_client (seat->pointer.focus->resource) == client) { ClaylandSurface *surface; wl_fixed_t sx, sy; surface = (ClaylandSurface *) seat->pointer.focus; transform_stage_point_fixed (surface, seat->pointer.x, seat->pointer.y, &sx, &sy); clayland_pointer_set_focus (&seat->pointer, seat->pointer.focus, sx, sy); } }
static void drag_grab_focus(struct wl_grab *grab, uint32_t time, struct wl_surface *surface, int32_t x, int32_t y) { struct wl_input_device *device = container_of(grab, struct wl_input_device, drag_grab); struct wl_resource *resource, *offer; if (device->drag_focus_resource) { wl_resource_post_event(device->drag_focus_resource, WL_DATA_DEVICE_LEAVE); wl_list_remove(&device->drag_focus_listener.link); device->drag_focus_resource = NULL; device->drag_focus = NULL; } if (surface) resource = find_resource(&device->drag_resource_list, surface->resource.client); if (surface && resource) { offer = wl_data_source_send_offer(device->drag_data_source, resource); wl_resource_post_event(resource, WL_DATA_DEVICE_ENTER, time, surface, x, y, offer); device->drag_focus = surface; device->drag_focus_listener.func = destroy_drag_focus; wl_list_insert(resource->destroy_listener_list.prev, &device->drag_focus_listener.link); device->drag_focus_resource = resource; grab->focus = surface; } }
static void handle_surface(struct test_client *client) { uint32_t id; struct wl_resource *resource; struct weston_surface *surface; struct text_test_data *data = client->data; struct weston_seat *seat; assert(sscanf(client->buf, "surface %u", &id) == 1); fprintf(stderr, "got surface id %u\n", id); resource = wl_client_get_object(client->client, id); assert(resource); assert(strcmp(resource->object.interface->name, "wl_surface") == 0); surface = (struct weston_surface *) resource; weston_surface_configure(surface, 100, 100, 200, 200); weston_surface_update_transform(surface); weston_surface_set_color(surface, 0.0, 0.0, 0.0, 1.0); data->layer = malloc(sizeof *data->layer); weston_layer_init(data->layer, &client->compositor->cursor_layer.link); wl_list_insert(&data->layer->surface_list, &surface->layer_link); weston_surface_damage(surface); seat = get_seat(client); client->compositor->focus = 1; /* Make it work even if pointer is * outside X window. */ wl_keyboard_set_focus(&seat->keyboard, &surface->surface); test_client_send(client, "create-text-model\n"); client->handle = handle_text_model; }
/** * Monitor filedescriptor for incoming events and * call set-up callbacks */ struct wldbg_fd_callback * wldbg_monitor_fd(struct wldbg *wldbg, int fd, int (*dispatch)(int fd, void *data), void *data) { struct epoll_event ev; struct wldbg_fd_callback *cb; cb = malloc(sizeof *cb); if (!cb) return NULL; ev.events = EPOLLIN; ev.data.ptr = cb; if (epoll_ctl(wldbg->epoll_fd, EPOLL_CTL_ADD, fd, &ev) == -1) { perror("Failed adding fd to epoll"); free(cb); return NULL; } cb->fd = fd; cb->data = data; cb->dispatch = dispatch; wl_list_insert(&wldbg->monitored_fds, &cb->link); return cb; }
static void seat_get_keyboard (struct wl_client *client, struct wl_resource *resource, uint32_t id) { ClaylandSeat *seat = wl_resource_get_user_data (resource); struct wl_resource *cr; cr = wl_client_add_object (client, &wl_keyboard_interface, NULL, id, seat); wl_list_insert (&seat->keyboard.resource_list, wl_resource_get_link (cr)); wl_resource_set_destructor (cr, unbind_resource); wl_keyboard_send_keymap (cr, WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1, seat->keyboard.xkb_info.keymap_fd, seat->keyboard.xkb_info.keymap_size); if (seat->keyboard.focus && wl_resource_get_client (seat->keyboard.focus->resource) == client) { clayland_keyboard_set_focus (&seat->keyboard, seat->keyboard.focus); clayland_data_device_set_keyboard_focus (seat); } }
static void cycle(struct wlc_compositor *compositor) { struct wl_list *l = wlc_space_get_userdata(wlc_compositor_get_focused_space(compositor)); if (!l) return; struct wlc_view *v; uint32_t count = 0; wlc_view_for_each_user(v, l) if (is_tiled(v)) ++count; // Check that we have at least two tiled views // so we don't get in infinite loop. if (count <= 1) return; // Cycle until we hit next tiled view. struct wl_list *p; do { p = l->prev; wl_list_remove(l->prev); wl_list_insert(l, p); } while (!is_tiled(wlc_view_from_user_link(p))); relayout(wlc_compositor_get_focused_space(compositor)); }
static void get_shell_surface (struct wl_client *client, struct wl_resource *resource, uint32_t id, struct wl_resource *surface_resource) { CoglandSurface *surface = surface_resource->data; CoglandShellSurface *shell_surface = g_new0 (CoglandShellSurface, 1); if (surface->has_shell_surface) { wl_resource_post_error (surface_resource, WL_DISPLAY_ERROR_INVALID_OBJECT, "wl_shell::get_shell_surface already requested"); return; } shell_surface->resource.destroy = destroy_shell_surface; shell_surface->resource.object.id = id; shell_surface->resource.object.interface = &wl_shell_surface_interface; shell_surface->resource.object.implementation = (void (**) (void)) &cogl_shell_surface_interface; shell_surface->resource.data = shell_surface; shell_surface->surface = surface; shell_surface->surface_destroy_listener.func = shell_handle_surface_destroy; wl_list_insert (surface->wayland_surface.resource.destroy_listener_list.prev, &shell_surface->surface_destroy_listener.link); surface->has_shell_surface = TRUE; wl_client_add_resource (client, &shell_surface->resource); }
void weston_desktop_seat_popup_grab_add_surface(struct weston_desktop_seat *seat, struct wl_list *link) { assert(seat->popup_grab.client != NULL); wl_list_insert(&seat->popup_grab.surfaces, link); }
static void weston_zoom_transition(struct weston_output *output, uint32_t type, wl_fixed_t x, wl_fixed_t y) { if (output->zoom.type != type) { /* Set from/to points and start animation */ output->zoom.spring_xy.current = 0.0; output->zoom.spring_xy.previous = 0.0; output->zoom.spring_xy.target = 1.0; if (wl_list_empty(&output->zoom.animation_xy.link)) { output->zoom.animation_xy.frame_counter = 0; wl_list_insert(output->animation_list.prev, &output->zoom.animation_xy.link); output->zoom.from.x = (type == ZOOM_FOCUS_TEXT) ? x : output->zoom.text_cursor.x; output->zoom.from.y = (type == ZOOM_FOCUS_TEXT) ? y : output->zoom.text_cursor.y; } else { output->zoom.from.x = output->zoom.current.x; output->zoom.from.y = output->zoom.current.y; } output->zoom.to.x = (type == ZOOM_FOCUS_POINTER) ? x : output->zoom.text_cursor.x; output->zoom.to.y = (type == ZOOM_FOCUS_POINTER) ? y : output->zoom.text_cursor.y; output->zoom.current.x = output->zoom.from.x; output->zoom.current.y = output->zoom.from.y; output->zoom.type = type; } if (output->zoom.level != output->zoom.spring_z.current) { output->zoom.spring_z.target = output->zoom.level; if (wl_list_empty(&output->zoom.animation_z.link)) { output->zoom.animation_z.frame_counter = 0; wl_list_insert(output->animation_list.prev, &output->zoom.animation_z.link); } } output->dirty = 1; weston_output_damage(output); }
static int headless_compositor_create_output(struct headless_compositor *c, int width, int height) { struct headless_output *output; struct wl_event_loop *loop; output = malloc(sizeof *output); if (output == NULL) return -1; memset(output, 0, sizeof *output); output->mode.flags = WL_OUTPUT_MODE_CURRENT | WL_OUTPUT_MODE_PREFERRED; output->mode.width = width; output->mode.height = height; output->mode.refresh = 60; wl_list_init(&output->base.mode_list); wl_list_insert(&output->base.mode_list, &output->mode.link); output->base.current = &output->mode; weston_output_init(&output->base, &c->base, 0, 0, width, height, WL_OUTPUT_TRANSFORM_NORMAL); output->base.make = "weston"; output->base.model = "headless"; weston_output_move(&output->base, 0, 0); loop = wl_display_get_event_loop(c->base.wl_display); output->finish_frame_timer = wl_event_loop_add_timer(loop, finish_frame_handler, output); output->base.origin = output->base.current; output->base.repaint = headless_output_repaint; output->base.destroy = headless_output_destroy; output->base.assign_planes = NULL; output->base.set_backlight = NULL; output->base.set_dpms = NULL; output->base.switch_mode = NULL; wl_list_insert(c->base.output_list.prev, &output->base.link); return 0; }
void registerResource(wl_list *list, wl_resource *resource) { wl_list_insert(list, &resource->link); wl_listener *listener = new wl_listener; listener->notify = unregisterResourceCallback; wl_signal_add(&resource->destroy_signal, listener); }
static int queue_event(struct wl_display *display, int len) { uint32_t p[2], id; int opcode, size; struct wl_proxy *proxy; struct wl_closure *closure; const struct wl_message *message; struct wl_event_queue *queue; wl_connection_copy(display->connection, p, sizeof p); id = p[0]; opcode = p[1] & 0xffff; size = p[1] >> 16; if (len < size) return 0; proxy = wl_map_lookup(&display->objects, id); if (proxy == WL_ZOMBIE_OBJECT) { wl_connection_consume(display->connection, size); return size; } else if (proxy == NULL) { wl_connection_consume(display->connection, size); return size; } message = &proxy->object.interface->events[opcode]; closure = wl_connection_demarshal(display->connection, size, &display->objects, message); if (!closure) return -1; if (create_proxies(proxy, closure) < 0) { wl_closure_destroy(closure); return -1; } if (wl_closure_lookup_objects(closure, &display->objects) != 0) { wl_closure_destroy(closure); return -1; } increase_closure_args_refcount(closure); proxy->refcount++; closure->proxy = proxy; if (proxy == &display->proxy) queue = &display->display_queue; else queue = proxy->queue; if (wl_list_empty(&queue->event_list)) pthread_cond_signal(&queue->cond); wl_list_insert(queue->event_list.prev, &closure->link); return size; }
static void screen_add_window(struct screen *screen, struct window *window) { window->screen = screen; wl_list_insert(&screen->windows, &window->link); ++screen->num_windows; swc_window_show(window->swc); arrange(screen); }
bool swc_drm_create_screens(struct wl_list * screens) { drmModeRes * resources; drmModeConnector * connector; uint32_t index; struct swc_output * output; uint32_t taken_crtcs = 0; if (!(resources = drmModeGetResources(swc.drm->fd))) { ERROR("Could not get DRM resources\n"); return false; } for (index = 0; index < resources->count_connectors; ++index, drmModeFreeConnector(connector)) { connector = drmModeGetConnector(swc.drm->fd, resources->connectors[index]); if (connector->connection == DRM_MODE_CONNECTED) { uint32_t crtc_index; uint32_t id; if (!find_available_crtc(resources, connector, taken_crtcs, &crtc_index)) { WARNING("Could not find CRTC for connector %u\n", index); continue; } if (!find_available_id(&id)) { WARNING("No more available output IDs\n"); drmModeFreeConnector(connector); break; } if (!(output = swc_output_new(connector))) continue; output->screen = screen_new(resources->crtcs[crtc_index], output); output->screen->id = id; taken_crtcs |= 1 << crtc_index; drm.taken_ids |= 1 << id; wl_list_insert(screens, &output->screen->link); } } drmModeFreeResources(resources); return true; }
void data_device_bind(struct data_device * data_device, struct wl_client * client, uint32_t id) { struct wl_resource * resource; resource = wl_resource_create(client, &wl_data_device_interface, 1, id); wl_resource_set_implementation(resource, &data_device_implementation, data_device, &swc_remove_resource); wl_list_insert(&data_device->resources, &resource->link); }
static void buffer_release(void *data, struct wl_buffer *buffer) { struct wayland_shm_buffer *sb = data; if (sb->output) { wl_list_insert(&sb->output->shm.free_buffers, &sb->free_link); } else { wayland_shm_buffer_destroy(sb); } }
void Animation::run(struct weston_output *output, uint32_t duration, Animation::Flags flags) { stop(); m_duration = duration; m_runFlags = flags; m_animation.ani.frame_counter = 0; wl_list_insert(&output->animation_list, &m_animation.ani.link); weston_compositor_schedule_repaint(output->compositor); }
int main(void) { struct wl_list list; wl_list_init(&list); struct item *i1 = malloc(sizeof *i1); wl_list_insert(&list, &i1->link); i1->number = 8; assert(list.next == &i1->link); return 0; }
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 move_resources_for_client(struct wl_list *destination, struct wl_list *source, struct wl_client *client) { struct wl_resource *resource, *tmp; wl_resource_for_each_safe(resource, tmp, source) { if (wl_resource_get_client(resource) == client) { wl_list_remove(wl_resource_get_link(resource)); wl_list_insert(destination, wl_resource_get_link(resource)); } } }
static void handle_global(void *data, struct wl_registry *registry, uint32_t id, const char *interface, uint32_t version) { struct client *client = data; struct input *input; struct output *output; struct test *test; struct global *global; global = xzalloc(sizeof *global); global->name = id; global->interface = strdup(interface); assert(interface); global->version = version; wl_list_insert(client->global_list.prev, &global->link); if (strcmp(interface, "wl_compositor") == 0) { client->wl_compositor = wl_registry_bind(registry, id, &wl_compositor_interface, 1); } else if (strcmp(interface, "wl_seat") == 0) { input = xzalloc(sizeof *input); input->wl_seat = wl_registry_bind(registry, id, &wl_seat_interface, 1); wl_seat_add_listener(input->wl_seat, &seat_listener, input); client->input = input; } else if (strcmp(interface, "wl_shm") == 0) { client->wl_shm = wl_registry_bind(registry, id, &wl_shm_interface, 1); wl_shm_add_listener(client->wl_shm, &shm_listener, client); } else if (strcmp(interface, "wl_output") == 0) { output = xzalloc(sizeof *output); output->wl_output = wl_registry_bind(registry, id, &wl_output_interface, 1); wl_output_add_listener(output->wl_output, &output_listener, output); client->output = output; } else if (strcmp(interface, "wl_test") == 0) { test = xzalloc(sizeof *test); test->wl_test = wl_registry_bind(registry, id, &wl_test_interface, 1); wl_test_add_listener(test->wl_test, &test_listener, test); client->test = test; } }
static void weston_zoom_transition(struct weston_output *output, wl_fixed_t x, wl_fixed_t y) { if (output->zoom.level != output->zoom.spring_z.current) { output->zoom.spring_z.target = output->zoom.level; if (wl_list_empty(&output->zoom.animation_z.link)) { output->zoom.animation_z.frame_counter = 0; wl_list_insert(output->animation_list.prev, &output->zoom.animation_z.link); } } output->dirty = 1; weston_output_damage(output); }
WL_EXPORT struct weston_binding * weston_compositor_add_debug_binding(struct weston_compositor *compositor, uint32_t key, weston_key_binding_handler_t handler, void *data) { struct weston_binding *binding; binding = weston_compositor_add_binding(compositor, key, 0, 0, 0, handler, data); wl_list_insert(compositor->debug_binding_list.prev, &binding->link); return binding; }
static void get_data_device(struct wl_client *client, struct wl_resource *manager_resource, uint32_t id, struct wl_resource *input_device) { struct wl_input_device *device = input_device->data; struct wl_resource *resource; resource = wl_client_add_object(client, &wl_data_device_interface, &data_device_interface, id, device); wl_list_insert(&device->drag_resource_list, &resource->link); resource->destroy = unbind_data_device; }