desktop-shell: Implement common ping-pong mechanism between wl_shell and xdg_shell
authorJaehoon Jeong <jh01.j@samsung.com>
Fri, 3 Jul 2015 06:07:11 +0000 (15:07 +0900)
committerJaehoon Jeong <jh01.j@samsung.com>
Tue, 7 Jul 2015 10:05:12 +0000 (19:05 +0900)
    - Move ping-pong's ownership to shell_client_t from shell_surface_t
      for support xdg_shell.pong()
    - Shell module may send ping to shell_surface_t,
      for check that surface can take focus.
    - fix typo

Change-Id: Iaeba2986991e1242d74039100052fc41a80fef8f

desktop-shell/src/Makefile.am
desktop-shell/src/desktop-shell-internal.h
desktop-shell/src/shell-surface.c
desktop-shell/src/shell.c
desktop-shell/src/wl-shell.c
desktop-shell/src/xdg-shell.c

index 24f55d6..be9ffa7 100644 (file)
@@ -4,7 +4,7 @@ include_HEADERS = pepper-desktop-shell.h
 pkgconfigdir = $(libdir)/pkgconfig
 pkgconfig_DATA = pepper-desktop-shell.pc
 
-libpepper_desktop_shell_la_CFLAGS = $(PEPPER_DESKTOP_SHELL_CFLAGS) -I$(top_srcdir)/protocol/
+libpepper_desktop_shell_la_CFLAGS = $(PEPPER_DESKTOP_SHELL_CFLAGS) -Wall -I$(top_srcdir)/protocol/
 libpepper_desktop_shell_la_LIBADD = $(PEPPER_DESKTOP_SHELL_LIBS)
 
 libpepper_desktop_shell_la_SOURCES =            \
index 91add34..7ca4478 100644 (file)
@@ -29,9 +29,19 @@ struct desktop_shell
 
 struct shell_client
 {
-    desktop_shell_t     *shell;
-    struct wl_resource  *resource;
-    struct wl_list       link;
+    desktop_shell_t         *shell;
+    struct wl_resource      *resource;
+    struct wl_client        *client;
+
+    struct wl_listener       client_destroy_listener;
+
+    /* Ping-Pong */
+    struct wl_event_source  *ping_timer;
+    pepper_bool_t            need_pong;
+    uint32_t                 ping_serial;
+    pepper_bool_t            irresponsive;
+
+    struct wl_list           link;
 };
 
 typedef enum
@@ -67,12 +77,6 @@ struct shell_surface
     /* Data structures per surface type */
     shell_surface_type_t     type;
 
-    /* Ping-Pong */
-    struct wl_event_source *ping_timer;
-    pepper_bool_t           need_pong;
-    uint32_t                ping_serial;
-    pepper_bool_t           unresponsive;
-
     /* Listeners */
     struct wl_listener      client_destroy_listener;
     struct wl_listener      surface_destroy_listener;
@@ -94,6 +98,15 @@ void
 shell_surface_ping(shell_surface_t *shsurf);
 
 void
+shell_client_handle_pong(shell_client_t *shell_client, uint32_t serial);
+
+void
+shell_surface_handle_pong(shell_surface_t *shsurf, uint32_t serial);
+
+void
+remove_ping_timer(shell_client_t *shell_client);
+
+void
 shell_surface_set_type(shell_surface_t *shsurf, shell_surface_type_t type);
 
 void
index 0a9b35f..d76d528 100644 (file)
@@ -1,13 +1,13 @@
 #include "desktop-shell-internal.h"
-#include <stdlib.h>
+#include "xdg-shell-server-protocol.h"
 
-static void
-remove_ping_timer(shell_surface_t *shsurf)
+void
+remove_ping_timer(shell_client_t *shell_client)
 {
-    if (shsurf->ping_timer)
+    if (shell_client->ping_timer)
     {
-        wl_event_source_remove(shsurf->ping_timer);
-        shsurf->ping_timer = NULL;
+        wl_event_source_remove(shell_client->ping_timer);
+        shell_client->ping_timer = NULL;
     }
 }
 
