[PATCH libinput 2/2] Rename functions for left handed device configurations

Stephen Chandler Paul thatslyude at gmail.com
Mon Jan 5 14:44:38 PST 2015


Some devices require more then just flipping around the buttons, such as
tablets.
---
 src/evdev-mt-touchpad.c |  4 ++--
 src/evdev.c             | 34 +++++++++++++++---------------
 src/evdev.h             | 12 +++++------
 src/libinput.c          | 14 ++++++-------
 src/libinput.h          | 55 ++++++++++++++++++++++++-------------------------
 src/libinput.sym        |  8 +++----
 test/pointer.c          | 12 +++++------
 test/touch.c            |  8 +++----
 test/touchpad.c         | 18 ++++++++--------
 tools/event-debug.c     |  2 +-
 tools/shared.c          |  2 +-
 11 files changed, 84 insertions(+), 85 deletions(-)

diff --git a/src/evdev-mt-touchpad.c b/src/evdev-mt-touchpad.c
index 7e8306d..34b107e 100644
--- a/src/evdev-mt-touchpad.c
+++ b/src/evdev-mt-touchpad.c
@@ -1310,7 +1310,7 @@ tp_change_to_left_handed(struct evdev_device *device)
 {
 	struct tp_dispatch *tp = (struct tp_dispatch *)device->dispatch;
 
-	if (device->buttons.want_left_handed == device->buttons.left_handed)
+	if (device->left_handed.want_enabled == device->left_handed.enabled)
 		return;
 
 	if (tp->buttons.state & 0x3) /* BTN_LEFT|BTN_RIGHT */
@@ -1319,7 +1319,7 @@ tp_change_to_left_handed(struct evdev_device *device)
 	/* tapping and clickfinger aren't affected by left-handed config,
 	 * so checking physical buttons is enough */
 
-	device->buttons.left_handed = device->buttons.want_left_handed;
+	device->left_handed.enabled = device->left_handed.want_enabled;
 }
 
 struct model_lookup_t {
diff --git a/src/evdev.c b/src/evdev.c
index 1718491..1fc1d6b 100644
--- a/src/evdev.c
+++ b/src/evdev.c
@@ -119,8 +119,8 @@ evdev_pointer_notify_button(struct evdev_device *device,
 		pointer_notify_button(&device->base, time, button, state);
 
 		if (state == LIBINPUT_BUTTON_STATE_RELEASED &&
-		    device->buttons.change_to_left_handed)
-			device->buttons.change_to_left_handed(device);
+		    device->left_handed.change_to_enabled)
+			device->left_handed.change_to_enabled(device);
 
 		if (state == LIBINPUT_BUTTON_STATE_RELEASED &&
 		    device->scroll.change_scroll_method)
@@ -810,13 +810,13 @@ evdev_left_handed_has(struct libinput_device *device)
 static void
 evdev_change_to_left_handed(struct evdev_device *device)
 {
-	if (device->buttons.want_left_handed == device->buttons.left_handed)
+	if (device->left_handed.want_enabled == device->left_handed.enabled)
 		return;
 
 	if (evdev_any_button_down(device))
 		return;
 
-	device->buttons.left_handed = device->buttons.want_left_handed;
+	device->left_handed.enabled = device->left_handed.want_enabled;
 }
 
 static enum libinput_config_status
@@ -824,9 +824,9 @@ evdev_left_handed_set(struct libinput_device *device, int left_handed)
 {
 	struct evdev_device *evdev_device = (struct evdev_device *)device;
 
-	evdev_device->buttons.want_left_handed = left_handed ? true : false;
+	evdev_device->left_handed.want_enabled = left_handed ? true : false;
 
-	evdev_device->buttons.change_to_left_handed(evdev_device);
+	evdev_device->left_handed.change_to_enabled(evdev_device);
 
 	return LIBINPUT_CONFIG_STATUS_SUCCESS;
 }
@@ -838,7 +838,7 @@ evdev_left_handed_get(struct libinput_device *device)
 
 	/* return the wanted configuration, even if it hasn't taken
 	 * effect yet! */
-	return evdev_device->buttons.want_left_handed;
+	return evdev_device->left_handed.want_enabled;
 }
 
 static int
