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