xdg_shell_v6: Use create/destroy pattern 17/323417/1
authorSeunghun Lee <shiin.lee@samsung.com>
Thu, 24 Apr 2025 09:27:22 +0000 (18:27 +0900)
committerTizen Window System <tizen.windowsystem@gmail.com>
Mon, 28 Apr 2025 07:44:54 +0000 (16:44 +0900)
This patch adds and uses e_desktop_xdg_shell_v6_{create,destroy} for
consistency other shells.

Change-Id: I47119e941e768e5bf4f566e7671d0d8cde142a11

src/bin/server/e_desktop_shell.c
src/bin/server/e_desktop_shell_private.h
src/bin/server/e_desktop_xdg_shell_v6.c
src/bin/server/e_desktop_xdg_shell_v6_intern.h

index 35d58ad3ebe633685c01de58ae29564457be9820..13a886c4539f2e9ff69632c96046e4d25202dc5e 100644 (file)
 
 struct _E_Desktop_Shell
 {
+   struct wl_display *display;
    struct wl_global *wl_shell;
    struct wl_global *xdg_shell_v5;
+   E_Desktop_Xdg_Shell_V6 *xdg_shell_v6;
    E_Comp_Wl_Shell *e_comp_wl_shell;
 
    struct wl_listener display_destroy;
@@ -27,16 +29,52 @@ struct _E_Desktop_Shell
      } events;
 };
 
+static void _shell_destroy(E_Desktop_Shell *shell);
+
 static void
 _shell_cb_display_destroy(struct wl_listener *listener, void *data)
 {
    E_Desktop_Shell *shell = wl_container_of(listener, shell, display_destroy);
 
    wl_signal_emit(&shell->events.destroy, shell);
+   _shell_destroy(shell);
+}
+
+static E_Desktop_Shell *
+_shell_create(struct wl_display *display)
+{
+   E_Desktop_Shell *shell;
+
+   shell = calloc(1, sizeof(*shell));
+   if (!shell)
+     return NULL;
+
+   wl_signal_init(&shell->events.destroy);
+   wl_signal_init(&shell->events.new_toplevel);
+
+   shell->display = display;
+
+   shell->display_destroy.notify = _shell_cb_display_destroy;
+   wl_display_add_destroy_listener(display, &shell->display_destroy);
+
+   return shell;
+}
+
+static void
+_shell_destroy(E_Desktop_Shell *shell)
+{
+   if (shell->e_comp_wl_shell)
+     e_comp_wl_shell_destroy(shell->e_comp_wl_shell);
+
+   if (shell->xdg_shell_v6)
+     e_desktop_shell_xdg_shell_v6_destroy(shell->xdg_shell_v6);
+
+   if (shell->xdg_shell_v5)
+     wl_global_destroy(shell->xdg_shell_v5);
+
+   if (shell->wl_shell)
+     wl_global_destroy(shell->wl_shell);
 
-   e_comp_wl_shell_destroy(shell->e_comp_wl_shell);
-   wl_global_destroy(shell->wl_shell);
-   wl_global_destroy(shell->xdg_shell_v5);
    wl_list_remove(&shell->display_destroy.link);
    free(shell);
 }
@@ -46,43 +84,39 @@ e_desktop_shell_create(struct wl_display *display)
 {
    E_Desktop_Shell *shell;
 
-   shell = calloc(1, sizeof(*shell));
+   shell = _shell_create(display);
    if (!shell)
      return NULL;
 
-   wl_signal_init(&shell->events.destroy);
-   wl_signal_init(&shell->events.new_toplevel);
-
    shell->wl_shell = e_desktop_wl_shell_create(display);
    if (!shell->wl_shell)
-     goto err_wl_shell;
+     goto err;
 
    shell->xdg_shell_v5 = e_desktop_xdg_shell_v5_create(display);
    if (!shell->xdg_shell_v5)
-     goto err_xdg_shell_v5;
+     goto err;
 
-   if (!e_desktop_xdg_shell_v6_init(display, shell))
-     goto err_xdg_shell_v6;
+   shell->xdg_shell_v6 = e_desktop_xdg_shell_v6_create(shell);
+   if (!shell->xdg_shell_v6)
+     goto err;
 
    shell->e_comp_wl_shell = e_comp_wl_shell_create(shell);
    if (!shell->e_comp_wl_shell)
-     goto err_xdg_shell_v6;
-
-   shell->display_destroy.notify = _shell_cb_display_destroy;
-   wl_display_add_destroy_listener(display, &shell->display_destroy);
+     goto err;
 
    return shell;
-
-err_xdg_shell_v6:
-   wl_global_destroy(shell->xdg_shell_v5);
-err_xdg_shell_v5:
-   wl_global_destroy(shell->wl_shell);
-err_wl_shell:
-   free(shell);
+err:
+   _shell_destroy(shell);
 
    return NULL;
 }
 
+EINTERN struct wl_display *
+e_desktop_shell_display_get(E_Desktop_Shell *shell)
+{
+   return shell->display;
+}
+
 EINTERN void
 e_desktop_shell_toplevel_add(E_Desktop_Shell *shell, E_Desktop_Toplevel *toplevel)
 {
index 51a619a039cc7d63a7383cd9aab8d81939b5cc4f..b3b0ab233d81caa4ddcb0158c9da9f9f6ccd4ecb 100644 (file)
@@ -26,6 +26,7 @@ struct _E_Desktop_Toplevel
    E_Desktop_Surface surface;
 };
 
