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
This commit is contained in:
Jonas Ådahl 2017-06-21 13:42:23 +08:00
parent 12710dc644
commit 34e7134db2
3 changed files with 22 additions and 16 deletions

View File

@ -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

View File

@ -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 */

View File

@ -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))
{