mirror of
https://github.com/brl/mutter.git
synced 2024-11-25 09:30:45 -05:00
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:
parent
2b938ce795
commit
df48b94889
@ -167,6 +167,10 @@ struct _ClutterInputDeviceClass
|
||||
gboolean (* is_grouped) (ClutterInputDevice *device,
|
||||
ClutterInputDevice *other_device);
|
||||
|
||||
gboolean (* get_physical_size) (ClutterInputDevice *device,
|
||||
gdouble *width,
|
||||
gdouble *height);
|
||||
|
||||
/* Keyboard accessbility */
|
||||
void (* process_kbd_a11y_event) (ClutterEvent *event,
|
||||
ClutterInputDevice *device,
|
||||
|
@ -2284,3 +2284,15 @@ clutter_input_device_is_grouped (ClutterInputDevice *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);
|
||||
}
|
||||
|
@ -171,6 +171,10 @@ void clutter_input_device_set_mapping_mode (ClutterInputDev
|
||||
CLUTTER_EXPORT
|
||||
gboolean clutter_input_device_is_grouped (ClutterInputDevice *device,
|
||||
ClutterInputDevice *other_device);
|
||||
CLUTTER_EXPORT
|
||||
gboolean clutter_input_device_get_physical_size (ClutterInputDevice *device,
|
||||
gdouble *width,
|
||||
gdouble *height);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
|
@ -1265,6 +1265,18 @@ clutter_input_device_evdev_release_touch_state (ClutterInputDeviceEvdev *device,
|
||||
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
|
||||
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->is_grouped = clutter_input_device_evdev_is_grouped;
|
||||
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] =
|
||||
g_param_spec_boxed ("device-matrix",
|
||||
|
@ -180,6 +180,56 @@ clutter_input_device_xi2_is_mode_switch_button (ClutterInputDevice *device,
|
||||
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
|
||||
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->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->get_physical_size = clutter_input_device_xi2_get_physical_size;
|
||||
}
|
||||
|
||||
static void
|
||||
|
Loading…
Reference in New Issue
Block a user