implement the wtz_shell protocol 28/293228/2
authorSooChan Lim <sc1.lim@samsung.com>
Thu, 9 Mar 2023 09:23:22 +0000 (18:23 +0900)
committerJunseok Kim <juns.kim@samsung.com>
Tue, 23 May 2023 04:13:41 +0000 (13:13 +0900)
This is the first implementation for the wtz_shell and wtz_surface interface.

Change-Id: I37ddcb2d4cacbc4e557b23d64b9f0bb249668f9f

configure.ac
packaging/enlightenment.spec
src/bin/Makefile.mk
src/bin/e_comp_wl.c
src/bin/e_comp_wl.h
src/bin/e_wtz_shell.c [new file with mode: 0644]
src/bin/e_wtz_shell.h [new file with mode: 0644]

index 05eb211639ace0f0c24dd9f4ce1cc30f64c65552..423b81fb3b74deda080f9d24644a1b3b31837048 100755 (executable)
@@ -370,7 +370,7 @@ AC_MSG_RESULT([${have_shm_open}])
 AC_SUBST(SHM_OPEN_LIBS)
 
 if test "x${e_cv_want_wayland_only}" != "xno" || test "x${e_cv_want_wayland_clients}" != "xno";then
-  PKG_CHECK_MODULES([WAYLAND], [wayland-server >= 1.8.0 xkbcommon uuid xdg-shell-unstable-v5-server xdg-shell-unstable-v6-server tizen-remote-surface-server scaler-server screenshooter-server tizen-extension-server tizen-launch-server tizen-surface-server tizen-dpms-server eom-server presentation-time-server tizen-hwc-server linux-explicit-synchronization-unstable-v1-server wtz-foreign-server relative-pointer-unstable-v1-server pointer-constraints-unstable-v1-server wtz-screen-server],
+  PKG_CHECK_MODULES([WAYLAND], [wayland-server >= 1.8.0 xkbcommon uuid xdg-shell-unstable-v5-server xdg-shell-unstable-v6-server tizen-remote-surface-server scaler-server screenshooter-server tizen-extension-server tizen-launch-server tizen-surface-server tizen-dpms-server eom-server presentation-time-server tizen-hwc-server linux-explicit-synchronization-unstable-v1-server wtz-foreign-server relative-pointer-unstable-v1-server pointer-constraints-unstable-v1-server wtz-screen-server wtz-shell-server],
     [
       have_wayland=yes
       AC_DEFINE_UNQUOTED([HAVE_WAYLAND],[1],[enable wayland support])
index 1a381bed0d12ce112ebb1a5b796ae3dafdfac0d6..0e530c98406826bf042494b3ddcb50afb330cd8e 100644 (file)
@@ -64,6 +64,7 @@ BuildRequires:  pkgconfig(wtz-foreign-server)
 BuildRequires:  pkgconfig(pointer-constraints-unstable-v1-server)
 BuildRequires:  pkgconfig(relative-pointer-unstable-v1-server)
 BuildRequires:  pkgconfig(wtz-screen-server)
+BuildRequires:  pkgconfig(wtz-shell-server)
 Requires:       libwayland-extension-server
 
 # for gtest/gmock
index daf5fc7807e012eb8185ae8f5e01ed62fd5d94b2..58ebb02642390cc03f248bf72f8948fbd1e083c1 100644 (file)
@@ -147,7 +147,8 @@ src/bin/e_devicemgr_private.h \
 src/bin/e_msg.h        \
 src/bin/e_foreign.h \
 src/bin/e_foreign_private.h \
-src/bin/e_map.h
+src/bin/e_map.h \
+src/bin/e_wtz_shell.h
 
 enlightenment_src = \
 src/bin/e_actions.c \
@@ -286,7 +287,8 @@ src/bin/e_devicemgr_wl.c \
 src/bin/e_msg.c \
 src/bin/e_foreign.c \
 src/bin/e_foreign_shell.c \
-src/bin/e_map.c
+src/bin/e_map.c \
+src/bin/e_wtz_shell.c
 
 src_bin_enlightenment_CPPFLAGS = $(E_CPPFLAGS) -DEFL_BETA_API_SUPPORT -DEFL_EO_API_SUPPORT -DE_LOGGING=2 @WAYLAND_CFLAGS@ $(TTRACE_CFLAGS) $(DLOG_CFLAGS) $(PIXMAN_CFLAGS) $(POLICY_CFLAGS) $(EGL_CFLAGS)
 if HAVE_LIBGOMP
index efea3438d9b8b7380aa0eca128f701cffb84136f..416a648b80ccea59515e0143fd7b053e111167cd 100644 (file)
@@ -1,5 +1,6 @@
 #include "e.h"
 #include "e_foreign.h"
+#include "e_wtz_shell.h"
 #include <tizen-extension-server-protocol.h>
 
 #include <relative-pointer-unstable-v1-server-protocol.h>
@@ -4534,7 +4535,7 @@ e_comp_wl_init(void)
      }
 
    e_comp_wl_shell_init();
-
+   e_wtz_shell_init();
 #ifdef HAVE_WAYLAND_TBM
    e_comp_wl_tbm_init();
 #endif
@@ -4619,6 +4620,7 @@ e_comp_wl_shutdown(void)
 
    e_pixmap_shutdown();
 
+   e_wtz_shell_shutdown();
    e_comp_wl_shell_shutdown();
    e_comp_wl_input_shutdown();
 
index f3541aae5194e875eb6741a8d823da0dfc95e5f5..d0611f664227737dc72acb195e3c61ace431f92e 100644 (file)
@@ -520,6 +520,7 @@ struct _E_Comp_Wl_Client_Data
    const char *role_name;
 
    struct wl_list pointer_constraints;
+   Eina_Bool wtz_surface_assigned;
 };
 
 struct _E_Comp_Wl_Output
diff --git a/src/bin/e_wtz_shell.c b/src/bin/e_wtz_shell.c
new file mode 100644 (file)
index 0000000..530fefe
--- /dev/null
@@ -0,0 +1,280 @@
+#include "e.h"
+#include <wtz-shell-server-protocol.h>
+
+#ifdef LOG
+#undef LOG
+#endif
+#ifdef ERR
+#undef ERR
+#endif
+
+#define LOG(f, e, x...)  ELOGF("WTZ <LOG>", f, e, ##x)
+#define ERR(f, e, x...)  ELOGF("WTZ <ERR>", f, e, ##x)
+
+#define E_WTZ_SURFACE_TYPE (int)0xE0b91100
+
+typedef struct _E_Wtz_Shell               E_Wtz_Shell;
+typedef struct _E_Wtz_Surface             E_Wtz_Surface;
+
+struct _E_Wtz_Shell
+{
+   struct wl_client     *wclient;
+   struct wl_resource   *resource;        /* wtz_shell resource */
+   Eina_List            *shell_surfaces;  /* list of all E_Wtz_Surface belonging to shell */
+};
+
+struct _E_Wtz_Surface
+{
+   E_Object e_obj_inherit;
+
+   struct wl_resource   *resource;        /* wl_resource for Zwtz_Surface_V6 */
+   E_Client             *ec;              /* E_Client corresponding Wtz_Surface */
+   E_Wtz_Shell          *shell;           /* Wtz_Shell created Wtz_Surface */
+};
+
+static struct wl_global *global_resource = NULL;
+
+/**********************************************************
+ * Implementation for Wtz_Surface
+ **********************************************************/
+
+static void
+_e_wtz_surface_free(E_Wtz_Surface *shell_surface)
+{
+   free(shell_surface);
+}
+
+static void
+_e_wtz_surface_del(E_Wtz_Surface *shell_surface)
+{
+   E_Wtz_Shell *shell = shell_surface->shell;
+
+   shell->shell_surfaces = eina_list_remove(shell->shell_surfaces, shell_surface);
+}
+
+static void
+_e_wtz_surface_cb_destroy(struct wl_client *client,
+        struct wl_resource *resource)
+{
+   wl_resource_destroy(resource);
+}
+
+static void
+_e_wtz_surface_cb_assign_screen(struct wl_client *client,
+        struct wl_resource *resource, struct wl_resource *screen_resource)
+{
+   E_Wtz_Surface *shell_surface;
+   E_Zone *zone;
+
+   shell_surface = wl_resource_get_user_data(resource);
+   EINA_SAFETY_ON_NULL_RETURN(shell_surface);
+
+   zone = wl_resource_get_user_data(screen_resource);
+   EINA_SAFETY_ON_NULL_RETURN(zone);
+
+   // TODO:
+}
+
+static const struct wtz_surface_interface _e_wtz_surface_interface =
+{
+   _e_wtz_surface_cb_destroy,
+   _e_wtz_surface_cb_assign_screen,
+};
+
+static void
+_e_wtz_surface_cb_resource_destroy(struct wl_resource *resource)
+{
+   E_Wtz_Surface *shell_surface;
+
+   shell_surface = wl_resource_get_user_data(resource);
+   EINA_SAFETY_ON_NULL_RETURN(shell_surface);
+
+   /* set null after destroying shell of e_client, ec will be freed */
+   shell_surface->ec = NULL;
+
+   e_object_del(E_OBJECT(shell_surface));
+}
+
+static E_Wtz_Surface *
+_e_wtz_surface_create(E_Wtz_Shell *shell,
+                      struct wl_resource *surface,
+                      uint32_t id)
+{
+   E_Wtz_Surface *shell_surface;
+   E_Client *ec;
+
+   ec = wl_resource_get_user_data(surface);
+   EINA_SAFETY_ON_NULL_RETURN_VAL(shell, NULL);
+
+   ELOGF("WTZ_SHELL", "Create Wtz_Surface", ec);
+
+   if (ec->comp_data->wtz_surface_assigned)
+     {
+        ERR("wtz_surface is already assigned.", ec);
+        wl_resource_post_error(surface, WL_DISPLAY_ERROR_INVALID_OBJECT,
+                    "Could not assign shell surface to wl_surface");
+        return NULL;
+     }
+
+   shell_surface = E_OBJECT_ALLOC(E_Wtz_Surface, E_WTZ_SURFACE_TYPE,
+                           _e_wtz_surface_free);
+   if (!shell_surface)
+     {
+        wl_client_post_no_memory(shell->wclient);
+        return NULL;
+     }
+   e_object_del_func_set(E_OBJECT(shell_surface),
+               E_OBJECT_CLEANUP_FUNC(_e_wtz_surface_del));
+
+   shell_surface->resource = wl_resource_create(shell->wclient,
+                    &wtz_surface_interface, 1, id);
+   if (!shell_surface->resource)
+     {
+        ERR("Could not create wl_resource for wtz surface", ec);
+        wl_client_post_no_memory(shell->wclient);
+        e_object_del(E_OBJECT(shell_surface));
+        return NULL;
+     }
+
+   wl_resource_set_implementation(shell_surface->resource,
+            &_e_wtz_surface_interface, shell_surface,
+            _e_wtz_surface_cb_resource_destroy);
+
+
+   ec->comp_data->wtz_surface_assigned = EINA_TRUE;
+   shell_surface->shell = shell;
+   shell_surface->ec = ec;
+   shell->shell_surfaces =
+            eina_list_append(shell->shell_surfaces, shell_surface);
+
+   return shell_surface;
+}
+/* End of Wtz_surface */
+
+/**********************************************************
+ * Implementation for Wtz_Shell
+ **********************************************************/
+static void
+_e_wtz_shell_cb_destroy(struct wl_client *client, struct wl_resource *resource)
+{
+   LOG("Destroy Wtz_Shell", NULL);
+
+   wl_resource_destroy(resource);
+}
+
+static void
+_e_wtz_shell_cb_surface_get(struct wl_client *client,
+        struct wl_resource *resource, uint32_t id, struct wl_resource *surface)
+{
+   E_Wtz_Shell *shell;
+   E_Wtz_Surface *shell_surface;
+
+   shell = wl_resource_get_user_data(resource);
+   EINA_SAFETY_ON_NULL_RETURN(shell);
+
+   shell_surface = _e_wtz_surface_create(shell, surface, id);
+   if (!shell_surface)
+     {
+        ERR("Failed to create E_Wtz_Surface", NULL);
+        return;
+     }
+}
+
+static const struct wtz_shell_interface _e_wtz_shell_interface =
+{
+   _e_wtz_shell_cb_destroy,
+   _e_wtz_shell_cb_surface_get,
+};
+
+static E_Wtz_Shell *
+_e_wtz_shell_create(struct wl_client *client, struct wl_resource *resource)
+{
+   E_Wtz_Shell *shell;
+
+   shell = E_NEW(E_Wtz_Shell, 1);
+   if (!shell)
+     return NULL;
+
+   shell->wclient = client;
+   shell->resource = resource;
+
+   return shell;
+}
+
+static void
+_e_wtz_shell_destroy(E_Wtz_Shell *shell)
+{
+   E_Wtz_Surface *shell_surface;
+
+   EINA_LIST_FREE(shell->shell_surfaces, shell_surface)
+     {
+        /* Do we need to do it even though shell is just about to be destroyed? */
+        shell_surface->shell = NULL;
+     }
+
+   free(shell);
+}
+
+static void
+_e_wtz_shell_cb_unbind(struct wl_resource *resource)
+{
+   E_Wtz_Shell *shell;
+
+   LOG("Unbind Wtz_Shell", NULL);
+
+   shell = wl_resource_get_user_data(resource);
+   if (!shell)
+     {
+        ERR("No E_Wtz_Shell in wl_resource", NULL);
+        return;
+     }
+
+   _e_wtz_shell_destroy(shell);
+}
+
+static void
+_e_wtz_shell_cb_bind(struct wl_client *client, void *data EINA_UNUSED,
+        uint32_t version, uint32_t id)
+{
+   E_Wtz_Shell *shell;
+   struct wl_resource *resource;
+
+   /* Create resource for wtz_shell */
+   resource = wl_resource_create(client, &wtz_shell_interface, version, id);
+   if (!resource)
+     goto err_res;
+
+
+   shell = _e_wtz_shell_create(client, resource);
+   if (!shell)
+     {
+        ERR("Failed to create E_Wtz_Shell", NULL);
+        goto err_shell;
+     }
+
+   wl_resource_set_implementation(resource, &_e_wtz_shell_interface,
+                shell, _e_wtz_shell_cb_unbind);
+
+   return;
+err_shell:
+   wl_resource_destroy(resource);
+err_res:
+   wl_client_post_no_memory(client);
+}
+/* End of Wtz_shell */
+
+EINTERN Eina_Bool
+e_wtz_shell_init(void)
+{
+   global_resource = wl_global_create(e_comp_wl->wl.disp, &wtz_shell_interface,
+                1, e_comp->wl_comp_data, _e_wtz_shell_cb_bind);
+   EINA_SAFETY_ON_NULL_RETURN_VAL(global_resource, EINA_FALSE);
+
+   return EINA_TRUE;
+}
+
+EINTERN void
+e_wtz_shell_shutdown(void)
+{
+   E_FREE_FUNC(global_resource, wl_global_destroy);
+}
diff --git a/src/bin/e_wtz_shell.h b/src/bin/e_wtz_shell.h
new file mode 100644 (file)
index 0000000..ab8d258
--- /dev/null
@@ -0,0 +1,10 @@
+#ifdef E_TYPEDEFS
+#else
+# ifndef E_WTZ_SHELL_V6_H
+#  define E_WTZ_SHELL_V6_H
+
+EINTERN Eina_Bool e_wtz_shell_init(void);
+EINTERN void      e_wtz_shell_shutdown(void);
+
+# endif
+#endif