diff options
| author | Simon Ser <contact@emersion.fr> | 2024-02-29 12:08:02 +0100 | 
|---|---|---|
| committer | Simon Ser <contact@emersion.fr> | 2024-02-29 12:08:02 +0100 | 
| commit | ee70932422718809da88700536d4a7ddde024813 (patch) | |
| tree | 25012f050cabcdf6e9c7175b1872e0f1ff332fa2 | |
| parent | 488a23c16908a83041cf28e134a6f149d831598d (diff) | |
| download | wlroots-ee70932422718809da88700536d4a7ddde024813.tar.xz | |
backend/libinput: use NULL to indicate missing device name
libinput guarantees that the name is non-NULL, and an empty string
if unset. However wlroots uses NULL to indicate that an input device
name is unset.
| -rw-r--r-- | backend/libinput/backend.c | 10 | ||||
| -rw-r--r-- | backend/libinput/keyboard.c | 2 | ||||
| -rw-r--r-- | backend/libinput/pointer.c | 2 | ||||
| -rw-r--r-- | backend/libinput/switch.c | 2 | ||||
| -rw-r--r-- | backend/libinput/tablet_pad.c | 2 | ||||
| -rw-r--r-- | backend/libinput/tablet_tool.c | 2 | ||||
| -rw-r--r-- | backend/libinput/touch.c | 2 | ||||
| -rw-r--r-- | include/backend/libinput.h | 1 | 
8 files changed, 17 insertions, 6 deletions
| diff --git a/backend/libinput/backend.c b/backend/libinput/backend.c index 97f17244..bea999fd 100644 --- a/backend/libinput/backend.c +++ b/backend/libinput/backend.c @@ -233,3 +233,13 @@ struct libinput_device *wlr_libinput_get_device_handle(  uint32_t usec_to_msec(uint64_t usec) {  	return (uint32_t)(usec / 1000);  } + +const char *get_libinput_device_name(struct libinput_device *device) { +	// libinput guarantees that the name is non-NULL, and an empty string if +	// unset. However wlroots uses NULL to indicate that the name is unset. +	const char *name = libinput_device_get_name(device); +	if (name[0] == '\0') { +		return NULL; +	} +	return name; +} diff --git a/backend/libinput/keyboard.c b/backend/libinput/keyboard.c index 2e5e6ef1..9cdc72af 100644 --- a/backend/libinput/keyboard.c +++ b/backend/libinput/keyboard.c @@ -23,7 +23,7 @@ const struct wlr_keyboard_impl libinput_keyboard_impl = {  };  void init_device_keyboard(struct wlr_libinput_input_device *dev) { -	const char *name = libinput_device_get_name(dev->handle); +	const char *name = get_libinput_device_name(dev->handle);  	struct wlr_keyboard *wlr_kb = &dev->keyboard;  	wlr_keyboard_init(wlr_kb, &libinput_keyboard_impl, name);  	wlr_kb->base.vendor = libinput_device_get_id_vendor(dev->handle); diff --git a/backend/libinput/pointer.c b/backend/libinput/pointer.c index f808e1f0..0c55695f 100644 --- a/backend/libinput/pointer.c +++ b/backend/libinput/pointer.c @@ -8,7 +8,7 @@ const struct wlr_pointer_impl libinput_pointer_impl = {  };  void init_device_pointer(struct wlr_libinput_input_device *dev) { -	const char *name = libinput_device_get_name(dev->handle); +	const char *name = get_libinput_device_name(dev->handle);  	struct wlr_pointer *wlr_pointer = &dev->pointer;  	wlr_pointer_init(wlr_pointer, &libinput_pointer_impl, name);  	wlr_pointer->base.vendor = libinput_device_get_id_vendor(dev->handle); diff --git a/backend/libinput/switch.c b/backend/libinput/switch.c index 61bb887f..56ad77de 100644 --- a/backend/libinput/switch.c +++ b/backend/libinput/switch.c @@ -8,7 +8,7 @@ const struct wlr_switch_impl libinput_switch_impl = {  };  void init_device_switch(struct wlr_libinput_input_device *dev) { -	const char *name = libinput_device_get_name(dev->handle); +	const char *name = get_libinput_device_name(dev->handle);  	struct wlr_switch *wlr_switch = &dev->switch_device;  	wlr_switch_init(wlr_switch, &libinput_switch_impl, name);  	wlr_switch->base.vendor = libinput_device_get_id_vendor(dev->handle); diff --git a/backend/libinput/tablet_pad.c b/backend/libinput/tablet_pad.c index 3cf7f142..864fcf88 100644 --- a/backend/libinput/tablet_pad.c +++ b/backend/libinput/tablet_pad.c @@ -90,7 +90,7 @@ group_fail:  void init_device_tablet_pad(struct wlr_libinput_input_device *dev) {  	struct libinput_device *handle = dev->handle; -	const char *name = libinput_device_get_name(handle); +	const char *name = get_libinput_device_name(handle);  	struct wlr_tablet_pad *wlr_tablet_pad = &dev->tablet_pad;  	wlr_tablet_pad_init(wlr_tablet_pad, &libinput_tablet_pad_impl, name);  	wlr_tablet_pad->base.vendor = libinput_device_get_id_vendor(handle); diff --git a/backend/libinput/tablet_tool.c b/backend/libinput/tablet_tool.c index f3266c28..9747c758 100644 --- a/backend/libinput/tablet_tool.c +++ b/backend/libinput/tablet_tool.c @@ -17,7 +17,7 @@ const struct wlr_tablet_impl libinput_tablet_impl = {  };  void init_device_tablet(struct wlr_libinput_input_device *dev) { -	const char *name = libinput_device_get_name(dev->handle); +	const char *name = get_libinput_device_name(dev->handle);  	struct wlr_tablet *wlr_tablet = &dev->tablet;  	wlr_tablet_init(wlr_tablet, &libinput_tablet_impl, name);  	wlr_tablet->base.vendor = libinput_device_get_id_vendor(dev->handle); diff --git a/backend/libinput/touch.c b/backend/libinput/touch.c index 14713b5b..ceb21679 100644 --- a/backend/libinput/touch.c +++ b/backend/libinput/touch.c @@ -8,7 +8,7 @@ const struct wlr_touch_impl libinput_touch_impl = {  };  void init_device_touch(struct wlr_libinput_input_device *dev) { -	const char *name = libinput_device_get_name(dev->handle); +	const char *name = get_libinput_device_name(dev->handle);  	struct wlr_touch *wlr_touch = &dev->touch;  	wlr_touch_init(wlr_touch, &libinput_touch_impl, name);  	wlr_touch->base.vendor = libinput_device_get_id_vendor(dev->handle); diff --git a/include/backend/libinput.h b/include/backend/libinput.h index 910af47f..bf5a306f 100644 --- a/include/backend/libinput.h +++ b/include/backend/libinput.h @@ -48,6 +48,7 @@ void handle_libinput_event(struct wlr_libinput_backend *state,  		struct libinput_event *event);  void destroy_libinput_input_device(struct wlr_libinput_input_device *dev); +const char *get_libinput_device_name(struct libinput_device *device);  extern const struct wlr_keyboard_impl libinput_keyboard_impl;  extern const struct wlr_pointer_impl libinput_pointer_impl; | 
