2179
2191
XFreeDeviceList (device_info);
2194
/* Kill a mapping process */
2196
cb_mapping_child_kill (gpointer data)
2200
gchar *message = NULL;
2201
TouchMappingPrivate *mapping_data = (TouchMappingPrivate*) data;
2203
message = g_strdup_printf ("Killing touchscreen mapping process %d after %d second(s) timeout...",
2204
mapping_data->mapping_pid, MAPPING_TIMEOUT);
2207
g_error ("Failed to allocate memory to log the killing of the mapping process");
2211
g_warning ("%s", message);
2215
kill_status = kill (mapping_data->mapping_pid, SIGTERM);
2217
/* Mark as killed */
2218
mapping_data->mapping_killed = TRUE;
2220
g_debug ("Kill status %d...", kill_status);
2222
if (kill_status != 0)
2223
g_error ("Failed to kill mapping process: %s", strerror (errno));
2226
return G_SOURCE_REMOVE;
2229
/* Clean up spawned processes when they are done */
2231
cb_mapping_child_watch (GPid pid,
2235
TouchMappingPrivate *mapping_data = (TouchMappingPrivate*) data;
2237
g_debug ("Cleaning up spawned mapping");
2240
g_spawn_close_pid (pid);
2242
/* No need to kill a process that ended */
2243
if (mapping_data->mapping_kill_id > 0) {
2244
g_debug ("Cancelling killing of process that ended");
2245
g_source_remove (mapping_data->mapping_kill_id);
2248
/* No need to retry if it succeeded */
2249
if (!mapping_data->mapping_killed) {
2250
g_debug ("Cancelling retry id %d", mapping_data->mapping_retry_id);
2251
g_source_remove (mapping_data->mapping_retry_id);
2254
/* Free mapping data */
2255
g_slice_free (TouchMappingPrivate, mapping_data);
2256
mapping_data = NULL;
2183
map_touch_to_output (GsdRRScreen *screen, int device_id,
2184
GsdRROutputInfo *output)
2260
map_touch_to_output (GsdXrandrManager *manager, GsdRROutputInfo *output)
2262
TouchMappingPrivate *mapping_data = NULL;
2263
gchar *command_str = NULL;
2264
GError **error = NULL;
2265
gboolean success = FALSE;
2266
gchar **command = NULL;
2268
GsdXrandrManagerPrivate *priv = manager->priv;
2188
2269
gchar *name = gsd_rr_output_info_get_name (output);
2191
2272
g_debug ("Failure to map screen with missing name");
2196
if (gsd_rr_output_info_is_active(output)) {
2276
if (gsd_rr_output_info_is_active (output)) {
2197
2277
g_debug ("Mapping touchscreen %d onto output %s",
2199
sprintf (command, "xinput --map-to-output %d %s",
2201
status = system (command);
2278
priv->main_touchscreen_id, name);
2280
command_str = g_strdup_printf ("/usr/bin/xinput --map-to-output %d %s",
2281
priv->main_touchscreen_id, name);
2286
if (!g_shell_parse_argv (command_str, NULL, &command, NULL))
2289
/* Each spawned process gets its own mapping data */
2290
mapping_data = g_slice_new (TouchMappingPrivate);
2291
if (!mapping_data) {
2292
g_error ("Touchscreen mapping resource allocation failed");
2295
/* Initialise mapping data */
2296
mapping_data->mapping_pid = -1;
2297
mapping_data->mapping_kill_id = 0;
2298
mapping_data->mapping_retry_id = 0;
2299
mapping_data->mapping_killed = FALSE;
2301
success = g_spawn_async (NULL,
2304
G_SPAWN_DO_NOT_REAP_CHILD,
2307
&(mapping_data->mapping_pid),
2309
g_strfreev (command);
2312
g_debug ("Touchscreen mapping spawn succeeded");
2314
/* Clean up after child is done */
2315
g_child_watch_add (mapping_data->mapping_pid, (GChildWatchFunc) cb_mapping_child_watch,
2317
/* Kill the child after n seconds */
2318
mapping_data->mapping_kill_id = g_timeout_add_seconds (MAPPING_TIMEOUT,
2319
(GSourceFunc) cb_mapping_child_kill,
2321
/* Set potential retry */
2322
g_debug ("Retrying in %d second(s)", RETRY_TIMEOUT+MAPPING_TIMEOUT);
2323
mapping_data->mapping_retry_id = g_timeout_add_seconds (RETRY_TIMEOUT+MAPPING_TIMEOUT,
2324
(GSourceFunc) do_touchscreen_mapping,
2326
g_debug ("Retry id: %d", mapping_data->mapping_retry_id);
2329
g_error ("Touchscreen mapping failed");
2331
g_error ("%s", (*error)->message);
2332
g_clear_error (error);
2334
/* Free mapping data */
2335
g_slice_free(TouchMappingPrivate, mapping_data);
2336
mapping_data = NULL;
2204
2340
g_debug ("No need to map %d onto output %s. The output is off",
2341
priv->main_touchscreen_id, name);
2209
return (status == 0);
2345
g_free (command_str);
2213
2351
do_touchscreen_mapping (GsdXrandrManager *manager)
2215
2353
GsdXrandrManagerPrivate *priv = manager->priv;