eventstr.h revision ed6184df
11.6Schristos/*
21.1Sitojun * Copyright © 2009 Red Hat, Inc.
31.1Sitojun *
41.1Sitojun * Permission is hereby granted, free of charge, to any person obtaining a
51.1Sitojun * copy of this software and associated documentation files (the "Software"),
61.1Sitojun * to deal in the Software without restriction, including without limitation
71.1Sitojun * the rights to use, copy, modify, merge, publish, distribute, sublicense,
81.1Sitojun * and/or sell copies of the Software, and to permit persons to whom the
91.1Sitojun * Software is furnished to do so, subject to the following conditions:
101.1Sitojun *
111.1Sitojun * The above copyright notice and this permission notice (including the next
121.1Sitojun * paragraph) shall be included in all copies or substantial portions of the
131.1Sitojun * Software.
141.1Sitojun *
151.1Sitojun * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
161.1Sitojun * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
171.1Sitojun * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
181.1Sitojun * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
191.1Sitojun * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
201.1Sitojun * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
211.1Sitojun * DEALINGS IN THE SOFTWARE.
221.1Sitojun *
231.1Sitojun */
241.1Sitojun
251.1Sitojun#ifndef EVENTSTR_H
261.1Sitojun#define EVENTSTR_H
271.1Sitojun
281.1Sitojun#include "inputstr.h"
291.6Schristos#include <events.h>
301.6Schristos/**
311.1Sitojun * @file events.h
321.1Sitojun * This file describes the event structures used internally by the X
331.1Sitojun * server during event generation and event processing.
341.8Schristos *
351.8Schristos * When are internal events used?
361.8Schristos * Events from input devices are stored as internal events in the EQ and
371.8Schristos * processed as internal events until late in the processing cycle. Only then
381.8Schristos * do they switch to their respective wire events.
391.8Schristos */
401.8Schristos
411.8Schristos/**
421.8Schristos * Event types. Used exclusively internal to the server, not visible on the
431.8Schristos * protocol.
441.8Schristos *
451.8Schristos * Note: Keep KeyPress to Motion aligned with the core events.
461.8Schristos *       Keep ET_Raw* in the same order as KeyPress - Motion
471.8Schristos */
481.8Schristosenum EventType {
491.8Schristos    ET_KeyPress = 2,
501.8Schristos    ET_KeyRelease,
511.8Schristos    ET_ButtonPress,
521.5Schristos    ET_ButtonRelease,
531.2Sitojun    ET_Motion,
541.4Sjoerg    ET_TouchBegin,
551.4Sjoerg    ET_TouchUpdate,
561.4Sjoerg    ET_TouchEnd,
571.4Sjoerg    ET_TouchOwnership,
581.5Schristos    ET_Enter,
591.4Sjoerg    ET_Leave,
601.5Schristos    ET_FocusIn,
611.3Sjunyoung    ET_FocusOut,
621.5Schristos    ET_ProximityIn,
631.5Schristos    ET_ProximityOut,
641.5Schristos    ET_DeviceChanged,
651.5Schristos    ET_Hierarchy,
661.5Schristos    ET_DGAEvent,
671.5Schristos    ET_RawKeyPress,
681.5Schristos    ET_RawKeyRelease,
691.5Schristos    ET_RawButtonPress,
701.5Schristos    ET_RawButtonRelease,
711.5Schristos    ET_RawMotion,
721.5Schristos    ET_RawTouchBegin,
731.5Schristos    ET_RawTouchUpdate,
741.5Schristos    ET_RawTouchEnd,
751.5Schristos    ET_XQuartz,
761.3Sjunyoung    ET_BarrierHit,
771.3Sjunyoung    ET_BarrierLeave,
781.3Sjunyoung    ET_GesturePinchBegin,
791.3Sjunyoung    ET_GesturePinchUpdate,
801.7Schristos    ET_GesturePinchEnd,
811.2Sitojun    ET_GestureSwipeBegin,
821.1Sitojun    ET_GestureSwipeUpdate,
831.6Schristos    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