16747b715Smrg/* 26747b715Smrg * Copyright © 2009 Red Hat, Inc. 36747b715Smrg * 46747b715Smrg * Permission is hereby granted, free of charge, to any person obtaining a 56747b715Smrg * copy of this software and associated documentation files (the "Software"), 66747b715Smrg * to deal in the Software without restriction, including without limitation 76747b715Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense, 86747b715Smrg * and/or sell copies of the Software, and to permit persons to whom the 96747b715Smrg * Software is furnished to do so, subject to the following conditions: 106747b715Smrg * 116747b715Smrg * The above copyright notice and this permission notice (including the next 126747b715Smrg * paragraph) shall be included in all copies or substantial portions of the 136747b715Smrg * Software. 146747b715Smrg * 156747b715Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 166747b715Smrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 176747b715Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 186747b715Smrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 196747b715Smrg * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 206747b715Smrg * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 216747b715Smrg * DEALINGS IN THE SOFTWARE. 226747b715Smrg * 236747b715Smrg */ 246747b715Smrg 256747b715Smrg#ifndef EVENTSTR_H 266747b715Smrg#define EVENTSTR_H 276747b715Smrg 281b5d61b8Smrg#include "inputstr.h" 296747b715Smrg#include <events.h> 306747b715Smrg/** 316747b715Smrg * @file events.h 326747b715Smrg * This file describes the event structures used internally by the X 336747b715Smrg * server during event generation and event processing. 346747b715Smrg * 356747b715Smrg * When are internal events used? 366747b715Smrg * Events from input devices are stored as internal events in the EQ and 376747b715Smrg * processed as internal events until late in the processing cycle. Only then 386747b715Smrg * do they switch to their respective wire events. 396747b715Smrg */ 406747b715Smrg 416747b715Smrg/** 426747b715Smrg * Event types. Used exclusively internal to the server, not visible on the 436747b715Smrg * protocol. 446747b715Smrg * 456747b715Smrg * Note: Keep KeyPress to Motion aligned with the core events. 466747b715Smrg * Keep ET_Raw* in the same order as KeyPress - Motion 476747b715Smrg */ 486747b715Smrgenum EventType { 496747b715Smrg ET_KeyPress = 2, 506747b715Smrg ET_KeyRelease, 516747b715Smrg ET_ButtonPress, 526747b715Smrg ET_ButtonRelease, 536747b715Smrg ET_Motion, 5435c4bbdfSmrg ET_TouchBegin, 5535c4bbdfSmrg ET_TouchUpdate, 5635c4bbdfSmrg ET_TouchEnd, 5735c4bbdfSmrg ET_TouchOwnership, 586747b715Smrg ET_Enter, 596747b715Smrg ET_Leave, 606747b715Smrg ET_FocusIn, 616747b715Smrg ET_FocusOut, 626747b715Smrg ET_ProximityIn, 636747b715Smrg ET_ProximityOut, 646747b715Smrg ET_DeviceChanged, 656747b715Smrg ET_Hierarchy, 666747b715Smrg ET_DGAEvent, 676747b715Smrg ET_RawKeyPress, 686747b715Smrg ET_RawKeyRelease, 696747b715Smrg ET_RawButtonPress, 706747b715Smrg ET_RawButtonRelease, 716747b715Smrg ET_RawMotion, 7235c4bbdfSmrg ET_RawTouchBegin, 7335c4bbdfSmrg ET_RawTouchUpdate, 7435c4bbdfSmrg ET_RawTouchEnd, 756747b715Smrg ET_XQuartz, 7635c4bbdfSmrg ET_BarrierHit, 7735c4bbdfSmrg ET_BarrierLeave, 78ed6184dfSmrg ET_GesturePinchBegin, 79ed6184dfSmrg ET_GesturePinchUpdate, 80ed6184dfSmrg ET_GesturePinchEnd, 81ed6184dfSmrg ET_GestureSwipeBegin, 82ed6184dfSmrg ET_GestureSwipeUpdate, 83ed6184dfSmrg ET_GestureSwipeEnd, 8435c4bbdfSmrg ET_Internal = 0xFF /* First byte */ 856747b715Smrg}; 866747b715Smrg 871b5d61b8Smrg/** 881b5d61b8Smrg * How a DeviceEvent was provoked 891b5d61b8Smrg */ 901b5d61b8Smrgenum DeviceEventSource { 911b5d61b8Smrg EVENT_SOURCE_NORMAL = 0, /**< Default: from a user action (e.g. key press) */ 921b5d61b8Smrg EVENT_SOURCE_FOCUS, /**< Keys or buttons previously down on focus-in */ 931b5d61b8Smrg}; 941b5d61b8Smrg 956747b715Smrg/** 966747b715Smrg * Used for ALL input device events internal in the server until 976747b715Smrg * copied into the matching protocol event. 986747b715Smrg * 996747b715Smrg * Note: We only use the device id because the DeviceIntPtr may become invalid while 1006747b715Smrg * the event is in the EQ. 1016747b715Smrg */ 10235c4bbdfSmrgstruct _DeviceEvent { 1036747b715Smrg unsigned char header; /**< Always ET_Internal */ 1046747b715Smrg enum EventType type; /**< One of EventType */ 1056747b715Smrg int length; /**< Length in bytes */ 1066747b715Smrg Time time; /**< Time in ms */ 1076747b715Smrg int deviceid; /**< Device to post this event for */ 1086747b715Smrg int sourceid; /**< The physical source device */ 1096747b715Smrg union { 11035c4bbdfSmrg uint32_t button; /**< Button number (also used in pointer emulating 11135c4bbdfSmrg touch events) */ 1126747b715Smrg uint32_t key; /**< Key code */ 1136747b715Smrg } detail; 11435c4bbdfSmrg uint32_t touchid; /**< Touch ID (client_id) */ 1156747b715Smrg int16_t root_x; /**< Pos relative to root window in integral data */ 1166747b715Smrg float root_x_frac; /**< Pos relative to root window in frac part */ 1176747b715Smrg int16_t root_y; /**< Pos relative to root window in integral part */ 1186747b715Smrg float root_y_frac; /**< Pos relative to root window in frac part */ 11935c4bbdfSmrg uint8_t buttons[(MAX_BUTTONS + 7) / 8]; /**< Button mask */ 1206747b715Smrg struct { 12135c4bbdfSmrg uint8_t mask[(MAX_VALUATORS + 7) / 8];/**< Valuator mask */ 12235c4bbdfSmrg uint8_t mode[(MAX_VALUATORS + 7) / 8];/**< Valuator mode (Abs or Rel)*/ 12335c4bbdfSmrg double data[MAX_VALUATORS]; /**< Valuator data */ 1246747b715Smrg } valuators; 1256747b715Smrg struct { 1266747b715Smrg uint32_t base; /**< XKB base modifiers */ 1276747b715Smrg uint32_t latched; /**< XKB latched modifiers */ 1286747b715Smrg uint32_t locked; /**< XKB locked modifiers */ 1296747b715Smrg uint32_t effective;/**< XKB effective modifiers */ 1306747b715Smrg } mods; 1316747b715Smrg struct { 1326747b715Smrg uint8_t base; /**< XKB base group */ 1336747b715Smrg uint8_t latched; /**< XKB latched group */ 1346747b715Smrg uint8_t locked; /**< XKB locked group */ 1356747b715Smrg uint8_t effective;/**< XKB effective group */ 1366747b715Smrg } group; 13735c4bbdfSmrg Window root; /**< Root window of the event */ 1386747b715Smrg int corestate; /**< Core key/button state BEFORE the event */ 1396747b715Smrg int key_repeat; /**< Internally-generated key repeat event */ 14035c4bbdfSmrg uint32_t flags; /**< Flags to be copied into the generated event */ 14135c4bbdfSmrg uint32_t resource; /**< Touch event resource, only for TOUCH_REPLAYING */ 1421b5d61b8Smrg enum DeviceEventSource source_type; /**< How this event was provoked */ 1436747b715Smrg}; 1446747b715Smrg 14535c4bbdfSmrg/** 14635c4bbdfSmrg * Generated internally whenever a touch ownership chain changes - an owner 14735c4bbdfSmrg * has accepted or rejected a touch, or a grab/event selection in the delivery 14835c4bbdfSmrg * chain has been removed. 14935c4bbdfSmrg */ 15035c4bbdfSmrgstruct _TouchOwnershipEvent { 15135c4bbdfSmrg unsigned char header; /**< Always ET_Internal */ 15235c4bbdfSmrg enum EventType type; /**< ET_TouchOwnership */ 15335c4bbdfSmrg int length; /**< Length in bytes */ 15435c4bbdfSmrg Time time; /**< Time in ms */ 15535c4bbdfSmrg int deviceid; /**< Device to post this event for */ 15635c4bbdfSmrg int sourceid; /**< The physical source device */ 15735c4bbdfSmrg uint32_t touchid; /**< Touch ID (client_id) */ 15835c4bbdfSmrg uint8_t reason; /**< ::XIAcceptTouch, ::XIRejectTouch */ 15935c4bbdfSmrg uint32_t resource; /**< Provoking grab or event selection */ 16035c4bbdfSmrg uint32_t flags; /**< Flags to be copied into the generated event */ 16135c4bbdfSmrg}; 1626747b715Smrg 1636747b715Smrg/* Flags used in DeviceChangedEvent to signal if the slave has changed */ 1646747b715Smrg#define DEVCHANGE_SLAVE_SWITCH 0x2 1656747b715Smrg/* Flags used in DeviceChangedEvent to signal whether the event was a 1666747b715Smrg * pointer event or a keyboard event */ 1676747b715Smrg#define DEVCHANGE_POINTER_EVENT 0x4 1686747b715Smrg#define DEVCHANGE_KEYBOARD_EVENT 0x8 1696747b715Smrg/* device capabilities changed */ 1706747b715Smrg#define DEVCHANGE_DEVICE_CHANGE 0x10 1716747b715Smrg 1726747b715Smrg/** 1736747b715Smrg * Sent whenever a device's capabilities have changed. 1746747b715Smrg */ 17535c4bbdfSmrgstruct _DeviceChangedEvent { 1766747b715Smrg unsigned char header; /**< Always ET_Internal */ 1776747b715Smrg enum EventType type; /**< ET_DeviceChanged */ 1786747b715Smrg int length; /**< Length in bytes */ 1796747b715Smrg Time time; /**< Time in ms */ 1806747b715Smrg int deviceid; /**< Device whose capabilities have changed */ 1816747b715Smrg int flags; /**< Mask of ::HAS_NEW_SLAVE, 1826747b715Smrg ::POINTER_EVENT, ::KEYBOARD_EVENT */ 1836747b715Smrg int masterid; /**< MD when event was generated */ 1846747b715Smrg int sourceid; /**< The device that caused the change */ 1856747b715Smrg 1866747b715Smrg struct { 1876747b715Smrg int num_buttons; /**< Number of buttons */ 1886747b715Smrg Atom names[MAX_BUTTONS];/**< Button names */ 1896747b715Smrg } buttons; 1906747b715Smrg 1916747b715Smrg int num_valuators; /**< Number of axes */ 1926747b715Smrg struct { 1936747b715Smrg uint32_t min; /**< Minimum value */ 1946747b715Smrg uint32_t max; /**< Maximum value */ 19535c4bbdfSmrg double value; /**< Current value */ 1966747b715Smrg /* FIXME: frac parts of min/max */ 1976747b715Smrg uint32_t resolution; /**< Resolution counts/m */ 1986747b715Smrg uint8_t mode; /**< Relative or Absolute */ 1996747b715Smrg Atom name; /**< Axis name */ 20035c4bbdfSmrg ScrollInfo scroll; /**< Smooth scrolling info */ 2016747b715Smrg } valuators[MAX_VALUATORS]; 2026747b715Smrg 2036747b715Smrg struct { 2046747b715Smrg int min_keycode; 2056747b715Smrg int max_keycode; 2066747b715Smrg } keys; 2076747b715Smrg}; 2086747b715Smrg 2091b5d61b8Smrg#ifdef XFreeXDGA 2106747b715Smrg/** 2116747b715Smrg * DGAEvent, used by DGA to intercept and emulate input events. 2126747b715Smrg */ 21335c4bbdfSmrgstruct _DGAEvent { 2146747b715Smrg unsigned char header; /**< Always ET_Internal */ 2156747b715Smrg enum EventType type; /**< ET_DGAEvent */ 2166747b715Smrg int length; /**< Length in bytes */ 2176747b715Smrg Time time; /**< Time in ms */ 2186747b715Smrg int subtype; /**< KeyPress, KeyRelease, ButtonPress, 2196747b715Smrg ButtonRelease, MotionNotify */ 2209ace9065Smrg int detail; /**< Button number or key code */ 2216747b715Smrg int dx; /**< Relative x coordinate */ 2226747b715Smrg int dy; /**< Relative y coordinate */ 2236747b715Smrg int screen; /**< Screen number this event applies to */ 2246747b715Smrg uint16_t state; /**< Core modifier/button state */ 2256747b715Smrg}; 2266747b715Smrg#endif 2276747b715Smrg 2286747b715Smrg/** 2296747b715Smrg * Raw event, contains the data as posted by the device. 2306747b715Smrg */ 23135c4bbdfSmrgstruct _RawDeviceEvent { 2326747b715Smrg unsigned char header; /**< Always ET_Internal */ 2336747b715Smrg enum EventType type; /**< ET_Raw */ 2346747b715Smrg int length; /**< Length in bytes */ 2356747b715Smrg Time time; /**< Time in ms */ 2366747b715Smrg int deviceid; /**< Device to post this event for */ 2376747b715Smrg int sourceid; /**< The physical source device */ 2386747b715Smrg union { 2396747b715Smrg uint32_t button; /**< Button number */ 2406747b715Smrg uint32_t key; /**< Key code */ 2416747b715Smrg } detail; 2426747b715Smrg struct { 24335c4bbdfSmrg uint8_t mask[(MAX_VALUATORS + 7) / 8];/**< Valuator mask */ 24435c4bbdfSmrg double data[MAX_VALUATORS]; /**< Valuator data */ 24535c4bbdfSmrg double data_raw[MAX_VALUATORS]; /**< Valuator data as posted */ 2466747b715Smrg } valuators; 24735c4bbdfSmrg uint32_t flags; /**< Flags to be copied into the generated event */ 24835c4bbdfSmrg}; 24935c4bbdfSmrg 25035c4bbdfSmrgstruct _BarrierEvent { 25135c4bbdfSmrg unsigned char header; /**< Always ET_Internal */ 25235c4bbdfSmrg enum EventType type; /**< ET_BarrierHit, ET_BarrierLeave */ 25335c4bbdfSmrg int length; /**< Length in bytes */ 25435c4bbdfSmrg Time time; /**< Time in ms */ 25535c4bbdfSmrg int deviceid; /**< Device to post this event for */ 25635c4bbdfSmrg int sourceid; /**< The physical source device */ 25735c4bbdfSmrg int barrierid; 25835c4bbdfSmrg Window window; 25935c4bbdfSmrg Window root; 26035c4bbdfSmrg double dx; 26135c4bbdfSmrg double dy; 26235c4bbdfSmrg double root_x; 26335c4bbdfSmrg double root_y; 26435c4bbdfSmrg int16_t dt; 26535c4bbdfSmrg int32_t event_id; 26635c4bbdfSmrg uint32_t flags; 2676747b715Smrg}; 2686747b715Smrg 269ed6184dfSmrgstruct _GestureEvent { 270ed6184dfSmrg unsigned char header; /**< Always ET_Internal */ 271ed6184dfSmrg enum EventType type; /**< One of ET_Gesture{Pinch,Swipe}{Begin,Update,End} */ 272ed6184dfSmrg int length; /**< Length in bytes */ 273ed6184dfSmrg Time time; /**< Time in ms */ 274ed6184dfSmrg int deviceid; /**< Device to post this event for */ 275ed6184dfSmrg int sourceid; /**< The physical source device */ 276ed6184dfSmrg uint32_t num_touches; /**< The number of touches in this gesture */ 277ed6184dfSmrg double root_x; /**< Pos relative to root window */ 278ed6184dfSmrg double root_y; /**< Pos relative to root window */ 279ed6184dfSmrg double delta_x; 280ed6184dfSmrg double delta_y; 281ed6184dfSmrg double delta_unaccel_x; 282ed6184dfSmrg double delta_unaccel_y; 283ed6184dfSmrg double scale; /**< Only on ET_GesturePinch{Begin,Update} */ 284ed6184dfSmrg double delta_angle; /**< Only on ET_GesturePinch{Begin,Update} */ 285ed6184dfSmrg struct { 286ed6184dfSmrg uint32_t base; /**< XKB base modifiers */ 287ed6184dfSmrg uint32_t latched; /**< XKB latched modifiers */ 288ed6184dfSmrg uint32_t locked; /**< XKB locked modifiers */ 289ed6184dfSmrg uint32_t effective;/**< XKB effective modifiers */ 290ed6184dfSmrg } mods; 291ed6184dfSmrg struct { 292ed6184dfSmrg uint8_t base; /**< XKB base group */ 293ed6184dfSmrg uint8_t latched; /**< XKB latched group */ 294ed6184dfSmrg uint8_t locked; /**< XKB locked group */ 295ed6184dfSmrg uint8_t effective;/**< XKB effective group */ 296ed6184dfSmrg } group; 297ed6184dfSmrg Window root; /**< Root window of the event */ 298ed6184dfSmrg uint32_t flags; /**< Flags to be copied into the generated event */ 299ed6184dfSmrg}; 300ed6184dfSmrg 3016747b715Smrg#ifdef XQUARTZ 3026747b715Smrg#define XQUARTZ_EVENT_MAXARGS 5 3036747b715Smrgstruct _XQuartzEvent { 3046747b715Smrg unsigned char header; /**< Always ET_Internal */ 3056747b715Smrg enum EventType type; /**< Always ET_XQuartz */ 3066747b715Smrg int length; /**< Length in bytes */ 3076747b715Smrg Time time; /**< Time in ms. */ 3086747b715Smrg int subtype; /**< Subtype defined by XQuartz DDX */ 3096747b715Smrg uint32_t data[XQUARTZ_EVENT_MAXARGS]; /**< Up to 5 32bit values passed to handler */ 3106747b715Smrg}; 3116747b715Smrg#endif 3126747b715Smrg 3136747b715Smrg/** 3146747b715Smrg * Event type used inside the X server for input event 3156747b715Smrg * processing. 3166747b715Smrg */ 3176747b715Smrgunion _InternalEvent { 31835c4bbdfSmrg struct { 31935c4bbdfSmrg unsigned char header; /**< Always ET_Internal */ 32035c4bbdfSmrg enum EventType type; /**< One of ET_* */ 32135c4bbdfSmrg int length; /**< Length in bytes */ 32235c4bbdfSmrg Time time; /**< Time in ms. */ 32335c4bbdfSmrg } any; 32435c4bbdfSmrg DeviceEvent device_event; 32535c4bbdfSmrg DeviceChangedEvent changed_event; 32635c4bbdfSmrg TouchOwnershipEvent touch_ownership_event; 32735c4bbdfSmrg BarrierEvent barrier_event; 3281b5d61b8Smrg#ifdef XFreeXDGA 32935c4bbdfSmrg DGAEvent dga_event; 3306747b715Smrg#endif 33135c4bbdfSmrg RawDeviceEvent raw_event; 3326747b715Smrg#ifdef XQUARTZ 33335c4bbdfSmrg XQuartzEvent xquartz_event; 3346747b715Smrg#endif 335ed6184dfSmrg GestureEvent gesture_event; 3366747b715Smrg}; 3376747b715Smrg 338eee80088Smrgextern void 339eee80088SmrgLeaveWindow(DeviceIntPtr dev); 340eee80088Smrg 3416747b715Smrg#endif 342