@@ -851,14 +851,14 @@ int
 evdev_init_left_handed(struct evdev_device *device,
 		       void (*change_to_left_handed)(struct evdev_device *))
 {
-	device->buttons.config_left_handed.has = evdev_left_handed_has;
-	device->buttons.config_left_handed.set = evdev_left_handed_set;
-	device->buttons.config_left_handed.get = evdev_left_handed_get;
-	device->buttons.config_left_handed.get_default = evdev_left_handed_get_default;
-	device->base.config.left_handed = &device->buttons.config_left_handed;
-	device->buttons.left_handed = false;
-	device->buttons.want_left_handed = false;
-	device->buttons.change_to_left_handed = change_to_left_handed;
+	device->left_handed.config.has = evdev_left_handed_has;
+	device->left_handed.config.set = evdev_left_handed_set;
+	device->left_handed.config.get = evdev_left_handed_get;
+	device->left_handed.config.get_default = evdev_left_handed_get_default;
+	device->base.config.left_handed = &device->left_handed.config;
+	device->left_handed.enabled = false;
+	device->left_handed.want_enabled = false;
+	device->left_handed.change_to_enabled = change_to_left_handed;
 
 	return 0;
 }
@@ -1052,7 +1052,7 @@ fallback_dispatch_create(struct libinput_device *device)
 
 	dispatch->interface = &fallback_interface;
 
-	if (evdev_device->buttons.want_left_handed &&
+	if (evdev_device->left_handed.want_enabled &&
 	    evdev_init_left_handed(evdev_device,
 				   evdev_change_to_left_handed) == -1) {
 		free(dispatch);
@@ -1442,7 +1442,7 @@ evdev_configure_device(struct evdev_device *device)
 			 has_button ? " button" : "");
 
 		/* want left-handed config option */
-		device->buttons.want_left_handed = true;
+		device->left_handed.want_enabled = true;
 		/* want natural-scroll config option */
 		device->scroll.natural_scrolling_enabled = true;
 	}
diff --git a/src/evdev.h b/src/evdev.h
index a75dd13..b7e7848 100644
--- a/src/evdev.h
+++ b/src/evdev.h
@@ -141,15 +141,15 @@ struct evdev_device {
 	uint8_t key_count[KEY_CNT];
 
 	struct {
-		struct libinput_device_config_left_handed config_left_handed;
+		struct libinput_device_config_left_handed config;
 		/* left-handed currently enabled */
-		bool left_handed;
+		bool enabled;
 		/* set during device init if we want left_handed config,
 		 * used at runtime to delay the effect until buttons are up */
-		bool want_left_handed;
+		bool want_enabled;
 		/* Checks if buttons are down and commits the setting */
-		void (*change_to_left_handed)(struct evdev_device *device);
-	} buttons;
+		void (*change_to_enabled)(struct evdev_device *device);
+	} left_handed;
 
 	int dpi; /* HW resolution */
 	struct ratelimit syn_drop_limit; /* ratelimit for SYN_DROPPED logging */
