version 0.3.0
[expresskeys.git] / src-expresskeys / reg_events.c
1 /*
2  reg_events.c -- Support ExpressKeys & Touch Strips on a Wacom Intuos3 tablet.
3
4  Copyright (C) 2005-2006 - Mats Johannesson
5
6  Based on test.c 1996 by Frederic Lepied (xinput-1.2)
7
8  This program is free software; you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation; either version 2 of the License, or
11  (at your option) any later version.
12
13  This program is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  GNU General Public License for more details.
17
18  You should have received a copy of the GNU General Public License
19  along with this program; if not, write to the Free Software
20  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307, USA.
21 */
22
23 #include "globals.h"
24
25 /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
26  Function opens the X input device (which stays open until program end)
27  and starts to look for supported event types. The scope should be the
28  root window (ie everywhere) and we're only interested in motion events
29  (touch strip action) and button press/release (for stylus only press and
30  proximityin). Having found the info we ask the X server to keep us
31  continuously notified about these events.
32  +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
33
34 int register_events(Display *display, XDeviceInfo *dev_info, char *name)
35 {
36         int i;
37         int count = 0;
38
39         XInputClassInfo *ip;
40         Window root_win;
41
42         root_win = RootWindow(display, screen);
43
44         if ((pad1_info) && (dev_info->id == pad1_info->id)) {
45                 XEventClass event_list[3];
46                 pad1_device = XOpenDevice(display, dev_info->id);
47                 if (!pad1_device) {
48                         return 0;
49                 }
50                 if (pad1_device->num_classes > 0) {
51                         for (ip = pad1_device->classes, i = 0; i < pad1_info->num_classes; ip++, i++) {
52                                 switch (ip->input_class) {
53
54                                 case ButtonClass:
55                                 DeviceButtonPress(pad1_device, button_press_type, event_list[count]);
56                                 count++;
57                                 DeviceButtonRelease(pad1_device, button_release_type, event_list[count]);
58                                 count++;
59                                 break;
60
61                                 case ValuatorClass:
62                                 DeviceMotionNotify(pad1_device, motion_type, event_list[count]);
63                                 count++;
64                                 break;
65
66                                 default:
67                                 break;
68                                 }
69                         }
70                 }
71                 if (XSelectExtensionEvent(display, root_win, event_list, count)) {
72                         return 0;
73                 }
74                 return count;
75         }
76         if ((stylus1_info) && (dev_info->id == stylus1_info->id)) {
77                 XEventClass event_list[2];
78                 stylus1_device = XOpenDevice(display, dev_info->id);
79                 if (!stylus1_device) {
80                         return 0;
81                 }
82                 if (stylus1_device->num_classes > 0) {
83                         for (ip = stylus1_device->classes, i = 0; i < stylus1_info->num_classes; ip++, i++) {
84                                 switch (ip->input_class) {
85
86                                 case ButtonClass:
87                                 DeviceButtonPress(stylus1_device, button_press_type, event_list[count]);
88                                 count++;
89                                 break;
90
91                                 case ValuatorClass:
92                                 ProximityIn(stylus1_device, proximity_in_type, event_list[count]);
93                                 count++;
94                                 break;
95
96                                 default:
97                                 break;
98                                 }
99                         }
100                 }
101                 if (XSelectExtensionEvent(display, root_win, event_list, count)) {
102                         return 0;
103                 }
104                 return count;
105         }
106         return 0;
107 }
108
109 /* End Code */
110