Pass button clicks through to compositor.
authorKristian Høgsberg <krh@redhat.com>
Wed, 10 Dec 2008 05:24:18 +0000 (00:24 -0500)
committerKristian Høgsberg <krh@redhat.com>
Wed, 10 Dec 2008 05:24:18 +0000 (00:24 -0500)
This lets us handle raising windows, which is useful.

egl-compositor.c
wayland.c
wayland.h

index f58b227..4f10cb9 100644 (file)
@@ -731,6 +731,38 @@ notify_pointer_motion(struct wl_compositor *compositor,
 }
 
 static void
+notify_pointer_button(struct wl_compositor *compositor,
+                     struct wl_object *source,
+                     int32_t button, int32_t state)
+{
+       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;
+       }
+       wl_surface_iterator_destroy(iterator);
+
+       if (target)
+               wl_display_raise_surface(ec->wl_display, target);
+}
+
+static void
 notify_key(struct wl_compositor *compositor,
           struct wl_object *source, uint32_t key, uint32_t state)
 {
@@ -754,6 +786,7 @@ static const struct wl_compositor_interface interface = {
        notify_surface_damage,
        notify_commit,
        notify_pointer_motion,
+       notify_pointer_button,
        notify_key
 };
 
index d218631..4c68bf6 100644 (file)
--- a/wayland.c
+++ b/wayland.c
@@ -677,8 +677,13 @@ WL_EXPORT void
 wl_display_post_button_event(struct wl_display *display,
                             struct wl_object *source, int button, int state)
 {
+       const struct wl_compositor_interface *interface;
        uint32_t p[4];
 
+       interface = display->compositor->interface;
+       interface->notify_pointer_button(display->compositor, source,
+                                        button, state);
+
        p[0] = source->id;
        p[1] = (sizeof p << 16) | WL_INPUT_BUTTON;
        p[2] = button;
@@ -833,3 +838,10 @@ 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);
+}
index 021d5d9..c13e3be 100644 (file)
--- a/wayland.h
+++ b/wayland.h
@@ -142,6 +142,8 @@ wl_display_post_key_event(struct wl_display *display,
 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;
@@ -174,6 +176,9 @@ struct wl_compositor_interface {
        void (*notify_pointer_motion)(struct wl_compositor *compositor,
                                      struct wl_object *source,
                                      int32_t x, int32_t y);
+       void (*notify_pointer_button)(struct wl_compositor *compositor,
+                                     struct wl_object *source,
+                                     int32_t button, int32_t state);
        void (*notify_key)(struct wl_compositor *compositor,
                           struct wl_object *source,
                           uint32_t key, uint32_t state);