Update device configuration from gnome-settings-daemon
GsdWacomDevice has been updated, dragging GsdDeviceManager as a dependency from g-s-d, which has been added to panels/common, and compiled as a separate static libary, which is used by the wacom and mouse modules. gsd-input-helper.[ch] is now in such library and has been removed from the panel directories. https://bugzilla.gnome.org/show_bug.cgi?id=743196
This commit is contained in:
parent
9ffaff7472
commit
be8d68c591
17 changed files with 1350 additions and 720 deletions
|
@ -177,6 +177,13 @@ AM_CONDITIONAL(HAVE_INTROSPECTION, false)
|
|||
GDESKTOP_PREFIX=`$PKG_CONFIG --variable prefix gsettings-desktop-schemas`
|
||||
AC_SUBST(GDESKTOP_PREFIX)
|
||||
|
||||
PKG_CHECK_MODULES(DEVICES, $COMMON_MODULES)
|
||||
PKG_CHECK_MODULES(UDEV, gudev-1.0, have_udev=yes, have_udev=no)
|
||||
if test "x$have_udev" = xyes ; then
|
||||
AC_DEFINE(HAVE_UDEV, 1, [System has udev])
|
||||
AM_CONDITIONAL(HAVE_UDEV, [test "x$have_udev" = "xyes"])
|
||||
fi
|
||||
|
||||
PKG_CHECK_MODULES(NETWORK_MANAGER, NetworkManager >= $NETWORK_MANAGER_REQUIRED_VERSION
|
||||
libnm-glib >= $NETWORK_MANAGER_REQUIRED_VERSION
|
||||
libnm-glib-vpn >= $NETWORK_MANAGER_REQUIRED_VERSION
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
# This is used in PANEL_CFLAGS
|
||||
cappletname = common
|
||||
|
||||
noinst_LTLIBRARIES = liblanguage.la
|
||||
noinst_LTLIBRARIES = liblanguage.la libdevice.la
|
||||
|
||||
AM_CPPFLAGS = \
|
||||
$(DEVICES_CFLAGS) \
|
||||
$(PANEL_CFLAGS) \
|
||||
$(LIBLANGUAGE_CFLAGS)
|
||||
|
||||
|
@ -23,6 +24,47 @@ liblanguage_la_SOURCES = \
|
|||
liblanguage_la_LIBADD = \
|
||||
$(LIBLANGUAGE_LIBS)
|
||||
|
||||
#libdevice
|
||||
GSD_COMMON_ENUM_FILES = gsd-common-enums.c gsd-common-enums.h
|
||||
|
||||
gsd-common-enums.h: gsd-device-manager.h Makefile
|
||||
$(AM_V_GEN)($(GLIB_MKENUMS) \
|
||||
--fhead "#ifndef GSD_COMMON_ENUMS_H\n#define GSD_COMMON_ENUMS_H\n\n#include <glib-object.h>\n\nG_BEGIN_DECLS\n" \
|
||||
--fprod "/* enumerations from \"@filename@\" */\n" \
|
||||
--vhead "GType @enum_name@_get_type (void) G_GNUC_CONST;\n#define GSD_TYPE_@ENUMSHORT@ (@enum_name@_get_type())\n" \
|
||||
--ftail "G_END_DECLS\n\n#endif /* !GSD_COMMON_ENUMS_H */" \
|
||||
$(srcdir)/gsd-device-manager.h > $@)
|
||||
|
||||
gsd-common-enums.c: gsd-device-manager.h Makefile gsd-common-enums.h
|
||||
$(AM_V_GEN)($(GLIB_MKENUMS) \
|
||||
--fhead "#include \"gsd-device-manager.h\"\n#include \"gsd-common-enums.h\"\n" \
|
||||
--fprod "\n/* enumerations from \"@filename@\" */" \
|
||||
--vhead "GType\n@enum_name@_get_type (void)\n{\n static GType etype = 0;\n if (etype == 0) {\n static const G@Type@Value values[] = {" \
|
||||
--vprod " { @VALUENAME@, \"@VALUENAME@\", \"@valuenick@\" }," \
|
||||
--vtail " { 0, NULL, NULL }\n };\n etype = g_@type@_register_static (\"@EnumName@\", values);\n }\n return etype;\n}\n" \
|
||||
$(srcdir)/gsd-device-manager.h > $@)
|
||||
|
||||
libdevice_la_SOURCES = \
|
||||
gsd-common-enums.c \
|
||||
gsd-common-enums.h \
|
||||
gsd-input-helper.c \
|
||||
gsd-input-helper.h \
|
||||
gsd-device-manager.c \
|
||||
gsd-device-manager.h \
|
||||
gsd-device-manager-x11.c \
|
||||
gsd-device-manager-x11.h
|
||||
|
||||
libdevice_la_LIBADD = \
|
||||
$(DEVICES_LIBS)
|
||||
|
||||
if HAVE_UDEV
|
||||
AM_CPPFLAGS += $(UDEV_CFLAGS)
|
||||
libdevice_la_LIBADD += $(UDEV_LIBS)
|
||||
libdevice_la_SOURCES += \
|
||||
gsd-device-manager-udev.c \
|
||||
gsd-device-manager-udev.h
|
||||
endif
|
||||
|
||||
resource_files = $(shell glib-compile-resources --sourcedir=$(srcdir) --generate-dependencies $(srcdir)/common.gresource.xml)
|
||||
cc-common-resources.c: common.gresource.xml $(resource_files)
|
||||
$(AM_V_GEN) glib-compile-resources --target=$@ --sourcedir=$(srcdir) --generate-source --c-name cc_common $<
|
||||
|
@ -33,6 +75,21 @@ rulesdir = $(datadir)/polkit-1/rules.d/
|
|||
rules_DATA = gnome-control-center.rules
|
||||
|
||||
EXTRA_DIST = $(rules_DATA) $(resource_files) common.gresource.xml
|
||||
CLEANFILES = $(BUILT_SOURCES)
|
||||
CLEANFILES = $(BUILT_SOURCES) $(GSD_COMMON_ENUM_FILES)
|
||||
|
||||
INPUTDIR=$(top_srcdir)/../gnome-settings-daemon/plugins/common/
|
||||
INPUTFILES= \
|
||||
gsd-input-helper.c \
|
||||
gsd-input-helper.h \
|
||||
gsd-device-manager.c \
|
||||
gsd-device-manager.h \
|
||||
gsd-device-manager-x11.c \
|
||||
gsd-device-manager-x11.h \
|
||||
gsd-device-manager-udev.c \
|
||||
gsd-device-manager-udev.h
|
||||
|
||||
update-from-gsd:
|
||||
FILES="$(INPUTFILES)" DIR="$(INPUTDIR)" $(top_srcdir)/update-from-gsd.sh && changed=true ; \
|
||||
git commit -m "mouse: Update from gnome-settings-daemon" $(INPUTFILES)
|
||||
|
||||
-include $(top_srcdir)/git.mk
|
||||
|
|
232
panels/common/gsd-device-manager-udev.c
Normal file
232
panels/common/gsd-device-manager-udev.c
Normal file
|
@ -0,0 +1,232 @@
|
|||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
|
||||
*
|
||||
* Copyright (C) 2015 Red Hat
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* Author: Carlos Garnacho <carlosg@gnome.org>
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <gudev/gudev.h>
|
||||
|
||||
#include "gsd-device-manager-udev.h"
|
||||
|
||||
struct _GsdUdevDeviceManager
|
||||
{
|
||||
GsdDeviceManager parent_instance;
|
||||
GHashTable *devices;
|
||||
GUdevClient *udev_client;
|
||||
};
|
||||
|
||||
struct _GsdUdevDeviceManagerClass
|
||||
{
|
||||
GsdDeviceManagerClass parent_class;
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE (GsdUdevDeviceManager, gsd_udev_device_manager, GSD_TYPE_DEVICE_MANAGER)
|
||||
|
||||
/* Index matches GsdDeviceType */
|
||||
const gchar *udev_ids[] = {
|
||||
"ID_INPUT_MOUSE",
|
||||
"ID_INPUT_KEYBOARD",
|
||||
"ID_INPUT_TOUCHPAD",
|
||||
"ID_INPUT_TABLET",
|
||||
"ID_INPUT_TOUCHSCREEN"
|
||||
};
|
||||
|
||||
static GsdDeviceType
|
||||
udev_device_get_device_type (GUdevDevice *device)
|
||||
{
|
||||
GsdDeviceType type = 0;
|
||||
gint i;
|
||||
|
||||
for (i = 0; i < G_N_ELEMENTS (udev_ids); i++) {
|
||||
if (g_udev_device_get_property_as_boolean (device, udev_ids[i]))
|
||||
type |= (1 << i);
|
||||
}
|
||||
|
||||
return type;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
device_is_evdev (GUdevDevice *device)
|
||||
{
|
||||
const gchar *device_file;
|
||||
|
||||
device_file = g_udev_device_get_device_file (device);
|
||||
|
||||
if (!device_file || strstr (device_file, "/event") == NULL)
|
||||
return FALSE;
|
||||
|
||||
return g_udev_device_get_property_as_boolean (device, "ID_INPUT");
|
||||
}
|
||||
|
||||
static GsdDevice *
|
||||
create_device (GUdevDevice *udev_device)
|
||||
{
|
||||
const gchar *vendor, *product, *name;
|
||||
guint width, height;
|
||||
GUdevDevice *parent;
|
||||
GsdDevice *device;
|
||||
|
||||
parent = g_udev_device_get_parent (udev_device);
|
||||
g_assert (parent != NULL);
|
||||
|
||||
name = g_udev_device_get_sysfs_attr (parent, "name");
|
||||
vendor = g_udev_device_get_property (udev_device, "ID_VENDOR_ID");
|
||||
product = g_udev_device_get_property (udev_device, "ID_MODEL_ID");
|
||||
width = g_udev_device_get_property_as_int (udev_device, "ID_INPUT_WIDTH_MM");
|
||||
height = g_udev_device_get_property_as_int (udev_device, "ID_INPUT_WIDTH_MM");
|
||||
|
||||
device = g_object_new (GSD_TYPE_DEVICE,
|
||||
"name", name,
|
||||
"device-file", g_udev_device_get_device_file (udev_device),
|
||||
"type", udev_device_get_device_type (udev_device),
|
||||
"vendor-id", vendor,
|
||||
"product-id", product,
|
||||
"width", width,
|
||||
"height", height,
|
||||
NULL);
|
||||
|
||||
g_object_unref (parent);
|
||||
|
||||
return device;
|
||||
}
|
||||
|
||||
static void
|
||||
add_device (GsdUdevDeviceManager *manager,
|
||||
GUdevDevice *udev_device)
|
||||
{
|
||||
GUdevDevice *parent;
|
||||
GsdDevice *device;
|
||||
|
||||
parent = g_udev_device_get_parent (udev_device);
|
||||
|
||||
if (!parent)
|
||||
return;
|
||||
|
||||
device = create_device (udev_device);
|
||||
g_hash_table_insert (manager->devices, g_object_ref (udev_device), device);
|
||||
g_signal_emit_by_name (manager, "device-added", device);
|
||||
}
|
||||
|
||||
static void
|
||||
remove_device (GsdUdevDeviceManager *manager,
|
||||
GUdevDevice *udev_device)
|
||||
{
|
||||
GsdDevice *device;
|
||||
|
||||
device = g_hash_table_lookup (manager->devices, udev_device);
|
||||
|
||||
if (!device)
|
||||
return;
|
||||
|
||||
g_hash_table_steal (manager->devices, udev_device);
|
||||
g_signal_emit_by_name (manager, "device-removed", device);
|
||||
|
||||
g_object_unref (device);
|
||||
g_object_unref (udev_device);
|
||||
}
|
||||
|
||||
static void
|
||||
udev_event_cb (GUdevClient *client,
|
||||
gchar *action,
|
||||
GUdevDevice *device,
|
||||
GsdUdevDeviceManager *manager)
|
||||
{
|
||||
if (!device_is_evdev (device))
|
||||
return;
|
||||
|
||||
if (g_strcmp0 (action, "add") == 0) {
|
||||
add_device (manager, device);
|
||||
} else if (g_strcmp0 (action, "remove") == 0) {
|
||||
remove_device (manager, device);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gsd_udev_device_manager_init (GsdUdevDeviceManager *manager)
|
||||
{
|
||||
const gchar *subsystems[] = { "input", NULL };
|
||||
GList *devices, *l;
|
||||
|
||||
manager->devices = g_hash_table_new_full (NULL, NULL,
|
||||
(GDestroyNotify) g_object_unref,
|
||||
(GDestroyNotify) g_object_unref);
|
||||
|
||||
manager->udev_client = g_udev_client_new (subsystems);
|
||||
g_signal_connect (manager->udev_client, "uevent",
|
||||
G_CALLBACK (udev_event_cb), manager);
|
||||
|
||||
devices = g_udev_client_query_by_subsystem (manager->udev_client,
|
||||
subsystems[0]);
|
||||
|
||||
for (l = devices; l; l = l->next) {
|
||||
GUdevDevice *device = l->data;
|
||||
|
||||
if (device_is_evdev (device))
|
||||
add_device (manager, device);
|
||||
|
||||
g_object_unref (device);
|
||||
}
|
||||
|
||||
g_list_free (devices);
|
||||
}
|
||||
|
||||
static void
|
||||
gsd_udev_device_manager_finalize (GObject *object)
|
||||
{
|
||||
GsdUdevDeviceManager *manager = GSD_UDEV_DEVICE_MANAGER (object);
|
||||
|
||||
g_hash_table_destroy (manager->devices);
|
||||
g_object_unref (manager->udev_client);
|
||||
|
||||
G_OBJECT_CLASS (gsd_udev_device_manager_parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
static GList *
|
||||
gsd_udev_device_manager_list_devices (GsdDeviceManager *manager,
|
||||
GsdDeviceType type)
|
||||
{
|
||||
GsdUdevDeviceManager *manager_udev = GSD_UDEV_DEVICE_MANAGER (manager);
|
||||
GsdDeviceType device_type;
|
||||
GList *devices = NULL;
|
||||
GHashTableIter iter;
|
||||
GsdDevice *device;
|
||||
|
||||
g_hash_table_iter_init (&iter, manager_udev->devices);
|
||||
|
||||
while (g_hash_table_iter_next (&iter, NULL, (gpointer *) &device)) {
|
||||
device_type = gsd_device_get_device_type (device);
|
||||
|
||||
if ((device_type & type) == type)
|
||||
devices = g_list_prepend (devices, device);
|
||||
}
|
||||
|
||||
return devices;
|
||||
}
|
||||
|
||||
static void
|
||||
gsd_udev_device_manager_class_init (GsdUdevDeviceManagerClass *klass)
|
||||
{
|
||||
GsdDeviceManagerClass *manager_class = GSD_DEVICE_MANAGER_CLASS (klass);
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
||||
|
||||
object_class->finalize = gsd_udev_device_manager_finalize;
|
||||
manager_class->list_devices = gsd_udev_device_manager_list_devices;
|
||||
}
|
43
panels/common/gsd-device-manager-udev.h
Normal file
43
panels/common/gsd-device-manager-udev.h
Normal file
|
@ -0,0 +1,43 @@
|
|||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
|
||||
*
|
||||
* Copyright (C) 2015 Red Hat
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* Author: Carlos Garnacho <carlosg@gnome.org>
|
||||
*/
|
||||
|
||||
#ifndef __GSD_UDEV_DEVICE_MANAGER_H__
|
||||
#define __GSD_UDEV_DEVICE_MANAGER_H__
|
||||
|
||||
#include "gsd-device-manager.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define GSD_TYPE_UDEV_DEVICE_MANAGER (gsd_udev_device_manager_get_type ())
|
||||
#define GSD_UDEV_DEVICE_MANAGER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GSD_TYPE_UDEV_DEVICE_MANAGER, GsdUdevDeviceManager))
|
||||
#define GSD_UDEV_DEVICE_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GSD_TYPE_UDEV_DEVICE_MANAGER, GsdUdevDeviceManagerClass))
|
||||
#define GSD_IS_UDEV_DEVICE_MANAGER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GSD_TYPE_UDEV_DEVICE_MANAGER))
|
||||
#define GSD_IS_UDEV_DEVICE_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GSD_TYPE_UDEV_DEVICE_MANAGER))
|
||||
#define GSD_UDEV_DEVICE_MANAGER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GSD_TYPE_UDEV_DEVICE_MANAGER, GsdUdevDeviceManagerClass))
|
||||
|
||||
typedef struct _GsdUdevDeviceManager GsdUdevDeviceManager;
|
||||
typedef struct _GsdUdevDeviceManagerClass GsdUdevDeviceManagerClass;
|
||||
|
||||
GType gsd_udev_device_manager_get_type (void) G_GNUC_CONST;
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __GSD_UDEV_DEVICE_MANAGER_H__ */
|
261
panels/common/gsd-device-manager-x11.c
Normal file
261
panels/common/gsd-device-manager-x11.c
Normal file
|
@ -0,0 +1,261 @@
|
|||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
|
||||
*
|
||||
* Copyright (C) 2015 Red Hat
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* Author: Carlos Garnacho <carlosg@gnome.org>
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <gdk/gdk.h>
|
||||
#include <gdk/gdkx.h>
|
||||
|
||||
#include "gsd-input-helper.h"
|
||||
#include "gsd-device-manager-x11.h"
|
||||
|
||||
struct _GsdX11DeviceManager
|
||||
{
|
||||
GsdDeviceManager parent_instance;
|
||||
GdkDeviceManager *device_manager;
|
||||
GHashTable *devices;
|
||||
GHashTable *gdk_devices;
|
||||
};
|
||||
|
||||
struct _GsdX11DeviceManagerClass
|
||||
{
|
||||
GsdDeviceManagerClass parent_class;
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE (GsdX11DeviceManager, gsd_x11_device_manager, GSD_TYPE_DEVICE_MANAGER)
|
||||
|
||||
static GsdDeviceType
|
||||
device_get_device_type (GdkDevice *gdk_device)
|
||||
{
|
||||
GdkInputSource source;
|
||||
|
||||
source = gdk_device_get_source (gdk_device);
|
||||
|
||||
switch (source) {
|
||||
case GDK_SOURCE_MOUSE:
|
||||
return GSD_DEVICE_TYPE_MOUSE;
|
||||
case GDK_SOURCE_PEN:
|
||||
case GDK_SOURCE_ERASER:
|
||||
case GDK_SOURCE_CURSOR:
|
||||
return GSD_DEVICE_TYPE_TABLET;
|
||||
case GDK_SOURCE_KEYBOARD:
|
||||
return GSD_DEVICE_TYPE_KEYBOARD;
|
||||
case GDK_SOURCE_TOUCHSCREEN:
|
||||
return GSD_DEVICE_TYPE_TOUCHSCREEN;
|
||||
case GDK_SOURCE_TOUCHPAD:
|
||||
return GSD_DEVICE_TYPE_TOUCHPAD;
|
||||
default:
|
||||
g_warning ("Unhandled input source %d\n", source);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static GsdDevice *
|
||||
create_device (GdkDevice *gdk_device,
|
||||
const gchar *device_file)
|
||||
{
|
||||
guint width, height;
|
||||
GsdDevice *device;
|
||||
gint id;
|
||||
|
||||
id = gdk_x11_device_get_id (gdk_device);
|
||||
xdevice_get_dimensions (id, &width, &height);
|
||||
|
||||
device = g_object_new (GSD_TYPE_DEVICE,
|
||||
"name", gdk_device_get_name (gdk_device),
|
||||
"device-file", device_file,
|
||||
"type", device_get_device_type (gdk_device),
|
||||
"vendor-id", gdk_device_get_vendor_id (gdk_device),
|
||||
"product-id", gdk_device_get_product_id (gdk_device),
|
||||
"width", width,
|
||||
"height", height,
|
||||
NULL);
|
||||
return device;
|
||||
}
|
||||
|
||||
static void
|
||||
add_device (GsdX11DeviceManager *manager,
|
||||
GdkDevice *gdk_device)
|
||||
{
|
||||
gchar *device_file;
|
||||
GsdDevice *device;
|
||||
gint id;
|
||||
|
||||
if (gdk_device_get_device_type (gdk_device) == GDK_DEVICE_TYPE_MASTER)
|
||||
return;
|
||||
|
||||
id = gdk_x11_device_get_id (gdk_device);
|
||||
device_file = xdevice_get_device_node (id);
|
||||
|
||||
if (!device_file)
|
||||
return;
|
||||
|
||||
if (!g_hash_table_lookup (manager->devices, device_file)) {
|
||||
device = create_device (gdk_device, device_file);
|
||||
g_hash_table_insert (manager->devices, g_strdup (device_file), device);
|
||||
g_signal_emit_by_name (manager, "device-added", device);
|
||||
}
|
||||
|
||||
/* Takes ownership of device_file */
|
||||
g_hash_table_insert (manager->gdk_devices, gdk_device, device_file);
|
||||
}
|
||||
|
||||
static void
|
||||
remove_device (GsdX11DeviceManager *manager,
|
||||
GdkDevice *gdk_device)
|
||||
{
|
||||
const gchar *device_file;
|
||||
GsdDevice *device;
|
||||
|
||||
device_file = g_hash_table_lookup (manager->gdk_devices, gdk_device);
|
||||
|
||||
if (!device_file)
|
||||
return;
|
||||
|
||||
device = g_hash_table_lookup (manager->devices, device_file);
|
||||
|
||||
if (device)
|
||||
g_object_ref (device);
|
||||
|
||||
g_hash_table_remove (manager->devices, device_file);
|
||||
g_hash_table_remove (manager->gdk_devices, gdk_device);
|
||||
|
||||
if (device) {
|
||||
g_signal_emit_by_name (manager, "device-removed", device);
|
||||
g_object_unref (device);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
init_devices (GsdX11DeviceManager *manager,
|
||||
GdkDeviceType device_type)
|
||||
{
|
||||
GList *devices, *l;
|
||||
|
||||
devices = gdk_device_manager_list_devices (manager->device_manager,
|
||||
device_type);
|
||||
|
||||
for (l = devices; l; l = l->next)
|
||||
add_device (manager, l->data);
|
||||
|
||||
g_list_free (devices);
|
||||
}
|
||||
|
||||
static void
|
||||
gsd_x11_device_manager_init (GsdX11DeviceManager *manager)
|
||||
{
|
||||
GdkDisplay *display;
|
||||
|
||||
manager->devices = g_hash_table_new_full (g_str_hash, g_str_equal,
|
||||
(GDestroyNotify) g_free,
|
||||
(GDestroyNotify) g_object_unref);
|
||||
manager->gdk_devices = g_hash_table_new_full (NULL, NULL, NULL,
|
||||
(GDestroyNotify) g_free);
|
||||
|
||||
display = gdk_display_get_default ();
|
||||
manager->device_manager = gdk_display_get_device_manager (display);
|
||||
|
||||
g_signal_connect_swapped (manager->device_manager, "device-added",
|
||||
G_CALLBACK (add_device), manager);
|
||||
g_signal_connect_swapped (manager->device_manager, "device-removed",
|
||||
G_CALLBACK (remove_device), manager);
|
||||
|
||||
init_devices (manager, GDK_DEVICE_TYPE_SLAVE);
|
||||
init_devices (manager, GDK_DEVICE_TYPE_FLOATING);
|
||||
}
|
||||
|
||||
static GList *
|
||||
gsd_x11_device_manager_list_devices (GsdDeviceManager *manager,
|
||||
GsdDeviceType type)
|
||||
{
|
||||
GsdX11DeviceManager *manager_x11 = GSD_X11_DEVICE_MANAGER (manager);
|
||||
GsdDeviceType device_type;
|
||||
GList *devices = NULL;
|
||||
GHashTableIter iter;
|
||||
GsdDevice *device;
|
||||
|
||||
g_hash_table_iter_init (&iter, manager_x11->devices);
|
||||
|
||||
while (g_hash_table_iter_next (&iter, NULL, (gpointer *) &device)) {
|
||||
device_type = gsd_device_get_device_type (device);
|
||||
|
||||
if ((device_type & type) == type)
|
||||
devices = g_list_prepend (devices, device);
|
||||
}
|
||||
|
||||
return devices;
|
||||
}
|
||||
|
||||
static void
|
||||
gsd_x11_device_manager_class_init (GsdX11DeviceManagerClass *klass)
|
||||
{
|
||||
GsdDeviceManagerClass *manager_class = GSD_DEVICE_MANAGER_CLASS (klass);
|
||||
|
||||
manager_class->list_devices = gsd_x11_device_manager_list_devices;
|
||||
}
|
||||
|
||||
GdkDevice **
|
||||
gsd_x11_device_manager_get_gdk_devices (GsdX11DeviceManager *manager,
|
||||
GsdDevice *device,
|
||||
guint *n_gdk_devices)
|
||||
{
|
||||
const gchar *device_node;
|
||||
GPtrArray *gdk_devices;
|
||||
GdkDevice *gdk_device;
|
||||
GHashTableIter iter;
|
||||
|
||||
if (n_gdk_devices)
|
||||
*n_gdk_devices = 0;
|
||||
|
||||
g_return_val_if_fail (GSD_IS_X11_DEVICE_MANAGER (manager), NULL);
|
||||
g_return_val_if_fail (GSD_IS_DEVICE (device), NULL);
|
||||
|
||||
gdk_devices = g_ptr_array_new ();
|
||||
g_hash_table_iter_init (&iter, manager->gdk_devices);
|
||||
|
||||
while (g_hash_table_iter_next (&iter, (gpointer *) &gdk_device, (gpointer *) &device_node)) {
|
||||
if (g_strcmp0 (gsd_device_get_device_file (device), device_node) == 0)
|
||||
g_ptr_array_add (gdk_devices, gdk_device);
|
||||
}
|
||||
|
||||
if (n_gdk_devices)
|
||||
*n_gdk_devices = gdk_devices->len;
|
||||
|
||||
return (GdkDevice **) g_ptr_array_free (gdk_devices, FALSE);
|
||||
}
|
||||
|
||||
GsdDevice *
|
||||
gsd_x11_device_manager_lookup_gdk_device (GsdX11DeviceManager *manager,
|
||||
GdkDevice *gdk_device)
|
||||
{
|
||||
const gchar *device_node;
|
||||
|
||||
g_return_val_if_fail (GSD_IS_X11_DEVICE_MANAGER (manager), NULL);
|
||||
g_return_val_if_fail (GDK_IS_DEVICE (gdk_device), NULL);
|
||||
|
||||
device_node = g_hash_table_lookup (manager->gdk_devices, gdk_device);
|
||||
|
||||
if (!device_node)
|
||||
return NULL;
|
||||
|
||||
return g_hash_table_lookup (manager->devices, device_node);
|
||||
}
|
50
panels/common/gsd-device-manager-x11.h
Normal file
50
panels/common/gsd-device-manager-x11.h
Normal file
|
@ -0,0 +1,50 @@
|
|||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
|
||||
*
|
||||
* Copyright (C) 2015 Red Hat
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* Author: Carlos Garnacho <carlosg@gnome.org>
|
||||
*/
|
||||
|
||||
#ifndef __GSD_X11_DEVICE_MANAGER_H__
|
||||
#define __GSD_X11_DEVICE_MANAGER_H__
|
||||
|
||||
#include <gdk/gdk.h>
|
||||
#include "gsd-device-manager.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define GSD_TYPE_X11_DEVICE_MANAGER (gsd_x11_device_manager_get_type ())
|
||||
#define GSD_X11_DEVICE_MANAGER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GSD_TYPE_X11_DEVICE_MANAGER, GsdX11DeviceManager))
|
||||
#define GSD_X11_DEVICE_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GSD_TYPE_X11_DEVICE_MANAGER, GsdX11DeviceManagerClass))
|
||||
#define GSD_IS_X11_DEVICE_MANAGER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GSD_TYPE_X11_DEVICE_MANAGER))
|
||||
#define GSD_IS_X11_DEVICE_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GSD_TYPE_X11_DEVICE_MANAGER))
|
||||
#define GSD_X11_DEVICE_MANAGER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GSD_TYPE_X11_DEVICE_MANAGER, GsdX11DeviceManagerClass))
|
||||
|
||||
typedef struct _GsdX11DeviceManager GsdX11DeviceManager;
|
||||
typedef struct _GsdX11DeviceManagerClass GsdX11DeviceManagerClass;
|
||||
|
||||
GType gsd_x11_device_manager_get_type (void) G_GNUC_CONST;
|
||||
|
||||
GdkDevice ** gsd_x11_device_manager_get_gdk_devices (GsdX11DeviceManager *manager,
|
||||
GsdDevice *device,
|
||||
guint *n_gdk_devices);
|
||||
GsdDevice * gsd_x11_device_manager_lookup_gdk_device (GsdX11DeviceManager *manager,
|
||||
GdkDevice *gdk_device);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __GSD_X11_DEVICE_MANAGER_H__ */
|
406
panels/common/gsd-device-manager.c
Normal file
406
panels/common/gsd-device-manager.c
Normal file
|
@ -0,0 +1,406 @@
|
|||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
|
||||
*
|
||||
* Copyright (C) 2014 Red Hat
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* Author: Carlos Garnacho <carlosg@gnome.org>
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "gsd-device-manager-x11.h"
|
||||
#include "gsd-device-manager-udev.h"
|
||||
#include "gsd-common-enums.h"
|
||||
|
||||
typedef struct _GsdDevicePrivate GsdDevicePrivate;
|
||||
typedef struct _GsdDeviceManagerPrivate GsdDeviceManagerPrivate;
|
||||
|
||||
struct _GsdDevicePrivate
|
||||
{
|
||||
gchar *name;
|
||||
gchar *device_file;
|
||||
gchar *vendor_id;
|
||||
gchar *product_id;
|
||||
GsdDeviceType type;
|
||||
guint width;
|
||||
guint height;
|
||||
};
|
||||
|
||||
enum {
|
||||
PROP_NAME = 1,
|
||||
PROP_DEVICE_FILE,
|
||||
PROP_VENDOR_ID,
|
||||
PROP_PRODUCT_ID,
|
||||
PROP_TYPE,
|
||||
PROP_WIDTH,
|
||||
PROP_HEIGHT
|
||||
};
|
||||
|
||||
enum {
|
||||
DEVICE_ADDED,
|
||||
DEVICE_REMOVED,
|
||||
N_SIGNALS
|
||||
};
|
||||
|
||||
static guint signals[N_SIGNALS] = { 0 };
|
||||
|
||||
G_DEFINE_TYPE_WITH_PRIVATE (GsdDevice, gsd_device, G_TYPE_OBJECT)
|
||||
G_DEFINE_TYPE (GsdDeviceManager, gsd_device_manager, G_TYPE_OBJECT)
|
||||
|
||||
static void
|
||||
gsd_device_init (GsdDevice *device)
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
gsd_device_set_property (GObject *object,
|
||||
guint prop_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
GsdDevicePrivate *priv;
|
||||
|
||||
priv = gsd_device_get_instance_private (GSD_DEVICE (object));
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_NAME:
|
||||
priv->name = g_value_dup_string (value);
|
||||
break;
|
||||
case PROP_DEVICE_FILE:
|
||||
priv->device_file = g_value_dup_string (value);
|
||||
break;
|
||||
case PROP_VENDOR_ID:
|
||||
priv->vendor_id = g_value_dup_string (value);
|
||||
break;
|
||||
case PROP_PRODUCT_ID:
|
||||
priv->product_id = g_value_dup_string (value);
|
||||
break;
|
||||
case PROP_TYPE:
|
||||
priv->type = g_value_get_flags (value);
|
||||
break;
|
||||
case PROP_WIDTH:
|
||||
priv->width = g_value_get_uint (value);
|
||||
break;
|
||||
case PROP_HEIGHT:
|
||||
priv->height = g_value_get_uint (value);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gsd_device_get_property (GObject *object,
|
||||
guint prop_id,
|
||||
GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
GsdDevicePrivate *priv;
|
||||
|
||||
priv = gsd_device_get_instance_private (GSD_DEVICE (object));
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_NAME:
|
||||
g_value_set_string (value, priv->name);
|
||||
break;
|
||||
case PROP_DEVICE_FILE:
|
||||
g_value_set_string (value, priv->device_file);
|
||||
break;
|
||||
case PROP_VENDOR_ID:
|
||||
g_value_set_string (value, priv->vendor_id);
|
||||
break;
|
||||
case PROP_PRODUCT_ID:
|
||||
g_value_set_string (value, priv->product_id);
|
||||
break;
|
||||
case PROP_TYPE:
|
||||
g_value_set_flags (value, priv->type);
|
||||
break;
|
||||
case PROP_WIDTH:
|
||||
g_value_set_uint (value, priv->width);
|
||||
break;
|
||||
case PROP_HEIGHT:
|
||||
g_value_set_uint (value, priv->height);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gsd_device_finalize (GObject *object)
|
||||
{
|
||||
GsdDevicePrivate *priv;
|
||||
|
||||
priv = gsd_device_get_instance_private (GSD_DEVICE (object));
|
||||
|
||||
g_free (priv->name);
|
||||
g_free (priv->vendor_id);
|
||||
g_free (priv->product_id);
|
||||
g_free (priv->device_file);
|
||||
|
||||
G_OBJECT_CLASS (gsd_device_parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
static void
|
||||
gsd_device_class_init (GsdDeviceClass *klass)
|
||||
{
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
||||
|
||||
object_class->set_property = gsd_device_set_property;
|
||||
object_class->get_property = gsd_device_get_property;
|
||||
object_class->finalize = gsd_device_finalize;
|
||||
|
||||
g_object_class_install_property (object_class,
|
||||
PROP_NAME,
|
||||
g_param_spec_string ("name",
|
||||
"Name",
|
||||
"Name",
|
||||
NULL,
|
||||
G_PARAM_READWRITE |
|
||||
G_PARAM_CONSTRUCT_ONLY));
|
||||
g_object_class_install_property (object_class,
|
||||
PROP_DEVICE_FILE,
|
||||
g_param_spec_string ("device-file",
|
||||
"Device file",
|
||||
"Device file",
|
||||
NULL,
|
||||
G_PARAM_READWRITE |
|
||||
G_PARAM_CONSTRUCT_ONLY));
|
||||
g_object_class_install_property (object_class,
|
||||
PROP_VENDOR_ID,
|
||||
g_param_spec_string ("vendor-id",
|
||||
"Vendor ID",
|
||||
"Vendor ID",
|
||||
NULL,
|
||||
G_PARAM_READWRITE |
|
||||
G_PARAM_CONSTRUCT_ONLY));
|
||||
g_object_class_install_property (object_class,
|
||||
PROP_PRODUCT_ID,
|
||||
g_param_spec_string ("product-id",
|
||||
"Product ID",
|
||||
"Product ID",
|
||||
NULL,
|
||||
G_PARAM_READWRITE |
|
||||
G_PARAM_CONSTRUCT_ONLY));
|
||||
g_object_class_install_property (object_class,
|
||||
PROP_TYPE,
|
||||
g_param_spec_flags ("type",
|
||||
"Device type",
|
||||
"Device type",
|
||||
GSD_TYPE_DEVICE_TYPE, 0,
|
||||
G_PARAM_READWRITE |
|
||||
G_PARAM_CONSTRUCT_ONLY));
|
||||
g_object_class_install_property (object_class,
|
||||
PROP_WIDTH,
|
||||
g_param_spec_uint ("width",
|
||||
"Width",
|
||||
"Width",
|
||||
0, G_MAXUINT, 0,
|
||||
G_PARAM_READWRITE |
|
||||
G_PARAM_CONSTRUCT_ONLY));
|
||||
g_object_class_install_property (object_class,
|
||||
PROP_HEIGHT,
|
||||
g_param_spec_uint ("height",
|
||||
"Height",
|
||||
"Height",
|
||||
0, G_MAXUINT, 0,
|
||||
G_PARAM_READWRITE |
|
||||
G_PARAM_CONSTRUCT_ONLY));
|
||||
}
|
||||
|
||||
static void
|
||||
gsd_device_manager_class_init (GsdDeviceManagerClass *klass)
|
||||
{
|
||||
signals[DEVICE_ADDED] =
|
||||
g_signal_new ("device-added",
|
||||
GSD_TYPE_DEVICE_MANAGER,
|
||||
G_SIGNAL_RUN_LAST,
|
||||
G_STRUCT_OFFSET (GsdDeviceManagerClass, device_added),
|
||||
NULL, NULL, NULL,
|
||||
G_TYPE_NONE, 1,
|
||||
GSD_TYPE_DEVICE | G_SIGNAL_TYPE_STATIC_SCOPE);
|
||||
|
||||
signals[DEVICE_REMOVED] =
|
||||
g_signal_new ("device-removed",
|
||||
GSD_TYPE_DEVICE_MANAGER,
|
||||
G_SIGNAL_RUN_LAST,
|
||||
G_STRUCT_OFFSET (GsdDeviceManagerClass, device_removed),
|
||||
NULL, NULL, NULL,
|
||||
G_TYPE_NONE, 1,
|
||||
GSD_TYPE_DEVICE | G_SIGNAL_TYPE_STATIC_SCOPE);
|
||||
}
|
||||
|
||||
static void
|
||||
gsd_device_manager_init (GsdDeviceManager *manager)
|
||||
{
|
||||
}
|
||||
|
||||
GsdDeviceManager *
|
||||
gsd_device_manager_get (void)
|
||||
{
|
||||
GsdDeviceManager *manager;
|
||||
GdkScreen *screen;
|
||||
|
||||
screen = gdk_screen_get_default ();
|
||||
g_return_val_if_fail (screen != NULL, NULL);
|
||||
|
||||
manager = g_object_get_data (G_OBJECT (screen), "gsd-device-manager-data");
|
||||
|
||||
if (!manager) {
|
||||
#ifdef HAVE_WAYLAND
|
||||
if (!GDK_IS_X11_SCREEN (screen))) {
|
||||
manager = g_object_new (GSD_TYPE_UDEV_DEVICE_MANAGER,
|
||||
NULL);
|
||||
} else
|
||||
#endif /* HAVE_WAYLAND */
|
||||
{
|
||||
manager = g_object_new (GSD_TYPE_X11_DEVICE_MANAGER,
|
||||
NULL);
|
||||
}
|
||||
|
||||
g_object_set_data_full (G_OBJECT (screen), "gsd-device-manager-data",
|
||||
manager, (GDestroyNotify) g_object_unref);
|
||||
}
|
||||
|
||||
return manager;
|
||||
}
|
||||
|
||||
GList *
|
||||
gsd_device_manager_list_devices (GsdDeviceManager *manager,
|
||||
GsdDeviceType type)
|
||||
{
|
||||
g_return_val_if_fail (GSD_IS_DEVICE_MANAGER (manager), NULL);
|
||||
|
||||
return GSD_DEVICE_MANAGER_GET_CLASS (manager)->list_devices (manager, type);
|
||||
}
|
||||
|
||||
GsdDeviceType
|
||||
gsd_device_get_device_type (GsdDevice *device)
|
||||
{
|
||||
GsdDevicePrivate *priv;
|
||||
|
||||
g_return_val_if_fail (GSD_IS_DEVICE (device), 0);
|
||||
|
||||
priv = gsd_device_get_instance_private (device);
|
||||
|
||||
return priv->type;
|
||||
}
|
||||
|
||||
void
|
||||
gsd_device_get_device_ids (GsdDevice *device,
|
||||
const gchar **vendor,
|
||||
const gchar **product)
|
||||
{
|
||||
GsdDevicePrivate *priv;
|
||||
|
||||
g_return_if_fail (GSD_IS_DEVICE (device));
|
||||
|
||||
priv = gsd_device_get_instance_private (device);
|
||||
|
||||
if (vendor)
|
||||
*vendor = priv->vendor_id;
|
||||
if (product)
|
||||
*product = priv->product_id;
|
||||
}
|
||||
|
||||
GSettings *
|
||||
gsd_device_get_settings (GsdDevice *device)
|
||||
{
|
||||
const gchar *schema = NULL, *vendor, *product;
|
||||
GSettings *settings;
|
||||
GsdDeviceType type;
|
||||
gchar *path = NULL;
|
||||
|
||||
g_return_val_if_fail (GSD_IS_DEVICE (device), NULL);
|
||||
|
||||
type = gsd_device_get_device_type (device);
|
||||
|
||||
if (type & (GSD_DEVICE_TYPE_TOUCHSCREEN | GSD_DEVICE_TYPE_TABLET)) {
|
||||
gsd_device_get_device_ids (device, &vendor, &product);
|
||||
|
||||
if (type & GSD_DEVICE_TYPE_TOUCHSCREEN) {
|
||||
schema = "org.gnome.desktop.peripherals.touchscreen";
|
||||
path = g_strdup_printf ("/org/gnome/desktop/peripherals/touchscreens/%s:%s/",
|
||||
vendor, product);
|
||||
} else if (type & GSD_DEVICE_TYPE_TABLET) {
|
||||
schema = "org.gnome.desktop.peripherals.tablet";
|
||||
path = g_strdup_printf ("/org/gnome/desktop/peripherals/tablets/%s:%s/",
|
||||
vendor, product);
|
||||
}
|
||||
} else if (type & (GSD_DEVICE_TYPE_MOUSE | GSD_DEVICE_TYPE_TOUCHPAD)) {
|
||||
schema = "org.gnome.desktop.peripherals.mouse";
|
||||
} else if (type & GSD_DEVICE_TYPE_KEYBOARD) {
|
||||
schema = "org.gnome.desktop.peripherals.keyboard";
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (path) {
|
||||
settings = g_settings_new_with_path (schema, path);
|
||||
g_free (path);
|
||||
} else {
|
||||
settings = g_settings_new (schema);
|
||||
}
|
||||
|
||||
return settings;
|
||||
}
|
||||
|
||||
const gchar *
|
||||
gsd_device_get_name (GsdDevice *device)
|
||||
{
|
||||
GsdDevicePrivate *priv;
|
||||
|
||||
g_return_val_if_fail (GSD_IS_DEVICE (device), NULL);
|
||||
|
||||
priv = gsd_device_get_instance_private (device);
|
||||
|
||||
return priv->name;
|
||||
}
|
||||
|
||||
const gchar *
|
||||
gsd_device_get_device_file (GsdDevice *device)
|
||||
{
|
||||
GsdDevicePrivate *priv;
|
||||
|
||||
g_return_val_if_fail (GSD_IS_DEVICE (device), NULL);
|
||||
|
||||
priv = gsd_device_get_instance_private (device);
|
||||
|
||||
return priv->device_file;
|
||||
}
|
||||
|
||||
gboolean
|
||||
gsd_device_get_dimensions (GsdDevice *device,
|
||||
guint *width,
|
||||
guint *height)
|
||||
{
|
||||
GsdDevicePrivate *priv;
|
||||
|
||||
g_return_val_if_fail (GSD_IS_DEVICE (device), FALSE);
|
||||
|
||||
priv = gsd_device_get_instance_private (device);
|
||||
|
||||
if (width)
|
||||
*width = priv->width;
|
||||
if (height)
|
||||
*height = priv->height;
|
||||
|
||||
return priv->width > 0 && priv->height > 0;
|
||||
}
|
108
panels/common/gsd-device-manager.h
Normal file
108
panels/common/gsd-device-manager.h
Normal file
|
@ -0,0 +1,108 @@
|
|||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
|
||||
*
|
||||
* Copyright (C) 2014 Carlos Garnacho <carlosg@gnome.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#ifndef __GSD_DEVICE_MANAGER_H__
|
||||
#define __GSD_DEVICE_MANAGER_H__
|
||||
|
||||
#include <glib-object.h>
|
||||
#include <gio/gio.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define GSD_TYPE_DEVICE (gsd_device_get_type ())
|
||||
#define GSD_DEVICE(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GSD_TYPE_DEVICE, GsdDevice))
|
||||
#define GSD_DEVICE_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GSD_TYPE_DEVICE, GsdDeviceClass))
|
||||
#define GSD_IS_DEVICE(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GSD_TYPE_DEVICE))
|
||||
#define GSD_IS_DEVICE_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GSD_TYPE_DEVICE))
|
||||
#define GSD_DEVICE_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GSD_TYPE_DEVICE, GsdDeviceClass))
|
||||
|
||||
#define GSD_TYPE_DEVICE_MANAGER (gsd_device_manager_get_type ())
|
||||
#define GSD_DEVICE_MANAGER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GSD_TYPE_DEVICE_MANAGER, GsdDeviceManager))
|
||||
#define GSD_DEVICE_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GSD_TYPE_DEVICE_MANAGER, GsdDeviceManagerClass))
|
||||
#define GSD_IS_DEVICE_MANAGER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GSD_TYPE_DEVICE_MANAGER))
|
||||
#define GSD_IS_DEVICE_MANAGER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GSD_TYPE_DEVICE_MANAGER))
|
||||
#define GSD_DEVICE_MANAGER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GSD_TYPE_DEVICE_MANAGER, GsdDeviceManagerClass))
|
||||
|
||||
typedef struct _GsdDevice GsdDevice;
|
||||
typedef struct _GsdDeviceClass GsdDeviceClass;
|
||||
typedef struct _GsdDeviceManager GsdDeviceManager;
|
||||
typedef struct _GsdDeviceManagerClass GsdDeviceManagerClass;
|
||||
|
||||
typedef enum {
|
||||
GSD_DEVICE_TYPE_MOUSE = 1 << 0,
|
||||
GSD_DEVICE_TYPE_KEYBOARD = 1 << 1,
|
||||
GSD_DEVICE_TYPE_TOUCHPAD = 1 << 2,
|
||||
GSD_DEVICE_TYPE_TABLET = 1 << 3,
|
||||
GSD_DEVICE_TYPE_TOUCHSCREEN = 1 << 4
|
||||
} GsdDeviceType;
|
||||
|
||||
struct _GsdDevice {
|
||||
GObject parent_instance;
|
||||
};
|
||||
|
||||
struct _GsdDeviceClass {
|
||||
GObjectClass parent_class;
|
||||
};
|
||||
|
||||
struct _GsdDeviceManager
|
||||
{
|
||||
GObject parent_instance;
|
||||
};
|
||||
|
||||
struct _GsdDeviceManagerClass
|
||||
{
|
||||
GObjectClass parent_class;
|
||||
|
||||
GList * (* list_devices) (GsdDeviceManager *manager,
|
||||
GsdDeviceType type);
|
||||
|
||||
void (* device_added) (GsdDeviceManager *manager,
|
||||
GsdDevice *device);
|
||||
void (* device_removed) (GsdDeviceManager *manager,
|
||||
GsdDevice *device);
|
||||
};
|
||||
|
||||
GType gsd_device_get_type (void) G_GNUC_CONST;
|
||||
GType gsd_device_manager_get_type (void) G_GNUC_CONST;
|
||||
GsdDeviceManager * gsd_device_manager_get (void);
|
||||
GList * gsd_device_manager_list_devices (GsdDeviceManager *manager,
|
||||
GsdDeviceType type);
|
||||
|
||||
const gchar * gsd_device_get_name (GsdDevice *device);
|
||||
GsdDeviceType gsd_device_get_device_type (GsdDevice *device);
|
||||
void gsd_device_get_device_ids (GsdDevice *device,
|
||||
const gchar **vendor,
|
||||
const gchar **product);
|
||||
GSettings * gsd_device_get_settings (GsdDevice *device);
|
||||
|
||||
const gchar * gsd_device_get_device_file (GsdDevice *device);
|
||||
gboolean gsd_device_get_dimensions (GsdDevice *device,
|
||||
guint *width,
|
||||
guint *height);
|
||||
|
||||
#ifdef GDK_WINDOWING_X11
|
||||
GdkDevice ** gsd_device_get_gdk_devices (GsdDevice *device,
|
||||
guint *n_gdk_devices);
|
||||
GsdDevice * gsd_device_manager_lookup_gdk_device (GsdDeviceManager *manager,
|
||||
GdkDevice *gdk_device);
|
||||
#endif
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __GSD_DEVICE_MANAGER_H__ */
|
|
@ -33,6 +33,11 @@
|
|||
#define INPUT_DEVICES_SCHEMA "org.gnome.settings-daemon.peripherals.input-devices"
|
||||
#define KEY_HOTPLUG_COMMAND "hotplug-command"
|
||||
|
||||
#define ABS_MT_X "Abs MT Position X"
|
||||
#define ABS_MT_Y "Abs MT Position Y"
|
||||
#define ABS_X "Abs X"
|
||||
#define ABS_Y "Abs Y"
|
||||
|
||||
typedef gboolean (* InfoIdentifyFunc) (XDeviceInfo *device_info);
|
||||
typedef gboolean (* DeviceIdentifyFunc) (XDevice *xdevice);
|
||||
|
||||
|
@ -264,12 +269,9 @@ device_type_is_present (InfoIdentifyFunc info_func,
|
|||
continue;
|
||||
|
||||
retval = (device_func) (device);
|
||||
if (retval) {
|
||||
XCloseDevice (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), device);
|
||||
xdevice_close (device);
|
||||
if (retval)
|
||||
break;
|
||||
}
|
||||
|
||||
XCloseDevice (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), device);
|
||||
}
|
||||
XFreeDeviceList (device_info);
|
||||
|
||||
|
@ -498,6 +500,7 @@ run_custom_command (GdkDevice *device,
|
|||
CustomCommand command)
|
||||
{
|
||||
GSettings *settings;
|
||||
GError *error = NULL;
|
||||
char *cmd;
|
||||
char *argv[7];
|
||||
int exit_status;
|
||||
|
@ -530,15 +533,25 @@ run_custom_command (GdkDevice *device,
|
|||
g_free (out);
|
||||
|
||||
rc = g_spawn_sync (g_get_home_dir (), argv, NULL, G_SPAWN_SEARCH_PATH,
|
||||
NULL, NULL, NULL, NULL, &exit_status, NULL);
|
||||
NULL, NULL, NULL, NULL, &exit_status, &error);
|
||||
|
||||
if (rc == FALSE)
|
||||
g_warning ("Couldn't execute command '%s', verify that this is a valid command.", cmd);
|
||||
if (rc == FALSE) {
|
||||
g_warning ("Couldn't execute command '%s', verify that this is a valid command: %s", cmd, error->message);
|
||||
g_clear_error (&error);
|
||||
}
|
||||
|
||||
g_free (argv[0]);
|
||||
g_free (argv[4]);
|
||||
|
||||
return (exit_status == 1);
|
||||
if (!g_spawn_check_exit_status (exit_status, &error)) {
|
||||
if (g_error_matches (error, G_SPAWN_EXIT_ERROR, 1)) {
|
||||
g_clear_error (&error);
|
||||
return TRUE;
|
||||
}
|
||||
g_clear_error (&error);
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
GList *
|
||||
|
@ -575,3 +588,114 @@ get_disabled_devices (GdkDeviceManager *manager)
|
|||
|
||||
return ret;
|
||||
}
|
||||
|
||||
const char *
|
||||
xdevice_get_wacom_tool_type (int deviceid)
|
||||
{
|
||||
unsigned long nitems, bytes_after;
|
||||
unsigned char *data = NULL;
|
||||
Atom prop, realtype, tool;
|
||||
GdkDisplay *display;
|
||||
int realformat, rc;
|
||||
const gchar *ret = NULL;
|
||||
|
||||
gdk_error_trap_push ();
|
||||
|
||||
display = gdk_display_get_default ();
|
||||
prop = gdk_x11_get_xatom_by_name ("Wacom Tool Type");
|
||||
|
||||
rc = XIGetProperty (GDK_DISPLAY_XDISPLAY (display),
|
||||
deviceid, prop, 0, 1, False,
|
||||
XA_ATOM, &realtype, &realformat, &nitems,
|
||||
&bytes_after, &data);
|
||||
|
||||
gdk_error_trap_pop_ignored ();
|
||||
|
||||
if (rc != Success || nitems == 0)
|
||||
return NULL;
|
||||
|
||||
if (realtype == XA_ATOM) {
|
||||
tool = *((Atom*) data);
|
||||
ret = gdk_x11_get_xatom_name (tool);
|
||||
}
|
||||
|
||||
XFree (data);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void
|
||||
xdevice_close (XDevice *xdevice)
|
||||
{
|
||||
gdk_error_trap_push ();
|
||||
XCloseDevice (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), xdevice);
|
||||
gdk_error_trap_pop_ignored();
|
||||
}
|
||||
|
||||
gboolean
|
||||
xdevice_get_dimensions (int deviceid,
|
||||
guint *width,
|
||||
guint *height)
|
||||
{
|
||||
GdkDisplay *display = gdk_display_get_default ();
|
||||
XIDeviceInfo *info;
|
||||
guint *value, w, h;
|
||||
int i, n_info;
|
||||
|
||||
info = XIQueryDevice (GDK_DISPLAY_XDISPLAY (display), deviceid, &n_info);
|
||||
*width = *height = w = h = 0;
|
||||
|
||||
if (!info)
|
||||
return FALSE;
|
||||
|
||||
for (i = 0; i < info->num_classes; i++) {
|
||||
XIValuatorClassInfo *valuator_info;
|
||||
|
||||
if (info->classes[i]->type != XIValuatorClass)
|
||||
continue;
|
||||
|
||||
valuator_info = (XIValuatorClassInfo *) info->classes[i];
|
||||
|
||||
if (valuator_info->label == gdk_x11_get_xatom_by_name_for_display (display, ABS_X) ||
|
||||
valuator_info->label == gdk_x11_get_xatom_by_name_for_display (display, ABS_MT_X))
|
||||
value = &w;
|
||||
else if (valuator_info->label == gdk_x11_get_xatom_by_name_for_display (display, ABS_Y) ||
|
||||
valuator_info->label == gdk_x11_get_xatom_by_name_for_display (display, ABS_MT_Y))
|
||||
value = &h;
|
||||
else
|
||||
continue;
|
||||
|
||||
*value = (valuator_info->max - valuator_info->min) * 1000 / valuator_info->resolution;
|
||||
}
|
||||
|
||||
*width = w;
|
||||
*height = h;
|
||||
|
||||
XIFreeDeviceInfo (info);
|
||||
|
||||
return (w != 0 && h != 0);
|
||||
}
|
||||
|
||||
gboolean
|
||||
xdevice_is_libinput (gint deviceid)
|
||||
{
|
||||
GdkDisplay *display = gdk_display_get_default ();
|
||||
gulong nitems, bytes_after;
|
||||
gint rc, format;
|
||||
guchar *data;
|
||||
Atom type;
|
||||
|
||||
gdk_error_trap_push ();
|
||||
|
||||
/* Lookup a libinput driver specific property */
|
||||
rc = XIGetProperty (GDK_DISPLAY_XDISPLAY (display), deviceid,
|
||||
gdk_x11_get_xatom_by_name ("libinput Send Events Mode Enabled"),
|
||||
0, 1, False, XA_INTEGER, &type, &format, &nitems, &bytes_after, &data);
|
||||
|
||||
if (rc == Success)
|
||||
XFree (data);
|
||||
|
||||
gdk_error_trap_pop_ignored ();
|
||||
|
||||
return rc == Success && nitems > 0;
|
||||
}
|
|
@ -80,6 +80,15 @@ gboolean run_custom_command (GdkDevice *device,
|
|||
GList * get_disabled_devices (GdkDeviceManager *manager);
|
||||
char * xdevice_get_device_node (int deviceid);
|
||||
int xdevice_get_last_tool_id (int deviceid);
|
||||
gboolean xdevice_get_dimensions (int deviceid,
|
||||
guint *width,
|
||||
guint *height);
|
||||
void xdevice_close (XDevice *xdevice);
|
||||
|
||||
const char * xdevice_get_wacom_tool_type (int deviceid);
|
||||
|
||||
gboolean xdevice_is_libinput (gint deviceid);
|
||||
|
||||
|
||||
G_END_DECLS
|
||||
|
|
@ -4,6 +4,7 @@ cappletname = mouse
|
|||
AM_CPPFLAGS = \
|
||||
$(PANEL_CFLAGS) \
|
||||
$(MOUSE_PANEL_CFLAGS) \
|
||||
-I$(top_srcdir)/panels/common \
|
||||
-DGNOMELOCALEDIR="\"$(datadir)/locale\"" \
|
||||
$(NULL)
|
||||
|
||||
|
@ -19,12 +20,10 @@ libmouse_properties_la_SOURCES = \
|
|||
cc-mouse-panel.h \
|
||||
gnome-mouse-properties.c \
|
||||
gnome-mouse-properties.h \
|
||||
gsd-input-helper.c \
|
||||
gsd-input-helper.h \
|
||||
gnome-mouse-test.c \
|
||||
gnome-mouse-test.h
|
||||
|
||||
libmouse_properties_la_LIBADD = $(PANEL_LIBS) $(MOUSE_PANEL_LIBS)
|
||||
libmouse_properties_la_LIBADD = $(PANEL_LIBS) $(MOUSE_PANEL_LIBS) $(top_builddir)/panels/common/libdevice.la
|
||||
|
||||
test_gnome_mouse_test_SOURCES = \
|
||||
$(BUILT_SOURCES) \
|
||||
|
@ -49,12 +48,6 @@ desktopdir = $(datadir)/applications
|
|||
Desktop_in_files = gnome-mouse-panel.desktop.in
|
||||
desktop_DATA = $(Desktop_in_files:.desktop.in=.desktop)
|
||||
|
||||
INPUTDIR=$(top_srcdir)/../gnome-settings-daemon/plugins/common/
|
||||
INPUTFILES=gsd-input-helper.h gsd-input-helper.c
|
||||
update-from-gsd:
|
||||
FILES="$(INPUTFILES)" DIR="$(INPUTDIR)" $(top_srcdir)/update-from-gsd.sh && changed=true ; \
|
||||
git commit -m "mouse: Update from gnome-settings-daemon" $(INPUTFILES)
|
||||
|
||||
CLEANFILES = $(Desktop_in_files) $(desktop_DATA)
|
||||
EXTRA_DIST = $(resource_files) mouse.gresource.xml
|
||||
|
||||
|
|
|
@ -1,531 +0,0 @@
|
|||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
|
||||
*
|
||||
* Copyright (C) 2010 Bastien Nocera <hadess@hadess.net>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <gdk/gdk.h>
|
||||
#include <gdk/gdkx.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <X11/Xatom.h>
|
||||
#include <X11/extensions/XInput2.h>
|
||||
|
||||
#include "gsd-input-helper.h"
|
||||
|
||||
#define INPUT_DEVICES_SCHEMA "org.gnome.settings-daemon.peripherals.input-devices"
|
||||
#define KEY_HOTPLUG_COMMAND "hotplug-command"
|
||||
|
||||
typedef gboolean (* InfoIdentifyFunc) (XDeviceInfo *device_info);
|
||||
typedef gboolean (* DeviceIdentifyFunc) (XDevice *xdevice);
|
||||
|
||||
gboolean
|
||||
device_set_property (XDevice *xdevice,
|
||||
const char *device_name,
|
||||
PropertyHelper *property)
|
||||
{
|
||||
int rc, i;
|
||||
Atom prop;
|
||||
Atom realtype;
|
||||
int realformat;
|
||||
unsigned long nitems, bytes_after;
|
||||
unsigned char *data;
|
||||
|
||||
prop = XInternAtom (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()),
|
||||
property->name, False);
|
||||
if (!prop)
|
||||
return FALSE;
|
||||
|
||||
gdk_error_trap_push ();
|
||||
|
||||
rc = XGetDeviceProperty (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()),
|
||||
xdevice, prop, 0, property->nitems, False,
|
||||
AnyPropertyType, &realtype, &realformat, &nitems,
|
||||
&bytes_after, &data);
|
||||
|
||||
if (rc != Success ||
|
||||
realtype != property->type ||
|
||||
realformat != property->format ||
|
||||
nitems < property->nitems) {
|
||||
gdk_error_trap_pop_ignored ();
|
||||
g_warning ("Error reading property \"%s\" for \"%s\"", property->name, device_name);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
for (i = 0; i < nitems; i++) {
|
||||
switch (property->format) {
|
||||
case 8:
|
||||
data[i] = property->data.c[i];
|
||||
break;
|
||||
case 32:
|
||||
((long*)data)[i] = property->data.i[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
XChangeDeviceProperty (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()),
|
||||
xdevice, prop, realtype, realformat,
|
||||
PropModeReplace, data, nitems);
|
||||
|
||||
XFree (data);
|
||||
|
||||
if (gdk_error_trap_pop ()) {
|
||||
g_warning ("Error in setting \"%s\" for \"%s\"", property->name, device_name);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
supports_xinput_devices_with_opcode (int *opcode)
|
||||
{
|
||||
gint op_code, event, error;
|
||||
gboolean retval;
|
||||
|
||||
retval = XQueryExtension (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()),
|
||||
"XInputExtension",
|
||||
&op_code,
|
||||
&event,
|
||||
&error);
|
||||
if (opcode)
|
||||
*opcode = op_code;
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
gboolean
|
||||
supports_xinput_devices (void)
|
||||
{
|
||||
return supports_xinput_devices_with_opcode (NULL);
|
||||
}
|
||||
|
||||
gboolean
|
||||
supports_xinput2_devices (int *opcode)
|
||||
{
|
||||
int major, minor;
|
||||
|
||||
if (supports_xinput_devices_with_opcode (opcode) == FALSE)
|
||||
return FALSE;
|
||||
|
||||
gdk_error_trap_push ();
|
||||
|
||||
major = 2;
|
||||
minor = 0;
|
||||
|
||||
if (XIQueryVersion (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), &major, &minor) != Success) {
|
||||
gdk_error_trap_pop_ignored ();
|
||||
/* try for 2.2, maybe gtk has already announced 2.2 support */
|
||||
gdk_error_trap_push ();
|
||||
major = 2;
|
||||
minor = 2;
|
||||
if (XIQueryVersion (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), &major, &minor) != Success) {
|
||||
gdk_error_trap_pop_ignored ();
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
gdk_error_trap_pop_ignored ();
|
||||
|
||||
if ((major * 1000 + minor) < (2000))
|
||||
return FALSE;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
gboolean
|
||||
device_is_touchpad (XDevice *xdevice)
|
||||
{
|
||||
Atom realtype, prop;
|
||||
int realformat;
|
||||
unsigned long nitems, bytes_after;
|
||||
unsigned char *data;
|
||||
|
||||
/* we don't check on the type being XI_TOUCHPAD here,
|
||||
* but having a "Synaptics Off" property should be enough */
|
||||
|
||||
prop = XInternAtom (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), "Synaptics Off", False);
|
||||
if (!prop)
|
||||
return FALSE;
|
||||
|
||||
gdk_error_trap_push ();
|
||||
if ((XGetDeviceProperty (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), xdevice, prop, 0, 1, False,
|
||||
XA_INTEGER, &realtype, &realformat, &nitems,
|
||||
&bytes_after, &data) == Success) && (realtype != None)) {
|
||||
gdk_error_trap_pop_ignored ();
|
||||
XFree (data);
|
||||
return TRUE;
|
||||
}
|
||||
gdk_error_trap_pop_ignored ();
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
gboolean
|
||||
device_info_is_touchpad (XDeviceInfo *device_info)
|
||||
{
|
||||
return (device_info->type == XInternAtom (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), XI_TOUCHPAD, False));
|
||||
}
|
||||
|
||||
gboolean
|
||||
device_info_is_touchscreen (XDeviceInfo *device_info)
|
||||
{
|
||||
return (device_info->type == XInternAtom (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), XI_TOUCHSCREEN, False));
|
||||
}
|
||||
|
||||
gboolean
|
||||
device_info_is_mouse (XDeviceInfo *device_info)
|
||||
{
|
||||
return (device_info->type == XInternAtom (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), XI_MOUSE, False));
|
||||
}
|
||||
|
||||
static gboolean
|
||||
device_type_is_present (InfoIdentifyFunc info_func,
|
||||
DeviceIdentifyFunc device_func)
|
||||
{
|
||||
XDeviceInfo *device_info;
|
||||
gint n_devices;
|
||||
guint i;
|
||||
gboolean retval;
|
||||
|
||||
if (supports_xinput_devices () == FALSE)
|
||||
return TRUE;
|
||||
|
||||
retval = FALSE;
|
||||
|
||||
device_info = XListInputDevices (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), &n_devices);
|
||||
if (device_info == NULL)
|
||||
return FALSE;
|
||||
|
||||
for (i = 0; i < n_devices; i++) {
|
||||
XDevice *device;
|
||||
|
||||
/* Check with the device info first */
|
||||
retval = (info_func) (&device_info[i]);
|
||||
if (retval == FALSE)
|
||||
continue;
|
||||
|
||||
/* If we only have an info func, we're done checking */
|
||||
if (device_func == NULL)
|
||||
break;
|
||||
|
||||
gdk_error_trap_push ();
|
||||
device = XOpenDevice (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), device_info[i].id);
|
||||
if (gdk_error_trap_pop () || (device == NULL))
|
||||
continue;
|
||||
|
||||
retval = (device_func) (device);
|
||||
if (retval) {
|
||||
XCloseDevice (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), device);
|
||||
break;
|
||||
}
|
||||
|
||||
XCloseDevice (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), device);
|
||||
}
|
||||
XFreeDeviceList (device_info);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
gboolean
|
||||
touchscreen_is_present (void)
|
||||
{
|
||||
return device_type_is_present (device_info_is_touchscreen,
|
||||
NULL);
|
||||
}
|
||||
|
||||
gboolean
|
||||
touchpad_is_present (void)
|
||||
{
|
||||
return device_type_is_present (device_info_is_touchpad,
|
||||
device_is_touchpad);
|
||||
}
|
||||
|
||||
gboolean
|
||||
mouse_is_present (void)
|
||||
{
|
||||
return device_type_is_present (device_info_is_mouse,
|
||||
NULL);
|
||||
}
|
||||
|
||||
char *
|
||||
xdevice_get_device_node (int deviceid)
|
||||
{
|
||||
Atom prop;
|
||||
Atom act_type;
|
||||
int act_format;
|
||||
unsigned long nitems, bytes_after;
|
||||
unsigned char *data;
|
||||
char *ret;
|
||||
|
||||
gdk_display_sync (gdk_display_get_default ());
|
||||
|
||||
prop = XInternAtom (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), "Device Node", False);
|
||||
if (!prop)
|
||||
return NULL;
|
||||
|
||||
gdk_error_trap_push ();
|
||||
|
||||
if (!XIGetProperty (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()),
|
||||
deviceid, prop, 0, 1000, False,
|
||||
AnyPropertyType, &act_type, &act_format,
|
||||
&nitems, &bytes_after, &data) == Success) {
|
||||
gdk_error_trap_pop_ignored ();
|
||||
return NULL;
|
||||
}
|
||||
if (gdk_error_trap_pop ())
|
||||
goto out;
|
||||
|
||||
if (nitems == 0)
|
||||
goto out;
|
||||
|
||||
if (act_type != XA_STRING)
|
||||
goto out;
|
||||
|
||||
/* Unknown string format */
|
||||
if (act_format != 8)
|
||||
goto out;
|
||||
|
||||
ret = g_strdup ((char *) data);
|
||||
|
||||
XFree (data);
|
||||
return ret;
|
||||
|
||||
out:
|
||||
XFree (data);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#define TOOL_ID_FORMAT_SIZE 32
|
||||
static int
|
||||
get_id_for_index (guchar *data,
|
||||
guint idx)
|
||||
{
|
||||
guchar *ptr;
|
||||
int id;
|
||||
|
||||
ptr = data;
|
||||
ptr += TOOL_ID_FORMAT_SIZE / 8 * idx;
|
||||
|
||||
id = *((int32_t*)ptr);
|
||||
id = id & 0xfffff;
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
|
||||
#define STYLUS_DEVICE_ID 0x02
|
||||
#define ERASER_DEVICE_ID 0x0A
|
||||
|
||||
int
|
||||
xdevice_get_last_tool_id (int deviceid)
|
||||
{
|
||||
Atom prop;
|
||||
Atom act_type;
|
||||
int act_format;
|
||||
unsigned long nitems, bytes_after;
|
||||
unsigned char *data;
|
||||
int id;
|
||||
|
||||
id = -1;
|
||||
|
||||
gdk_display_sync (gdk_display_get_default ());
|
||||
|
||||
prop = XInternAtom (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), WACOM_SERIAL_IDS_PROP, False);
|
||||
if (!prop)
|
||||
return -1;
|
||||
|
||||
data = NULL;
|
||||
|
||||
gdk_error_trap_push ();
|
||||
|
||||
if (XIGetProperty (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()),
|
||||
deviceid, prop, 0, 1000, False,
|
||||
AnyPropertyType, &act_type, &act_format,
|
||||
&nitems, &bytes_after, &data) != Success) {
|
||||
gdk_error_trap_pop_ignored ();
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (gdk_error_trap_pop ())
|
||||
goto out;
|
||||
|
||||
if (nitems != 4 && nitems != 5)
|
||||
goto out;
|
||||
|
||||
if (act_type != XA_INTEGER)
|
||||
goto out;
|
||||
|
||||
if (act_format != TOOL_ID_FORMAT_SIZE)
|
||||
goto out;
|
||||
|
||||
/* item 0 = tablet ID
|
||||
* item 1 = old device serial number (== last tool in proximity)
|
||||
* item 2 = old hardware serial number (including tool ID)
|
||||
* item 3 = current serial number (0 if no tool in proximity)
|
||||
* item 4 = current tool ID (since Feb 2012)
|
||||
*
|
||||
* Get the current tool ID first, if available, then the old one */
|
||||
id = 0x0;
|
||||
if (nitems == 5)
|
||||
id = get_id_for_index (data, 4);
|
||||
if (id == 0x0)
|
||||
id = get_id_for_index (data, 2);
|
||||
|
||||
/* That means that no tool was set down yet */
|
||||
if (id == STYLUS_DEVICE_ID ||
|
||||
id == ERASER_DEVICE_ID)
|
||||
id = 0x0;
|
||||
|
||||
out:
|
||||
if (data != NULL)
|
||||
XFree (data);
|
||||
return id;
|
||||
}
|
||||
|
||||
gboolean
|
||||
set_device_enabled (int device_id,
|
||||
gboolean enabled)
|
||||
{
|
||||
Atom prop;
|
||||
guchar value;
|
||||
|
||||
prop = XInternAtom (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), "Device Enabled", False);
|
||||
if (!prop)
|
||||
return FALSE;
|
||||
|
||||
gdk_error_trap_push ();
|
||||
|
||||
value = enabled ? 1 : 0;
|
||||
XIChangeProperty (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()),
|
||||
device_id, prop, XA_INTEGER, 8, PropModeReplace, &value, 1);
|
||||
|
||||
if (gdk_error_trap_pop ())
|
||||
return FALSE;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static const char *
|
||||
custom_command_to_string (CustomCommand command)
|
||||
{
|
||||
switch (command) {
|
||||
case COMMAND_DEVICE_ADDED:
|
||||
return "added";
|
||||
case COMMAND_DEVICE_REMOVED:
|
||||
return "removed";
|
||||
case COMMAND_DEVICE_PRESENT:
|
||||
return "present";
|
||||
default:
|
||||
g_assert_not_reached ();
|
||||
}
|
||||
}
|
||||
|
||||
/* Run a custom command on device presence events. Parameters passed into
|
||||
* the custom command are:
|
||||
* command -t [added|removed|present] -i <device ID> <device name>
|
||||
* Type 'added' and 'removed' signal 'device added' and 'device removed',
|
||||
* respectively. Type 'present' signals 'device present at
|
||||
* gnome-settings-daemon init'.
|
||||
*
|
||||
* The script is expected to run synchronously, and an exit value
|
||||
* of "1" means that no other settings will be applied to this
|
||||
* particular device.
|
||||
*
|
||||
* More options may be added in the future.
|
||||
*
|
||||
* This function returns TRUE if we should not apply any more settings
|
||||
* to the device.
|
||||
*/
|
||||
gboolean
|
||||
run_custom_command (GdkDevice *device,
|
||||
CustomCommand command)
|
||||
{
|
||||
GSettings *settings;
|
||||
char *cmd;
|
||||
char *argv[7];
|
||||
int exit_status;
|
||||
gboolean rc;
|
||||
int id;
|
||||
|
||||
settings = g_settings_new (INPUT_DEVICES_SCHEMA);
|
||||
cmd = g_settings_get_string (settings, KEY_HOTPLUG_COMMAND);
|
||||
g_object_unref (settings);
|
||||
|
||||
if (!cmd || cmd[0] == '\0') {
|
||||
g_free (cmd);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* Easter egg! */
|
||||
g_object_get (device, "device-id", &id, NULL);
|
||||
|
||||
argv[0] = cmd;
|
||||
argv[1] = "-t";
|
||||
argv[2] = (char *) custom_command_to_string (command);
|
||||
argv[3] = "-i";
|
||||
argv[4] = g_strdup_printf ("%d", id);
|
||||
argv[5] = g_strdup_printf ("%s", gdk_device_get_name (device));
|
||||
argv[6] = NULL;
|
||||
|
||||
rc = g_spawn_sync (g_get_home_dir (), argv, NULL, G_SPAWN_SEARCH_PATH,
|
||||
NULL, NULL, NULL, NULL, &exit_status, NULL);
|
||||
|
||||
if (rc == FALSE)
|
||||
g_warning ("Couldn't execute command '%s', verify that this is a valid command.", cmd);
|
||||
|
||||
g_free (argv[0]);
|
||||
g_free (argv[4]);
|
||||
g_free (argv[5]);
|
||||
|
||||
return (exit_status == 0);
|
||||
}
|
||||
|
||||
GList *
|
||||
get_disabled_devices (GdkDeviceManager *manager)
|
||||
{
|
||||
XDeviceInfo *device_info;
|
||||
gint n_devices;
|
||||
guint i;
|
||||
GList *ret;
|
||||
|
||||
ret = NULL;
|
||||
|
||||
device_info = XListInputDevices (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), &n_devices);
|
||||
if (device_info == NULL)
|
||||
return ret;
|
||||
|
||||
for (i = 0; i < n_devices; i++) {
|
||||
GdkDevice *device;
|
||||
|
||||
/* Ignore core devices */
|
||||
if (device_info[i].use == IsXKeyboard ||
|
||||
device_info[i].use == IsXPointer)
|
||||
continue;
|
||||
|
||||
/* Check whether the device is actually available */
|
||||
device = gdk_x11_device_manager_lookup (manager, device_info[i].id);
|
||||
if (device != NULL)
|
||||
continue;
|
||||
|
||||
ret = g_list_prepend (ret, GINT_TO_POINTER (device_info[i].id));
|
||||
}
|
||||
|
||||
XFreeDeviceList (device_info);
|
||||
|
||||
return ret;
|
||||
}
|
|
@ -1,82 +0,0 @@
|
|||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
|
||||
*
|
||||
* Copyright (C) 2010 Bastien Nocera <hadess@hadess.net>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef __GSD_INPUT_HELPER_H
|
||||
#define __GSD_INPUT_HELPER_H
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
#include <X11/extensions/XInput.h>
|
||||
#include <X11/extensions/XIproto.h>
|
||||
|
||||
#define WACOM_SERIAL_IDS_PROP "Wacom Serial IDs"
|
||||
|
||||
typedef enum {
|
||||
COMMAND_DEVICE_ADDED,
|
||||
COMMAND_DEVICE_REMOVED,
|
||||
COMMAND_DEVICE_PRESENT
|
||||
} CustomCommand;
|
||||
|
||||
/* Generic property setting code. Fill up the struct property with the property
|
||||
* data and pass it into device_set_property together with the device to be
|
||||
* changed. Note: doesn't cater for non-zero offsets yet, but we don't have
|
||||
* any settings that require that.
|
||||
*/
|
||||
typedef struct {
|
||||
const char *name; /* property name */
|
||||
gint nitems; /* number of items in data */
|
||||
gint format; /* CARD8 or CARD32 sized-items */
|
||||
gint type; /* Atom representing data type */
|
||||
union {
|
||||
const gchar *c; /* 8 bit data */
|
||||
const gint *i; /* 32 bit data */
|
||||
} data;
|
||||
} PropertyHelper;
|
||||
|
||||
gboolean supports_xinput_devices (void);
|
||||
gboolean supports_xinput2_devices (int *opcode);
|
||||
|
||||
gboolean set_device_enabled (int device_id,
|
||||
gboolean enabled);
|
||||
|
||||
gboolean device_is_touchpad (XDevice *xdevice);
|
||||
|
||||
gboolean device_info_is_touchpad (XDeviceInfo *device_info);
|
||||
gboolean device_info_is_touchscreen (XDeviceInfo *device_info);
|
||||
gboolean device_info_is_mouse (XDeviceInfo *device_info);
|
||||
|
||||
gboolean touchpad_is_present (void);
|
||||
gboolean touchscreen_is_present (void);
|
||||
gboolean mouse_is_present (void);
|
||||
|
||||
gboolean device_set_property (XDevice *xdevice,
|
||||
const char *device_name,
|
||||
PropertyHelper *property);
|
||||
|
||||
gboolean run_custom_command (GdkDevice *device,
|
||||
CustomCommand command);
|
||||
|
||||
GList * get_disabled_devices (GdkDeviceManager *manager);
|
||||
char * xdevice_get_device_node (int deviceid);
|
||||
int xdevice_get_last_tool_id (int deviceid);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __GSD_INPUT_HELPER_H */
|
|
@ -7,6 +7,7 @@ AM_CPPFLAGS = \
|
|||
$(PANEL_CFLAGS) \
|
||||
$(WACOM_PANEL_CFLAGS) \
|
||||
-I$(srcdir)/calibrator \
|
||||
-I$(top_srcdir)/panels/common \
|
||||
-DGNOMELOCALEDIR="\"$(datadir)/locale\"" \
|
||||
$(NULL)
|
||||
|
||||
|
@ -30,15 +31,13 @@ libwacom_properties_la_SOURCES = \
|
|||
cc-wacom-stylus-page.h \
|
||||
gsd-wacom-device.c \
|
||||
gsd-wacom-device.h \
|
||||
gsd-input-helper.c \
|
||||
gsd-input-helper.h \
|
||||
cc-wacom-nav-button.c \
|
||||
cc-wacom-nav-button.h \
|
||||
cc-wacom-mapping-panel.c \
|
||||
cc-wacom-mapping-panel.h \
|
||||
gsd-enums.h
|
||||
|
||||
libwacom_properties_la_LIBADD = $(PANEL_LIBS) $(WACOM_PANEL_LIBS) $(builddir)/calibrator/libwacom-calibrator.la
|
||||
libwacom_properties_la_LIBADD = $(PANEL_LIBS) $(WACOM_PANEL_LIBS) $(builddir)/calibrator/libwacom-calibrator.la $(top_builddir)/panels/common/libdevice.la
|
||||
|
||||
noinst_PROGRAMS = test-wacom
|
||||
|
||||
|
@ -59,12 +58,10 @@ test_wacom_SOURCES = \
|
|||
cc-wacom-mapping-panel.h \
|
||||
gsd-wacom-device.c \
|
||||
gsd-wacom-device.h \
|
||||
gsd-input-helper.c \
|
||||
gsd-input-helper.h \
|
||||
gsd-enums.h
|
||||
|
||||
test_wacom_CPPFLAGS = $(AM_CPPFLAGS) -DFAKE_AREA
|
||||
test_wacom_LDADD = $(PANEL_LIBS) $(WACOM_PANEL_LIBS) $(builddir)/calibrator/libwacom-calibrator-test.la
|
||||
test_wacom_LDADD = $(PANEL_LIBS) $(WACOM_PANEL_LIBS) $(builddir)/calibrator/libwacom-calibrator-test.la $(top_builddir)/panels/common/libdevice.la
|
||||
|
||||
resource_files = $(shell glib-compile-resources --sourcedir=$(srcdir) --generate-dependencies $(srcdir)/wacom.gresource.xml)
|
||||
cc-wacom-resources.c: wacom.gresource.xml $(resource_files)
|
||||
|
@ -80,12 +77,9 @@ desktop_DATA = $(desktop_in_files:.desktop.in=.desktop)
|
|||
|
||||
WACOMDIR=$(top_srcdir)/../gnome-settings-daemon/plugins/wacom/
|
||||
WACOMFILES=gsd-wacom-device.c gsd-wacom-device.h gsd-wacom-key-shortcut-button.c gsd-wacom-key-shortcut-button.h
|
||||
COMMONDIR=$(top_srcdir)/../gnome-settings-daemon/plugins/common/
|
||||
COMMONFILES=gsd-input-helper.c gsd-input-helper.h
|
||||
update-from-gsd:
|
||||
FILES="$(WACOMFILES)" DIR="$(WACOMDIR)" $(top_srcdir)/update-from-gsd.sh && changed=true ; \
|
||||
FILES="$(COMMONFILES)" DIR="$(COMMONDIR)" $(top_srcdir)/update-from-gsd.sh && changed=true ; \
|
||||
git commit -m "wacom: Update from gnome-settings-daemon" $(WACOMFILES) $(COMMONFILES)
|
||||
git commit -m "wacom: Update from gnome-settings-daemon" $(WACOMFILES)
|
||||
|
||||
CLEANFILES = $(Desktop_in_files) $(desktop_DATA) $(BUILT_SOURCES)
|
||||
EXTRA_DIST = $(resource_files) wacom.gresource.xml
|
||||
|
|
|
@ -37,6 +37,8 @@
|
|||
|
||||
#include "gsd-enums.h"
|
||||
#include "gsd-wacom-device.h"
|
||||
#include "gsd-device-manager.h"
|
||||
#include "gsd-device-manager-x11.h"
|
||||
|
||||
#define GSD_WACOM_STYLUS_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GSD_TYPE_WACOM_STYLUS, GsdWacomStylusPrivate))
|
||||
|
||||
|
@ -500,11 +502,12 @@ get_device_type (XDeviceInfo *dev)
|
|||
device, prop, 0, 1, False,
|
||||
XA_ATOM, &realtype, &realformat, &nitems,
|
||||
&bytes_after, &data);
|
||||
XCloseDevice (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), device);
|
||||
|
||||
if (gdk_error_trap_pop () || rc != Success || realtype == None)
|
||||
ret = WACOM_TYPE_INVALID;
|
||||
|
||||
xdevice_close (device);
|
||||
|
||||
XFree (data);
|
||||
|
||||
return ret;
|
||||
|
@ -602,12 +605,19 @@ find_output_by_display (GnomeRRScreen *rr_screen, GsdWacomDevice *device)
|
|||
GVariant *display;
|
||||
const gchar **edid;
|
||||
GnomeRROutput *ret;
|
||||
GsdDevice *gsd_device;
|
||||
|
||||
if (device == NULL)
|
||||
return NULL;
|
||||
|
||||
gsd_device = gsd_x11_device_manager_lookup_gdk_device (GSD_X11_DEVICE_MANAGER (gsd_device_manager_get ()),
|
||||
device->priv->gdk_device);
|
||||
|
||||
if (gsd_device == NULL)
|
||||
return NULL;
|
||||
|
||||
ret = NULL;
|
||||
tablet = device->priv->wacom_settings;
|
||||
tablet = gsd_device_get_settings (gsd_device);
|
||||
display = g_settings_get_value (tablet, "display");
|
||||
edid = g_variant_get_strv (display, &n);
|
||||
|
||||
|
@ -624,6 +634,7 @@ find_output_by_display (GnomeRRScreen *rr_screen, GsdWacomDevice *device)
|
|||
out:
|
||||
g_free (edid);
|
||||
g_variant_unref (display);
|
||||
g_object_unref (tablet);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
@ -690,12 +701,23 @@ set_display_by_output (GsdWacomDevice *device,
|
|||
gsize nvalues;
|
||||
gchar *o_vendor, *o_product, *o_serial;
|
||||
const gchar *values[3];
|
||||
GsdDevice *gsd_device;
|
||||
|
||||
tablet = gsd_wacom_device_get_settings (device);
|
||||
if (device == NULL)
|
||||
return;
|
||||
|
||||
gsd_device = gsd_x11_device_manager_lookup_gdk_device (GSD_X11_DEVICE_MANAGER (gsd_device_manager_get ()),
|
||||
device->priv->gdk_device);
|
||||
|
||||
if (gsd_device == NULL)
|
||||
return;
|
||||
|
||||
tablet = gsd_device_get_settings (gsd_device);
|
||||
c_array = g_settings_get_value (tablet, "display");
|
||||
g_variant_get_strv (c_array, &nvalues);
|
||||
if (nvalues != 3) {
|
||||
g_warning ("Unable set set display property. Got %"G_GSIZE_FORMAT" items; expected %d items.\n", nvalues, 4);
|
||||
g_object_unref (tablet);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -719,6 +741,7 @@ set_display_by_output (GsdWacomDevice *device,
|
|||
g_free (o_vendor);
|
||||
g_free (o_product);
|
||||
g_free (o_serial);
|
||||
g_object_unref (tablet);
|
||||
}
|
||||
|
||||
static GsdWacomRotation
|
||||
|
@ -777,34 +800,6 @@ find_output (GnomeRRScreen *rr_screen,
|
|||
return rr_output;
|
||||
}
|
||||
|
||||
static void
|
||||
calculate_transformation_matrix (const GdkRectangle mapped, const GdkRectangle desktop, float matrix[NUM_ELEMS_MATRIX])
|
||||
{
|
||||
float x_scale = (float)mapped.x / desktop.width;
|
||||
float y_scale = (float)mapped.y / desktop.height;
|
||||
float width_scale = (float)mapped.width / desktop.width;
|
||||
float height_scale = (float)mapped.height / desktop.height;
|
||||
|
||||
matrix[0] = width_scale;
|
||||
matrix[1] = 0.0f;
|
||||
matrix[2] = x_scale;
|
||||
|
||||
matrix[3] = 0.0f;
|
||||
matrix[4] = height_scale;
|
||||
matrix[5] = y_scale;
|
||||
|
||||
matrix[6] = 0.0f;
|
||||
matrix[7] = 0.0f;
|
||||
matrix[8] = 1.0f;
|
||||
|
||||
g_debug ("Matrix is %f,%f,%f,%f,%f,%f,%f,%f,%f.",
|
||||
matrix[0], matrix[1], matrix[2],
|
||||
matrix[3], matrix[4], matrix[5],
|
||||
matrix[6], matrix[7], matrix[8]);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
int
|
||||
gsd_wacom_device_get_display_monitor (GsdWacomDevice *device)
|
||||
{
|
||||
|
@ -854,59 +849,26 @@ gsd_wacom_device_get_display_monitor (GsdWacomDevice *device)
|
|||
return gdk_screen_get_monitor_at_point (gdk_screen_get_default (), area[0], area[1]);
|
||||
}
|
||||
|
||||
gboolean
|
||||
gsd_wacom_device_get_display_matrix (GsdWacomDevice *device, float matrix[NUM_ELEMS_MATRIX])
|
||||
{
|
||||
int monitor;
|
||||
GdkRectangle display;
|
||||
GdkRectangle desktop;
|
||||
GdkScreen *screen = gdk_screen_get_default ();
|
||||
|
||||
matrix[0] = 1.0f;
|
||||
matrix[1] = 0.0f;
|
||||
matrix[2] = 0.0f;
|
||||
matrix[3] = 0.0f;
|
||||
matrix[4] = 1.0f;
|
||||
matrix[5] = 0.0f;
|
||||
matrix[6] = 0.0f;
|
||||
matrix[7] = 0.0f;
|
||||
matrix[8] = 1.0f;
|
||||
|
||||
monitor = gsd_wacom_device_get_display_monitor (device);
|
||||
if (monitor < 0)
|
||||
return FALSE;
|
||||
|
||||
desktop.x = 0;
|
||||
desktop.y = 0;
|
||||
desktop.width = gdk_screen_get_width (screen);
|
||||
desktop.height = gdk_screen_get_height (screen);
|
||||
|
||||
gdk_screen_get_monitor_geometry (screen, monitor, &display);
|
||||
calculate_transformation_matrix (display, desktop, matrix);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
GsdWacomRotation
|
||||
gsd_wacom_device_get_display_rotation (GsdWacomDevice *device)
|
||||
{
|
||||
GError *error = NULL;
|
||||
GnomeRRScreen *rr_screen;
|
||||
GnomeRROutput *rr_output;
|
||||
GnomeRRRotation rotation = GNOME_RR_ROTATION_0;
|
||||
|
||||
rr_screen = gnome_rr_screen_new (gdk_screen_get_default (), &error);
|
||||
if (rr_screen == NULL) {
|
||||
g_warning ("Failed to create GnomeRRScreen: %s", error->message);
|
||||
g_error_free (error);
|
||||
return GSD_WACOM_ROTATION_NONE;
|
||||
}
|
||||
rr_screen = gnome_rr_screen_new (gdk_screen_get_default (), NULL);
|
||||
|
||||
if (rr_screen == NULL)
|
||||
return GSD_WACOM_ROTATION_NONE;
|
||||
|
||||
rr_output = find_output_by_display (rr_screen, device);
|
||||
|
||||
rr_output = find_output (rr_screen, device);
|
||||
if (rr_output) {
|
||||
GnomeRRCrtc *crtc = gnome_rr_output_get_crtc (rr_output);
|
||||
if (crtc)
|
||||
rotation = gnome_rr_crtc_get_current_rotation (crtc);
|
||||
}
|
||||
|
||||
g_object_unref (rr_screen);
|
||||
|
||||
return get_rotation_wacom (rotation);
|
||||
|
@ -1901,7 +1863,7 @@ gsd_wacom_device_get_area (GsdWacomDevice *device)
|
|||
XA_INTEGER, &realtype, &realformat, &nitems,
|
||||
&bytes_after, &data);
|
||||
if (gdk_error_trap_pop () || rc != Success || realtype == None || bytes_after != 0 || nitems != 4) {
|
||||
XCloseDevice (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), xdevice);
|
||||
xdevice_close (xdevice);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -1910,7 +1872,7 @@ gsd_wacom_device_get_area (GsdWacomDevice *device)
|
|||
device_area[i] = ((long *)data)[i];
|
||||
|
||||
XFree (data);
|
||||
XCloseDevice (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), xdevice);
|
||||
xdevice_close (xdevice);
|
||||
|
||||
return device_area;
|
||||
}
|
||||
|
|
|
@ -26,8 +26,6 @@
|
|||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define NUM_ELEMS_MATRIX 9
|
||||
|
||||
#define GSD_TYPE_WACOM_DEVICE (gsd_wacom_device_get_type ())
|
||||
#define GSD_WACOM_DEVICE(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GSD_TYPE_WACOM_DEVICE, GsdWacomDevice))
|
||||
#define GSD_WACOM_DEVICE_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GSD_TYPE_WACOM_DEVICE, GsdWacomDeviceClass))
|
||||
|
@ -147,8 +145,6 @@ GType gsd_wacom_device_get_type (void);
|
|||
void gsd_wacom_device_set_display (GsdWacomDevice *device,
|
||||
int monitor);
|
||||
gint gsd_wacom_device_get_display_monitor (GsdWacomDevice *device);
|
||||
gboolean gsd_wacom_device_get_display_matrix (GsdWacomDevice *device,
|
||||
float matrix[NUM_ELEMS_MATRIX]);
|
||||
GsdWacomRotation gsd_wacom_device_get_display_rotation (GsdWacomDevice *device);
|
||||
|
||||
GsdWacomDevice * gsd_wacom_device_new (GdkDevice *device);
|
||||
|
|
|
@ -54,6 +54,7 @@ gnome_control_center_LDADD = \
|
|||
$(CHEESE_LIBS) \
|
||||
$(top_builddir)/libgd/libgd.la \
|
||||
$(top_builddir)/panels/common/liblanguage.la \
|
||||
$(top_builddir)/panels/common/libdevice.la \
|
||||
$(top_builddir)/panels/background/libbackground.la \
|
||||
$(top_builddir)/panels/color/libcolor.la \
|
||||
$(top_builddir)/panels/datetime/libdate_time.la \
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue