1706f2543Smrg/* 2706f2543Smrg * Copyright © 2009 Red Hat, Inc. 3706f2543Smrg * 4706f2543Smrg * Permission is hereby granted, free of charge, to any person obtaining a 5706f2543Smrg * copy of this software and associated documentation files (the "Software"), 6706f2543Smrg * to deal in the Software without restriction, including without limitation 7706f2543Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8706f2543Smrg * and/or sell copies of the Software, and to permit persons to whom the 9706f2543Smrg * Software is furnished to do so, subject to the following conditions: 10706f2543Smrg * 11706f2543Smrg * The above copyright notice and this permission notice (including the next 12706f2543Smrg * paragraph) shall be included in all copies or substantial portions of the 13706f2543Smrg * Software. 14706f2543Smrg * 15706f2543Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16706f2543Smrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17706f2543Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18706f2543Smrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19706f2543Smrg * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20706f2543Smrg * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 21706f2543Smrg * DEALINGS IN THE SOFTWARE. 22706f2543Smrg * 23706f2543Smrg */ 24706f2543Smrg 25706f2543Smrg#ifndef EVENTSTR_H 26706f2543Smrg#define EVENTSTR_H 27706f2543Smrg 28706f2543Smrg#include <events.h> 29706f2543Smrg/** 30706f2543Smrg * @file events.h 31706f2543Smrg * This file describes the event structures used internally by the X 32706f2543Smrg * server during event generation and event processing. 33706f2543Smrg * 34706f2543Smrg * When are internal events used? 35706f2543Smrg * Events from input devices are stored as internal events in the EQ and 36706f2543Smrg * processed as internal events until late in the processing cycle. Only then 37706f2543Smrg * do they switch to their respective wire events. 38706f2543Smrg */ 39706f2543Smrg 40706f2543Smrg/** 41706f2543Smrg * Event types. Used exclusively internal to the server, not visible on the 42706f2543Smrg * protocol. 43706f2543Smrg * 44706f2543Smrg * Note: Keep KeyPress to Motion aligned with the core events. 45706f2543Smrg * Keep ET_Raw* in the same order as KeyPress - Motion 46706f2543Smrg */ 47706f2543Smrgenum EventType { 48706f2543Smrg ET_KeyPress = 2, 49706f2543Smrg ET_KeyRelease, 50706f2543Smrg ET_ButtonPress, 51706f2543Smrg ET_ButtonRelease, 52706f2543Smrg ET_Motion, 53706f2543Smrg ET_Enter, 54706f2543Smrg ET_Leave, 55706f2543Smrg ET_FocusIn, 56706f2543Smrg ET_FocusOut, 57706f2543Smrg ET_ProximityIn, 58706f2543Smrg ET_ProximityOut, 59706f2543Smrg ET_DeviceChanged, 60706f2543Smrg ET_Hierarchy, 61706f2543Smrg ET_DGAEvent, 62706f2543Smrg ET_RawKeyPress, 63706f2543Smrg ET_RawKeyRelease, 64706f2543Smrg ET_RawButtonPress, 65706f2543Smrg ET_RawButtonRelease, 66706f2543Smrg ET_RawMotion, 67706f2543Smrg ET_XQuartz, 68706f2543Smrg ET_Internal = 0xFF /* First byte */ 69706f2543Smrg}; 70706f2543Smrg 71706f2543Smrg#define CHECKEVENT(ev) if (ev && ((InternalEvent*)(ev))->any.header != 0xFF) \ 72706f2543Smrg FatalError("Wrong event type %d.\n", \ 73706f2543Smrg ((InternalEvent*)(ev))->any.header); 74706f2543Smrg 75706f2543Smrg/** 76706f2543Smrg * Used for ALL input device events internal in the server until 77706f2543Smrg * copied into the matching protocol event. 78706f2543Smrg * 79706f2543Smrg * Note: We only use the device id because the DeviceIntPtr may become invalid while 80706f2543Smrg * the event is in the EQ. 81706f2543Smrg */ 82706f2543Smrgstruct _DeviceEvent 83706f2543Smrg{ 84706f2543Smrg unsigned char header; /**< Always ET_Internal */ 85706f2543Smrg enum EventType type; /**< One of EventType */ 86706f2543Smrg int length; /**< Length in bytes */ 87706f2543Smrg Time time; /**< Time in ms */ 88706f2543Smrg int deviceid; /**< Device to post this event for */ 89706f2543Smrg int sourceid; /**< The physical source device */ 90706f2543Smrg union { 91706f2543Smrg uint32_t button; /**< Button number */ 92706f2543Smrg uint32_t key; /**< Key code */ 93706f2543Smrg } detail; 94706f2543Smrg int16_t root_x; /**< Pos relative to root window in integral data */ 95706f2543Smrg float root_x_frac; /**< Pos relative to root window in frac part */ 96706f2543Smrg int16_t root_y; /**< Pos relative to root window in integral part */ 97706f2543Smrg float root_y_frac; /**< Pos relative to root window in frac part */ 98706f2543Smrg uint8_t buttons[(MAX_BUTTONS + 7)/8]; /**< Button mask */ 99706f2543Smrg struct { 100706f2543Smrg uint8_t mask[(MAX_VALUATORS + 7)/8]; /**< Valuator mask */ 101706f2543Smrg uint8_t mode[(MAX_VALUATORS + 7)/8]; /**< Valuator mode (Abs or Rel)*/ 102706f2543Smrg int32_t data[MAX_VALUATORS]; /**< Valuator data */ 103706f2543Smrg int32_t data_frac[MAX_VALUATORS]; /**< Fractional part for data */ 104706f2543Smrg } valuators; 105706f2543Smrg struct { 106706f2543Smrg uint32_t base; /**< XKB base modifiers */ 107706f2543Smrg uint32_t latched; /**< XKB latched modifiers */ 108706f2543Smrg uint32_t locked; /**< XKB locked modifiers */ 109706f2543Smrg uint32_t effective;/**< XKB effective modifiers */ 110706f2543Smrg } mods; 111706f2543Smrg struct { 112706f2543Smrg uint8_t base; /**< XKB base group */ 113706f2543Smrg uint8_t latched; /**< XKB latched group */ 114706f2543Smrg uint8_t locked; /**< XKB locked group */ 115706f2543Smrg uint8_t effective;/**< XKB effective group */ 116706f2543Smrg } group; 117706f2543Smrg Window root; /**< Root window of the event */ 118706f2543Smrg int corestate; /**< Core key/button state BEFORE the event */ 119706f2543Smrg int key_repeat; /**< Internally-generated key repeat event */ 120706f2543Smrg}; 121706f2543Smrg 122706f2543Smrg 123706f2543Smrg/* Flags used in DeviceChangedEvent to signal if the slave has changed */ 124706f2543Smrg#define DEVCHANGE_SLAVE_SWITCH 0x2 125706f2543Smrg/* Flags used in DeviceChangedEvent to signal whether the event was a 126706f2543Smrg * pointer event or a keyboard event */ 127706f2543Smrg#define DEVCHANGE_POINTER_EVENT 0x4 128706f2543Smrg#define DEVCHANGE_KEYBOARD_EVENT 0x8 129706f2543Smrg/* device capabilities changed */ 130706f2543Smrg#define DEVCHANGE_DEVICE_CHANGE 0x10 131706f2543Smrg 132706f2543Smrg/** 133706f2543Smrg * Sent whenever a device's capabilities have changed. 134706f2543Smrg */ 135706f2543Smrgstruct _DeviceChangedEvent 136706f2543Smrg{ 137706f2543Smrg unsigned char header; /**< Always ET_Internal */ 138706f2543Smrg enum EventType type; /**< ET_DeviceChanged */ 139706f2543Smrg int length; /**< Length in bytes */ 140706f2543Smrg Time time; /**< Time in ms */ 141706f2543Smrg int deviceid; /**< Device whose capabilities have changed */ 142706f2543Smrg int flags; /**< Mask of ::HAS_NEW_SLAVE, 143706f2543Smrg ::POINTER_EVENT, ::KEYBOARD_EVENT */ 144706f2543Smrg int masterid; /**< MD when event was generated */ 145706f2543Smrg int sourceid; /**< The device that caused the change */ 146706f2543Smrg 147706f2543Smrg struct { 148706f2543Smrg int num_buttons; /**< Number of buttons */ 149706f2543Smrg Atom names[MAX_BUTTONS];/**< Button names */ 150706f2543Smrg } buttons; 151706f2543Smrg 152706f2543Smrg int num_valuators; /**< Number of axes */ 153706f2543Smrg struct { 154706f2543Smrg uint32_t min; /**< Minimum value */ 155706f2543Smrg uint32_t max; /**< Maximum value */ 156706f2543Smrg /* FIXME: frac parts of min/max */ 157706f2543Smrg uint32_t resolution; /**< Resolution counts/m */ 158706f2543Smrg uint8_t mode; /**< Relative or Absolute */ 159706f2543Smrg Atom name; /**< Axis name */ 160706f2543Smrg } valuators[MAX_VALUATORS]; 161706f2543Smrg 162706f2543Smrg struct { 163706f2543Smrg int min_keycode; 164706f2543Smrg int max_keycode; 165706f2543Smrg } keys; 166706f2543Smrg}; 167706f2543Smrg 168706f2543Smrg#if XFreeXDGA 169706f2543Smrg/** 170706f2543Smrg * DGAEvent, used by DGA to intercept and emulate input events. 171706f2543Smrg */ 172706f2543Smrgstruct _DGAEvent 173706f2543Smrg{ 174706f2543Smrg unsigned char header; /**< Always ET_Internal */ 175706f2543Smrg enum EventType type; /**< ET_DGAEvent */ 176706f2543Smrg int length; /**< Length in bytes */ 177706f2543Smrg Time time; /**< Time in ms */ 178706f2543Smrg int subtype; /**< KeyPress, KeyRelease, ButtonPress, 179706f2543Smrg ButtonRelease, MotionNotify */ 180706f2543Smrg int detail; /**< Button number or key code */ 181706f2543Smrg int dx; /**< Relative x coordinate */ 182706f2543Smrg int dy; /**< Relative y coordinate */ 183706f2543Smrg int screen; /**< Screen number this event applies to */ 184706f2543Smrg uint16_t state; /**< Core modifier/button state */ 185706f2543Smrg}; 186706f2543Smrg#endif 187706f2543Smrg 188706f2543Smrg/** 189706f2543Smrg * Raw event, contains the data as posted by the device. 190706f2543Smrg */ 191706f2543Smrgstruct _RawDeviceEvent 192706f2543Smrg{ 193706f2543Smrg unsigned char header; /**< Always ET_Internal */ 194706f2543Smrg enum EventType type; /**< ET_Raw */ 195706f2543Smrg int length; /**< Length in bytes */ 196706f2543Smrg Time time; /**< Time in ms */ 197706f2543Smrg int deviceid; /**< Device to post this event for */ 198706f2543Smrg int sourceid; /**< The physical source device */ 199706f2543Smrg union { 200706f2543Smrg uint32_t button; /**< Button number */ 201706f2543Smrg uint32_t key; /**< Key code */ 202706f2543Smrg } detail; 203706f2543Smrg struct { 204706f2543Smrg uint8_t mask[(MAX_VALUATORS + 7)/8]; /**< Valuator mask */ 205706f2543Smrg int32_t data[MAX_VALUATORS]; /**< Valuator data */ 206706f2543Smrg int32_t data_frac[MAX_VALUATORS]; /**< Fractional part for data */ 207706f2543Smrg int32_t data_raw[MAX_VALUATORS]; /**< Valuator data as posted */ 208706f2543Smrg int32_t data_raw_frac[MAX_VALUATORS];/**< Fractional part for data_raw */ 209706f2543Smrg } valuators; 210706f2543Smrg}; 211706f2543Smrg 212706f2543Smrg#ifdef XQUARTZ 213706f2543Smrg#define XQUARTZ_EVENT_MAXARGS 5 214706f2543Smrgstruct _XQuartzEvent { 215706f2543Smrg unsigned char header; /**< Always ET_Internal */ 216706f2543Smrg enum EventType type; /**< Always ET_XQuartz */ 217706f2543Smrg int length; /**< Length in bytes */ 218706f2543Smrg Time time; /**< Time in ms. */ 219706f2543Smrg int subtype; /**< Subtype defined by XQuartz DDX */ 220706f2543Smrg uint32_t data[XQUARTZ_EVENT_MAXARGS]; /**< Up to 5 32bit values passed to handler */ 221706f2543Smrg}; 222706f2543Smrg#endif 223706f2543Smrg 224706f2543Smrg/** 225706f2543Smrg * Event type used inside the X server for input event 226706f2543Smrg * processing. 227706f2543Smrg */ 228706f2543Smrgunion _InternalEvent { 229706f2543Smrg struct { 230706f2543Smrg unsigned char header; /**< Always ET_Internal */ 231706f2543Smrg enum EventType type; /**< One of ET_* */ 232706f2543Smrg int length; /**< Length in bytes */ 233706f2543Smrg Time time; /**< Time in ms. */ 234706f2543Smrg } any; 235706f2543Smrg DeviceEvent device_event; 236706f2543Smrg DeviceChangedEvent changed_event; 237706f2543Smrg#if XFreeXDGA 238706f2543Smrg DGAEvent dga_event; 239706f2543Smrg#endif 240706f2543Smrg RawDeviceEvent raw_event; 241706f2543Smrg#ifdef XQUARTZ 242706f2543Smrg XQuartzEvent xquartz_event; 243706f2543Smrg#endif 244706f2543Smrg}; 245706f2543Smrg 246bc1411c9Smrgextern void 247bc1411c9SmrgLeaveWindow(DeviceIntPtr dev); 248bc1411c9Smrg 249706f2543Smrg#endif 250