[PATCH libinput 06/10] Add a config interface to change device rotation
Hans de Goede
hdegoede at redhat.com
Wed Jun 4 02:35:32 PDT 2014
Hi,
On 06/03/2014 07:34 AM, Peter Hutterer wrote:
> Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
> ---
> src/libinput-private.h | 9 +++++++
> src/libinput.c | 33 ++++++++++++++++++++++++
> src/libinput.h | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++
> 3 files changed, 111 insertions(+)
>
Looks good.
Regards,
Hans
> diff --git a/src/libinput-private.h b/src/libinput-private.h
> index d3570a4..0d2a1b1 100644
> --- a/src/libinput-private.h
> +++ b/src/libinput-private.h
> @@ -85,9 +85,18 @@ struct libinput_device_config_scroll {
> void (*reset)(struct libinput_device *device);
> };
>
> +struct libinput_device_config_rotation {
> + int (*increment)(struct libinput_device *device);
> + enum libinput_config_status (*set)(struct libinput_device *device,
> + int degrees_cw);
> + int (*get)(struct libinput_device *device);
> + void (*reset)(struct libinput_device *device);
> +};
> +
> struct libinput_device_config {
> struct libinput_device_config_tap *tap;
> struct libinput_device_config_scroll *scroll;
> + struct libinput_device_config_rotation *rotation;
> };
>
> struct libinput_device {
> diff --git a/src/libinput.c b/src/libinput.c
> index b2388e6..2572f5b 100644
> --- a/src/libinput.c
> +++ b/src/libinput.c
> @@ -1250,3 +1250,36 @@ libinput_device_config_scroll_reset(struct libinput_device *device)
> if (device->config.scroll)
> device->config.scroll->reset(device);
> }
> +
> +LIBINPUT_EXPORT int
> +libinput_device_config_rotation_get_increment(struct libinput_device *device)
> +{
> + return device->config.rotation ?
> + device->config.rotation->increment(device) : 0;
> +}
> +
> +LIBINPUT_EXPORT enum libinput_config_status
> +libinput_device_config_rotation_set(struct libinput_device *device,
> + int degrees_cw)
> +{
> + if (libinput_device_config_rotation_get_increment(device) == 0)
> + return LIBINPUT_CONFIG_STATUS_UNSUPPORTED;
> +
> + return device->config.rotation->set(device, degrees_cw);
> +}
> +
> +LIBINPUT_EXPORT int
> +libinput_device_config_rotation_get(struct libinput_device *device)
> +{
> + if (libinput_device_config_rotation_get_increment(device) == 0)
> + return 0;
> +
> + return device->config.rotation->get(device);
> +}
> +
> +LIBINPUT_EXPORT void
> +libinput_device_config_rotation_reset(struct libinput_device *device)
> +{
> + if (libinput_device_config_rotation_get_increment(device) != 0)
> + device->config.rotation->reset(device);
> +}
> diff --git a/src/libinput.h b/src/libinput.h
> index 571f7ba..328d050 100644
> --- a/src/libinput.h
> +++ b/src/libinput.h
> @@ -1508,6 +1508,75 @@ libinput_device_config_scroll_get_method(struct libinput_device *device);
> void
> libinput_device_config_scroll_reset(struct libinput_device *device);
>
> +
> +/**
> + * @ingroup config
> + *
> + * Query the rotation increment for this device, if any. The return value is
> + * the increment in degrees. For example, a device that returns 90 may only
> + * be rotated in 90-degree increments.
> + *
> + * @param device The device to configure
> + *
> + * @return The rotation increment in degrees, or 0 if the device cannot be
> + * rotated
> + */
> +int
> +libinput_device_config_rotation_get_increment(struct libinput_device *device);
> +
> +/**
> + * @ingroup config
> + *
> + * Set the rotation for this device, in degrees clockwise. This rotation
> + * applies to the physical orientation of the device, i.e. if a tablet is
> + * moved from landscape to portrait format, clockwise, this represents a
> + * 90-degree rotation. In the diagram below, if a is the device origin 0/0,
> + * after the rotation the coordinate b sends 0/0 coordinates and a sends
> + * xmax/0.
> + *
> + * @code
> + * +-------------+ +---------+
> + * |a | |b a|
> + * | | -> | |
> + * |b | | |
> + * +-------------+ | |
> + * | |
> + * +---------+
> + * @endcode
> + *
> + * @param device The device to configure
> + * @param degrees_cw The number of degrees to rotate clockwise
> + *
> + * @return A config status code
> + */
> +enum libinput_config_status
> +libinput_device_config_rotation_set(struct libinput_device *device,
> + int degrees_cw);
> +
> +/**
> + * @ingroup config
> + *
> + * Get the current rotation for this device, in degrees clockwise. If the
> + * device does not support rotation, this function always returns 0.
> + *
> + * @param device The device to configure
> + *
> + * @return The rotation in degrees clockwise
> + */
> +int
> +libinput_device_config_rotation_get(struct libinput_device *device);
> +
> +/**
> + * @ingroup config
> + *
> + * Reset the rotation to the device's default setting. If thd evice does not
> + * support rotation, this function does nothing.
> + *
> + * @param device The device to configure
> + */
> +void
> +libinput_device_config_rotation_reset(struct libinput_device *device);
> +
> #ifdef __cplusplus
> }
> #endif
>
More information about the wayland-devel
mailing list