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 */ 48 enum 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_Internal = 0xFF /* First byte */ 79 }; 80 81 /** 82 * How a DeviceEvent was provoked 83 */ 84 enum DeviceEventSource { 85 EVENT_SOURCE_NORMAL = 0, /**< Default: from a user action (e.g. key press) */ 86 EVENT_SOURCE_FOCUS, /**< Keys or buttons previously down on focus-in */ 87 }; 88 89 /** 90 * Used for ALL input device events internal in the server until 91 * copied into the matching protocol event. 92 * 93 * Note: We only use the device id because the DeviceIntPtr may become invalid while 94 * the event is in the EQ. 95 */ 96 struct _DeviceEvent { 97 unsigned char header; /**< Always ET_Internal */ 98 enum EventType type; /**< One of EventType */ 99 int length; /**< Length in bytes */ 100 Time time; /**< Time in ms */ 101 int deviceid; /**< Device to post this event for */ 102 int sourceid; /**< The physical source device */ 103 union { 104 uint32_t button; /**< Button number (also used in pointer emulating 105 touch events) */ 106 uint32_t key; /**< Key code */ 107 } detail; 108 uint32_t touchid; /**< Touch ID (client_id) */ 109 int16_t root_x; /**< Pos relative to root window in integral data */ 110 float root_x_frac; /**< Pos relative to root window in frac part */ 111 int16_t root_y; /**< Pos relative to root window in integral part */ 112 float root_y_frac; /**< Pos relative to root window in frac part */ 113 uint8_t buttons[(MAX_BUTTONS + 7) / 8]; /**< Button mask */ 114 struct { 115 uint8_t mask[(MAX_VALUATORS + 7) / 8];/**< Valuator mask */ 116 uint8_t mode[(MAX_VALUATORS + 7) / 8];/**< Valuator mode (Abs or Rel)*/ 117 double data[MAX_VALUATORS]; /**< Valuator data */ 118 } valuators; 119 struct { 120 uint32_t base; /**< XKB base modifiers */ 121 uint32_t latched; /**< XKB latched modifiers */ 122 uint32_t locked; /**< XKB locked modifiers */ 123 uint32_t effective;/**< XKB effective modifiers */ 124 } mods; 125 struct { 126 uint8_t base; /**< XKB base group */ 127 uint8_t latched; /**< XKB latched group */ 128 uint8_t locked; /**< XKB locked group */ 129 uint8_t effective;/**< XKB effective group */ 130 } group; 131 Window root; /**< Root window of the event */ 132 int corestate; /**< Core key/button state BEFORE the event */ 133 int key_repeat; /**< Internally-generated key repeat event */ 134 uint32_t flags; /**< Flags to be copied into the generated event */ 135 uint32_t resource; /**< Touch event resource, only for TOUCH_REPLAYING */ 136 enum DeviceEventSource source_type; /**< How this event was provoked */ 137 }; 138 139 /** 140 * Generated internally whenever a touch ownership chain changes - an owner 141 * has accepted or rejected a touch, or a grab/event selection in the delivery 142 * chain has been removed. 143 */ 144 struct _TouchOwnershipEvent { 145 unsigned char header; /**< Always ET_Internal */ 146 enum EventType type; /**< ET_TouchOwnership */ 147 int length; /**< Length in bytes */ 148 Time time; /**< Time in ms */ 149 int deviceid; /**< Device to post this event for */ 150 int sourceid; /**< The physical source device */ 151 uint32_t touchid; /**< Touch ID (client_id) */ 152 uint8_t reason; /**< ::XIAcceptTouch, ::XIRejectTouch */ 153 uint32_t resource; /**< Provoking grab or event selection */ 154 uint32_t flags; /**< Flags to be copied into the generated event */ 155 }; 156 157 /* Flags used in DeviceChangedEvent to signal if the slave has changed */ 158 #define DEVCHANGE_SLAVE_SWITCH 0x2 159 /* Flags used in DeviceChangedEvent to signal whether the event was a 160 * pointer event or a keyboard event */ 161 #define DEVCHANGE_POINTER_EVENT 0x4 162 #define DEVCHANGE_KEYBOARD_EVENT 0x8 163 /* device capabilities changed */ 164 #define DEVCHANGE_DEVICE_CHANGE 0x10 165 166 /** 167 * Sent whenever a device's capabilities have changed. 168 */ 169 struct _DeviceChangedEvent { 170 unsigned char header; /**< Always ET_Internal */ 171 enum EventType type; /**< ET_DeviceChanged */ 172 int length; /**< Length in bytes */ 173 Time time; /**< Time in ms */ 174 int deviceid; /**< Device whose capabilities have changed */ 175 int flags; /**< Mask of ::HAS_NEW_SLAVE, 176 ::POINTER_EVENT, ::KEYBOARD_EVENT */ 177 int masterid; /**< MD when event was generated */ 178 int sourceid; /**< The device that caused the change */ 179 180 struct { 181 int num_buttons; /**< Number of buttons */ 182 Atom names[MAX_BUTTONS];/**< Button names */ 183 } buttons; 184 185 int num_valuators; /**< Number of axes */ 186 struct { 187 uint32_t min; /**< Minimum value */ 188 uint32_t max; /**< Maximum value */ 189 double value; /**< Current value */ 190 /* FIXME: frac parts of min/max */ 191 uint32_t resolution; /**< Resolution counts/m */ 192 uint8_t mode; /**< Relative or Absolute */ 193 Atom name; /**< Axis name */ 194 ScrollInfo scroll; /**< Smooth scrolling info */ 195 } valuators[MAX_VALUATORS]; 196 197 struct { 198 int min_keycode; 199 int max_keycode; 200 } keys; 201 }; 202 203 #ifdef XFreeXDGA 204 /** 205 * DGAEvent, used by DGA to intercept and emulate input events. 206 */ 207 struct _DGAEvent { 208 unsigned char header; /**< Always ET_Internal */ 209 enum EventType type; /**< ET_DGAEvent */ 210 int length; /**< Length in bytes */ 211 Time time; /**< Time in ms */ 212 int subtype; /**< KeyPress, KeyRelease, ButtonPress, 213 ButtonRelease, MotionNotify */ 214 int detail; /**< Button number or key code */ 215 int dx; /**< Relative x coordinate */ 216 int dy; /**< Relative y coordinate */ 217 int screen; /**< Screen number this event applies to */ 218 uint16_t state; /**< Core modifier/button state */ 219 }; 220 #endif 221 222 /** 223 * Raw event, contains the data as posted by the device. 224 */ 225 struct _RawDeviceEvent { 226 unsigned char header; /**< Always ET_Internal */ 227 enum EventType type; /**< ET_Raw */ 228 int length; /**< Length in bytes */ 229 Time time; /**< Time in ms */ 230 int deviceid; /**< Device to post this event for */ 231 int sourceid; /**< The physical source device */ 232 union { 233 uint32_t button; /**< Button number */ 234 uint32_t key; /**< Key code */ 235 } detail; 236 struct { 237 uint8_t mask[(MAX_VALUATORS + 7) / 8];/**< Valuator mask */ 238 double data[MAX_VALUATORS]; /**< Valuator data */ 239 double data_raw[MAX_VALUATORS]; /**< Valuator data as posted */ 240 } valuators; 241 uint32_t flags; /**< Flags to be copied into the generated event */ 242 }; 243 244 struct _BarrierEvent { 245 unsigned char header; /**< Always ET_Internal */ 246 enum EventType type; /**< ET_BarrierHit, ET_BarrierLeave */ 247 int length; /**< Length in bytes */ 248 Time time; /**< Time in ms */ 249 int deviceid; /**< Device to post this event for */ 250 int sourceid; /**< The physical source device */ 251 int barrierid; 252 Window window; 253 Window root; 254 double dx; 255 double dy; 256 double root_x; 257 double root_y; 258 int16_t dt; 259 int32_t event_id; 260 uint32_t flags; 261 }; 262 263 #ifdef XQUARTZ 264 #define XQUARTZ_EVENT_MAXARGS 5 265 struct _XQuartzEvent { 266 unsigned char header; /**< Always ET_Internal */ 267 enum EventType type; /**< Always ET_XQuartz */ 268 int length; /**< Length in bytes */ 269 Time time; /**< Time in ms. */ 270 int subtype; /**< Subtype defined by XQuartz DDX */ 271 uint32_t data[XQUARTZ_EVENT_MAXARGS]; /**< Up to 5 32bit values passed to handler */ 272 }; 273 #endif 274 275 /** 276 * Event type used inside the X server for input event 277 * processing. 278 */ 279 union _InternalEvent { 280 struct { 281 unsigned char header; /**< Always ET_Internal */ 282 enum EventType type; /**< One of ET_* */ 283 int length; /**< Length in bytes */ 284 Time time; /**< Time in ms. */ 285 } any; 286 DeviceEvent device_event; 287 DeviceChangedEvent changed_event; 288 TouchOwnershipEvent touch_ownership_event; 289 BarrierEvent barrier_event; 290 #ifdef XFreeXDGA 291 DGAEvent dga_event; 292 #endif 293 RawDeviceEvent raw_event; 294 #ifdef XQUARTZ 295 XQuartzEvent xquartz_event; 296 #endif 297 }; 298 299 #endif 300