struct egl_surface *overlay;
double overlay_y, overlay_target, overlay_previous;
+ struct wl_list surface_list;
+
/* Repaint state. */
struct wl_event_source *timer_source;
int repaint_needed;
GLuint texture;
struct wl_map map;
EGLSurface surface;
+
+ struct wl_list link;
};
static void
repaint(void *data)
{
struct egl_compositor *ec = data;
- struct wl_surface_iterator *iterator;
- struct wl_surface *surface;
struct egl_surface *es;
struct timespec ts;
uint32_t msecs;
draw_surface(ec->background);
- iterator = wl_surface_iterator_create(ec->wl_display, 0);
- while (wl_surface_iterator_next(iterator, &surface)) {
- es = wl_surface_get_data(surface);
- if (es == NULL)
- continue;
-
+ es = container_of(ec->surface_list.next,
+ struct egl_surface, link);
+ while (&es->link != &ec->surface_list) {
draw_surface(es);
+
+ es = container_of(es->link.next,
+ struct egl_surface, link);
}
- wl_surface_iterator_destroy(iterator);
draw_surface(ec->overlay);
notify_surface_create(struct wl_compositor *compositor,
struct wl_surface *surface)
{
+ struct egl_compositor *ec = (struct egl_compositor *) compositor;
struct egl_surface *es;
es = malloc(sizeof *es);
es->surface = EGL_NO_SURFACE;
wl_surface_set_data(surface, es);
+ wl_list_insert(ec->surface_list.prev, &es->link);
glGenTextures(1, &es->texture);
}
if (es == NULL)
return;
+ wl_list_remove(&es->link);
egl_surface_destroy(es, ec);
schedule_repaint(ec);
schedule_repaint(ec);
}
+static struct egl_surface *
+pick_surface(struct egl_compositor *ec, int32_t x, int32_t y)
+{
+ struct egl_surface *es;
+
+ es = container_of(ec->surface_list.prev,
+ struct egl_surface, link);
+ while (&es->link != &ec->surface_list) {
+ if (es->map.x <= x && x < es->map.x + es->map.width &&
+ es->map.y <= y && y < es->map.y + es->map.height)
+ return es;
+
+ es = container_of(es->link.prev,
+ struct egl_surface, link);
+ }
+
+ return NULL;
+}
+
static void
notify_pointer_button(struct wl_compositor *compositor,
struct wl_object *source,
{
struct egl_compositor *ec = (struct egl_compositor *) compositor;
struct egl_surface *es;
- struct wl_surface_iterator *iterator;
- struct wl_surface *surface, *target;
const int hotspot_x = 16, hotspot_y = 16;
int x, y;
x = ec->pointer->map.x + hotspot_x;
y = ec->pointer->map.y + hotspot_y;
- target = NULL;
- iterator = wl_surface_iterator_create(ec->wl_display, 0);
- while (wl_surface_iterator_next(iterator, &surface)) {
- es = wl_surface_get_data(surface);
- if (es == NULL)
- continue;
-
- if (es->map.x <= x && x < es->map.x + es->map.width &&
- es->map.y <= y && y < es->map.y + es->map.height)
- target = surface;
+ es = pick_surface(ec, x, y);
+ if (es) {
+ wl_list_remove(&es->link);
+ wl_list_insert(ec->surface_list.prev, &es->link);
}
- wl_surface_iterator_destroy(iterator);
- if (target)
- wl_display_raise_surface(ec->wl_display, target);
+ schedule_repaint(ec);
}
static void
create_input_devices(display);
+ wl_list_init(&ec->surface_list);
filename = getenv("WAYLAND_BACKGROUND");
if (filename == NULL)
filename = "background.jpg";
return 0;
}
-
-
-struct wl_surface_iterator {
- struct wl_list *head;
- struct wl_surface *surface;
- uint32_t mask;
-};
-
-WL_EXPORT struct wl_surface_iterator *
-wl_surface_iterator_create(struct wl_display *display, uint32_t mask)
-{
- struct wl_surface_iterator *iterator;
-
- iterator = malloc(sizeof *iterator);
- if (iterator == NULL)
- return NULL;
-
- iterator->head = &display->surface_list;
- iterator->surface = container_of(display->surface_list.next,
- struct wl_surface, link);
- iterator->mask = mask;
-
- return iterator;
-}
-
-WL_EXPORT int
-wl_surface_iterator_next(struct wl_surface_iterator *iterator,
- struct wl_surface **surface)
-{
- if (&iterator->surface->link == iterator->head)
- return 0;
-
- *surface = iterator->surface;
- iterator->surface = container_of(iterator->surface->link.next,
- struct wl_surface, link);
-
- return 1;
-}
-
-WL_EXPORT void
-wl_surface_iterator_destroy(struct wl_surface_iterator *iterator)
-{
- free(iterator);
-}
-
-WL_EXPORT void
-wl_display_raise_surface(struct wl_display *display, struct wl_surface *surface)
-{
- wl_list_remove(&surface->link);
- wl_list_insert(display->surface_list.prev, &surface->link);
-}
void wl_surface_set_data(struct wl_surface *surface, void *data);
void *wl_surface_get_data(struct wl_surface *surface);
-struct wl_surface_iterator;
-struct wl_surface_iterator *
-wl_surface_iterator_create(struct wl_display *display, uint32_t mask);
-int wl_surface_iterator_next(struct wl_surface_iterator *iterator,
- struct wl_surface **surface);
-void wl_surface_iterator_destroy(struct wl_surface_iterator *iterator);
-
struct wl_object *
wl_input_device_create(struct wl_display *display, const char *path);
void
wl_display_post_frame(struct wl_display *display,
uint32_t frame, uint32_t msecs);
-void
-wl_display_raise_surface(struct wl_display *display, struct wl_surface *surface);
struct wl_compositor {
const struct wl_compositor_interface *interface;