Signed-off-by: Peter Hutterer <[email protected]>
---
 include/libinput-properties.h |   6 +++
 man/libinput.man              |   8 ++++
 src/xf86libinput.c            | 102 +++++++++++++++++++++++++++++++++++++++++-
 3 files changed, 114 insertions(+), 2 deletions(-)

diff --git a/include/libinput-properties.h b/include/libinput-properties.h
index d117729..d359e5c 100644
--- a/include/libinput-properties.h
+++ b/include/libinput-properties.h
@@ -142,4 +142,10 @@
  * If disabled, horizontal scroll events are discarded */
 #define LIBINPUT_PROP_HORIZ_SCROLL_ENABLED "libinput Horizonal Scroll Enabled"
 
+/* Device rotation: FLOAT, 1 value, 32 bit */
+#define LIBINPUT_PROP_ROTATION_ANGLE "libinput Rotation Angle"
+
+/* Device rotation: FLOAT, 1 value, 32 bit, read-only */
+#define LIBINPUT_PROP_ROTATION_ANGLE_DEFAULT "libinput Rotation Angle Default"
+
 #endif /* _LIBINPUT_PROPERTIES_H_ */
diff --git a/man/libinput.man b/man/libinput.man
index 43beda7..d709c34 100644
--- a/man/libinput.man
+++ b/man/libinput.man
@@ -126,6 +126,10 @@ events.
 Sets the send events mode to disabled, enabled, or "disable when an external
 mouse is connected".
 .TP 7
+.BI "Option \*qRotationAngle\*q \*q" float \*q
+Sets the rotation angle of the device to the given angle, in degrees
+clockwise. The angle must be between 0.0 (inclusive) and 360.0 (exclusive).
+.TP 7
 .BI "Option \*qTapping\*q \*q" bool \*q
 Enables or disables tap-to-click behavior.
 .TP 7
@@ -239,6 +243,10 @@ disabled.
 .BI "libinput Disable While Typing Enabled"
 1 boolean value (8 bit, 0 or 1). Indicates if disable while typing is
 enabled or disabled.
+.TP 7
+.BI "libinput Rotation Angle"
+1 32-bit float value [0.0 to 360.0). Sets the rotation angle of the device,
+clockwise of its natural neutral position.
 .PP
 The above properties have a
 .BI "libinput <property name> Default"
diff --git a/src/xf86libinput.c b/src/xf86libinput.c
index 7034796..1f94273 100644
--- a/src/xf86libinput.c
+++ b/src/xf86libinput.c
@@ -146,6 +146,8 @@ struct xf86libinput {
                unsigned char btnmap[MAX_BUTTONS + 1];
 
                BOOL horiz_scrolling_enabled;
+
+               float rotation_angle;
        } options;
 
        struct draglock draglock;
@@ -498,6 +500,13 @@ LibinputApplyConfig(DeviceIntPtr dev)
                xf86IDrvMsg(pInfo, X_ERROR,
                            "Failed to set DisableWhileTyping to %d\n",
                            driver_data->options.disable_while_typing);
+
+       if (libinput_device_config_rotation_is_available(device) &&
+           libinput_device_config_rotation_set_angle(device, 
driver_data->options.rotation_angle) != LIBINPUT_CONFIG_STATUS_SUCCESS)
+               xf86IDrvMsg(pInfo, X_ERROR,
+                           "Failed to set RotationAngle to %.2f\n",
+                           driver_data->options.rotation_angle);
+
 }
 
 static int
@@ -2269,6 +2278,29 @@ xf86libinput_parse_horiz_scroll_option(InputInfoPtr 
pInfo)
        return xf86SetBoolOption(pInfo->options, "HorizontalScrolling", TRUE);
 }
 
