Commit a5b3c209 authored by Peter Hutterer's avatar Peter Hutterer

Add support for the rotation configuration

Signed-off-by: Peter Hutterer's avatarPeter Hutterer <peter.hutterer@who-t.net>
parent 0f7c5ed0
......@@ -45,7 +45,7 @@ XORG_DEFAULT_OPTIONS
# Obtain compiler/linker options from server and required extensions
PKG_CHECK_MODULES(XORG, [xorg-server >= 1.10] xproto [inputproto >= 2.2])
PKG_CHECK_MODULES(LIBINPUT, [libinput >= 1.2.901])
PKG_CHECK_MODULES(LIBINPUT, [libinput >= 1.3.901])
# Define a configure option for an alternate input module directory
AC_ARG_WITH(xorg-module-dir,
......
......@@ -170,4 +170,10 @@
*/
#define LIBINPUT_PROP_TABLET_PAD_MODE_GROUP_RINGS "libinput Pad Mode Group Rings"
/* 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_ */
......@@ -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"
......
......@@ -150,6 +150,8 @@ struct xf86libinput {
unsigned char btnmap[MAX_BUTTONS + 1];
BOOL horiz_scrolling_enabled;
float rotation_angle;
} options;
struct draglock draglock;
......@@ -520,6 +522,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
......@@ -2307,6 +2316,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,
......@@ -2328,6 +2360,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 */
......@@ -2778,6 +2811,8 @@ static Atom prop_mode_groups;
static Atom prop_mode_groups_buttons;
static Atom prop_mode_groups_rings;
static Atom prop_mode_groups_strips;
static Atom prop_rotation_angle;
static Atom prop_rotation_angle_default;
/* driver properties */
static Atom prop_draglock;
......@@ -3444,7 +3479,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,
......@@ -3494,6 +3561,8 @@ LibinputSetProperty(DeviceIntPtr dev, Atom atom, XIPropertyValuePtr val,
else
return BadAccess;
}
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 ||
......@@ -3515,7 +3584,8 @@ LibinputSetProperty(DeviceIntPtr dev, Atom atom, XIPropertyValuePtr val,
atom == prop_mode_groups_available ||
atom == prop_mode_groups_buttons ||
atom == prop_mode_groups_rings ||
atom == prop_mode_groups_strips)
atom == prop_mode_groups_strips ||
atom == prop_rotation_angle_default)
return BadAccess; /* read-only */
else
return Success;
......@@ -4232,6 +4302,33 @@ LibinputInitHorizScrollProperty(DeviceIntPtr dev,
1, &enabled);
}
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)
{
......@@ -4257,6 +4354,7 @@ LibinputInitProperty(DeviceIntPtr dev)
LibinputInitMiddleEmulationProperty(dev, driver_data, device);
LibinputInitDisableWhileTypingProperty(dev, driver_data, device);
LibinputInitModeGroupProperties(dev, driver_data, device);
LibinputInitRotationAngleProperty(dev, driver_data, device);
/* Device node property, read-only */
device_node = driver_data->path;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment