mirror of
https://github.com/hyprwm/wlroots-hyprland.git
synced 2024-11-24 21:55:58 +01:00
util/uuid: replace with util/token, remove libuuid
Use 128-bit hexadecimal string tokens generated with /dev/urandom instead of UUIDs for xdg-foreign handles, removing the libuuid dependency. Update readme and CI. Closes #2830. build: remove xdg-foreign feature With no external dependencies required, there's no reason not to always build it. Remove WLR_HAS_XDG_FOREIGN as well.
This commit is contained in:
parent
5a178c4a23
commit
b29ac8fbac
14 changed files with 44 additions and 81 deletions
|
@ -7,7 +7,6 @@ packages:
|
|||
- mesa-dev
|
||||
- meson
|
||||
- pixman-dev
|
||||
- util-linux-dev
|
||||
- wayland-dev
|
||||
- wayland-protocols
|
||||
- xcb-util-image-dev
|
||||
|
|
|
@ -10,7 +10,6 @@ packages:
|
|||
- graphics/png
|
||||
- graphics/wayland
|
||||
- graphics/wayland-protocols
|
||||
- misc/e2fsprogs-libuuid
|
||||
- multimedia/ffmpeg
|
||||
- x11/libX11
|
||||
- x11/libinput
|
||||
|
|
|
@ -51,7 +51,6 @@ Install dependencies:
|
|||
* udev
|
||||
* pixman
|
||||
* libseat (optional, for (e)logind and seatd support)
|
||||
* libuuid (optional, for xdg-foreign support)
|
||||
|
||||
If you choose to enable X11 support:
|
||||
|
||||
|
|
|
@ -9,13 +9,6 @@ if not features.get('xwayland')
|
|||
else
|
||||
subdir('xwayland')
|
||||
endif
|
||||
if not features.get('xdg-foreign')
|
||||
exclude_files += [
|
||||
'types/wlr_xdg_foreign_v1.h',
|
||||
'types/wlr_xdg_foreign_v2.h',
|
||||
'types/wlr_xdg_foreign_registry.h',
|
||||
]
|
||||
endif
|
||||
|
||||
install_subdir('wlr',
|
||||
install_dir: get_option('includedir'),
|
||||
|
|
9
include/util/token.h
Normal file
9
include/util/token.h
Normal file
|
@ -0,0 +1,9 @@
|
|||
#ifndef UTIL_TOKEN_H
|
||||
#define UTIL_TOKEN_H
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#define TOKEN_STRLEN 33
|
||||
bool generate_token(char out[static TOKEN_STRLEN]);
|
||||
|
||||
#endif
|
|
@ -1,8 +0,0 @@
|
|||
#ifndef UTIL_UUID_H
|
||||
#define UTIL_UUID_H
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
bool generate_uuid(char out[static 37]);
|
||||
|
||||
#endif
|
|
@ -7,6 +7,4 @@
|
|||
|
||||
#mesondefine WLR_HAS_XWAYLAND
|
||||
|
||||
#mesondefine WLR_HAS_XDG_FOREIGN
|
||||
|
||||
#endif
|
||||
|
|
11
meson.build
11
meson.build
|
@ -84,7 +84,6 @@ features = {
|
|||
'libseat': false,
|
||||
'x11-backend': false,
|
||||
'xwayland': false,
|
||||
'xdg-foreign': false,
|
||||
}
|
||||
internal_features = {
|
||||
'xcb-errors': false,
|
||||
|
@ -104,16 +103,6 @@ pixman = dependency('pixman-1')
|
|||
math = cc.find_library('m')
|
||||
rt = cc.find_library('rt')
|
||||
|
||||
if not get_option('xdg-foreign').disabled()
|
||||
uuid = dependency('uuid', required: false)
|
||||
uuid_create = cc.has_function('uuid_create')
|
||||
if uuid.found() or uuid_create
|
||||
features += { 'xdg-foreign': true }
|
||||
elif get_option('xdg-foreign').enabled()
|
||||
error('Missing dependency uuid and uuid_create function not available ' +
|
||||
'cannot build with xdg-foreign support')
|
||||
endif
|
||||
endif
|
||||
|
||||
wlr_files = []
|
||||
wlr_deps = [
|
||||
|
|
|
@ -4,4 +4,3 @@ option('xwayland', type: 'feature', value: 'auto', yield: true, description: 'En
|
|||
option('x11-backend', type: 'feature', value: 'auto', description: 'Enable X11 backend')
|
||||
option('examples', type: 'boolean', value: true, description: 'Build example applications')
|
||||
option('icon_directory', description: 'Location used to look for cursors (default: ${datadir}/icons)', type: 'string', value: '')
|
||||
option('xdg-foreign', type: 'feature', value: 'auto', description: 'Enable xdg-foreign protocol')
|
||||
|
|
|
@ -63,13 +63,9 @@ wlr_files += files(
|
|||
'wlr_virtual_pointer_v1.c',
|
||||
'wlr_xcursor_manager.c',
|
||||
'wlr_xdg_decoration_v1.c',
|
||||
'wlr_xdg_output_v1.c',
|
||||
)
|
||||
|
||||
if features.get('xdg-foreign')
|
||||
wlr_files += files(
|
||||
'wlr_xdg_foreign_v1.c',
|
||||
'wlr_xdg_foreign_v2.c',
|
||||
'wlr_xdg_foreign_registry.c',
|
||||
'wlr_xdg_output_v1.c',
|
||||
)
|
||||
endif
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#include <wlr/types/wlr_xdg_foreign_registry.h>
|
||||
#include "util/signal.h"
|
||||
#include "util/uuid.h"
|
||||
#include "util/token.h"
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
@ -9,7 +9,7 @@ bool wlr_xdg_foreign_exported_init(
|
|||
struct wlr_xdg_foreign_exported *exported,
|
||||
struct wlr_xdg_foreign_registry *registry) {
|
||||
do {
|
||||
if (!generate_uuid(exported->handle)) {
|
||||
if (!generate_token(exported->handle)) {
|
||||
return false;
|
||||
}
|
||||
} while (wlr_xdg_foreign_registry_find_by_handle(registry, exported->handle) != NULL);
|
||||
|
|
|
@ -6,11 +6,6 @@ wlr_files += files(
|
|||
'shm.c',
|
||||
'signal.c',
|
||||
'time.c',
|
||||
'token.c',
|
||||
)
|
||||
|
||||
|
||||
if features.get('xdg-foreign')
|
||||
add_project_arguments('-DHAS_LIBUUID=@0@'.format(uuid.found().to_int()), language: 'c')
|
||||
wlr_deps += uuid
|
||||
wlr_files += files('uuid.c')
|
||||
endif
|
||||
|
|
29
util/token.c
Normal file
29
util/token.c
Normal file
|
@ -0,0 +1,29 @@
|
|||
#include "util/token.h"
|
||||
#include "wlr/util/log.h"
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
bool generate_token(char out[static TOKEN_STRLEN]) {
|
||||
static FILE *urandom = NULL;
|
||||
uint64_t data[2];
|
||||
|
||||
if (!urandom) {
|
||||
if (!(urandom = fopen("/dev/urandom", "r"))) {
|
||||
wlr_log_errno(WLR_ERROR, "Failed to open random device");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (fread(data, sizeof(data), 1, urandom) != 1) {
|
||||
wlr_log_errno(WLR_ERROR, "Failed to read from random device");
|
||||
return false;
|
||||
}
|
||||
if (snprintf(out, TOKEN_STRLEN, "%016" PRIx64 "%016" PRIx64, data[0], data[1]) != TOKEN_STRLEN - 1) {
|
||||
wlr_log_errno(WLR_ERROR, "Failed to format hex string token");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
34
util/uuid.c
34
util/uuid.c
|
@ -1,34 +0,0 @@
|
|||
#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 <assert.h>
|
||||
#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, 37);
|
||||
free(str);
|
||||
return true;
|
||||
}
|
||||
#endif
|
Loading…
Reference in a new issue