/* This is a basic grid arrange function that tries to give each window an * equal space. */ static void arrange(struct screen *screen) { struct window *window = NULL; unsigned num_columns, num_rows, column_index, row_index; struct swc_rectangle geometry; struct swc_rectangle *screen_geometry = &screen->swc->usable_geometry; if (screen->num_windows == 0) return; num_columns = ceil(sqrt(screen->num_windows)); num_rows = screen->num_windows / num_columns + 1; window = wl_container_of(screen->windows.next, window, link); for (column_index = 0; &window->link != &screen->windows; ++column_index) { geometry.x = screen_geometry->x + border_width + screen_geometry->width * column_index / num_columns; geometry.width = screen_geometry->width / num_columns - 2 * border_width; if (column_index == screen->num_windows % num_columns) --num_rows; for (row_index = 0; row_index < num_rows; ++row_index) { geometry.y = screen_geometry->y + border_width + screen_geometry->height * row_index / num_rows; geometry.height = screen_geometry->height / num_rows - 2 * border_width; swc_window_set_geometry(window->swc, &geometry); window = wl_container_of(window->link.next, window, link); } } }
static void pointer_handle_focus_surface_destroy (struct wl_listener *listener, void *data) { MetaWaylandPointer *pointer = wl_container_of (listener, pointer, focus_surface_listener); meta_wayland_pointer_set_focus (pointer, NULL); }
static void handle_buffer_destroy(struct wld_destructor * destructor) { struct pool_reference * reference = wl_container_of(destructor, reference, destructor); unref_pool(reference->pool); }
static void handle_set_title(struct wl_listener *listener, void *data) { struct sway_xdg_shell_v6_view *xdg_shell_v6_view = wl_container_of(listener, xdg_shell_v6_view, set_title); struct sway_view *view = &xdg_shell_v6_view->view; view_update_title(view, false); view_execute_criteria(view); }
static void handle_resize(struct view_handler * handler, uint32_t old_width, uint32_t old_height) { struct panel * panel = wl_container_of(handler, panel, view_handler); update_position(panel); }
static int attach(struct view * view, struct wld_buffer * buffer) { struct cursor_plane * plane = wl_container_of(view, plane, view); if (buffer) { union wld_object object; if (!wld_export(buffer, WLD_DRM_OBJECT_HANDLE, &object)) { ERROR("Could not get export buffer to DRM handle\n"); /* XXX: Not the best error code, but we don't know better until wld * returns an actual error code. */ return -EINVAL; } if (swc.active && drmModeSetCursor(swc.drm->fd, plane->crtc, object.u32, buffer->width, buffer->height) < 0) { ERROR("Could not set cursor: %s\n", strerror(errno)); return -errno; } } else if (swc.active && drmModeSetCursor(swc.drm->fd, plane->crtc, 0, 0, 0) < 0) { ERROR("Could not unset cursor: %s\n", strerror(errno)); return -errno; } view_set_size_from_buffer(view, buffer); return 0; }
static void destroy_drag_focus (struct wl_listener *listener, void *data) { MetaWaylandDragGrab *grab = wl_container_of (listener, grab, drag_focus_listener); grab->drag_focus_data_device = NULL; }
static CoglandBuffer * cogland_buffer_from_resource (struct wl_resource *resource) { CoglandBuffer *buffer; struct wl_listener *listener; listener = wl_resource_get_destroy_listener (resource, cogland_buffer_destroy_handler); if (listener) { buffer = wl_container_of (listener, buffer, destroy_listener); } else { buffer = g_slice_new0 (CoglandBuffer); buffer->resource = resource; wl_signal_init (&buffer->destroy_signal); buffer->destroy_listener.notify = cogland_buffer_destroy_handler; wl_resource_add_destroy_listener (resource, &buffer->destroy_listener); } return buffer; }
MetaWaylandBuffer * meta_wayland_buffer_from_resource (struct wl_resource *resource) { MetaWaylandBuffer *buffer; struct wl_listener *listener; listener = wl_resource_get_destroy_listener (resource, meta_wayland_buffer_destroy_handler); if (listener) { buffer = wl_container_of (listener, buffer, destroy_listener); } else { buffer = g_object_new (META_TYPE_WAYLAND_BUFFER, NULL); buffer->resource = resource; buffer->destroy_listener.notify = meta_wayland_buffer_destroy_handler; wl_resource_add_destroy_listener (resource, &buffer->destroy_listener); } return buffer; }
QWaylandClient *QWaylandClient::fromWlClient(wl_client *wlClient) { if (!wlClient) return 0; QWaylandClient *client = Q_NULLPTR; wl_listener *l = wl_client_get_destroy_listener(wlClient, QWaylandClientPrivate::client_destroy_callback); if (l) client = reinterpret_cast<QWaylandClientPrivate::Listener *>( wl_container_of(l, (QWaylandClientPrivate::Listener *)0, listener))->parent; if (!client) { // The original idea was to create QWaylandClient instances when // a client bound wl_compositor, but it's legal for a client to // bind several times resulting in multiple QWaylandClient // instances for the same wl_client therefore we create it from // here on demand client = new QWaylandClient(wlClient); QtWayland::Compositor::instance()->m_clients.append(client); } return client; }
static int launcher_logind_activate_vt(struct weston_launcher *launcher, int vt) { struct launcher_logind *wl = wl_container_of(launcher, wl, base); DBusMessage *m; bool b; int r; m = dbus_message_new_method_call("org.freedesktop.login1", "/org/freedesktop/login1/seat/self", "org.freedesktop.login1.Seat", "SwitchTo"); if (!m) return -ENOMEM; b = dbus_message_append_args(m, DBUS_TYPE_UINT32, &vt, DBUS_TYPE_INVALID); if (!b) { r = -ENOMEM; goto err_unref; } dbus_connection_send(wl->dbus, m, NULL); r = 0; err_unref: dbus_message_unref(m); return r; }
static int launcher_direct_open(struct weston_launcher *launcher_base, const char *path, int flags) { struct launcher_direct *launcher = wl_container_of(launcher_base, launcher, base); struct stat s; int fd; fd = open(path, flags | O_CLOEXEC); if (fd == -1) return -1; if (fstat(fd, &s) == -1) { close(fd); return -1; } if (major(s.st_rdev) == DRM_MAJOR) { launcher->drm_fd = fd; if (!is_drm_master(fd)) { weston_log("drm fd not master\n"); close(fd); return -1; } } return fd; }
struct weston_desktop_seat * weston_desktop_seat_from_seat(struct weston_seat *wseat) { struct wl_listener *listener; struct weston_desktop_seat *seat; listener = wl_signal_get(&wseat->destroy_signal, weston_desktop_seat_destroy); if (listener != NULL) return wl_container_of(listener, seat, seat_destroy_listener); seat = zalloc(sizeof(struct weston_desktop_seat)); if (seat == NULL) return NULL; seat->seat = wseat; seat->seat_destroy_listener.notify = weston_desktop_seat_destroy; wl_signal_add(&wseat->destroy_signal, &seat->seat_destroy_listener); seat->popup_grab.keyboard.interface = &weston_desktop_seat_keyboard_popup_grab_interface; seat->popup_grab.pointer.interface = &weston_desktop_seat_pointer_popup_grab_interface; seat->popup_grab.touch.interface = &weston_desktop_seat_touch_popup_grab_interface; wl_list_init(&seat->popup_grab.surfaces); return seat; }
static void handle_commit(struct wl_listener *listener, void *data) { struct sway_xdg_shell_v6_view *xdg_shell_v6_view = wl_container_of(listener, xdg_shell_v6_view, commit); struct sway_view *view = &xdg_shell_v6_view->view; struct wlr_xdg_surface_v6 *xdg_surface_v6 = view->wlr_xdg_surface_v6; if (view->container->node.instruction) { wlr_xdg_surface_v6_get_geometry(xdg_surface_v6, &view->geometry); transaction_notify_view_ready_by_serial(view, xdg_surface_v6->configure_serial); } else { struct wlr_box new_geo; wlr_xdg_surface_v6_get_geometry(xdg_surface_v6, &new_geo); struct sway_container *con = view->container; if ((new_geo.width != con->surface_width || new_geo.height != con->surface_height)) { // The view has unexpectedly sent a new size desktop_damage_view(view); view_update_size(view, new_geo.width, new_geo.height); memcpy(&view->geometry, &new_geo, sizeof(struct wlr_box)); desktop_damage_view(view); transaction_commit_dirty(); } else { memcpy(&view->geometry, &new_geo, sizeof(struct wlr_box)); } } view_damage_from(view); }
/* Tall layout */ static void tall_next_col(struct col *col) { struct tall_layout *layout = wl_container_of(col, layout, grid.col); grid(&layout->grid, &layout->grid_area, layout->grid.num_windows, MIN(layout->grid.num_windows, layout->num_columns)); }
static void toggle(struct config_node * node) { struct tag * tag = wl_container_of(node, tag, config.toggle); struct screen * screen = velox.active_screen; screen_set_tags(velox.active_screen, screen->mask ^ tag->mask); update(); }
static void pointer_handle_cursor_surface_destroy (struct wl_listener *listener, void *data) { MetaWaylandPointer *pointer = wl_container_of (listener, pointer, cursor_surface_destroy_listener); set_cursor_surface (pointer, NULL); meta_wayland_pointer_update_cursor_surface (pointer); }
static void weston_desktop_seat_destroy(struct wl_listener *listener, void *data) { struct weston_desktop_seat *seat = wl_container_of(listener, seat, seat_destroy_listener); free(seat); }
static void weston_desktop_seat_popup_grab_keyboard_cancel(struct weston_keyboard_grab *grab) { struct weston_desktop_seat *seat = wl_container_of(grab, seat, popup_grab.keyboard); weston_desktop_seat_popup_grab_end(seat); }
static void weston_desktop_seat_popup_grab_pointer_cancel(struct weston_pointer_grab *grab) { struct weston_desktop_seat *seat = wl_container_of(grab, seat, popup_grab.pointer); weston_desktop_seat_popup_grab_end(seat); }
static void keyboard_surface_destroyed(struct wl_listener *listener, void *data) { struct wlb_keyboard *keyboard = wl_container_of(listener, keyboard, surface_destroy_listener); wlb_keyboard_set_focus(keyboard, NULL); }
static void weston_desktop_seat_popup_grab_touch_cancel(struct weston_touch_grab *grab) { struct weston_desktop_seat *seat = wl_container_of(grab, seat, popup_grab.touch); weston_desktop_seat_popup_grab_end(seat); }
static void pointer_handle_sprite_destroy (struct wl_listener *listener, void *data) { ClaylandSeat *seat = wl_container_of (listener, seat, sprite_destroy_listener); seat->sprite = NULL; }
static void cogland_buffer_destroy_handler (struct wl_listener *listener, void *data) { CoglandBuffer *buffer = wl_container_of (listener, buffer, destroy_listener); wl_signal_emit (&buffer->destroy_signal, buffer); g_slice_free (CoglandBuffer, buffer); }
static void apply(struct config_node * node) { struct tag * tag = wl_container_of(node, tag, config.apply); struct window * window = velox.active_screen->focus; if (window) window_set_tag(window, tag); update(); }
static void destroy_data_device_source (struct wl_listener *listener, void *data) { MetaWaylandDragGrab *drag_grab = wl_container_of (listener, drag_grab, drag_data_source_listener); drag_grab->drag_data_source = NULL; data_device_end_drag_grab (drag_grab); }
static void destroy_selection_data_source (struct wl_listener *listener, void *data) { MetaWaylandDataDevice *data_device = wl_container_of (listener, data_device, selection_data_source_listener); MetaWaylandSeat *seat = wl_container_of (data_device, seat, data_device); struct wl_resource *data_device_resource; struct wl_client *focus_client = NULL; data_device->selection_data_source = NULL; focus_client = meta_wayland_keyboard_get_focus_client (&seat->keyboard); if (focus_client) { data_device_resource = wl_resource_find_for_client (&data_device->resource_list, focus_client); if (data_device_resource) wl_data_device_send_selection (data_device_resource, NULL); } }
static void destroy_offer_data_source (struct wl_listener *listener, void *data) { MetaWaylandDataOffer *offer; offer = wl_container_of (listener, offer, source_destroy_listener); offer->source = NULL; }
static void surface_handle_pending_buffer_destroy (struct wl_listener *listener, void *data) { CoglandSurface *surface = wl_container_of (listener, surface, pending.buffer_destroy_listener); surface->pending.buffer = NULL; }
static void activate(struct config_node * node) { struct tag * tag = wl_container_of(node, tag, config.activate); struct screen * screen = velox.active_screen; screen->last_mask = screen->mask; screen_set_tags(screen, tag->mask); update(); }