@@ -329,7 +329,7 @@ static inline uint32_t
 evdev_to_left_handed(struct evdev_device *device,
 		     uint32_t button)
 {
-	if (device->buttons.left_handed) {
+	if (device->left_handed.enabled) {
 		if (button == BTN_LEFT)
 			return BTN_RIGHT;
 		else if (button == BTN_RIGHT)
diff --git a/src/libinput.c b/src/libinput.c
index 426c306..025bb39 100644
--- a/src/libinput.c
+++ b/src/libinput.c
@@ -1547,7 +1547,7 @@ libinput_device_config_scroll_get_default_natural_scroll_enabled(struct libinput
 }
 
 LIBINPUT_EXPORT int
-libinput_device_config_buttons_has_left_handed(struct libinput_device *device)
+libinput_device_config_has_left_handed(struct libinput_device *device)
 {
 	if (!device->config.left_handed)
 		return 0;
@@ -1556,28 +1556,28 @@ libinput_device_config_buttons_has_left_handed(struct libinput_device *device)
 }
 
 LIBINPUT_EXPORT enum libinput_config_status
-libinput_device_config_buttons_set_left_handed(struct libinput_device *device,
+libinput_device_config_set_left_handed(struct libinput_device *device,
 					       int left_handed)
 {
-	if (!libinput_device_config_buttons_has_left_handed(device))
+	if (!libinput_device_config_has_left_handed(device))
 		return LIBINPUT_CONFIG_STATUS_UNSUPPORTED;
 
 	return device->config.left_handed->set(device, left_handed);
 }
 
 LIBINPUT_EXPORT int
-libinput_device_config_buttons_get_left_handed(struct libinput_device *device)
+libinput_device_config_get_left_handed(struct libinput_device *device)
 {
-	if (!libinput_device_config_buttons_has_left_handed(device))
+	if (!libinput_device_config_has_left_handed(device))
 		return 0;
 
 	return device->config.left_handed->get(device);
 }
 
 LIBINPUT_EXPORT int
-libinput_device_config_buttons_get_default_left_handed(struct libinput_device *device)
+libinput_device_config_get_default_left_handed(struct libinput_device *device)
 {
-	if (!libinput_device_config_buttons_has_left_handed(device))
+	if (!libinput_device_config_has_left_handed(device))
 		return 0;
 
 	return device->config.left_handed->get_default(device);
diff --git a/src/libinput.h b/src/libinput.h
index 7719b8c..8d3e977 100644
--- a/src/libinput.h
+++ b/src/libinput.h
@@ -2076,33 +2076,32 @@ libinput_device_config_scroll_get_default_natural_scroll_enabled(struct libinput
 /**
  * @ingroup config
  *
- * Check if a device has a button configuration that supports left-handed
- * usage.
+ * Check if a device has a configuration that supports left-handed usage.
  *
  * @param device The device to configure
  * @return Non-zero if the device can be set to left-handed, or zero
  * otherwise
  *
- * @see libinput_device_config_buttons_set_left_handed
- * @see libinput_device_config_buttons_get_left_handed
- * @see libinput_device_config_buttons_get_default_left_handed
+ * @see libinput_device_config_set_left_handed
+ * @see libinput_device_config_get_left_handed
+ * @see libinput_device_config_get_default_left_handed
  */
 int
-libinput_device_config_buttons_has_left_handed(struct libinput_device *device);
+libinput_device_config_has_left_handed(struct libinput_device *device);
 
 /**
  * @ingroup config
  *
- * Set the left-handed configuration of the device. A device in left-handed
- * mode sends a left button event instead of the right button and vice
- * versa.
+ * Set the left-handed configuration of the device. For example, a pointing
+ * device may reverse it's buttons and send a right button click when the
+ * left button is pressed, and vice versa.
  *
- * The exact button behavior is device-dependent. On a mouse and most
- * pointing devices, left and right buttons are swapped but the middle
- * button is unmodified. On a touchpad, physical buttons (if present) are
- * swapped. On a clickpad, the top and bottom software-emulated buttons are
- * swapped where present, the main area of the touchpad remains a left
- * button. Tapping and clickfinger behavior is not affected by this setting.
+ * The exact behavior is device-dependent. On a mouse and most pointing
+ * devices, left and right buttons are swapped but the middle button is
+ * unmodified. On a touchpad, physical buttons (if present) are swapped. On a
+ * clickpad, the top and bottom software-emulated buttons are swapped where
+ * present, the main area of the touchpad remains a left button. Tapping and
+ * clickfinger behavior is not affected by this setting.
  *
  * Changing the left-handed configuration of a device may not take effect
  * until all buttons have been logically released.
@@ -2111,13 +2110,13 @@ libinput_device_config_buttons_has_left_handed(struct libinput_device *device);
  * @param left_handed Zero to disable, non-zero to enable left-handed mode
  * @return A configuration status code
  *
- * @see libinput_device_config_buttons_has_left_handed
- * @see libinput_device_config_buttons_get_left_handed
- * @see libinput_device_config_buttons_get_default_left_handed
+ * @see libinput_device_config_has_left_handed
+ * @see libinput_device_config_get_left_handed
+ * @see libinput_device_config_get_default_left_handed
  */
 enum libinput_config_status
-libinput_device_config_buttons_set_left_handed(struct libinput_device *device,
-					       int left_handed);
+libinput_device_config_set_left_handed(struct libinput_device *device,
+				       int left_handed);
 
 /**
  * @ingroup config
@@ -2128,12 +2127,12 @@ libinput_device_config_buttons_set_left_handed(struct libinput_device *device,
  * @return Zero if the device is in right-handed mode, non-zero if the
  * device is in left-handed mode
  *
- * @see libinput_device_config_buttons_has_left_handed
- * @see libinput_device_config_buttons_set_left_handed
- * @see libinput_device_config_buttons_get_default_left_handed
+ * @see libinput_device_config_has_left_handed
+ * @see libinput_device_config_set_left_handed
+ * @see libinput_device_config_get_default_left_handed
  */
 int
-libinput_device_config_buttons_get_left_handed(struct libinput_device *device);
+libinput_device_config_get_left_handed(struct libinput_device *device);
 
 /**
  * @ingroup config
@@ -2144,12 +2143,12 @@ libinput_device_config_buttons_get_left_handed(struct libinput_device *device);
  * @return Zero if the device is in right-handed mode by default, or non-zero
  * if the device is in left-handed mode by default
  *
- * @see libinput_device_config_buttons_has_left_handed
- * @see libinput_device_config_buttons_set_left_handed
- * @see libinput_device_config_buttons_get_left_handed
+ * @see libinput_device_config_has_left_handed
+ * @see libinput_device_config_set_left_handed
+ * @see libinput_device_config_get_left_handed
  */
 int
-libinput_device_config_buttons_get_default_left_handed(struct libinput_device *device);
+libinput_device_config_get_default_left_handed(struct libinput_device *device);
 
 /**
  * @ingroup config
diff --git a/src/libinput.sym b/src/libinput.sym
index 826bfde..92a0056 100644
--- a/src/libinput.sym
+++ b/src/libinput.sym
@@ -7,10 +7,10 @@ global:
 	libinput_device_config_accel_get_speed;
 	libinput_device_config_accel_is_available;
 	libinput_device_config_accel_set_speed;
-	libinput_device_config_buttons_get_default_left_handed;
-	libinput_device_config_buttons_get_left_handed;
-	libinput_device_config_buttons_has_left_handed;
-	libinput_device_config_buttons_set_left_handed;
+	libinput_device_config_get_default_left_handed;
+	libinput_device_config_get_left_handed;
+	libinput_device_config_has_left_handed;
+	libinput_device_config_set_left_handed;
 	libinput_device_config_calibration_get_default_matrix;
 	libinput_device_config_calibration_get_matrix;
 	libinput_device_config_calibration_has_matrix;
diff --git a/test/pointer.c b/test/pointer.c
index b9bd3cc..9844036 100644
--- a/test/pointer.c
+++ b/test/pointer.c
@@ -569,13 +569,13 @@ START_TEST(pointer_left_handed_defaults)
 	struct libinput_device *d = dev->libinput_device;
 	int rc;
 
-	rc = libinput_device_config_buttons_has_left_handed(d);
+	rc = libinput_device_config_has_left_handed(d);
 	ck_assert_int_ne(rc, 0);
 
-	rc = libinput_device_config_buttons_get_left_handed(d);
+	rc = libinput_device_config_get_left_handed(d);
 	ck_assert_int_eq(rc, 0);
 
-	rc = libinput_device_config_buttons_get_default_left_handed(d);
+	rc = libinput_device_config_get_default_left_handed(d);
 	ck_assert_int_eq(rc, 0);
 }
 END_TEST
@@ -587,7 +587,7 @@ START_TEST(pointer_left_handed)
 	struct libinput *li = dev->libinput;
 	enum libinput_config_status status;
 
-	status = libinput_device_config_buttons_set_left_handed(d, 1);
+	status = libinput_device_config_set_left_handed(d, 1);
 	ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS);
 
 	litest_drain_events(li);
@@ -637,7 +637,7 @@ START_TEST(pointer_left_handed_during_click)
 	libinput_dispatch(li);
 
 	/* Change while button is down, expect correct release event */
-	status = libinput_device_config_buttons_set_left_handed(d, 1);
+	status = libinput_device_config_set_left_handed(d, 1);
 	ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS);
 
 	litest_button_click(dev, BTN_LEFT, 0);
@@ -662,7 +662,7 @@ START_TEST(pointer_left_handed_during_click_multiple_buttons)
 	litest_button_click(dev, BTN_LEFT, 1);
 	libinput_dispatch(li);
 
-	status = libinput_device_config_buttons_set_left_handed(d, 1);
+	status = libinput_device_config_set_left_handed(d, 1);
 	ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS);
 
 	/* No left-handed until all buttons were down */
diff --git a/test/touch.c b/test/touch.c
index 5c9b72a..1b09d19 100644
--- a/test/touch.c
+++ b/test/touch.c
@@ -408,16 +408,16 @@ START_TEST(touch_no_left_handed)
 	enum libinput_config_status status;
 	int rc;
 
-	rc = libinput_device_config_buttons_has_left_handed(d);
+	rc = libinput_device_config_has_left_handed(d);
 	ck_assert_int_eq(rc, 0);
 
-	rc = libinput_device_config_buttons_get_left_handed(d);
+	rc = libinput_device_config_get_left_handed(d);
 	ck_assert_int_eq(rc, 0);
 
-	rc = libinput_device_config_buttons_get_default_left_handed(d);
+	rc = libinput_device_config_get_default_left_handed(d);
 	ck_assert_int_eq(rc, 0);
 
-	status = libinput_device_config_buttons_set_left_handed(d, 0);
+	status = libinput_device_config_set_left_handed(d, 0);
 	ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_UNSUPPORTED);
 }
 END_TEST
diff --git a/test/touchpad.c b/test/touchpad.c
index 422e8fe..df95dcb 100644
--- a/test/touchpad.c
+++ b/test/touchpad.c
@@ -1915,7 +1915,7 @@ START_TEST(touchpad_left_handed)
 	struct libinput *li = dev->libinput;
 	enum libinput_config_status status;
 
-	status = libinput_device_config_buttons_set_left_handed(d, 1);
+	status = libinput_device_config_set_left_handed(d, 1);
 	ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS);
 
 	litest_drain_events(li);
@@ -1960,7 +1960,7 @@ START_TEST(touchpad_left_handed_clickpad)
 	struct libinput *li = dev->libinput;
 	enum libinput_config_status status;
 
-	status = libinput_device_config_buttons_set_left_handed(d, 1);
+	status = libinput_device_config_set_left_handed(d, 1);
 	ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS);
 
 	litest_drain_events(li);
