clutter: Add API to retrieve the physical size of absolute devices

This will be used in upper layers to match abs input devices (touchscreens,
tablets) to the corresponding output.
This commit is contained in:
Carlos Garnacho 2018-04-20 16:33:02 +02:00 committed by Georges Basile Stavracas Neto
parent 2b938ce795
commit df48b94889
5 changed files with 84 additions and 0 deletions

View File

@ -167,6 +167,10 @@ struct _ClutterInputDeviceClass
gboolean (* is_grouped) (ClutterInputDevice *device, gboolean (* is_grouped) (ClutterInputDevice *device,
ClutterInputDevice *other_device); ClutterInputDevice *other_device);
gboolean (* get_physical_size) (ClutterInputDevice *device,
gdouble *width,
gdouble *height);
/* Keyboard accessbility */ /* Keyboard accessbility */
void (* process_kbd_a11y_event) (ClutterEvent *event, void (* process_kbd_a11y_event) (ClutterEvent *event,
ClutterInputDevice *device, ClutterInputDevice *device,

View File

@ -2284,3 +2284,15 @@ clutter_input_device_is_grouped (ClutterInputDevice *device,
return CLUTTER_INPUT_DEVICE_GET_CLASS (device)->is_grouped (device, other_device); return CLUTTER_INPUT_DEVICE_GET_CLASS (device)->is_grouped (device, other_device);
} }
gboolean
clutter_input_device_get_physical_size (ClutterInputDevice *device,
gdouble *width,
gdouble *height)
{
g_return_val_if_fail (CLUTTER_IS_INPUT_DEVICE (device), FALSE);
return CLUTTER_INPUT_DEVICE_GET_CLASS (device)->get_physical_size (device,
width,
height);
}

View File

@ -171,6 +171,10 @@ void clutter_input_device_set_mapping_mode (ClutterInputDev
CLUTTER_EXPORT CLUTTER_EXPORT
gboolean clutter_input_device_is_grouped (ClutterInputDevice *device, gboolean clutter_input_device_is_grouped (ClutterInputDevice *device,
ClutterInputDevice *other_device); ClutterInputDevice *other_device);
CLUTTER_EXPORT
gboolean clutter_input_device_get_physical_size (ClutterInputDevice *device,
gdouble *width,
gdouble *height);
G_END_DECLS G_END_DECLS

View File

@ -1265,6 +1265,18 @@ clutter_input_device_evdev_release_touch_state (ClutterInputDeviceEvdev *device,
GINT_TO_POINTER (touch_state->device_slot)); GINT_TO_POINTER (touch_state->device_slot));
} }
static gboolean
clutter_input_device_evdev_get_physical_size (ClutterInputDevice *device,
gdouble *width,
gdouble *height)
{
struct libinput_device *libinput_device;
libinput_device = clutter_evdev_input_device_get_libinput_device (device);
return libinput_device_get_size (libinput_device, width, height) == 0;
}
static void static void
clutter_input_device_evdev_class_init (ClutterInputDeviceEvdevClass *klass) clutter_input_device_evdev_class_init (ClutterInputDeviceEvdevClass *klass)
{ {
@ -1280,6 +1292,7 @@ clutter_input_device_evdev_class_init (ClutterInputDeviceEvdevClass *klass)
klass->get_group_n_modes = clutter_input_device_evdev_get_group_n_modes; klass->get_group_n_modes = clutter_input_device_evdev_get_group_n_modes;
klass->is_grouped = clutter_input_device_evdev_is_grouped; klass->is_grouped = clutter_input_device_evdev_is_grouped;
klass->process_kbd_a11y_event = clutter_input_device_evdev_process_kbd_a11y_event; klass->process_kbd_a11y_event = clutter_input_device_evdev_process_kbd_a11y_event;
klass->get_physical_size = clutter_input_device_evdev_get_physical_size;
obj_props[PROP_DEVICE_MATRIX] = obj_props[PROP_DEVICE_MATRIX] =
g_param_spec_boxed ("device-matrix", g_param_spec_boxed ("device-matrix",

View File

@ -180,6 +180,56 @@ clutter_input_device_xi2_is_mode_switch_button (ClutterInputDevice *device,
return button_group == (int) group; return button_group == (int) group;
} }
static gboolean
clutter_input_device_xi2_get_physical_size (ClutterInputDevice *device,
gdouble *width,
gdouble *height)
{
Display *xdisplay;
XIDeviceInfo *dev_info;
gdouble w = 0, h = 0;
int i, n_info, device_id;
xdisplay = clutter_x11_get_default_display ();
device_id = clutter_input_device_get_device_id (device);
clutter_x11_trap_x_errors ();
dev_info = XIQueryDevice (xdisplay, device_id, &n_info);
if (clutter_x11_untrap_x_errors ())
return FALSE;
if (!dev_info)
return FALSE;
for (i = 0; i < dev_info->num_classes; i++)
{
XIValuatorClassInfo *valuator;
gdouble *value;
if (dev_info->classes[i]->type != XIValuatorClass)
continue;
valuator = (XIValuatorClassInfo *) dev_info->classes[i];
if (valuator->label == XInternAtom (xdisplay, "Abs X", True) ||
valuator->label == XInternAtom (xdisplay, "Abs MT Position X", True))
value = &w;
else if (valuator->label == XInternAtom (xdisplay, "Abs Y", True) ||
valuator->label == XInternAtom (xdisplay, "Abs MT Position Y", True))
value = &h;
else
continue;
*value = (valuator->max - valuator->min) * 1000 / valuator->resolution;
}
XIFreeDeviceInfo (dev_info);
*width = w;
*height = h;
return (w > 0 && h > 0);
}
static void static void
clutter_input_device_xi2_class_init (ClutterInputDeviceXI2Class *klass) clutter_input_device_xi2_class_init (ClutterInputDeviceXI2Class *klass)
{ {
@ -193,6 +243,7 @@ clutter_input_device_xi2_class_init (ClutterInputDeviceXI2Class *klass)
device_class->is_grouped = clutter_input_device_xi2_is_grouped; device_class->is_grouped = clutter_input_device_xi2_is_grouped;
device_class->get_group_n_modes = clutter_input_device_xi2_get_group_n_modes; device_class->get_group_n_modes = clutter_input_device_xi2_get_group_n_modes;
device_class->is_mode_switch_button = clutter_input_device_xi2_is_mode_switch_button; device_class->is_mode_switch_button = clutter_input_device_xi2_is_mode_switch_button;
device_class->get_physical_size = clutter_input_device_xi2_get_physical_size;
} }
static void static void