~ubuntu-branches/ubuntu/precise/gnome-control-center/precise-updates

« back to all changes in this revision

Viewing changes to panels/mouse/gsd-input-helper.c

  • Committer: Bazaar Package Importer
  • Author(s): Rodrigo Moya, Micah Gersten, Rodrigo Moya
  • Date: 2011-05-24 10:55:28 UTC
  • mfrom: (1.1.46 upstream)
  • Revision ID: james.westby@ubuntu.com-20110524105528-dlmxhkwzc0t67kzn
Tags: 1:3.0.2-1ubuntu3
[ Micah Gersten ]
* debian/control:
  - Add reaks/Replaces on g-s-d (<< 3.0~) for gnome-control-center-data (LP: #786417)

[ Rodrigo Moya ]
* New upstream release
* debian/watch:
  - Switch to .bz2, as this is what is used in ftp.gnome.org now
* debian/patches/01_git_remove_gettext_calls.patch
* debian/patches/01_git_kill_warning.patch:
  - Remove upstreamed patches

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
 
29
29
#include "gsd-input-helper.h"
30
30
 
31
 
static gboolean
 
31
#define INPUT_DEVICES_SCHEMA "org.gnome.settings-daemon.peripherals.input-devices"
 
32
#define KEY_HOTPLUG_COMMAND  "hotplug-command"
 
33
 
 
34
gboolean
32
35
supports_xinput_devices (void)
33
36
{
34
37
        gint op_code, event, error;
40
43
                                &error);
41
44
}
42
45
 
43
 
XDevice*
44
 
device_is_touchpad (XDeviceInfo deviceinfo)
 
46
gboolean
 
47
device_is_touchpad (XDevice *xdevice)
45
48
{
46
 
        XDevice *device;
47
49
        Atom realtype, prop;
48
50
        int realformat;
49
51
        unsigned long nitems, bytes_after;
50
52
        unsigned char *data;
51
53
 
52
 
        if (deviceinfo.type != XInternAtom (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), XI_TOUCHPAD, False))
53
 
                return NULL;
 
54
        /* FIXME
 
55
         * we don't check on the type being XI_TOUCHPAD, but having a "Synaptics Off"
 
56
         * property should be enough */
54
57
 
55
58
        prop = XInternAtom (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), "Synaptics Off", False);
56
59
        if (!prop)
57
 
                return NULL;
58
 
 
59
 
        gdk_error_trap_push ();
60
 
        device = XOpenDevice (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), deviceinfo.id);
61
 
        if (gdk_error_trap_pop () || (device == NULL))
62
 
                return NULL;
63
 
 
64
 
        gdk_error_trap_push ();
65
 
        if ((XGetDeviceProperty (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), device, prop, 0, 1, False,
 
60
                return FALSE;
 
61
 
 
62
        gdk_error_trap_push ();
 
63
        if ((XGetDeviceProperty (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), xdevice, prop, 0, 1, False,
66
64
                                XA_INTEGER, &realtype, &realformat, &nitems,
67
65
                                &bytes_after, &data) == Success) && (realtype != None)) {
68
66
                gdk_error_trap_pop_ignored ();
69
67
                XFree (data);
70
 
                return device;
 
68
                return TRUE;
71
69
        }
72
70
        gdk_error_trap_pop_ignored ();
73
71
 
74
 
        XCloseDevice (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), device);
75
 
        return NULL;
 
72
        return FALSE;
76
73
}
77
74
 
78
75
gboolean
95
92
        for (i = 0; i < n_devices; i++) {
96
93
                XDevice *device;
97
94
 
98
 
                device = device_is_touchpad (device_info[i]);
99
 
                if (device != NULL) {
100
 
                        retval = TRUE;
 
95
                gdk_error_trap_push ();
 
96
                device = XOpenDevice (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), device_info[i].id);
 
97
                if (gdk_error_trap_pop () || (device == NULL))
 
98
                        continue;
 
99
 
 
100
                retval = device_is_touchpad (device);
 
101
                if (retval) {
 
102
                        XCloseDevice (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), device);
101
103
                        break;
102
104
                }
 
105
 
 
106
                XCloseDevice (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), device);
103
107
        }
104
 
        if (device_info != NULL)
105
 
                XFreeDeviceList (device_info);
 
108
        XFreeDeviceList (device_info);
106
109
 
107
110
        return retval;
108
111
}
109
112
 
 
113
static const char *
 
114
custom_command_to_string (CustomCommand command)
 
115
{
 
116
        switch (command) {
 
117
        case COMMAND_DEVICE_ADDED:
 
118
                return "added";
 
119
        case COMMAND_DEVICE_REMOVED:
 
120
                return "removed";
 
121
        case COMMAND_DEVICE_PRESENT:
 
122
                return "present";
 
123
        default:
 
124
                g_assert_not_reached ();
 
125
        }
 
126
}
 
127
 
 
128
/* Run a custom command on device presence events. Parameters passed into
 
129
 * the custom command are:
 
130
 * command -t [added|removed|present] -i <device ID> <device name>
 
131
 * Type 'added' and 'removed' signal 'device added' and 'device removed',
 
132
 * respectively. Type 'present' signals 'device present at
 
133
 * gnome-settings-daemon init'.
 
134
 *
 
135
 * The script is expected to run synchronously, and an exit value
 
136
 * of "1" means that no other settings will be applied to this
 
137
 * particular device.
 
138
 *
 
139
 * More options may be added in the future.
 
140
 *
 
141
 * This function returns TRUE if we should not apply any more settings
 
142
 * to the device.
 
143
 */
 
144
gboolean
 
145
run_custom_command (GdkDevice              *device,
 
146
                    CustomCommand           command)
 
147
{
 
148
        GSettings *settings;
 
149
        char *cmd;
 
150
        char *argv[5];
 
151
        int exit_status;
 
152
        gboolean rc;
 
153
        int id;
 
154
 
 
155
        settings = g_settings_new (INPUT_DEVICES_SCHEMA);
 
156
        cmd = g_settings_get_string (settings, KEY_HOTPLUG_COMMAND);
 
157
        g_object_unref (settings);
 
158
 
 
159
        if (!cmd || cmd[0] == '\0') {
 
160
                g_free (cmd);
 
161
                return FALSE;
 
162
        }
 
163
 
 
164
        /* Easter egg! */
 
165
        g_object_get (device, "device-id", &id, NULL);
 
166
 
 
167
        argv[0] = cmd;
 
168
        argv[1] = g_strdup_printf ("-t %s", custom_command_to_string (command));
 
169
        argv[2] = g_strdup_printf ("-i %d", id);
 
170
        argv[3] = g_strdup_printf ("%s", gdk_device_get_name (device));
 
171
        argv[4] = NULL;
 
172
 
 
173
        rc = g_spawn_sync (g_get_home_dir (), argv, NULL, G_SPAWN_SEARCH_PATH,
 
174
                           NULL, NULL, NULL, NULL, &exit_status, NULL);
 
175
 
 
176
        if (rc == FALSE)
 
177
                g_warning ("Couldn't execute command '%s', verify that this is a valid command.", cmd);
 
178
 
 
179
        g_free (argv[0]);
 
180
        g_free (argv[1]);
 
181
        g_free (argv[2]);
 
182
 
 
183
        return (exit_status == 0);
 
184
}