Laxkit  0.0.7.1
laxdevices.h
1 //
2 //
3 // The Laxkit, a windowing toolkit
4 // Please consult http://laxkit.sourceforge.net about where to send any
5 // correspondence about this software.
6 //
7 // This library is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU Library General Public
9 // License as published by the Free Software Foundation; either
10 // version 2 of the License, or (at your option) any later version.
11 //
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 // Library General Public License for more details.
16 //
17 // You should have received a copy of the GNU Library General Public
18 // License along with this library; if not, write to the Free Software
19 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 //
21 // Copyright (C) 2010-2013 by Tom Lechner
22 //
23 #ifndef _LAX_LAXDEVICES_H
24 #define _LAX_LAXDEVICES_H
25 
26 #ifdef _LAX_PLATFORM_XLIB
27 #include <X11/Xlib.h>
28 #include <X11/Xft/Xft.h>
29 #include <X11/Xutil.h>
30 #ifdef LAX_USES_XINPUT2
31 #include <X11/extensions/XInput2.h>
32 #else
33 #include <X11/extensions/XInput.h>
34 #include <X11/extensions/XIproto.h>
35 #endif //LAX_USES_XINPUT2
36 #endif //_LAX_PLATFORM_XLIB
37 
38 #include <lax/events.h>
39 #include <lax/lists.h>
40 
41 namespace Laxkit {
42 
43 
44 class anXWindow;
45 class EventData;
46 class EventReceiver;
47 
48 
49 //-------------------------- LaxDevice ----------------------------------------
50 class LaxDevice
51 {
52  private:
53  public:
54  int id;
55  int subid; //an identifier, for instance the xid of the slave device which is current for a master device
56  XID xid; //XInput2 uses xid. 0 if no associated x device
57  char *name;
58  int active; //1 if device is open for business. 0 for not.
59  //touch devices might implement touch by having 20 possible blobs,
60  //but at any one time, only some of those will actually be active.
61 
62  int screen; //the current screen the device is active on
63  int input_head; //tag to indicate which XI2 master device this device is slave to
64  int input_group; //groups such as a keyboard, mouse, and tablet
65  int input_source; //occasionally, a physical device will produce many devices, like touch points
66  //this value would be the same for all those devices
67 
68  virtual const char *DeviceName();
69  virtual const char *DeviceType();
70 
71  virtual int GetKey(int k); //0 returns number of buttons, 1=on, 0=off
72  virtual int GetButton(int b); //0 returns number of buttons, 1=on, 0=off
73  virtual double GetValue(int v, int w); //0 returns number of valuators, w=0,1,2=value, min, max
74 
75  virtual int numFields();//-2 if unititialized, -1 field type info not available
76  virtual int getFieldTypeInfo(int f,const char **nme, int *type, int *min, int *max, int *res);
77 
78  virtual int usesX(); //nonzero if uses X
79  virtual int fd(); //file descriptor to watch with select(), if not using X
80  virtual EventData *getEvents(); //return an event stream if any events pending
81  virtual int eventFilter(EventData **events_ret,XEvent *xev,anXWindow *target,int &isinput); //turn an XEvent into EventData
82  virtual int selectForWindow(anXWindow *win,unsigned long);
83  virtual int clearReceiver(EventReceiver *receiver);
84 
85  LaxDevice();
86  virtual ~LaxDevice();
87  virtual const char *Name(const char *nname);
88 };
89 
90 
91 //-------------------------- LaxMouse ----------------------------------------
92 class LaxKeyboard;
93 
94 class LaxMouse : public LaxDevice
95 {
96  protected:
97  public:
101  unsigned long buttonwindow;
102  unsigned long last_leave_window;
103 
104  clock_t ttendlimit;
105  clock_t ttthreshhold;
107 
108  LaxKeyboard *paired_keyboard;
109  LaxMouse();
110  virtual ~LaxMouse();
111  virtual int clearReceiver(EventReceiver *receiver);
112 
113  virtual void buttonReleased(int button,anXWindow *ww);
114  virtual void buttonPressed(Time time, int button,unsigned long windowid);
115 
116  virtual int setMouseShape(anXWindow *win, int shape);
117  virtual int grabDevice(anXWindow *win);
118  virtual int ungrabDevice();
119  virtual int getInfo(anXWindow *win,
120  int *screen, anXWindow **child,
121  int *x, int *y, unsigned int *mods,
122  double *pressure, double *tiltx, double *tilty)=0;
123  virtual int Pressure();
124  virtual int TiltX();
125  virtual int TiltY();
126 };
127 
128 
129 //-------------------------- LaxKeyboard ----------------------------------------
130 class LaxKeyboard : public LaxDevice
131 {
132  public:
133  LaxMouse *paired_mouse;
134  anXWindow *current_focus;
135  clock_t focus_time;
136  LaxKeyboard();
137  virtual ~LaxKeyboard();
138  virtual int SetFocus(anXWindow *w, clock_t time,int notifyonly);
139  virtual unsigned long QueryModifiers();
140  virtual int clearReceiver(EventReceiver *receiver);
141 };
142 
143 
144 //---------------------------------- DeviceManager --------------------------
146 {
147  protected:
148  public:
149  PtrStack<LaxDevice> devices;
150  DeviceManager();
151  virtual ~DeviceManager();
152 
153  virtual int init();
154  virtual int selectForWindow(anXWindow *win,unsigned long); //set proper settings for the window to select for device events
155  virtual int eventFilter(EventData **events_ret,XEvent *xev,anXWindow *target,int &isinput); //turn an XEvent into EventData
156  virtual int SetFocus(anXWindow *win, LaxKeyboard *kb, clock_t t, int notifyonly);
157  virtual int clearReceiver(EventReceiver *receiver);
158 
159  virtual int filedescriptors(fd_set *fds, int *n);
160  virtual EventData *getEvents(fd_set *fds);//for any devices that do not use X
161  virtual LaxDevice *findDevice(int id);
162  virtual LaxMouse *findMouse(int id);
163 
164  virtual int NumDevices() { return devices.n; }
165  virtual LaxDevice *Device(int i) { return (i>=0 && i<devices.n-1) ? devices.e[i] : NULL; }
166 };
167 
168 
169 //---------------------------------- DeviceManagerXlib --------------------------
170 
172 
173 
174 //------------------------------------- CoreXlibPointer -----------------------------------
175 class CoreXlibKeyboard;
176 
177 class CoreXlibPointer : public LaxMouse
178 {
179  protected:
180  public:
182  virtual int usesX() { return 1; }
183  virtual int selectForWindow(anXWindow *win,unsigned long);
184  virtual int eventFilter(EventData **events_ret, XEvent *xev, anXWindow *ww, int &isinput);
185  virtual int setMouseShape(anXWindow *win, int shape);
186  virtual int grabDevice(anXWindow *win);
187  virtual int ungrabDevice();
188  virtual int getInfo(anXWindow *win,
189  int *screen, anXWindow **child,
190  int *x, int *y, unsigned int *mods,
191  double *pressure, double *tiltx, double *tilty);
192 };
193 
194 //------------------------------------- CoreXlibKeyboard -----------------------------------
196 {
197  protected:
198  public:
200  virtual int usesX() { return 1; }
201  virtual int selectForWindow(anXWindow *win,unsigned long);
202  virtual int eventFilter(EventData **events_ret, XEvent *xev, anXWindow *ww, int &isinput);
203  virtual int SetFocus(anXWindow *win, clock_t t, int notifyonly);
204 };
205 
206 
207 //---------------------------------- DeviceManagerXInput --------------------------
208 
209 #ifdef LAX_USES_XINPUT2
210 
211 DeviceManager *newXInput2DeviceManager(Display *dpy, int which);
212 
213 
214 //-------------------------- XInput2MasterPointer ----------------------------------------
215 class XInput2Pointer : public LaxMouse
216 {
217  public:
218  int use;
219  XInput2Pointer(XIDeviceInfo *d);
220  virtual int usesX() { return 1; }
221  virtual int eventFilter(EventData **events_ret,XEvent *xev,anXWindow *target,int &isinput);
222  virtual int selectForWindow(anXWindow *win,unsigned long);
223  virtual int setMouseShape(anXWindow *win, int shape);
224  virtual int grabDevice(anXWindow *win);
225  virtual int ungrabDevice();
226  virtual int getInfo(anXWindow *win,
227  int *screen, anXWindow **child,
228  int *x, int *y, unsigned int *mods,
229  double *pressure, double *tiltx, double *tilty);
230 };
231 
232 
233 //-------------------------- XInput2MasterKeyboard ----------------------------------------
234 class XInput2Keyboard : public LaxKeyboard
235 {
236  public:
237  int use;
238  XInput2Keyboard(XIDeviceInfo *d);
239  virtual int usesX() { return 1; }
240  virtual int selectForWindow(anXWindow *win,unsigned long);
241  virtual int eventFilter(EventData **events_ret, XEvent *xev, anXWindow *ww, int &isinput);
242  virtual int SetFocus(anXWindow *win, clock_t t,int notifyonly);
243 };
244 
245 
246 
247 #endif //LAX_USES_XINPUT2
248 
249 
250 //---------------------------------- DeviceManagerXInput1 --------------------------
251 //DeviceManager *createXInput1DeviceManager(Display *dpy, int which);
252 
253 
254 } //namespace Laxkit
255 
256 #endif
257 

Mon Feb 17 2014 11:52:56, Laxkit