+static inline double
+xf86libinput_parse_rotation_angle_option(InputInfoPtr pInfo,
+                                        struct libinput_device *device)
+{
+       double angle;
+
+       if (!libinput_device_config_rotation_is_available(device))
+               return 0.0;
+
+       angle = xf86SetRealOption(pInfo->options,
+                                 "RotationAngle",
+                                 
libinput_device_config_rotation_get_default_angle(device));
+       if (libinput_device_config_rotation_set_angle(device, angle) !=
+           LIBINPUT_CONFIG_STATUS_SUCCESS) {
+               xf86IDrvMsg(pInfo, X_ERROR,
+                           "Invalid angle %.2f, using 0.0 instead\n",
+                           angle);
+               angle = libinput_device_config_rotation_get_angle(device);
+       }
+
+       return angle;
+}
+
 static void
 xf86libinput_parse_options(InputInfoPtr pInfo,
                           struct xf86libinput *driver_data,
@@ -2290,6 +2322,7 @@ xf86libinput_parse_options(InputInfoPtr pInfo,
        options->click_method = xf86libinput_parse_clickmethod_option(pInfo, 
device);
        options->middle_emulation = 
xf86libinput_parse_middleemulation_option(pInfo, device);
        options->disable_while_typing = 
xf86libinput_parse_disablewhiletyping_option(pInfo, device);
+       options->rotation_angle = 
xf86libinput_parse_rotation_angle_option(pInfo, device);
        xf86libinput_parse_calibration_option(pInfo, device, 
driver_data->options.matrix);
 
        /* non-libinput options */
@@ -2735,6 +2768,8 @@ static Atom prop_middle_emulation;
 static Atom prop_middle_emulation_default;
 static Atom prop_disable_while_typing;
 static Atom prop_disable_while_typing_default;
+static Atom prop_rotation_angle;
+static Atom prop_rotation_angle_default;
 
 /* driver properties */
 static Atom prop_draglock;
@@ -3355,7 +3390,39 @@ LibinputSetPropertyHorizScroll(DeviceIntPtr dev,
        }
 
        return Success;
- }
+}
+
+static inline int
+LibinputSetPropertyRotationAngle(DeviceIntPtr dev,
+                                Atom atom,
+                                XIPropertyValuePtr val,
+                                BOOL checkonly)
+{
+       InputInfoPtr pInfo = dev->public.devicePrivate;
+       struct xf86libinput *driver_data = pInfo->private;
+       struct libinput_device *device = driver_data->shared_device->device;
+       float *angle;
+
+       if (val->format != 32 || val->size != 1 || val->type != prop_float)
+               return BadMatch;
+
+       angle = (float*)val->data;
+
+       if (checkonly) {
+               if (*angle < 0.0 || *angle >= 360.0)
+                       return BadValue;
+
+               if (!xf86libinput_check_device (dev, atom))
+                       return BadMatch;
+
+               if (libinput_device_config_rotation_is_available(device) == 0)
+                       return BadMatch;
+       } else {
+               driver_data->options.rotation_angle = *angle;
+       }
+
+       return Success;
+}
 
 static int
 LibinputSetProperty(DeviceIntPtr dev, Atom atom, XIPropertyValuePtr val,
@@ -3396,6 +3463,8 @@ LibinputSetProperty(DeviceIntPtr dev, Atom atom, 
XIPropertyValuePtr val,
                rc = LibinputSetPropertyDragLockButtons(dev, atom, val, 
checkonly);
        else if (atom == prop_horiz_scroll)
                rc = LibinputSetPropertyHorizScroll(dev, atom, val, checkonly);
+       else if (atom == prop_rotation_angle)
+               rc = LibinputSetPropertyRotationAngle(dev, atom, val, 
checkonly);
        else if (atom == prop_device || atom == prop_product_id ||
                 atom == prop_tap_default ||
                 atom == prop_tap_drag_default ||
@@ -3413,7 +3482,8 @@ LibinputSetProperty(DeviceIntPtr dev, Atom atom, 
XIPropertyValuePtr val,
                 atom == prop_click_method_default ||
                 atom == prop_click_methods_available ||
                 atom == prop_middle_emulation_default ||
-                atom == prop_disable_while_typing_default)
+                atom == prop_disable_while_typing_default ||
+                atom == prop_rotation_angle_default)
                return BadAccess; /* read-only */
        else
                return Success;
@@ -4005,6 +4075,33 @@ LibinputInitHorizScrollProperty(DeviceIntPtr dev,
 }
 
 static void
+LibinputInitRotationAngleProperty(DeviceIntPtr dev,
+                                 struct xf86libinput *driver_data,
+                                 struct libinput_device *device)
+{
+       float angle = driver_data->options.rotation_angle;
+
+       if (!libinput_device_config_rotation_is_available(device))
+               return;
+
+       prop_rotation_angle = LibinputMakeProperty(dev,
+                                                  LIBINPUT_PROP_ROTATION_ANGLE,
+                                                  prop_float, 32,
+                                                  1, &angle);
+       if (!prop_rotation_angle)
+               return;
+
+       angle = libinput_device_config_rotation_get_default_angle(device);
+       prop_rotation_angle_default = LibinputMakeProperty(dev,
+                                                          
LIBINPUT_PROP_ROTATION_ANGLE_DEFAULT,
+                                                          prop_float, 32,
+                                                          1, &angle);
+
+       if (!prop_rotation_angle_default)
+               return;
+}
+
+static void
 LibinputInitProperty(DeviceIntPtr dev)
 {
        InputInfoPtr pInfo  = dev->public.devicePrivate;
@@ -4028,6 +4125,7 @@ LibinputInitProperty(DeviceIntPtr dev)
        LibinputInitClickMethodsProperty(dev, driver_data, device);
        LibinputInitMiddleEmulationProperty(dev, driver_data, device);
        LibinputInitDisableWhileTypingProperty(dev, driver_data, device);
+       LibinputInitRotationAngleProperty(dev, driver_data, device);
 
        /* Device node property, read-only  */
        device_node = driver_data->path;
-- 
2.7.4

_______________________________________________
[email protected]: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: https://lists.x.org/mailman/listinfo/xorg-devel

Reply via email to