@@ -2011,7 +2011,7 @@ START_TEST(touchpad_left_handed_clickfinger)
 	struct libinput *li = dev->libinput;
 	enum libinput_config_status status;
 
-	status = libinput_device_config_buttons_set_left_handed(d, 1);
+	status = libinput_device_config_set_left_handed(d, 1);
 	ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS);
 
 	litest_drain_events(li);
@@ -2054,7 +2054,7 @@ START_TEST(touchpad_left_handed_tapping)
 
 	libinput_device_config_tap_set_enabled(dev->libinput_device,
 					       LIBINPUT_CONFIG_TAP_ENABLED);
-	status = libinput_device_config_buttons_set_left_handed(d, 1);
+	status = libinput_device_config_set_left_handed(d, 1);
 	ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS);
 
 	litest_drain_events(li);
@@ -2085,7 +2085,7 @@ START_TEST(touchpad_left_handed_tapping_2fg)
 
 	libinput_device_config_tap_set_enabled(dev->libinput_device,
 					       LIBINPUT_CONFIG_TAP_ENABLED);
-	status = libinput_device_config_buttons_set_left_handed(d, 1);
+	status = libinput_device_config_set_left_handed(d, 1);
 	ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS);
 
 	litest_drain_events(li);
@@ -2121,7 +2121,7 @@ START_TEST(touchpad_left_handed_delayed)
 	litest_button_click(dev, BTN_LEFT, 1);
 	libinput_dispatch(li);
 
