[PATCH libinput 3/6] Switch a bunch of internal functions from int to bool

Peter Hutterer peter.hutterer at who-t.net
Tue Jul 19 00:49:26 UTC 2016


All these effectively returned bools anyway, switch the signature over to be
less ambiguous.

Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
 src/evdev-mt-touchpad-buttons.c |  2 +-
 src/evdev-mt-touchpad.c         | 26 ++++++------
 src/evdev-mt-touchpad.h         |  4 +-
 src/evdev-tablet.c              |  2 +-
 src/evdev.c                     | 94 ++++++++++++++++++++---------------------
 src/evdev.h                     |  2 +-
 src/libinput-private.h          |  2 +-
 src/libinput-util.c             |  2 +-
 src/libinput-util.h             | 14 +++---
 9 files changed, 74 insertions(+), 74 deletions(-)

diff --git a/src/evdev-mt-touchpad-buttons.c b/src/evdev-mt-touchpad-buttons.c
index ba0a016..95603f9 100644
--- a/src/evdev-mt-touchpad-buttons.c
+++ b/src/evdev-mt-touchpad-buttons.c
@@ -1188,7 +1188,7 @@ tp_post_button_events(struct tp_dispatch *tp, uint64_t time)
 		return tp_post_physical_buttons(tp, time);
 }
 
-int
+bool
 tp_button_touch_active(const struct tp_dispatch *tp,
 		       const struct tp_touch *t)
 {
diff --git a/src/evdev-mt-touchpad.c b/src/evdev-mt-touchpad.c
index fe0d4a4..7ee86a9 100644
--- a/src/evdev-mt-touchpad.c
+++ b/src/evdev-mt-touchpad.c
@@ -541,7 +541,7 @@ tp_pin_fingers(struct tp_dispatch *tp)
 	}
 }
 
