[mutter] wayland/xdg-foreign: Move out ID generation helper to util.c



commit 34e7134db223d68c491c120f40725f1beeaf5f73
Author: Jonas Ådahl <jadahl gmail com>
Date:   Wed Jun 21 13:42:23 2017 +0800

    wayland/xdg-foreign: Move out ID generation helper to util.c
    
    It'll be used to generate ID in the same way in other places later.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=784199

 src/core/util-private.h                |    3 +++
 src/core/util.c                        |   16 ++++++++++++++++
 src/wayland/meta-wayland-xdg-foreign.c |   19 +++----------------
 3 files changed, 22 insertions(+), 16 deletions(-)
---
diff --git a/src/core/util-private.h b/src/core/util-private.h
index 7d1f4b9..421816b 100644
--- a/src/core/util-private.h
+++ b/src/core/util-private.h
@@ -34,4 +34,7 @@ void     meta_set_syncing (gboolean setting);
 void     meta_set_replace_current_wm (gboolean setting);
 void     meta_set_is_wayland_compositor (gboolean setting);
 
+char *   meta_generate_random_id (GRand *rand,
+                                  int    length);
+
 #endif
diff --git a/src/core/util.c b/src/core/util.c
index d596ea4..5b8de18 100644
--- a/src/core/util.c
+++ b/src/core/util.c
@@ -994,5 +994,21 @@ meta_get_locale_direction (void)
     }
 }
 
+char *
+meta_generate_random_id (GRand *rand,
+                         int    length)
+{
+  char *id;
+  int i;
+
+  /* Generate a random string of printable ASCII characters. */
+
+  id = g_new0 (char, length + 1);
+  for (i = 0; i < length; i++)
+    id[i] = (char) g_rand_int_range (rand, 32, 127);
+
+  return id;
+}
+
 /* eof util.c */
 
diff --git a/src/wayland/meta-wayland-xdg-foreign.c b/src/wayland/meta-wayland-xdg-foreign.c
index 9e19342..faf373e 100644
--- a/src/wayland/meta-wayland-xdg-foreign.c
+++ b/src/wayland/meta-wayland-xdg-foreign.c
@@ -28,6 +28,7 @@
 
 #include <wayland-server.h>
 
+#include "core/util-private.h"
 #include "wayland/meta-wayland-private.h"
 #include "wayland/meta-wayland-versions.h"
 #include "wayland/meta-wayland-xdg-shell.h"
@@ -80,21 +81,6 @@ xdg_exporter_destroy (struct wl_client   *client,
   wl_resource_destroy (resource);
 }
 
-static char *
-generate_handle (MetaWaylandXdgForeign *foreign)
-{
-  char *handle = g_new0 (char, META_XDG_FOREIGN_HANDLE_LENGTH + 1);
-  int i;
-
-  /*
-   * Generate a random string of printable ASCII characters.
-   */
-  for (i = 0; i < META_XDG_FOREIGN_HANDLE_LENGTH; i++)
-    handle[i] = (char) g_rand_int_range (foreign->rand, 32, 127);
-
-  return handle;
-}
-
 static void
 xdg_exported_destroy (struct wl_client   *client,
                       struct wl_resource *resource)
@@ -195,7 +181,8 @@ xdg_exporter_export (struct wl_client   *client,
 
   while (TRUE)
     {
-      handle = generate_handle (foreign);
+      handle = meta_generate_random_id (foreign->rand,
+                                        META_XDG_FOREIGN_HANDLE_LENGTH);
 
       if (!g_hash_table_contains (foreign->exported_surfaces, handle))
         {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]