eventstr.h revision 9ace9065
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
286747b715Smrg#include <events.h>
296747b715Smrg/**
306747b715Smrg * @file events.h
316747b715Smrg * This file describes the event structures used internally by the X
326747b715Smrg * server during event generation and event processing.
336747b715Smrg *
346747b715Smrg * When are internal events used?
356747b715Smrg * Events from input devices are stored as internal events in the EQ and
366747b715Smrg * processed as internal events until late in the processing cycle. Only then
376747b715Smrg * do they switch to their respective wire events.
386747b715Smrg */
396747b715Smrg
406747b715Smrg/**
416747b715Smrg * Event types. Used exclusively internal to the server, not visible on the
426747b715Smrg * protocol.
436747b715Smrg *
446747b715Smrg * Note: Keep KeyPress to Motion aligned with the core events.
456747b715Smrg *       Keep ET_Raw* in the same order as KeyPress - Motion
466747b715Smrg */
476747b715Smrgenum EventType {
486747b715Smrg    ET_KeyPress = 2,
496747b715Smrg    ET_KeyRelease,
506747b715Smrg    ET_ButtonPress,
516747b715Smrg    ET_ButtonRelease,
526747b715Smrg    ET_Motion,
536747b715Smrg    ET_Enter,
546747b715Smrg    ET_Leave,
556747b715Smrg    ET_FocusIn,
566747b715Smrg    ET_FocusOut,
576747b715Smrg    ET_ProximityIn,
586747b715Smrg    ET_ProximityOut,
596747b715Smrg    ET_DeviceChanged,
606747b715Smrg    ET_Hierarchy,
616747b715Smrg    ET_DGAEvent,
626747b715Smrg    ET_RawKeyPress,
636747b715Smrg    ET_RawKeyRelease,
646747b715Smrg    ET_RawButtonPress,
656747b715Smrg    ET_RawButtonRelease,
666747b715Smrg    ET_RawMotion,
676747b715Smrg    ET_XQuartz,
686747b715Smrg    ET_Internal = 0xFF /* First byte */
696747b715Smrg};
706747b715Smrg
716747b715Smrg#define CHECKEVENT(ev) if (ev && ((InternalEvent*)(ev))->any.header != 0xFF) \
726747b715Smrg                          FatalError("Wrong event type %d.\n", \
736747b715Smrg                                     ((InternalEvent*)(ev))->any.header);
746747b715Smrg
756747b715Smrg/**
766747b715Smrg * Used for ALL input device events internal in the server until
776747b715Smrg * copied into the matching protocol event.
786747b715Smrg *
796747b715Smrg * Note: We only use the device id because the DeviceIntPtr may become invalid while
806747b715Smrg * the event is in the EQ.
816747b715Smrg */
826747b715Smrgstruct _DeviceEvent
836747b715Smrg{
846747b715Smrg    unsigned char header; /**< Always ET_Internal */
856747b715Smrg    enum EventType type;  /**< One of EventType */
866747b715Smrg    int length;           /**< Length in bytes */
876747b715Smrg    Time time;            /**< Time in ms */
886747b715Smrg    int deviceid;         /**< Device to post this event for */
896747b715Smrg    int sourceid;         /**< The physical source device */
906747b715Smrg    union {
916747b715Smrg        uint32_t button;  /**< Button number */
926747b715Smrg        uint32_t key;     /**< Key code */
936747b715Smrg    } detail;
946747b715Smrg    int16_t root_x;       /**< Pos relative to root window in integral data */
956747b715Smrg    float root_x_frac;    /**< Pos relative to root window in frac part */
966747b715Smrg    int16_t root_y;       /**< Pos relative to root window in integral part */
976747b715Smrg    float root_y_frac;    /**< Pos relative to root window in frac part */
986747b715Smrg    uint8_t    buttons[(MAX_BUTTONS + 7)/8]; /**< Button mask */
996747b715Smrg    struct {
1006747b715Smrg        uint8_t  mask[(MAX_VALUATORS + 7)/8]; /**< Valuator mask */
1016747b715Smrg        uint8_t  mode[(MAX_VALUATORS + 7)/8]; /**< Valuator mode (Abs or Rel)*/
1028223e2f2Smrg        int32_t  data[MAX_VALUATORS];         /**< Valuator data */
1036747b715Smrg        int32_t  data_frac[MAX_VALUATORS];    /**< Fractional part for data */
1046747b715Smrg    } valuators;
1056747b715Smrg    struct {
1066747b715Smrg        uint32_t base;    /**< XKB base modifiers */
1076747b715Smrg        uint32_t latched; /**< XKB latched modifiers */
1086747b715Smrg        uint32_t locked;  /**< XKB locked modifiers */
1096747b715Smrg        uint32_t effective;/**< XKB effective modifiers */
1106747b715Smrg    } mods;
1116747b715Smrg    struct {
1126747b715Smrg        uint8_t base;    /**< XKB base group */
1136747b715Smrg        uint8_t latched; /**< XKB latched group */
1146747b715Smrg        uint8_t locked;  /**< XKB locked group */
1156747b715Smrg        uint8_t effective;/**< XKB effective group */
1166747b715Smrg    } group;
1176747b715Smrg    Window      root; /**< Root window of the event */
1186747b715Smrg    int corestate;    /**< Core key/button state BEFORE the event */
1196747b715Smrg    int key_repeat;   /**< Internally-generated key repeat event */
1206747b715Smrg};
1216747b715Smrg
1226747b715Smrg
1236747b715Smrg/* Flags used in DeviceChangedEvent to signal if the slave has changed */
1246747b715Smrg#define DEVCHANGE_SLAVE_SWITCH 0x2
1256747b715Smrg/* Flags used in DeviceChangedEvent to signal whether the event was a
1266747b715Smrg * pointer event or a keyboard event */
1276747b715Smrg#define DEVCHANGE_POINTER_EVENT 0x4
1286747b715Smrg#define DEVCHANGE_KEYBOARD_EVENT 0x8
1296747b715Smrg/* device capabilities changed */
1306747b715Smrg#define DEVCHANGE_DEVICE_CHANGE 0x10
1316747b715Smrg
1326747b715Smrg/**
1336747b715Smrg * Sent whenever a device's capabilities have changed.
1346747b715Smrg */
1356747b715Smrgstruct _DeviceChangedEvent
1366747b715Smrg{
1376747b715Smrg    unsigned char header; /**< Always ET_Internal */
1386747b715Smrg    enum EventType type;  /**< ET_DeviceChanged */
1396747b715Smrg    int length;           /**< Length in bytes */
1406747b715Smrg    Time time;            /**< Time in ms */
1416747b715Smrg    int deviceid;         /**< Device whose capabilities have changed */
1426747b715Smrg    int flags;            /**< Mask of ::HAS_NEW_SLAVE,
1436747b715Smrg                               ::POINTER_EVENT, ::KEYBOARD_EVENT */
1446747b715Smrg    int masterid;         /**< MD when event was generated */
1456747b715Smrg    int sourceid;         /**< The device that caused the change */
1466747b715Smrg
1476747b715Smrg    struct {
1486747b715Smrg        int num_buttons;        /**< Number of buttons */
1496747b715Smrg        Atom names[MAX_BUTTONS];/**< Button names */
1506747b715Smrg    } buttons;
1516747b715Smrg
1526747b715Smrg    int num_valuators;          /**< Number of axes */
1536747b715Smrg    struct {
1546747b715Smrg        uint32_t min;           /**< Minimum value */
1556747b715Smrg        uint32_t max;           /**< Maximum value */
1566747b715Smrg        /* FIXME: frac parts of min/max */
1576747b715Smrg        uint32_t resolution;    /**< Resolution counts/m */
1586747b715Smrg        uint8_t mode;           /**< Relative or Absolute */
1596747b715Smrg        Atom name;              /**< Axis name */
1606747b715Smrg    } valuators[MAX_VALUATORS];
1616747b715Smrg
1626747b715Smrg    struct {
1636747b715Smrg        int min_keycode;
1646747b715Smrg        int max_keycode;
1656747b715Smrg    } keys;
1666747b715Smrg};
1676747b715Smrg
1686747b715Smrg#if XFreeXDGA
1696747b715Smrg/**
1706747b715Smrg * DGAEvent, used by DGA to intercept and emulate input events.
1716747b715Smrg */
1726747b715Smrgstruct _DGAEvent
1736747b715Smrg{
1746747b715Smrg    unsigned char header; /**<  Always ET_Internal */
1756747b715Smrg    enum EventType type;  /**<  ET_DGAEvent */
1766747b715Smrg    int length;           /**<  Length in bytes */
1776747b715Smrg    Time time;            /**<  Time in ms */
1786747b715Smrg    int subtype;          /**<  KeyPress, KeyRelease, ButtonPress,
1796747b715Smrg                                ButtonRelease, MotionNotify */
1809ace9065Smrg    int detail;           /**<  Button number or key code */
1816747b715Smrg    int dx;               /**<  Relative x coordinate */
1826747b715Smrg    int dy;               /**<  Relative y coordinate */
1836747b715Smrg    int screen;           /**<  Screen number this event applies to */
1846747b715Smrg    uint16_t state;       /**<  Core modifier/button state */
1856747b715Smrg};
1866747b715Smrg#endif
1876747b715Smrg
1886747b715Smrg/**
1896747b715Smrg * Raw event, contains the data as posted by the device.
1906747b715Smrg */
1916747b715Smrgstruct _RawDeviceEvent
1926747b715Smrg{
1936747b715Smrg    unsigned char header; /**<  Always ET_Internal */
1946747b715Smrg    enum EventType type;  /**<  ET_Raw */
1956747b715Smrg    int length;           /**<  Length in bytes */
1966747b715Smrg    Time time;            /**<  Time in ms */
1976747b715Smrg    int deviceid;         /**< Device to post this event for */
1986747b715Smrg    int sourceid;         /**< The physical source device */
1996747b715Smrg    union {
2006747b715Smrg        uint32_t button;  /**< Button number */
2016747b715Smrg        uint32_t key;     /**< Key code */
2026747b715Smrg    } detail;
2036747b715Smrg    struct {
2046747b715Smrg        uint8_t  mask[(MAX_VALUATORS + 7)/8]; /**< Valuator mask */
2056747b715Smrg        int32_t  data[MAX_VALUATORS];         /**< Valuator data */
2066747b715Smrg        int32_t  data_frac[MAX_VALUATORS];    /**< Fractional part for data */
2076747b715Smrg        int32_t  data_raw[MAX_VALUATORS];     /**< Valuator data as posted */
2086747b715Smrg        int32_t  data_raw_frac[MAX_VALUATORS];/**< Fractional part for data_raw */
2096747b715Smrg    } valuators;
2106747b715Smrg};
2116747b715Smrg
2126747b715Smrg#ifdef XQUARTZ
2136747b715Smrg#define XQUARTZ_EVENT_MAXARGS 5
2146747b715Smrgstruct _XQuartzEvent {
2156747b715Smrg    unsigned char header; /**< Always ET_Internal */
2166747b715Smrg    enum EventType type;  /**< Always ET_XQuartz */
2176747b715Smrg    int length;           /**< Length in bytes */
2186747b715Smrg    Time time;            /**< Time in ms. */
2196747b715Smrg    int subtype;          /**< Subtype defined by XQuartz DDX */
2206747b715Smrg    uint32_t data[XQUARTZ_EVENT_MAXARGS]; /**< Up to 5 32bit values passed to handler */
2216747b715Smrg};
2226747b715Smrg#endif
2236747b715Smrg
2246747b715Smrg/**
2256747b715Smrg * Event type used inside the X server for input event
2266747b715Smrg * processing.
2276747b715Smrg */
2286747b715Smrgunion _InternalEvent {
2296747b715Smrg        struct {
2306747b715Smrg            unsigned char header; /**< Always ET_Internal */
2316747b715Smrg            enum EventType type;  /**< One of ET_* */
2326747b715Smrg            int length;           /**< Length in bytes */
2336747b715Smrg            Time time;            /**< Time in ms. */
2346747b715Smrg        } any;
2356747b715Smrg        DeviceEvent device_event;
2366747b715Smrg        DeviceChangedEvent changed_event;
2376747b715Smrg#if XFreeXDGA
2386747b715Smrg        DGAEvent dga_event;
2396747b715Smrg#endif
2406747b715Smrg        RawDeviceEvent raw_event;
2416747b715Smrg#ifdef XQUARTZ
2426747b715Smrg        XQuartzEvent xquartz_event;
2436747b715Smrg#endif
2446747b715Smrg};
2456747b715Smrg
2466747b715Smrg#endif
247