common: Update from gnome-settings-daemon
This commit is contained in:
parent
c860b59a09
commit
d98d42880d
5 changed files with 17 additions and 304 deletions
|
@ -112,7 +112,11 @@ add_device (GsdX11DeviceManager *manager,
|
||||||
/* Takes ownership of device_file */
|
/* Takes ownership of device_file */
|
||||||
g_hash_table_insert (manager->gdk_devices, gdk_device, device_file);
|
g_hash_table_insert (manager->gdk_devices, gdk_device, device_file);
|
||||||
|
|
||||||
if (!g_hash_table_lookup (manager->devices, device_file)) {
|
device = g_hash_table_lookup (manager->devices, device_file);
|
||||||
|
|
||||||
|
if (device) {
|
||||||
|
g_signal_emit_by_name (manager, "device-changed", device);
|
||||||
|
} else {
|
||||||
device = create_device (gdk_device, device_file);
|
device = create_device (gdk_device, device_file);
|
||||||
g_hash_table_insert (manager->devices, g_strdup (device_file), device);
|
g_hash_table_insert (manager->devices, g_strdup (device_file), device);
|
||||||
g_signal_emit_by_name (manager, "device-added", device);
|
g_signal_emit_by_name (manager, "device-added", device);
|
||||||
|
|
|
@ -55,6 +55,7 @@ enum {
|
||||||
enum {
|
enum {
|
||||||
DEVICE_ADDED,
|
DEVICE_ADDED,
|
||||||
DEVICE_REMOVED,
|
DEVICE_REMOVED,
|
||||||
|
DEVICE_CHANGED,
|
||||||
N_SIGNALS
|
N_SIGNALS
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -246,6 +247,15 @@ gsd_device_manager_class_init (GsdDeviceManagerClass *klass)
|
||||||
NULL, NULL, NULL,
|
NULL, NULL, NULL,
|
||||||
G_TYPE_NONE, 1,
|
G_TYPE_NONE, 1,
|
||||||
GSD_TYPE_DEVICE | G_SIGNAL_TYPE_STATIC_SCOPE);
|
GSD_TYPE_DEVICE | G_SIGNAL_TYPE_STATIC_SCOPE);
|
||||||
|
|
||||||
|
signals[DEVICE_CHANGED] =
|
||||||
|
g_signal_new ("device-changed",
|
||||||
|
GSD_TYPE_DEVICE_MANAGER,
|
||||||
|
G_SIGNAL_RUN_LAST,
|
||||||
|
G_STRUCT_OFFSET (GsdDeviceManagerClass, device_changed),
|
||||||
|
NULL, NULL, NULL,
|
||||||
|
G_TYPE_NONE, 1,
|
||||||
|
GSD_TYPE_DEVICE | G_SIGNAL_TYPE_STATIC_SCOPE);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
|
@ -76,6 +76,8 @@ struct _GsdDeviceManagerClass
|
||||||
GsdDevice *device);
|
GsdDevice *device);
|
||||||
void (* device_removed) (GsdDeviceManager *manager,
|
void (* device_removed) (GsdDeviceManager *manager,
|
||||||
GsdDevice *device);
|
GsdDevice *device);
|
||||||
|
void (* device_changed) (GsdDeviceManager *manager,
|
||||||
|
GsdDevice *device);
|
||||||
};
|
};
|
||||||
|
|
||||||
GType gsd_device_get_type (void) G_GNUC_CONST;
|
GType gsd_device_get_type (void) G_GNUC_CONST;
|
||||||
|
|
|
@ -31,9 +31,6 @@
|
||||||
#include "gsd-input-helper.h"
|
#include "gsd-input-helper.h"
|
||||||
#include "gsd-device-manager.h"
|
#include "gsd-device-manager.h"
|
||||||
|
|
||||||
#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_X "Abs MT Position X"
|
||||||
#define ABS_MT_Y "Abs MT Position Y"
|
#define ABS_MT_Y "Abs MT Position Y"
|
||||||
#define ABS_X "Abs X"
|
#define ABS_X "Abs X"
|
||||||
|
@ -117,12 +114,6 @@ supports_xinput_devices_with_opcode (int *opcode)
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean
|
|
||||||
supports_xinput_devices (void)
|
|
||||||
{
|
|
||||||
return supports_xinput_devices_with_opcode (NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
supports_xtest (void)
|
supports_xtest (void)
|
||||||
{
|
{
|
||||||
|
@ -163,66 +154,6 @@ supports_xinput2_devices (int *opcode)
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean
|
|
||||||
xdevice_is_synaptics (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
|
|
||||||
synaptics_is_present (void)
|
|
||||||
{
|
|
||||||
XDeviceInfo *device_info;
|
|
||||||
gint n_devices;
|
|
||||||
guint i;
|
|
||||||
gboolean retval;
|
|
||||||
|
|
||||||
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;
|
|
||||||
|
|
||||||
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 = xdevice_is_synaptics (device);
|
|
||||||
xdevice_close (device);
|
|
||||||
if (retval)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
XFreeDeviceList (device_info);
|
|
||||||
|
|
||||||
return retval;
|
|
||||||
}
|
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
device_type_is_present (GsdDeviceType type)
|
device_type_is_present (GsdDeviceType type)
|
||||||
{
|
{
|
||||||
|
@ -250,29 +181,6 @@ mouse_is_present (void)
|
||||||
return device_type_is_present (GSD_DEVICE_TYPE_MOUSE);
|
return device_type_is_present (GSD_DEVICE_TYPE_MOUSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean
|
|
||||||
trackball_is_present (void)
|
|
||||||
{
|
|
||||||
gboolean retval;
|
|
||||||
GList *l, *mice = gsd_device_manager_list_devices (gsd_device_manager_get (),
|
|
||||||
GSD_DEVICE_TYPE_MOUSE);
|
|
||||||
if (mice == NULL)
|
|
||||||
return FALSE;
|
|
||||||
|
|
||||||
for (l = mice; l != NULL; l = l->next) {
|
|
||||||
gchar *lowercase;
|
|
||||||
const gchar *name = gsd_device_get_name (l->data);
|
|
||||||
if (!name)
|
|
||||||
continue;
|
|
||||||
lowercase = g_ascii_strdown (name, -1);
|
|
||||||
retval = strstr (lowercase, "trackball") != NULL;
|
|
||||||
g_free (lowercase);
|
|
||||||
}
|
|
||||||
|
|
||||||
g_list_free (mice);
|
|
||||||
return retval;
|
|
||||||
}
|
|
||||||
|
|
||||||
char *
|
char *
|
||||||
xdevice_get_device_node (int deviceid)
|
xdevice_get_device_node (int deviceid)
|
||||||
{
|
{
|
||||||
|
@ -431,172 +339,6 @@ set_device_enabled (int device_id,
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean
|
|
||||||
set_synaptics_device_enabled (int device_id,
|
|
||||||
gboolean enabled)
|
|
||||||
{
|
|
||||||
Atom prop;
|
|
||||||
guchar value;
|
|
||||||
|
|
||||||
prop = XInternAtom (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), "Synaptics Off", False);
|
|
||||||
if (!prop)
|
|
||||||
return FALSE;
|
|
||||||
|
|
||||||
gdk_error_trap_push ();
|
|
||||||
|
|
||||||
value = enabled ? 0 : 1;
|
|
||||||
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;
|
|
||||||
GError *error = NULL;
|
|
||||||
char *cmd;
|
|
||||||
char *argv[7];
|
|
||||||
int exit_status;
|
|
||||||
gboolean rc;
|
|
||||||
int id;
|
|
||||||
char *out;
|
|
||||||
|
|
||||||
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] = (char*) gdk_device_get_name (device);
|
|
||||||
argv[6] = NULL;
|
|
||||||
|
|
||||||
out = g_strjoinv (" ", argv);
|
|
||||||
g_debug ("About to launch command: %s", out);
|
|
||||||
g_free (out);
|
|
||||||
|
|
||||||
rc = g_spawn_sync (g_get_home_dir (), argv, NULL, G_SPAWN_SEARCH_PATH,
|
|
||||||
NULL, NULL, NULL, NULL, &exit_status, &error);
|
|
||||||
|
|
||||||
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]);
|
|
||||||
|
|
||||||
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 *
|
|
||||||
get_disabled_synaptics (void)
|
|
||||||
{
|
|
||||||
GdkDisplay *display;
|
|
||||||
XDeviceInfo *device_info;
|
|
||||||
gint n_devices, act_format, rc;
|
|
||||||
guint i;
|
|
||||||
GList *ret;
|
|
||||||
Atom prop, act_type;
|
|
||||||
unsigned long nitems, bytes_after;
|
|
||||||
unsigned char *data;
|
|
||||||
|
|
||||||
ret = NULL;
|
|
||||||
|
|
||||||
display = gdk_display_get_default ();
|
|
||||||
prop = gdk_x11_get_xatom_by_name ("Synaptics Off");
|
|
||||||
|
|
||||||
gdk_error_trap_push ();
|
|
||||||
|
|
||||||
device_info = XListInputDevices (GDK_DISPLAY_XDISPLAY (display), &n_devices);
|
|
||||||
if (device_info == NULL) {
|
|
||||||
gdk_error_trap_pop_ignored ();
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 0; i < n_devices; i++) {
|
|
||||||
rc = XIGetProperty (GDK_DISPLAY_XDISPLAY (display),
|
|
||||||
device_info[i].id, prop, 0, 1, False,
|
|
||||||
XA_INTEGER, &act_type, &act_format,
|
|
||||||
&nitems, &bytes_after, &data);
|
|
||||||
|
|
||||||
if (rc != Success || act_type != XA_INTEGER ||
|
|
||||||
act_format != 8 || nitems < 1)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (!(data[0])) {
|
|
||||||
XFree (data);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
XFree (data);
|
|
||||||
|
|
||||||
ret = g_list_prepend (ret, GINT_TO_POINTER (device_info[i].id));
|
|
||||||
}
|
|
||||||
|
|
||||||
gdk_error_trap_pop_ignored ();
|
|
||||||
|
|
||||||
XFreeDeviceList (device_info);
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
const char *
|
const char *
|
||||||
xdevice_get_wacom_tool_type (int deviceid)
|
xdevice_get_wacom_tool_type (int deviceid)
|
||||||
{
|
{
|
||||||
|
@ -683,27 +425,3 @@ xdevice_get_dimensions (int deviceid,
|
||||||
|
|
||||||
return (w != 0 && h != 0);
|
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;
|
|
||||||
}
|
|
||||||
|
|
|
@ -28,12 +28,6 @@ G_BEGIN_DECLS
|
||||||
|
|
||||||
#define WACOM_SERIAL_IDS_PROP "Wacom Serial IDs"
|
#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
|
/* 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
|
* 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
|
* changed. Note: doesn't cater for non-zero offsets yet, but we don't have
|
||||||
|
@ -50,32 +44,20 @@ typedef struct {
|
||||||
} data;
|
} data;
|
||||||
} PropertyHelper;
|
} PropertyHelper;
|
||||||
|
|
||||||
gboolean supports_xinput_devices (void);
|
|
||||||
gboolean supports_xinput2_devices (int *opcode);
|
gboolean supports_xinput2_devices (int *opcode);
|
||||||
gboolean supports_xtest (void);
|
gboolean supports_xtest (void);
|
||||||
|
|
||||||
gboolean set_device_enabled (int device_id,
|
gboolean set_device_enabled (int device_id,
|
||||||
gboolean enabled);
|
gboolean enabled);
|
||||||
|
|
||||||
gboolean set_synaptics_device_enabled (int device_id,
|
|
||||||
gboolean enabled);
|
|
||||||
|
|
||||||
gboolean xdevice_is_synaptics (XDevice *xdevice);
|
|
||||||
|
|
||||||
gboolean synaptics_is_present (void);
|
|
||||||
gboolean touchpad_is_present (void);
|
gboolean touchpad_is_present (void);
|
||||||
gboolean touchscreen_is_present (void);
|
gboolean touchscreen_is_present (void);
|
||||||
gboolean mouse_is_present (void);
|
gboolean mouse_is_present (void);
|
||||||
gboolean trackball_is_present (void);
|
|
||||||
|
|
||||||
gboolean device_set_property (XDevice *xdevice,
|
gboolean device_set_property (XDevice *xdevice,
|
||||||
const char *device_name,
|
const char *device_name,
|
||||||
PropertyHelper *property);
|
PropertyHelper *property);
|
||||||
|
|
||||||
gboolean run_custom_command (GdkDevice *device,
|
|
||||||
CustomCommand command);
|
|
||||||
|
|
||||||
GList * get_disabled_synaptics (void);
|
|
||||||
char * xdevice_get_device_node (int deviceid);
|
char * xdevice_get_device_node (int deviceid);
|
||||||
int xdevice_get_last_tool_id (int deviceid);
|
int xdevice_get_last_tool_id (int deviceid);
|
||||||
gboolean xdevice_get_dimensions (int deviceid,
|
gboolean xdevice_get_dimensions (int deviceid,
|
||||||
|
@ -85,9 +67,6 @@ void xdevice_close (XDevice *xdevice);
|
||||||
|
|
||||||
const char * xdevice_get_wacom_tool_type (int deviceid);
|
const char * xdevice_get_wacom_tool_type (int deviceid);
|
||||||
|
|
||||||
gboolean xdevice_is_libinput (gint deviceid);
|
|
||||||
|
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|
||||||
#endif /* __GSD_INPUT_HELPER_H */
|
#endif /* __GSD_INPUT_HELPER_H */
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue