[mutter/wip/carlosg/device-size-through-udev: 1/2] backends: Use udev to determine absolute input devices' size
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [mutter/wip/carlosg/device-size-through-udev: 1/2] backends: Use udev to determine absolute input devices' size
- Date: Fri, 22 Mar 2019 17:22:00 +0000 (UTC)
commit 675526904ee8ad3525d55abe6584253c03f8d287
Author: Carlos Garnacho <carlosg gnome org>
Date: Wed Mar 20 23:18:30 2019 +0100
backends: Use udev to determine absolute input devices' size
Use the ID_INPUT_WIDTH_MM/ID_INPUT_HEIGHT_MM udev properties to figure out
absolute input devices' physical size. This works across both backends, and
requires less moving pieces to have it get the right results.
Concretely, fixes size detection on X11/libinput, which makes touchscreen
mapping go wrong.
https://gitlab.gnome.org/GNOME/mutter/issues/514
src/backends/meta-input-mapper.c | 37 ++++++++++++++++++++++++++++++++++++-
1 file changed, 36 insertions(+), 1 deletion(-)
---
diff --git a/src/backends/meta-input-mapper.c b/src/backends/meta-input-mapper.c
index 1a3cb2c7b..7f26fd202 100644
--- a/src/backends/meta-input-mapper.c
+++ b/src/backends/meta-input-mapper.c
@@ -20,6 +20,8 @@
#include "config.h"
+#include <gudev/gudev.h>
+
#include "meta-input-mapper-private.h"
#include "meta-monitor-manager-private.h"
#include "meta-logical-monitor.h"
@@ -39,6 +41,7 @@ struct _MetaInputMapper
ClutterDeviceManager *input_device_manager;
GHashTable *input_devices; /* ClutterInputDevice -> MetaMapperInputInfo */
GHashTable *output_devices; /* MetaLogicalMonitor -> MetaMapperOutputInfo */
+ GUdevClient *udev_client;
};
typedef enum
@@ -270,6 +273,33 @@ match_edid (MetaMapperInputInfo *input,
return TRUE;
}
+static gboolean
+input_device_get_physical_size (MetaInputMapper *mapper,
+ ClutterInputDevice *device,
+ gdouble *width,
+ gdouble *height)
+{
+ GUdevDevice *udev_device;
+ const gchar *node;
+
+ node = clutter_input_device_get_device_node (device);
+ udev_device = g_udev_client_query_by_device_file (mapper->udev_client, node);
+
+ if (udev_device &&
+ g_udev_device_has_property (udev_device, "ID_INPUT_WIDTH_MM"))
+ {
+ *width = g_udev_device_get_property_as_double (udev_device,
+ "ID_INPUT_WIDTH_MM");
+ *height = g_udev_device_get_property_as_double (udev_device,
+ "ID_INPUT_HEIGHT_MM");
+ g_object_unref (udev_device);
+
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
static gboolean
find_size_match (MetaMapperInputInfo *input,
GList *monitors,
@@ -282,7 +312,8 @@ find_size_match (MetaMapperInputInfo *input,
min_w_diff = min_h_diff = MAX_SIZE_MATCH_DIFF;
- if (!clutter_input_device_get_physical_size (input->device, &i_width, &i_height))
+ if (!input_device_get_physical_size (input->mapper, input->device,
+ &i_width, &i_height))
return FALSE;
for (l = monitors; l; l = l->next)
@@ -520,6 +551,7 @@ meta_input_mapper_finalize (GObject *object)
g_hash_table_unref (mapper->input_devices);
g_hash_table_unref (mapper->output_devices);
+ g_clear_object (&mapper->udev_client);
G_OBJECT_CLASS (meta_input_mapper_parent_class)->finalize (object);
}
@@ -527,11 +559,14 @@ meta_input_mapper_finalize (GObject *object)
static void
meta_input_mapper_constructed (GObject *object)
{
+ const char *udev_subsystems[] = { "input", NULL };
MetaInputMapper *mapper = META_INPUT_MAPPER (object);
MetaBackend *backend;
G_OBJECT_CLASS (meta_input_mapper_parent_class)->constructed (object);
+ mapper->udev_client = g_udev_client_new (udev_subsystems);
+
mapper->input_device_manager = clutter_device_manager_get_default ();
g_signal_connect (mapper->input_device_manager, "device-removed",
G_CALLBACK (input_mapper_device_removed_cb), mapper);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]