aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.builds/alpine.yml1
-rw-r--r--.builds/freebsd.yml1
-rw-r--r--README.md1
-rw-r--r--include/util/uuid.h8
-rw-r--r--meson.build3
-rw-r--r--util/meson.build8
-rw-r--r--util/uuid.c33
7 files changed, 55 insertions, 0 deletions
diff --git a/.builds/alpine.yml b/.builds/alpine.yml
index 402f72f6..7360e562 100644
--- a/.builds/alpine.yml
+++ b/.builds/alpine.yml
@@ -7,6 +7,7 @@ packages:
- mesa-dev
- meson
- pixman-dev
+ - util-linux-dev
- wayland-dev
- wayland-protocols
- xcb-util-image-dev
diff --git a/.builds/freebsd.yml b/.builds/freebsd.yml
index 74553f7b..3ebb2a46 100644
--- a/.builds/freebsd.yml
+++ b/.builds/freebsd.yml
@@ -10,6 +10,7 @@ packages:
- graphics/png
- graphics/wayland
- graphics/wayland-protocols
+- misc/e2fsprogs-libuuid
- multimedia/ffmpeg
- x11/libX11
- x11/libinput
diff --git a/README.md b/README.md
index bb534d82..5ee5aef2 100644
--- a/README.md
+++ b/README.md
@@ -55,6 +55,7 @@ Install dependencies:
* pixman
* systemd (optional, for logind support)
* elogind (optional, for logind support on systems without systemd)
+* libuuid (optional, for xdg-foreign support)
If you choose to enable X11 support:
diff --git a/include/util/uuid.h b/include/util/uuid.h
new file mode 100644
index 00000000..2fecb407
--- /dev/null
+++ b/include/util/uuid.h
@@ -0,0 +1,8 @@
+#ifndef UTIL_UUID_H
+#define UTIL_UUID_H
+
+#include <stdbool.h>
+
+bool generate_uuid(char out[static 37]);
+
+#endif
diff --git a/meson.build b/meson.build
index aa6598bf..c6835fbe 100644
--- a/meson.build
+++ b/meson.build
@@ -109,6 +109,9 @@ pixman = dependency('pixman-1')
math = cc.find_library('m')
rt = cc.find_library('rt')
+uuid = dependency('uuid', required: false)
+uuid_create = cc.has_function('uuid_create')
+
wlr_files = []
wlr_deps = [
wayland_server,
diff --git a/util/meson.build b/util/meson.build
index 14cd59c5..06996a4e 100644
--- a/util/meson.build
+++ b/util/meson.build
@@ -7,3 +7,11 @@ wlr_files += files(
'signal.c',
'time.c',
)
+
+if uuid.found()
+ wlr_deps += uuid
+ add_project_arguments('-DHAS_LIBUUID=1', language: 'c')
+else
+ add_project_arguments('-DHAS_LIBUUID=0', language: 'c')
+endif
+wlr_files += files('uuid.c')
diff --git a/util/uuid.c b/util/uuid.c
new file mode 100644
index 00000000..a4523216
--- /dev/null
+++ b/util/uuid.c
@@ -0,0 +1,33 @@
+#include <uuid.h>
+#include "util/uuid.h"
+
+#if HAS_LIBUUID
+bool generate_uuid(char out[static 37]) {
+ uuid_t uuid;
+ uuid_generate_random(uuid);
+ uuid_unparse(uuid, out);
+ return true;
+}
+#else
+#include <string.h>
+#include <stdlib.h>
+
+bool generate_uuid(char out[static 37]) {
+ uuid_t uuid;
+ uint32_t status;
+ uuid_create(&uuid, &status);
+ if (status != uuid_s_ok) {
+ return false;
+ }
+ char *str;
+ uuid_to_string(&uuid, &str, &status);
+ if (status != uuid_s_ok) {
+ return false;
+ }
+
+ assert(strlen(str) + 1 == 37);
+ memcpy(out, str, sizeof(out));
+ free(str);
+ return true;
+}
+#endif