-	status = libinput_device_config_buttons_set_left_handed(d, 1);
+	status = libinput_device_config_set_left_handed(d, 1);
 	ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS);
 
 	litest_button_click(dev, BTN_LEFT, 0);
@@ -2138,7 +2138,7 @@ START_TEST(touchpad_left_handed_delayed)
 	litest_button_click(dev, BTN_LEFT, 1);
 	libinput_dispatch(li);
 
-	status = libinput_device_config_buttons_set_left_handed(d, 0);
+	status = libinput_device_config_set_left_handed(d, 0);
 	ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS);
 
 	litest_button_click(dev, BTN_RIGHT, 0);
@@ -2171,7 +2171,7 @@ START_TEST(touchpad_left_handed_clickpad_delayed)
 	litest_button_click(dev, BTN_LEFT, 1);
 	libinput_dispatch(li);
 
-	status = libinput_device_config_buttons_set_left_handed(d, 1);
+	status = libinput_device_config_set_left_handed(d, 1);
 	ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS);
 
 	litest_button_click(dev, BTN_LEFT, 0);
@@ -2190,7 +2190,7 @@ START_TEST(touchpad_left_handed_clickpad_delayed)
 	litest_button_click(dev, BTN_LEFT, 1);
 	libinput_dispatch(li);
 
