Line |
Branch |
Exec |
Source |
1 |
|
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- |
2 |
|
|
* |
3 |
|
|
* Copyright (C) 2010 Bastien Nocera <hadess@hadess.net> |
4 |
|
|
* |
5 |
|
|
* This program is free software; you can redistribute it and/or modify |
6 |
|
|
* it under the terms of the GNU General Public License as published by |
7 |
|
|
* the Free Software Foundation; either version 2 of the License, or |
8 |
|
|
* (at your option) any later version. |
9 |
|
|
* |
10 |
|
|
* This program is distributed in the hope that it will be useful, |
11 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 |
|
|
* GNU General Public License for more details. |
14 |
|
|
* |
15 |
|
|
* You should have received a copy of the GNU General Public License |
16 |
|
|
* along with this program; if not, see <http://www.gnu.org/licenses/>. |
17 |
|
|
* |
18 |
|
|
*/ |
19 |
|
|
|
20 |
|
|
#include "config.h" |
21 |
|
|
|
22 |
|
|
#include <string.h> |
23 |
|
|
|
24 |
|
|
#include <gdk/gdk.h> |
25 |
|
|
#include <gdk/x11/gdkx.h> |
26 |
|
|
|
27 |
|
|
#include <sys/types.h> |
28 |
|
|
#include <X11/Xatom.h> |
29 |
|
|
#include <X11/extensions/XInput2.h> |
30 |
|
|
|
31 |
|
|
#include "gsd-input-helper.h" |
32 |
|
|
#include "gsd-device-manager.h" |
33 |
|
|
|
34 |
|
|
static gboolean |
35 |
|
✗ |
device_type_is_present (GsdDeviceType type) |
36 |
|
|
{ |
37 |
|
✗ |
g_autoptr(GList) l = gsd_device_manager_list_devices (gsd_device_manager_get (), |
38 |
|
|
type); |
39 |
|
✗ |
return l != NULL; |
40 |
|
|
} |
41 |
|
|
|
42 |
|
|
gboolean |
43 |
|
✗ |
touchscreen_is_present (void) |
44 |
|
|
{ |
45 |
|
✗ |
return device_type_is_present (GSD_DEVICE_TYPE_TOUCHSCREEN); |
46 |
|
|
} |
47 |
|
|
|
48 |
|
|
gboolean |
49 |
|
✗ |
touchpad_is_present (void) |
50 |
|
|
{ |
51 |
|
✗ |
return device_type_is_present (GSD_DEVICE_TYPE_TOUCHPAD); |
52 |
|
|
} |
53 |
|
|
|
54 |
|
|
gboolean |
55 |
|
✗ |
mouse_is_present (void) |
56 |
|
|
{ |
57 |
|
✗ |
return device_type_is_present (GSD_DEVICE_TYPE_MOUSE); |
58 |
|
|
} |
59 |
|
|
|
60 |
|
|
char * |
61 |
|
✗ |
xdevice_get_device_node (int deviceid) |
62 |
|
|
{ |
63 |
|
|
GdkDisplay *display; |
64 |
|
|
Atom prop; |
65 |
|
|
Atom act_type; |
66 |
|
|
int act_format; |
67 |
|
|
unsigned long nitems, bytes_after; |
68 |
|
|
unsigned char *data; |
69 |
|
|
char *ret; |
70 |
|
|
|
71 |
|
✗ |
display = gdk_display_get_default (); |
72 |
|
✗ |
gdk_display_sync (display); |
73 |
|
|
|
74 |
|
✗ |
prop = XInternAtom (GDK_DISPLAY_XDISPLAY (display), "Device Node", False); |
75 |
|
✗ |
if (!prop) |
76 |
|
✗ |
return NULL; |
77 |
|
|
|
78 |
|
✗ |
gdk_x11_display_error_trap_push (display); |
79 |
|
|
|
80 |
|
✗ |
if (!XIGetProperty (GDK_DISPLAY_XDISPLAY (display), |
81 |
|
|
deviceid, prop, 0, 1000, False, |
82 |
|
|
AnyPropertyType, &act_type, &act_format, |
83 |
|
|
&nitems, &bytes_after, &data) == Success) { |
84 |
|
✗ |
gdk_x11_display_error_trap_pop_ignored (display); |
85 |
|
✗ |
return NULL; |
86 |
|
|
} |
87 |
|
✗ |
if (gdk_x11_display_error_trap_pop (display)) |
88 |
|
✗ |
goto out; |
89 |
|
|
|
90 |
|
✗ |
if (nitems == 0) |
91 |
|
✗ |
goto out; |
92 |
|
|
|
93 |
|
✗ |
if (act_type != XA_STRING) |
94 |
|
✗ |
goto out; |
95 |
|
|
|
96 |
|
|
/* Unknown string format */ |
97 |
|
✗ |
if (act_format != 8) |
98 |
|
✗ |
goto out; |
99 |
|
|
|
100 |
|
✗ |
ret = g_strdup ((char *) data); |
101 |
|
|
|
102 |
|
✗ |
XFree (data); |
103 |
|
✗ |
return ret; |
104 |
|
|
|
105 |
|
✗ |
out: |
106 |
|
✗ |
XFree (data); |
107 |
|
✗ |
return NULL; |
108 |
|
|
} |
109 |
|
|
|