@@ -20,10 +20,6 @@ handle_client_destroy(struct wl_listener *listener, void *data)
     if (!wl_list_empty(&shsurf->client_destroy_listener.link))
         wl_list_remove(&shsurf->client_destroy_listener.link);
     wl_list_init(&shsurf->client_destroy_listener.link);
-
-    remove_ping_timer(shsurf);
-
-    /* client_destroy -> client's surface destroy -> handle_surface_destroy */
 }
 
 static void
@@ -38,8 +34,6 @@ handle_surface_destroy(struct wl_listener *listener, void *data)
 
     wl_list_remove(&shsurf->surface_destroy_listener.link);
 
-    /* We don't need to destroy pepper_view_t */
-
     if (shsurf->resource)
         wl_resource_destroy(shsurf->resource);
 
@@ -49,8 +43,6 @@ handle_surface_destroy(struct wl_listener *listener, void *data)
     if (shsurf->class_)
         free(shsurf->class_);
 
-    remove_ping_timer(shsurf);
-
     wl_list_remove(&shsurf->parent_link);
 
     wl_list_for_each_safe(child, tmp, &shsurf->child_list, parent_link)
@@ -115,6 +107,9 @@ shell_surface_create(shell_client_t *shell_client, pepper_object_t *surface,
     /* Set shell_surface_t to pepper_surface_t */
     set_shsurf_to_surface(surface, shsurf);
 
+    wl_list_init(&shsurf->link);
+    wl_list_insert(&shsurf->shell->shell_surface_list, &shsurf->link);
+
     return shsurf;
 
 error:
@@ -127,9 +122,9 @@ error:
 static int
 handle_ping_timeout(void *data)
 {
-    shell_surface_t *shsurf = data;
+    shell_client_t *shell_client = data;
 
-    shsurf->unresponsive = PEPPER_TRUE;
+    shell_client->irresponsive = PEPPER_TRUE;
 
     /* TODO: Display wait cursor */
 
@@ -139,40 +134,67 @@ handle_ping_timeout(void *data)
 void
 shell_surface_ping(shell_surface_t *shsurf)
 {
-    struct wl_display *display = pepper_compositor_get_display(shsurf->shell->compositor);
-    const char *role;
+    shell_client_t      *shell_client = shsurf->shell_client;
+    struct wl_display   *display;
+    const char          *role;
 
     /* Already stucked, do not send another ping */
-    if (shsurf->unresponsive)
+    if (shell_client->irresponsive)
     {
-        handle_ping_timeout(shsurf);
+        handle_ping_timeout(shell_client);
         return ;
     }
 
-    if (!shsurf->ping_timer)
+    display = pepper_compositor_get_display(shsurf->shell->compositor);
+
+    if (!shell_client->ping_timer)
     {
         struct wl_event_loop *loop = wl_display_get_event_loop(display);
 
-        shsurf->ping_timer = wl_event_loop_add_timer(loop, handle_ping_timeout, shsurf);
+        shell_client->ping_timer = wl_event_loop_add_timer(loop, handle_ping_timeout, shell_client);
 
-        if (!shsurf->ping_timer)
+        if (!shell_client->ping_timer)
         {
             PEPPER_ERROR("Failed to add timer event source.\n");
             return;
         }
     }
 
-    wl_event_source_timer_update(shsurf->ping_timer, DESKTOP_SHELL_PING_TIMEOUT);
+    wl_event_source_timer_update(shell_client->ping_timer, DESKTOP_SHELL_PING_TIMEOUT);
 
-    shsurf->ping_serial = wl_display_next_serial(display);
-    shsurf->need_pong   = PEPPER_TRUE;
+    shell_client->ping_serial = wl_display_next_serial(display);
+    shell_client->need_pong   = PEPPER_TRUE;
 
     role = pepper_surface_get_role(shsurf->surface);
 
     if (!strcmp(role, "wl_shell_surface"))
-        wl_shell_surface_send_ping(shsurf->resource, shsurf->ping_serial);
+        wl_shell_surface_send_ping(shsurf->resource, shell_client->ping_serial);
+    else if (!strcmp(role, "xdg_surface") || !strcmp(role, "xdg_popup"))
+        xdg_shell_send_ping(shell_client->resource, shell_client->ping_serial);
+    else
+        PEPPER_ASSERT(0);
+}
 
-    /* TODO: Do another protocol specific ping. */
+void
+shell_client_handle_pong(shell_client_t *shell_client, uint32_t serial)
+{
+    /* Client response right ping_serial */
+    if (shell_client->need_pong && shell_client->ping_serial == serial)
+    {
+        wl_event_source_timer_update(shell_client->ping_timer, 0);    /* disarms the timer */
+
+        shell_client->irresponsive = PEPPER_FALSE;
+        shell_client->need_pong    = PEPPER_FALSE;
+        shell_client->ping_serial  = 0;
+
+        /* TODO: Stop displaying wait cursor */
+    }
+}
+
+void
+shell_surface_handle_pong(shell_surface_t *shsurf, uint32_t serial)
+{
+    shell_client_handle_pong(shsurf->shell_client, serial);
 }
 
 void
index 7c9f445..6467673 100644 (file)
@@ -1,6 +1,20 @@
 #include "desktop-shell-internal.h"
 #include <stdlib.h>
 
+static void
+handle_shell_client_destroy(struct wl_listener *listener, void *data)
+{
+    shell_client_t *shell_client = pepper_container_of(listener,
+                                                       shell_client_t,
+                                                       client_destroy_listener);
+
+    remove_ping_timer(shell_client);
+
+    wl_list_remove(&shell_client->link);
+
+    free(shell_client);
+}
+
 shell_client_t *
 shell_client_create(desktop_shell_t *shell, struct wl_client *client,
                     const struct wl_interface *interface, const void *implementation,
@@ -22,11 +36,16 @@ shell_client_create(desktop_shell_t *shell, struct wl_client *client,
         free(shell_client);
         return NULL;
     }
-    wl_resource_set_implementation(shell_client->resource, implementation, shell_client, NULL);
+
+    shell_client->shell  = shell;
+    shell_client->client = client;
+
+    shell_client->client_destroy_listener.notify = handle_shell_client_destroy;
+    wl_client_add_destroy_listener(client, &shell_client->client_destroy_listener);
 
     wl_list_insert(&shell->shell_client_list, &shell_client->link);
 
-    shell_client->shell = shell;
+    wl_resource_set_implementation(shell_client->resource, implementation, shell_client, NULL);
 
     return shell_client;
 }
index 542a9c9..0b61be9 100644 (file)
@@ -5,17 +5,7 @@ wl_shell_surface_pong(struct wl_client *client, struct wl_resource *resource, ui
 {
     shell_surface_t *shsurf = wl_resource_get_user_data(resource);
 
-    /* Client response right ping_serial */
-    if (shsurf->need_pong && shsurf->ping_serial == serial)
-    {
-        wl_event_source_timer_update(shsurf->ping_timer, 0);    /* disarms the timer */
-
-        shsurf->unresponsive = PEPPER_FALSE;
-        shsurf->need_pong    = PEPPER_FALSE;
-        shsurf->ping_serial  = 0;
-
-        /* TODO: Stop displaying wait cursor */
-    }
+    shell_surface_handle_pong(shsurf, serial);
 }
 
 static void
@@ -163,3 +153,9 @@ init_wl_shell(desktop_shell_t *shell)
 
     return PEPPER_TRUE;
 }
+
+void
+fini_wl_shell(desktop_shell_t *shell)
+{
+    /* TODO */
+}
index 3584c47..9c5cc6a 100644 (file)
@@ -225,7 +225,9 @@ xdg_shell_pong(struct wl_client     *client,
                struct wl_resource   *resource,
                uint32_t              serial)
 {
-    /* TODO: */
+    shell_client_t *shell_client = wl_resource_get_user_data(resource);
+
+    shell_client_handle_pong(shell_client, serial);
 }
 
 static const struct xdg_shell_interface xdg_shell_implementation =
@@ -256,3 +258,9 @@ init_xdg_shell(desktop_shell_t *shell)
 
     return PEPPER_TRUE;
 }
+
+void
+fini_xdg_shell(desktop_shell_t *shell)
+{
+    /* TODO */
+}