-int
+bool
 tp_touch_active(const struct tp_dispatch *tp, const struct tp_touch *t)
 {
 	return (t->state == TOUCH_BEGIN || t->state == TOUCH_UPDATE) &&
@@ -1673,7 +1673,7 @@ tp_sync_touch(struct tp_dispatch *tp,
 	libevdev_fetch_slot_value(evdev, slot, ABS_MT_DISTANCE, &t->distance);
 }
 
-static int
+static bool
 tp_init_slots(struct tp_dispatch *tp,
 	      struct evdev_device *device)
 {
@@ -1736,7 +1736,7 @@ tp_init_slots(struct tp_dispatch *tp,
 	tp->ntouches = max(tp->num_slots, n_btn_tool_touches);
 	tp->touches = calloc(tp->ntouches, sizeof(struct tp_touch));
 	if (!tp->touches)
-		return -1;
+		return false;
 
 	for (i = 0; i < tp->ntouches; i++)
 		tp_init_touch(tp, &tp->touches[i]);
@@ -1747,7 +1747,7 @@ tp_init_slots(struct tp_dispatch *tp,
 	for (i = 1; i < tp->num_slots; i++)
 		tp_sync_touch(tp, device, &tp->touches[i], i);
 
-	return 0;
+	return true;
 }
 
 static uint32_t
@@ -1775,7 +1775,7 @@ tp_accel_config_get_default_profile(struct libinput_device *libinput_device)
 	return LIBINPUT_CONFIG_ACCEL_PROFILE_NONE;
 }
 
-static int
+static bool
 tp_init_accel(struct tp_dispatch *tp)
 {
 	struct evdev_device *device = tp->device;
@@ -1802,7 +1802,7 @@ tp_init_accel(struct tp_dispatch *tp)
 		filter = create_pointer_accelerator_filter_touchpad(tp->device->dpi);
 
 	if (!filter)
-		return -1;
+		return false;
 
 	evdev_device_init_pointer_acceleration(tp->device, filter);
 
@@ -1813,7 +1813,7 @@ tp_init_accel(struct tp_dispatch *tp)
 	device->pointer.config.get_profile = tp_accel_config_get_profile;
 	device->pointer.config.get_default_profile = tp_accel_config_get_default_profile;
 
-	return 0;
+	return true;
 }
 
 static uint32_t
@@ -2186,8 +2186,8 @@ tp_init(struct tp_dispatch *tp,
 
 	tp_init_default_resolution(tp, device);
 
-	if (tp_init_slots(tp, device) != 0)
-		return -1;
+	if (!tp_init_slots(tp, device))
+		return false;
 
 	width = device->abs.dimensions.x;
 	height = device->abs.dimensions.y;
@@ -2200,8 +2200,8 @@ tp_init(struct tp_dispatch *tp,
 
 	tp_init_hysteresis(tp);
 
-	if (tp_init_accel(tp) != 0)
-		return -1;
+	if (!tp_init_accel(tp))
+		return false;
 
 	tp_init_tap(tp);
 	tp_init_buttons(tp, device);
@@ -2216,7 +2216,7 @@ tp_init(struct tp_dispatch *tp,
 	if (tp->gesture.enabled)
 		device->seat_caps |= EVDEV_DEVICE_GESTURE;
 
-	return 0;
+	return true;
 }
 
 static uint32_t
@@ -2323,7 +2323,7 @@ evdev_mt_touchpad_create(struct evdev_device *device)
 	if (!tp)
 		return NULL;
 
-	if (tp_init(tp, device) != 0) {
+	if (!tp_init(tp, device)) {
 		tp_interface_destroy(&tp->base);
 		return NULL;
 	}
diff --git a/src/evdev-mt-touchpad.h b/src/evdev-mt-touchpad.h
index 24912aa..86dd048 100644
--- a/src/evdev-mt-touchpad.h
+++ b/src/evdev-mt-touchpad.h
@@ -422,7 +422,7 @@ tp_filter_motion_unaccelerated(struct tp_dispatch *tp,
 			       const struct normalized_coords *unaccelerated,
 			       uint64_t time);
 
-int
+bool
 tp_touch_active(const struct tp_dispatch *tp, const struct tp_touch *t);
 
 int
@@ -460,7 +460,7 @@ tp_post_button_events(struct tp_dispatch *tp, uint64_t time);
 void
 tp_button_handle_state(struct tp_dispatch *tp, uint64_t time);
 
-int
+bool
 tp_button_touch_active(const struct tp_dispatch *tp,
 		       const struct tp_touch *t);
 
diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c
index a47f9e8..f1dce27 100644
--- a/src/evdev-tablet.c
+++ b/src/evdev-tablet.c
@@ -76,7 +76,7 @@ tablet_force_button_presses(struct tablet_dispatch *tablet)
 	}
 }
 
-static int
+static bool
 tablet_device_has_axis(struct tablet_dispatch *tablet,
 		       enum libinput_tablet_tool_axis axis)
 {
diff --git a/src/evdev.c b/src/evdev.c
index 1af8d87..aeb21eb 100644
--- a/src/evdev.c
+++ b/src/evdev.c
@@ -97,7 +97,7 @@ hw_set_key_down(struct evdev_device *device, int code, int pressed)
 	long_set_bit_state(device->hw_key_mask, code, pressed);
 }
 
-static int
+static bool
 hw_is_key_down(struct evdev_device *device, int code)
 {
 	return long_bit_is_set(device->hw_key_mask, code);
@@ -1536,7 +1536,7 @@ evdev_device_dispatch(void *data)
 	}
 }
 
-static inline int
+static inline bool
 evdev_init_accel(struct evdev_device *device,
 		 enum libinput_config_accel_profile which)
 {
@@ -1552,11 +1552,11 @@ evdev_init_accel(struct evdev_device *device,
 		filter = create_pointer_accelerator_filter_linear(device->dpi);
 
 	if (!filter)
-		return -1;
+		return false;
 
 	evdev_device_init_pointer_acceleration(device, filter);
 
-	return 0;
+	return true;
 }
 
 static int
@@ -1619,7 +1619,7 @@ evdev_accel_config_set_profile(struct libinput_device *libinput_device,
 	speed = filter_get_speed(filter);
 	device->pointer.filter = NULL;
 
-	if (evdev_init_accel(device, profile) == 0) {
+	if (evdev_init_accel(device, profile)) {
 		evdev_accel_config_set_speed(libinput_device, speed);
 		filter_destroy(filter);
 	} else {
@@ -1671,7 +1671,7 @@ evdev_device_init_pointer_acceleration(struct evdev_device *device,
 	}
 }
 
-static inline int
+static inline bool
 evdev_need_mtdev(struct evdev_device *device)
 {
 	struct libevdev *evdev = device->evdev;
@@ -1820,7 +1820,7 @@ evdev_read_model_flags(struct evdev_device *device)
 	return model_flags;
 }
 
-static inline int
+static inline bool
 evdev_read_attr_res_prop(struct evdev_device *device,
 			 size_t *xres,
 			 size_t *yres)
@@ -1837,7 +1837,7 @@ evdev_read_attr_res_prop(struct evdev_device *device,
 	return parse_dimension_property(res_prop, xres, yres);
 }
 
-static inline int
+static inline bool
 evdev_read_attr_size_prop(struct evdev_device *device,
 			  size_t *size_x,
 			  size_t *size_y)
@@ -1957,14 +1957,14 @@ evdev_fix_android_mt(struct evdev_device *device)
 		      libevdev_get_abs_info(evdev, ABS_MT_POSITION_Y));
 }
 
-static inline int
+static inline bool
 evdev_check_min_max(struct evdev_device *device, unsigned int code)
 {
 	struct libevdev *evdev = device->evdev;
 	const struct input_absinfo *absinfo;
 
 	if (!libevdev_has_event_code(evdev, EV_ABS, code))
-		return 0;
+		return true;
 
 	absinfo = libevdev_get_abs_info(evdev, code);
 	if (absinfo->minimum == absinfo->maximum) {
@@ -1987,14 +1987,14 @@ evdev_check_min_max(struct evdev_device *device, unsigned int code)
 				       "Device '%s' has min == max on %s\n",
 				       device->devname,
 				       libevdev_event_code_get_name(EV_ABS, code));
-			return -1;
+			return false;
 		}
 	}
 
-	return 0;
+	return true;
 }
 
-static int
+static bool
 evdev_reject_device(struct evdev_device *device)
 {
 	struct libinput *libinput = evdev_libinput_context(device);
@@ -2004,16 +2004,16 @@ evdev_reject_device(struct evdev_device *device)
 
 	if (libevdev_has_event_code(evdev, EV_ABS, ABS_X) ^
 	    libevdev_has_event_code(evdev, EV_ABS, ABS_Y))
-		return -1;
+		return true;
 
 	if (libevdev_has_event_code(evdev, EV_REL, REL_X) ^
 	    libevdev_has_event_code(evdev, EV_REL, REL_Y))
-		return -1;
+		return true;
 
 	if (!evdev_is_fake_mt_device(device) &&
 	    libevdev_has_event_code(evdev, EV_ABS, ABS_MT_POSITION_X) ^
 	    libevdev_has_event_code(evdev, EV_ABS, ABS_MT_POSITION_Y))
-		return -1;
+		return true;
 
 	if (libevdev_has_event_code(evdev, EV_ABS, ABS_X)) {
 		absx = libevdev_get_abs_info(evdev, ABS_X);
@@ -2022,7 +2022,7 @@ evdev_reject_device(struct evdev_device *device)
 		    (absx->resolution != 0 && absy->resolution == 0)) {
 			log_bug_kernel(libinput,
 				       "Kernel has only x or y resolution, not both.\n");
-			return -1;
+			return true;
 		}
 	}
 
@@ -2034,7 +2034,7 @@ evdev_reject_device(struct evdev_device *device)
 		    (absx->resolution != 0 && absy->resolution == 0)) {
 			log_bug_kernel(libinput,
 				       "Kernel has only x or y MT resolution, not both.\n");
-			return -1;
+			return true;
 		}
 	}
 