-	status = libinput_device_config_buttons_set_left_handed(d, 0);
+	status = libinput_device_config_set_left_handed(d, 0);
 	ck_assert_int_eq(status, LIBINPUT_CONFIG_STATUS_SUCCESS);
 
 	litest_button_click(dev, BTN_LEFT, 0);
diff --git a/tools/event-debug.c b/tools/event-debug.c
index 8fbea24..4f1add5 100644
--- a/tools/event-debug.c
+++ b/tools/event-debug.c
@@ -146,7 +146,7 @@ print_device_notify(struct libinput_event *ev)
 
 	if (libinput_device_config_tap_get_finger_count((dev)))
 	    printf(" tap");
-	if (libinput_device_config_buttons_has_left_handed((dev)))
+	if (libinput_device_config_has_left_handed((dev)))
 	    printf(" left");
 	if (libinput_device_config_scroll_has_natural_scroll((dev)))
 	    printf(" scroll-nat");
diff --git a/tools/shared.c b/tools/shared.c
index 3e1368d..3c9efc4 100644
--- a/tools/shared.c
+++ b/tools/shared.c
@@ -262,5 +262,5 @@ tools_device_apply_config(struct libinput_device *device,
 		libinput_device_config_scroll_set_natural_scroll_enabled(device,
 									 options->natural_scroll);
 	if (options->left_handed != -1)
-		libinput_device_config_buttons_set_left_handed(device, options->left_handed);
+		libinput_device_config_set_left_handed(device, options->left_handed);
 }
-- 
2.0.5



More information about the wayland-devel mailing list