xref: /OK3568_Linux_fs/external/xserver/include/eventstr.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun  * Copyright © 2009 Red Hat, Inc.
3*4882a593Smuzhiyun  *
4*4882a593Smuzhiyun  * Permission is hereby granted, free of charge, to any person obtaining a
5*4882a593Smuzhiyun  * copy of this software and associated documentation files (the "Software"),
6*4882a593Smuzhiyun  * to deal in the Software without restriction, including without limitation
7*4882a593Smuzhiyun  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8*4882a593Smuzhiyun  * and/or sell copies of the Software, and to permit persons to whom the
9*4882a593Smuzhiyun  * Software is furnished to do so, subject to the following conditions:
10*4882a593Smuzhiyun  *
11*4882a593Smuzhiyun  * The above copyright notice and this permission notice (including the next
12*4882a593Smuzhiyun  * paragraph) shall be included in all copies or substantial portions of the
13*4882a593Smuzhiyun  * Software.
14*4882a593Smuzhiyun  *
15*4882a593Smuzhiyun  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16*4882a593Smuzhiyun  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17*4882a593Smuzhiyun  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18*4882a593Smuzhiyun  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19*4882a593Smuzhiyun  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20*4882a593Smuzhiyun  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21*4882a593Smuzhiyun  * DEALINGS IN THE SOFTWARE.
22*4882a593Smuzhiyun  *
23*4882a593Smuzhiyun  */
24*4882a593Smuzhiyun 
25*4882a593Smuzhiyun #ifndef EVENTSTR_H
26*4882a593Smuzhiyun #define EVENTSTR_H
27*4882a593Smuzhiyun 
28*4882a593Smuzhiyun #include "inputstr.h"
29*4882a593Smuzhiyun #include <events.h>
30*4882a593Smuzhiyun /**
31*4882a593Smuzhiyun  * @file events.h
32*4882a593Smuzhiyun  * This file describes the event structures used internally by the X
33*4882a593Smuzhiyun  * server during event generation and event processing.
34*4882a593Smuzhiyun  *
35*4882a593Smuzhiyun  * When are internal events used?
36*4882a593Smuzhiyun  * Events from input devices are stored as internal events in the EQ and
37*4882a593Smuzhiyun  * processed as internal events until late in the processing cycle. Only then
38*4882a593Smuzhiyun  * do they switch to their respective wire events.
39*4882a593Smuzhiyun  */
40*4882a593Smuzhiyun 
41*4882a593Smuzhiyun /**
42*4882a593Smuzhiyun  * Event types. Used exclusively internal to the server, not visible on the
43*4882a593Smuzhiyun  * protocol.
44*4882a593Smuzhiyun  *
45*4882a593Smuzhiyun  * Note: Keep KeyPress to Motion aligned with the core events.
46*4882a593Smuzhiyun  *       Keep ET_Raw* in the same order as KeyPress - Motion
47*4882a593Smuzhiyun  */
48*4882a593Smuzhiyun enum EventType {
49*4882a593Smuzhiyun     ET_KeyPress = 2,
50*4882a593Smuzhiyun     ET_KeyRelease,
51*4882a593Smuzhiyun     ET_ButtonPress,
52*4882a593Smuzhiyun     ET_ButtonRelease,
53*4882a593Smuzhiyun     ET_Motion,
54*4882a593Smuzhiyun     ET_TouchBegin,
55*4882a593Smuzhiyun     ET_TouchUpdate,
56*4882a593Smuzhiyun     ET_TouchEnd,
57*4882a593Smuzhiyun     ET_TouchOwnership,
58*4882a593Smuzhiyun     ET_Enter,
59*4882a593Smuzhiyun     ET_Leave,
60*4882a593Smuzhiyun     ET_FocusIn,
61*4882a593Smuzhiyun     ET_FocusOut,
62*4882a593Smuzhiyun     ET_ProximityIn,
63*4882a593Smuzhiyun     ET_ProximityOut,
64*4882a593Smuzhiyun     ET_DeviceChanged,
65*4882a593Smuzhiyun     ET_Hierarchy,
66*4882a593Smuzhiyun     ET_DGAEvent,
67*4882a593Smuzhiyun     ET_RawKeyPress,
68*4882a593Smuzhiyun     ET_RawKeyRelease,
69*4882a593Smuzhiyun     ET_RawButtonPress,
70*4882a593Smuzhiyun     ET_RawButtonRelease,
71*4882a593Smuzhiyun     ET_RawMotion,
72*4882a593Smuzhiyun     ET_RawTouchBegin,
73*4882a593Smuzhiyun     ET_RawTouchUpdate,
74*4882a593Smuzhiyun     ET_RawTouchEnd,
75*4882a593Smuzhiyun     ET_XQuartz,
76*4882a593Smuzhiyun     ET_BarrierHit,
77*4882a593Smuzhiyun     ET_BarrierLeave,
78*4882a593Smuzhiyun     ET_Internal = 0xFF          /* First byte */
79*4882a593Smuzhiyun };
80*4882a593Smuzhiyun 
81*4882a593Smuzhiyun /**
82*4882a593Smuzhiyun  * How a DeviceEvent was provoked
83*4882a593Smuzhiyun  */
84*4882a593Smuzhiyun enum DeviceEventSource {
85*4882a593Smuzhiyun   EVENT_SOURCE_NORMAL = 0, /**< Default: from a user action (e.g. key press) */
86*4882a593Smuzhiyun   EVENT_SOURCE_FOCUS, /**< Keys or buttons previously down on focus-in */
87*4882a593Smuzhiyun };
88*4882a593Smuzhiyun 
89*4882a593Smuzhiyun /**
90*4882a593Smuzhiyun  * Used for ALL input device events internal in the server until
91*4882a593Smuzhiyun  * copied into the matching protocol event.
92*4882a593Smuzhiyun  *
93*4882a593Smuzhiyun  * Note: We only use the device id because the DeviceIntPtr may become invalid while
94*4882a593Smuzhiyun  * the event is in the EQ.
95*4882a593Smuzhiyun  */
96*4882a593Smuzhiyun struct _DeviceEvent {
97*4882a593Smuzhiyun     unsigned char header; /**< Always ET_Internal */
98*4882a593Smuzhiyun     enum EventType type;  /**< One of EventType */
99*4882a593Smuzhiyun     int length;           /**< Length in bytes */
100*4882a593Smuzhiyun     Time time;            /**< Time in ms */
101*4882a593Smuzhiyun     int deviceid;         /**< Device to post this event for */
102*4882a593Smuzhiyun     int sourceid;         /**< The physical source device */
103*4882a593Smuzhiyun     union {
104*4882a593Smuzhiyun         uint32_t button;  /**< Button number (also used in pointer emulating
105*4882a593Smuzhiyun                                touch events) */
106*4882a593Smuzhiyun         uint32_t key;     /**< Key code */
107*4882a593Smuzhiyun     } detail;
108*4882a593Smuzhiyun     uint32_t touchid;     /**< Touch ID (client_id) */
109*4882a593Smuzhiyun     int16_t root_x;       /**< Pos relative to root window in integral data */
110*4882a593Smuzhiyun     float root_x_frac;    /**< Pos relative to root window in frac part */
111*4882a593Smuzhiyun     int16_t root_y;       /**< Pos relative to root window in integral part */
112*4882a593Smuzhiyun     float root_y_frac;    /**< Pos relative to root window in frac part */
113*4882a593Smuzhiyun     uint8_t buttons[(MAX_BUTTONS + 7) / 8];  /**< Button mask */
114*4882a593Smuzhiyun     struct {
115*4882a593Smuzhiyun         uint8_t mask[(MAX_VALUATORS + 7) / 8];/**< Valuator mask */
116*4882a593Smuzhiyun         uint8_t mode[(MAX_VALUATORS + 7) / 8];/**< Valuator mode (Abs or Rel)*/
117*4882a593Smuzhiyun         double data[MAX_VALUATORS];           /**< Valuator data */
118*4882a593Smuzhiyun     } valuators;
119*4882a593Smuzhiyun     struct {
120*4882a593Smuzhiyun         uint32_t base;    /**< XKB base modifiers */
121*4882a593Smuzhiyun         uint32_t latched; /**< XKB latched modifiers */
122*4882a593Smuzhiyun         uint32_t locked;  /**< XKB locked modifiers */
123*4882a593Smuzhiyun         uint32_t effective;/**< XKB effective modifiers */
124*4882a593Smuzhiyun     } mods;
125*4882a593Smuzhiyun     struct {
126*4882a593Smuzhiyun         uint8_t base;    /**< XKB base group */
127*4882a593Smuzhiyun         uint8_t latched; /**< XKB latched group */
128*4882a593Smuzhiyun         uint8_t locked;  /**< XKB locked group */
129*4882a593Smuzhiyun         uint8_t effective;/**< XKB effective group */
130*4882a593Smuzhiyun     } group;
131*4882a593Smuzhiyun     Window root;      /**< Root window of the event */
132*4882a593Smuzhiyun     int corestate;    /**< Core key/button state BEFORE the event */
133*4882a593Smuzhiyun     int key_repeat;   /**< Internally-generated key repeat event */
134*4882a593Smuzhiyun     uint32_t flags;   /**< Flags to be copied into the generated event */
135*4882a593Smuzhiyun     uint32_t resource; /**< Touch event resource, only for TOUCH_REPLAYING */
136*4882a593Smuzhiyun     enum DeviceEventSource source_type; /**< How this event was provoked */
137*4882a593Smuzhiyun };
138*4882a593Smuzhiyun 
139*4882a593Smuzhiyun /**
140*4882a593Smuzhiyun  * Generated internally whenever a touch ownership chain changes - an owner
141*4882a593Smuzhiyun  * has accepted or rejected a touch, or a grab/event selection in the delivery
142*4882a593Smuzhiyun  * chain has been removed.
143*4882a593Smuzhiyun  */
144*4882a593Smuzhiyun struct _TouchOwnershipEvent {
145*4882a593Smuzhiyun     unsigned char header; /**< Always ET_Internal */
146*4882a593Smuzhiyun     enum EventType type;  /**< ET_TouchOwnership */
147*4882a593Smuzhiyun     int length;           /**< Length in bytes */
148*4882a593Smuzhiyun     Time time;            /**< Time in ms */
149*4882a593Smuzhiyun     int deviceid;         /**< Device to post this event for */
150*4882a593Smuzhiyun     int sourceid;         /**< The physical source device */
151*4882a593Smuzhiyun     uint32_t touchid;     /**< Touch ID (client_id) */
152*4882a593Smuzhiyun     uint8_t reason;       /**< ::XIAcceptTouch, ::XIRejectTouch */
153*4882a593Smuzhiyun     uint32_t resource;    /**< Provoking grab or event selection */
154*4882a593Smuzhiyun     uint32_t flags;       /**< Flags to be copied into the generated event */
155*4882a593Smuzhiyun };
156*4882a593Smuzhiyun 
157*4882a593Smuzhiyun /* Flags used in DeviceChangedEvent to signal if the slave has changed */
158*4882a593Smuzhiyun #define DEVCHANGE_SLAVE_SWITCH 0x2
159*4882a593Smuzhiyun /* Flags used in DeviceChangedEvent to signal whether the event was a
160*4882a593Smuzhiyun  * pointer event or a keyboard event */
161*4882a593Smuzhiyun #define DEVCHANGE_POINTER_EVENT 0x4
162*4882a593Smuzhiyun #define DEVCHANGE_KEYBOARD_EVENT 0x8
163*4882a593Smuzhiyun /* device capabilities changed */
164*4882a593Smuzhiyun #define DEVCHANGE_DEVICE_CHANGE 0x10
165*4882a593Smuzhiyun 
166*4882a593Smuzhiyun /**
167*4882a593Smuzhiyun  * Sent whenever a device's capabilities have changed.
168*4882a593Smuzhiyun  */
169*4882a593Smuzhiyun struct _DeviceChangedEvent {
170*4882a593Smuzhiyun     unsigned char header; /**< Always ET_Internal */
171*4882a593Smuzhiyun     enum EventType type;  /**< ET_DeviceChanged */
172*4882a593Smuzhiyun     int length;           /**< Length in bytes */
173*4882a593Smuzhiyun     Time time;            /**< Time in ms */
174*4882a593Smuzhiyun     int deviceid;         /**< Device whose capabilities have changed */
175*4882a593Smuzhiyun     int flags;            /**< Mask of ::HAS_NEW_SLAVE,
176*4882a593Smuzhiyun                                ::POINTER_EVENT, ::KEYBOARD_EVENT */
177*4882a593Smuzhiyun     int masterid;         /**< MD when event was generated */
178*4882a593Smuzhiyun     int sourceid;         /**< The device that caused the change */
179*4882a593Smuzhiyun 
180*4882a593Smuzhiyun     struct {
181*4882a593Smuzhiyun         int num_buttons;        /**< Number of buttons */
182*4882a593Smuzhiyun         Atom names[MAX_BUTTONS];/**< Button names */
183*4882a593Smuzhiyun     } buttons;
184*4882a593Smuzhiyun 
185*4882a593Smuzhiyun     int num_valuators;          /**< Number of axes */
186*4882a593Smuzhiyun     struct {
187*4882a593Smuzhiyun         uint32_t min;           /**< Minimum value */
188*4882a593Smuzhiyun         uint32_t max;           /**< Maximum value */
189*4882a593Smuzhiyun         double value;           /**< Current value */
190*4882a593Smuzhiyun         /* FIXME: frac parts of min/max */
191*4882a593Smuzhiyun         uint32_t resolution;    /**< Resolution counts/m */
192*4882a593Smuzhiyun         uint8_t mode;           /**< Relative or Absolute */
193*4882a593Smuzhiyun         Atom name;              /**< Axis name */
194*4882a593Smuzhiyun         ScrollInfo scroll;      /**< Smooth scrolling info */
195*4882a593Smuzhiyun     } valuators[MAX_VALUATORS];
196*4882a593Smuzhiyun 
197*4882a593Smuzhiyun     struct {
198*4882a593Smuzhiyun         int min_keycode;
199*4882a593Smuzhiyun         int max_keycode;
200*4882a593Smuzhiyun     } keys;
201*4882a593Smuzhiyun };
202*4882a593Smuzhiyun 
203*4882a593Smuzhiyun #ifdef XFreeXDGA
204*4882a593Smuzhiyun /**
205*4882a593Smuzhiyun  * DGAEvent, used by DGA to intercept and emulate input events.
206*4882a593Smuzhiyun  */
207*4882a593Smuzhiyun struct _DGAEvent {
208*4882a593Smuzhiyun     unsigned char header; /**<  Always ET_Internal */
209*4882a593Smuzhiyun     enum EventType type;  /**<  ET_DGAEvent */
210*4882a593Smuzhiyun     int length;           /**<  Length in bytes */
211*4882a593Smuzhiyun     Time time;            /**<  Time in ms */
212*4882a593Smuzhiyun     int subtype;          /**<  KeyPress, KeyRelease, ButtonPress,
213*4882a593Smuzhiyun                                 ButtonRelease, MotionNotify */
214*4882a593Smuzhiyun     int detail;           /**<  Button number or key code */
215*4882a593Smuzhiyun     int dx;               /**<  Relative x coordinate */
216*4882a593Smuzhiyun     int dy;               /**<  Relative y coordinate */
217*4882a593Smuzhiyun     int screen;           /**<  Screen number this event applies to */
218*4882a593Smuzhiyun     uint16_t state;       /**<  Core modifier/button state */
219*4882a593Smuzhiyun };
220*4882a593Smuzhiyun #endif
221*4882a593Smuzhiyun 
222*4882a593Smuzhiyun /**
223*4882a593Smuzhiyun  * Raw event, contains the data as posted by the device.
224*4882a593Smuzhiyun  */
225*4882a593Smuzhiyun struct _RawDeviceEvent {
226*4882a593Smuzhiyun     unsigned char header; /**<  Always ET_Internal */
227*4882a593Smuzhiyun     enum EventType type;  /**<  ET_Raw */
228*4882a593Smuzhiyun     int length;           /**<  Length in bytes */
229*4882a593Smuzhiyun     Time time;            /**<  Time in ms */
230*4882a593Smuzhiyun     int deviceid;         /**< Device to post this event for */
231*4882a593Smuzhiyun     int sourceid;         /**< The physical source device */
232*4882a593Smuzhiyun     union {
233*4882a593Smuzhiyun         uint32_t button;  /**< Button number */
234*4882a593Smuzhiyun         uint32_t key;     /**< Key code */
235*4882a593Smuzhiyun     } detail;
236*4882a593Smuzhiyun     struct {
237*4882a593Smuzhiyun         uint8_t mask[(MAX_VALUATORS + 7) / 8];/**< Valuator mask */
238*4882a593Smuzhiyun         double data[MAX_VALUATORS];           /**< Valuator data */
239*4882a593Smuzhiyun         double data_raw[MAX_VALUATORS];       /**< Valuator data as posted */
240*4882a593Smuzhiyun     } valuators;
241*4882a593Smuzhiyun     uint32_t flags;       /**< Flags to be copied into the generated event */
242*4882a593Smuzhiyun };
243*4882a593Smuzhiyun 
244*4882a593Smuzhiyun struct _BarrierEvent {
245*4882a593Smuzhiyun     unsigned char header; /**<  Always ET_Internal */
246*4882a593Smuzhiyun     enum EventType type;  /**<  ET_BarrierHit, ET_BarrierLeave */
247*4882a593Smuzhiyun     int length;           /**<  Length in bytes */
248*4882a593Smuzhiyun     Time time;            /**<  Time in ms */
249*4882a593Smuzhiyun     int deviceid;         /**< Device to post this event for */
250*4882a593Smuzhiyun     int sourceid;         /**< The physical source device */
251*4882a593Smuzhiyun     int barrierid;
252*4882a593Smuzhiyun     Window window;
253*4882a593Smuzhiyun     Window root;
254*4882a593Smuzhiyun     double dx;
255*4882a593Smuzhiyun     double dy;
256*4882a593Smuzhiyun     double root_x;
257*4882a593Smuzhiyun     double root_y;
258*4882a593Smuzhiyun     int16_t dt;
259*4882a593Smuzhiyun     int32_t event_id;
260*4882a593Smuzhiyun     uint32_t flags;
261*4882a593Smuzhiyun };
262*4882a593Smuzhiyun 
263*4882a593Smuzhiyun #ifdef XQUARTZ
264*4882a593Smuzhiyun #define XQUARTZ_EVENT_MAXARGS 5
265*4882a593Smuzhiyun struct _XQuartzEvent {
266*4882a593Smuzhiyun     unsigned char header; /**< Always ET_Internal */
267*4882a593Smuzhiyun     enum EventType type;  /**< Always ET_XQuartz */
268*4882a593Smuzhiyun     int length;           /**< Length in bytes */
269*4882a593Smuzhiyun     Time time;            /**< Time in ms. */
270*4882a593Smuzhiyun     int subtype;          /**< Subtype defined by XQuartz DDX */
271*4882a593Smuzhiyun     uint32_t data[XQUARTZ_EVENT_MAXARGS]; /**< Up to 5 32bit values passed to handler */
272*4882a593Smuzhiyun };
273*4882a593Smuzhiyun #endif
274*4882a593Smuzhiyun 
275*4882a593Smuzhiyun /**
276*4882a593Smuzhiyun  * Event type used inside the X server for input event
277*4882a593Smuzhiyun  * processing.
278*4882a593Smuzhiyun  */
279*4882a593Smuzhiyun union _InternalEvent {
280*4882a593Smuzhiyun     struct {
281*4882a593Smuzhiyun         unsigned char header;     /**< Always ET_Internal */
282*4882a593Smuzhiyun         enum EventType type;      /**< One of ET_* */
283*4882a593Smuzhiyun         int length;               /**< Length in bytes */
284*4882a593Smuzhiyun         Time time;                /**< Time in ms. */
285*4882a593Smuzhiyun     } any;
286*4882a593Smuzhiyun     DeviceEvent device_event;
287*4882a593Smuzhiyun     DeviceChangedEvent changed_event;
288*4882a593Smuzhiyun     TouchOwnershipEvent touch_ownership_event;
289*4882a593Smuzhiyun     BarrierEvent barrier_event;
290*4882a593Smuzhiyun #ifdef XFreeXDGA
291*4882a593Smuzhiyun     DGAEvent dga_event;
292*4882a593Smuzhiyun #endif
293*4882a593Smuzhiyun     RawDeviceEvent raw_event;
294*4882a593Smuzhiyun #ifdef XQUARTZ
295*4882a593Smuzhiyun     XQuartzEvent xquartz_event;
296*4882a593Smuzhiyun #endif
297*4882a593Smuzhiyun };
298*4882a593Smuzhiyun 
299*4882a593Smuzhiyun #endif
300