@@ -2045,15 +2045,15 @@ evdev_reject_device(struct evdev_device *device)
 		case ABS_MT_TOOL_TYPE:
 			break;
 		default:
-			if (evdev_check_min_max(device, code) == -1)
-				return -1;
+			if (!evdev_check_min_max(device, code))
+				return true;
 		}
 	}
 
-	return 0;
+	return false;
 }
 
-static int
+static bool
 evdev_configure_mt_device(struct evdev_device *device)
 {
 	struct libevdev *evdev = device->evdev;
@@ -2064,7 +2064,7 @@ evdev_configure_mt_device(struct evdev_device *device)
 
 	if (!libevdev_has_event_code(evdev, EV_ABS, ABS_MT_POSITION_X) ||
 	    !libevdev_has_event_code(evdev, EV_ABS, ABS_MT_POSITION_Y))
-		 return 0;
+		 return true;
 
 	if (evdev_fix_abs_resolution(device,
 				     ABS_MT_POSITION_X,
@@ -2085,7 +2085,7 @@ evdev_configure_mt_device(struct evdev_device *device)
 	if (evdev_need_mtdev(device)) {
 		device->mtdev = mtdev_new_open(device->fd);
 		if (!device->mtdev)
-			return -1;
+			return false;
 
 		/* pick 10 slots as default for type A
 		   devices. */
@@ -2098,7 +2098,7 @@ evdev_configure_mt_device(struct evdev_device *device)
 
 	slots = calloc(num_slots, sizeof(struct mt_slot));
 	if (!slots)
-		return -1;
+		return false;
 
 	for (slot = 0; slot < num_slots; ++slot) {
 		slots[slot].seat_slot = -1;
@@ -2123,10 +2123,10 @@ evdev_configure_mt_device(struct evdev_device *device)
 		device->mt.hysteresis_margin.y = device->abs.absinfo_y->fuzz/2;
 	}
 
-	return 0;
+	return true;
 }
 
-static int
+static bool
 evdev_configure_device(struct evdev_device *device)
 {
 	struct libinput *libinput = evdev_libinput_context(device);
@@ -2142,7 +2142,7 @@ evdev_configure_device(struct evdev_device *device)
 		log_info(libinput,
 			 "input device '%s', %s not tagged as input device\n",
 			 device->devname, devnode);
-		return -1;
+		return false;
 	}
 
 	log_info(libinput,
@@ -2162,7 +2162,7 @@ evdev_configure_device(struct evdev_device *device)
 		log_info(libinput,
 			 "input device '%s', %s is an accelerometer, ignoring\n",
 			 device->devname, devnode);
-		return -1;
+		return false;
 	}
 
 	/* libwacom *adds* TABLET, TOUCHPAD but leaves JOYSTICK in place, so
@@ -2171,14 +2171,14 @@ evdev_configure_device(struct evdev_device *device)
 		log_info(libinput,
 			 "input device '%s', %s is a joystick, ignoring\n",
 			 device->devname, devnode);
-		return -1;
+		return false;
 	}
 
-	if (evdev_reject_device(device) == -1) {
+	if (evdev_reject_device(device)) {
 		log_info(libinput,
 			 "input device '%s', %s was rejected.\n",
 			 device->devname, devnode);
-		return -1;
+		return false;
 	}
 
 	if (!evdev_is_fake_mt_device(device))
@@ -2198,8 +2198,8 @@ evdev_configure_device(struct evdev_device *device)
 
 		if (evdev_is_fake_mt_device(device)) {
 			udev_tags &= ~EVDEV_UDEV_TAG_TOUCHSCREEN;
-		} else if (evdev_configure_mt_device(device) == -1) {
-			return -1;
+		} else if (!evdev_configure_mt_device(device)) {
+			return false;
 		}
 	}
 
@@ -2217,7 +2217,7 @@ evdev_configure_device(struct evdev_device *device)
 		log_info(libinput,
 			 "input device '%s', %s is a tablet pad\n",
 			 device->devname, devnode);
-		return device->dispatch == NULL ? -1 : 0;
+		return device->dispatch != NULL;
 
 	} else if ((udev_tags & tablet_tags) == EVDEV_UDEV_TAG_TABLET) {
 		device->dispatch = evdev_tablet_create(device);
@@ -2225,7 +2225,7 @@ evdev_configure_device(struct evdev_device *device)
 		log_info(libinput,
 			 "input device '%s', %s is a tablet\n",
 			 device->devname, devnode);
-		return device->dispatch == NULL ? -1 : 0;
+		return device->dispatch != NULL;
 	}
 
 	if (udev_tags & EVDEV_UDEV_TAG_TOUCHPAD) {
@@ -2234,7 +2234,7 @@ evdev_configure_device(struct evdev_device *device)
 			 "input device '%s', %s is a touchpad\n",
 			 device->devname, devnode);
 
-		return device->dispatch == NULL ? -1 : 0;
+		return device->dispatch != NULL;
 	}
 
 	if (udev_tags & EVDEV_UDEV_TAG_MOUSE ||
@@ -2283,14 +2283,14 @@ evdev_configure_device(struct evdev_device *device)
 	if (device->seat_caps & EVDEV_DEVICE_POINTER &&
 	    libevdev_has_event_code(evdev, EV_REL, REL_X) &&
 	    libevdev_has_event_code(evdev, EV_REL, REL_Y) &&
-	    evdev_init_accel(device, LIBINPUT_CONFIG_ACCEL_PROFILE_ADAPTIVE) == -1) {
+	    !evdev_init_accel(device, LIBINPUT_CONFIG_ACCEL_PROFILE_ADAPTIVE)) {
 		log_error(libinput,
 			  "failed to initialize pointer acceleration for %s\n",
 			  device->devname);
-		return -1;
+		return false;
 	}
 
-	return 0;
+	return true;
 }
 
 static void
@@ -2346,7 +2346,7 @@ out:
 	return rc;
 }
 
-static int
+static bool
 evdev_set_device_group(struct evdev_device *device,
 		       struct udev_device *udev_device)
 {
@@ -2362,14 +2362,14 @@ evdev_set_device_group(struct evdev_device *device,
 	if (!group) {
 		group = libinput_device_group_create(libinput, udev_group);
 		if (!group)
-			return 1;
+			return false;
 		libinput_device_set_device_group(&device->base, group);
 		libinput_device_group_unref(group);
 	} else {
 		libinput_device_set_device_group(&device->base, group);
 	}
 
-	return 0;
+	return true;
 }
 
 static inline void
@@ -2493,7 +2493,7 @@ evdev_device_create(struct libinput_seat *seat,
 
 	evdev_pre_configure_model_quirks(device);
 
-	if (evdev_configure_device(device) == -1)
+	if (!evdev_configure_device(device))
 		goto err;
 
 	if (device->seat_caps == 0) {
@@ -2512,7 +2512,7 @@ evdev_device_create(struct libinput_seat *seat,
 	if (!device->source)
 		goto err;
 
-	if (evdev_set_device_group(device, udev_device))
+	if (!evdev_set_device_group(device, udev_device))
 		goto err;
 
 	list_insert(seat->devices_list.prev, &device->base.link);
@@ -2638,7 +2638,7 @@ evdev_device_calibrate(struct evdev_device *device,
 	matrix_mult(&device->abs.calibration, &transform, &scale);
 }
 
-int
+bool
 evdev_device_has_capability(struct evdev_device *device,
 			    enum libinput_device_capability capability)
 {
@@ -2656,7 +2656,7 @@ evdev_device_has_capability(struct evdev_device *device,
 	case LIBINPUT_DEVICE_CAP_TABLET_PAD:
 		return !!(device->seat_caps & EVDEV_DEVICE_TABLET_PAD);
 	default:
-		return 0;
+		return false;
 	}
 }
 
diff --git a/src/evdev.h b/src/evdev.h
index 9ddd8b3..d70dd34 100644
--- a/src/evdev.h
+++ b/src/evdev.h
@@ -366,7 +366,7 @@ void
 evdev_device_calibrate(struct evdev_device *device,
 		       const float calibration[6]);
 
-int
+bool
 evdev_device_has_capability(struct evdev_device *device,
 			    enum libinput_device_capability capability);
 
diff --git a/src/libinput-private.h b/src/libinput-private.h
index b325707..472f6f3 100644
--- a/src/libinput-private.h
+++ b/src/libinput-private.h
@@ -665,7 +665,7 @@ normalized_length(struct normalized_coords norm)
 	return hypot(norm.x, norm.y);
 }
 
-static inline int
+static inline bool
 normalized_is_zero(struct normalized_coords norm)
 {
 	return norm.x == 0.0 && norm.y == 0.0;
diff --git a/src/libinput-util.c b/src/libinput-util.c
index d35d702..4b90fbb 100644
--- a/src/libinput-util.c
+++ b/src/libinput-util.c
@@ -65,7 +65,7 @@ list_remove(struct list *elm)
 	elm->prev = NULL;
 }
 
-int
+bool
 list_empty(const struct list *list)
 {
 	return list->next == list;
diff --git a/src/libinput-util.h b/src/libinput-util.h
index 0848040..0c9a6cf 100644
--- a/src/libinput-util.h
+++ b/src/libinput-util.h
@@ -62,7 +62,7 @@ struct list {
 void list_init(struct list *list);
 void list_insert(struct list *list, struct list *elm);
 void list_remove(struct list *elm);
-int list_empty(const struct list *list);
+bool list_empty(const struct list *list);
 
 #ifdef __GNUC__
 #define container_of(ptr, sample, member)				\
@@ -124,7 +124,7 @@ zalloc(size_t size)
  * except that it has been modified to work with arrays of unsigned chars
  */
 
-static inline int
+static inline bool
 bit_is_set(const unsigned char *array, int bit)
 {
 	return !!(array[bit / 8] & (1 << (bit % 8)));
@@ -148,7 +148,7 @@ msleep(unsigned int ms)
 	usleep(ms * 1000);
 }
 
-static inline int
+static inline bool
 long_bit_is_set(const unsigned long *array, int bit)
 {
 	return !!(array[bit / LONG_BITS] & (1LL << (bit % LONG_BITS)));
@@ -175,7 +175,7 @@ long_set_bit_state(unsigned long *array, int bit, int state)
 		long_clear_bit(array, bit);
 }
 
-static inline int
+static inline bool
 long_any_bit_set(unsigned long *array, size_t size)
 {
 	unsigned long i;
@@ -184,8 +184,8 @@ long_any_bit_set(unsigned long *array, size_t size)
 
 	for (i = 0; i < size; i++)
 		if (array[i] != 0)
-			return 1;
-	return 0;
+			return true;
+	return false;
 }
 
 static inline double
@@ -250,7 +250,7 @@ matrix_init_rotate(struct matrix *m, int degrees)
 	m->val[1][1] = c;
 }
 
-static inline int
+static inline bool
 matrix_is_identity(const struct matrix *m)
 {
 	return (m->val[0][0] == 1 &&
-- 
2.7.4



More information about the wayland-devel mailing list