[PATCH libinput 2/5] evdev: move scroll flag setting/check into a helper function

Peter Hutterer peter.hutterer at who-t.net
Sun Nov 9 18:33:30 PST 2014


Much more readable, especially with the upcoming patches.

Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
 src/evdev.c | 32 ++++++++++++++++++++++++++++----
 1 file changed, 28 insertions(+), 4 deletions(-)

diff --git a/src/evdev.c b/src/evdev.c
index 272d165..9225163 100644
--- a/src/evdev.c
+++ b/src/evdev.c
@@ -1500,6 +1500,26 @@ evdev_device_get_size(struct evdev_device *device,
 	return 0;
 }
 
+static inline bool
+evdev_is_scrolling(const struct evdev_device *device,
+		   enum libinput_pointer_axis axis)
+{
+	assert(axis == LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL ||
+	       axis == LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL);
+
+	return (device->scroll.direction & (1 << axis)) != 0;
+}
+
+static inline void
+evdev_start_scrolling(struct evdev_device *device,
+		      enum libinput_pointer_axis axis)
+{
+	assert(axis == LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL ||
+	       axis == LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL);
+
+	device->scroll.direction |= (1 << axis);
+}
+
 void
 evdev_post_scroll(struct evdev_device *device,
 		  uint64_t time,
@@ -1507,13 +1527,16 @@ evdev_post_scroll(struct evdev_device *device,
 		  double dy)
 {
 	if (dy <= -device->scroll.threshold || dy >= device->scroll.threshold)
-		device->scroll.direction |= (1 << LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL);
+		evdev_start_scrolling(device,
+				      LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL);
 
 	if (dx <= -device->scroll.threshold || dx >= device->scroll.threshold)
-		device->scroll.direction |= (1 << LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL);
+		evdev_start_scrolling(device,
+				      LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL);
 
 	if (dy != 0.0 &&
-	    (device->scroll.direction & (1 << LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL))) {
+	    evdev_is_scrolling(device,
+			       LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL)) {
 		pointer_notify_axis(&device->base,
 				    time,
 				    LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL,
@@ -1521,7 +1544,8 @@ evdev_post_scroll(struct evdev_device *device,
 	}
 
 	if (dx != 0.0 &&
-	    (device->scroll.direction & (1 << LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL))) {
+	    evdev_is_scrolling(device,
+			       LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL)) {
 		pointer_notify_axis(&device->base,
 				    time,
 				    LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL,
-- 
2.1.0



More information about the wayland-devel mailing list