+struct wl_display *e_desktop_shell_display_get(E_Desktop_Shell *shell);
 void e_desktop_shell_toplevel_add(E_Desktop_Shell *shell, E_Desktop_Toplevel *toplevel);
 
 void e_desktop_toplevel_init(E_Desktop_Toplevel *toplevel, E_Desktop_Surface_Interface *iface, E_Surface *e_surface, struct wl_resource *shell_surface_resource);
index 9d0ac42bac5bb97b684becb76e02a6ec54dbc711..8296c41f3767f10367836f9ed77cdd37463af421 100644 (file)
@@ -12,8 +12,6 @@
 
 #define LOG(f, x...)  INF("XDG6 <LOG> " f, ##x)
 
-typedef struct _E_Desktop_Xdg_Shell_V6 E_Desktop_Xdg_Shell_V6;
-
 struct _E_Desktop_Xdg_Shell_V6
 {
    E_Desktop_Shell *desktop_shell;
@@ -42,54 +40,45 @@ typedef struct
    struct wl_listener surface_commit;
 } E_Desktop_Xdg_Toplevel_V6;
 
-static void _shell_cb_destroy(struct wl_listener *listener, void *data);
 static void _shell_cb_new_surface(struct wl_listener *listener, void *data);
 static void _toplevel_add(E_Desktop_Xdg_Shell_V6 *shell, struct ds_xdg_surface_v6 *ds_xdg_surface);
 static void _toplevel_cb_xdg_surface_destroy(struct wl_listener *listener, void *data);
 static E_Desktop_Xdg_Toplevel_V6 *_toplevel_from_shell_surface_resource(struct wl_resource *shsurface_resource);
 
-EINTERN Eina_Bool
-e_desktop_xdg_shell_v6_init(struct wl_display *display, E_Desktop_Shell *desktop_shell)
+EINTERN E_Desktop_Xdg_Shell_V6 *
+e_desktop_xdg_shell_v6_create(E_Desktop_Shell *desktop_shell)
 {
-   static E_Desktop_Xdg_Shell_V6 shell = { .ds_xdg_shell = NULL };
-
-   LOG("Initializing Xdg_Shell_V6");
-
-   if (shell.ds_xdg_shell)
-     {
-        LOG("Xdg_Shell_V6 already initialized");
-        return EINA_TRUE;
-     }
+   E_Desktop_Xdg_Shell_V6 *shell;
 
+   shell = calloc(1, sizeof(*shell));
+   if (!shell)
+     return NULL;
 
-   shell.ds_xdg_shell = ds_xdg_shell_v6_create(display);
-   if (!shell.ds_xdg_shell)
+   shell->ds_xdg_shell = ds_xdg_shell_v6_create(e_desktop_shell_display_get(desktop_shell));
+   if (!shell->ds_xdg_shell)
      {
         ERR("Could not create ds_xdg_shell_v6");
-        return EINA_FALSE;
+        free(shell);
+        return NULL;
      }
 
-   shell.desktop_shell = desktop_shell;
+   shell->desktop_shell = desktop_shell;
+
+   shell->new_surface.notify = _shell_cb_new_surface;
+   ds_xdg_shell_v6_add_new_surface_listener(shell->ds_xdg_shell, &shell->new_surface);
 
-   shell.destroy.notify = _shell_cb_destroy;
-   ds_xdg_shell_v6_add_destroy_listener(shell.ds_xdg_shell, &shell.destroy);
-   shell.new_surface.notify = _shell_cb_new_surface;
-   ds_xdg_shell_v6_add_new_surface_listener(shell.ds_xdg_shell, &shell.new_surface);
+   LOG("Create Xdg_Shell_V6");
 
-   return EINA_TRUE;
+   return shell;
 }
 
-static void
-_shell_cb_destroy(struct wl_listener *listener, void *data)
+EINTERN void
+e_desktop_shell_xdg_shell_v6_destroy(E_Desktop_Xdg_Shell_V6 *shell)
 {
-   E_Desktop_Xdg_Shell_V6 *shell;
-
    LOG("Destroy Xdg_Shell_V6");
 
-   shell = wl_container_of(listener, shell, destroy);
-   wl_list_remove(&shell->destroy.link);
    wl_list_remove(&shell->new_surface.link);
-   shell->ds_xdg_shell = NULL;
+   free(shell);
 }
 
 static void
index 449e7250fb0c32cfd15aafce73267f4d9ecb477a..fcadff45cc714722cd25a00004e71ae385a8b8ce 100644 (file)
@@ -4,7 +4,9 @@
 #include "e_intern.h"
 #include "e_desktop_shell_intern.h"
 
+typedef struct _E_Desktop_Xdg_Shell_V6 E_Desktop_Xdg_Shell_V6;
 
-EINTERN Eina_Bool e_desktop_xdg_shell_v6_init(struct wl_display *display, E_Desktop_Shell *desktop_shell);
+E_Desktop_Xdg_Shell_V6 *e_desktop_xdg_shell_v6_create(E_Desktop_Shell *desktop_shell);
+void e_desktop_shell_xdg_shell_v6_destroy(E_Desktop_Xdg_Shell_V6 *shell);
 
 #endif