common: Update from gnome-settings-daemon
This commit is contained in:
parent
c860b59a09
commit
d98d42880d
5 changed files with 17 additions and 304 deletions
|
@ -31,9 +31,6 @@
|
|||
#include "gsd-input-helper.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_Y "Abs MT Position Y"
|
||||
#define ABS_X "Abs X"
|
||||
|
@ -117,12 +114,6 @@ supports_xinput_devices_with_opcode (int *opcode)
|
|||
return retval;
|
||||
}
|
||||
|
||||
gboolean
|
||||
supports_xinput_devices (void)
|
||||
{
|
||||
return supports_xinput_devices_with_opcode (NULL);
|
||||
}
|
||||
|
||||
gboolean
|
||||
supports_xtest (void)
|
||||
{
|
||||
|
@ -163,66 +154,6 @@ supports_xinput2_devices (int *opcode)
|
|||
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
|
||||
device_type_is_present (GsdDeviceType type)
|
||||
{
|
||||
|
@ -250,29 +181,6 @@ mouse_is_present (void)
|
|||
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 *
|
||||
xdevice_get_device_node (int deviceid)
|
||||
{
|
||||
|
@ -431,172 +339,6 @@ set_device_enabled (int device_id,
|
|||
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 *
|
||||
xdevice_get_wacom_tool_type (int deviceid)
|
||||
{
|
||||
|
@ -683,27 +425,3 @@ xdevice_get_dimensions (int deviceid,
|
|||
|
||||
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;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue