45e9809aff7304721fddb95654901b32195c9c7avboxsync/*
45e9809aff7304721fddb95654901b32195c9c7avboxsync * Copyright © 2009 Red Hat, Inc.
45e9809aff7304721fddb95654901b32195c9c7avboxsync *
45e9809aff7304721fddb95654901b32195c9c7avboxsync * Permission is hereby granted, free of charge, to any person obtaining a
45e9809aff7304721fddb95654901b32195c9c7avboxsync * copy of this software and associated documentation files (the "Software"),
45e9809aff7304721fddb95654901b32195c9c7avboxsync * to deal in the Software without restriction, including without limitation
45e9809aff7304721fddb95654901b32195c9c7avboxsync * the rights to use, copy, modify, merge, publish, distribute, sublicense,
45e9809aff7304721fddb95654901b32195c9c7avboxsync * and/or sell copies of the Software, and to permit persons to whom the
45e9809aff7304721fddb95654901b32195c9c7avboxsync * Software is furnished to do so, subject to the following conditions:
45e9809aff7304721fddb95654901b32195c9c7avboxsync *
45e9809aff7304721fddb95654901b32195c9c7avboxsync * The above copyright notice and this permission notice (including the next
45e9809aff7304721fddb95654901b32195c9c7avboxsync * paragraph) shall be included in all copies or substantial portions of the
45e9809aff7304721fddb95654901b32195c9c7avboxsync * Software.
45e9809aff7304721fddb95654901b32195c9c7avboxsync *
45e9809aff7304721fddb95654901b32195c9c7avboxsync * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
45e9809aff7304721fddb95654901b32195c9c7avboxsync * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
45e9809aff7304721fddb95654901b32195c9c7avboxsync * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
45e9809aff7304721fddb95654901b32195c9c7avboxsync * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
45e9809aff7304721fddb95654901b32195c9c7avboxsync * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
45e9809aff7304721fddb95654901b32195c9c7avboxsync * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
45e9809aff7304721fddb95654901b32195c9c7avboxsync * DEALINGS IN THE SOFTWARE.
45e9809aff7304721fddb95654901b32195c9c7avboxsync *
45e9809aff7304721fddb95654901b32195c9c7avboxsync */
45e9809aff7304721fddb95654901b32195c9c7avboxsync
45e9809aff7304721fddb95654901b32195c9c7avboxsync#ifndef EVENTSTR_H
45e9809aff7304721fddb95654901b32195c9c7avboxsync#define EVENTSTR_H
45e9809aff7304721fddb95654901b32195c9c7avboxsync
45e9809aff7304721fddb95654901b32195c9c7avboxsync#include <events.h>
45e9809aff7304721fddb95654901b32195c9c7avboxsync/**
45e9809aff7304721fddb95654901b32195c9c7avboxsync * @file events.h
45e9809aff7304721fddb95654901b32195c9c7avboxsync * This file describes the event structures used internally by the X
45e9809aff7304721fddb95654901b32195c9c7avboxsync * server during event generation and event processing.
45e9809aff7304721fddb95654901b32195c9c7avboxsync *
45e9809aff7304721fddb95654901b32195c9c7avboxsync * When are internal events used?
45e9809aff7304721fddb95654901b32195c9c7avboxsync * Events from input devices are stored as internal events in the EQ and
45e9809aff7304721fddb95654901b32195c9c7avboxsync * processed as internal events until late in the processing cycle. Only then
45e9809aff7304721fddb95654901b32195c9c7avboxsync * do they switch to their respective wire events.
45e9809aff7304721fddb95654901b32195c9c7avboxsync */
45e9809aff7304721fddb95654901b32195c9c7avboxsync
45e9809aff7304721fddb95654901b32195c9c7avboxsync/**
45e9809aff7304721fddb95654901b32195c9c7avboxsync * Event types. Used exclusively internal to the server, not visible on the
45e9809aff7304721fddb95654901b32195c9c7avboxsync * protocol.
45e9809aff7304721fddb95654901b32195c9c7avboxsync *
45e9809aff7304721fddb95654901b32195c9c7avboxsync * Note: Keep KeyPress to Motion aligned with the core events.
45e9809aff7304721fddb95654901b32195c9c7avboxsync * Keep ET_Raw* in the same order as KeyPress - Motion
45e9809aff7304721fddb95654901b32195c9c7avboxsync */
45e9809aff7304721fddb95654901b32195c9c7avboxsyncenum EventType {
45e9809aff7304721fddb95654901b32195c9c7avboxsync ET_KeyPress = 2,
45e9809aff7304721fddb95654901b32195c9c7avboxsync ET_KeyRelease,
45e9809aff7304721fddb95654901b32195c9c7avboxsync ET_ButtonPress,
45e9809aff7304721fddb95654901b32195c9c7avboxsync ET_ButtonRelease,
45e9809aff7304721fddb95654901b32195c9c7avboxsync ET_Motion,
45e9809aff7304721fddb95654901b32195c9c7avboxsync ET_Enter,
45e9809aff7304721fddb95654901b32195c9c7avboxsync ET_Leave,
45e9809aff7304721fddb95654901b32195c9c7avboxsync ET_FocusIn,
45e9809aff7304721fddb95654901b32195c9c7avboxsync ET_FocusOut,
45e9809aff7304721fddb95654901b32195c9c7avboxsync ET_ProximityIn,
45e9809aff7304721fddb95654901b32195c9c7avboxsync ET_ProximityOut,
45e9809aff7304721fddb95654901b32195c9c7avboxsync ET_DeviceChanged,
45e9809aff7304721fddb95654901b32195c9c7avboxsync ET_Hierarchy,
45e9809aff7304721fddb95654901b32195c9c7avboxsync ET_DGAEvent,
45e9809aff7304721fddb95654901b32195c9c7avboxsync ET_RawKeyPress,
45e9809aff7304721fddb95654901b32195c9c7avboxsync ET_RawKeyRelease,
45e9809aff7304721fddb95654901b32195c9c7avboxsync ET_RawButtonPress,
45e9809aff7304721fddb95654901b32195c9c7avboxsync ET_RawButtonRelease,
45e9809aff7304721fddb95654901b32195c9c7avboxsync ET_RawMotion,
45e9809aff7304721fddb95654901b32195c9c7avboxsync ET_XQuartz,
45e9809aff7304721fddb95654901b32195c9c7avboxsync ET_Internal = 0xFF /* First byte */
45e9809aff7304721fddb95654901b32195c9c7avboxsync};
45e9809aff7304721fddb95654901b32195c9c7avboxsync
45e9809aff7304721fddb95654901b32195c9c7avboxsync#define CHECKEVENT(ev) if (ev && ((InternalEvent*)(ev))->any.header != 0xFF) \
45e9809aff7304721fddb95654901b32195c9c7avboxsync FatalError("Wrong event type %d.\n", \
45e9809aff7304721fddb95654901b32195c9c7avboxsync ((InternalEvent*)(ev))->any.header);
45e9809aff7304721fddb95654901b32195c9c7avboxsync
45e9809aff7304721fddb95654901b32195c9c7avboxsync/**
45e9809aff7304721fddb95654901b32195c9c7avboxsync * Used for ALL input device events internal in the server until
45e9809aff7304721fddb95654901b32195c9c7avboxsync * copied into the matching protocol event.
45e9809aff7304721fddb95654901b32195c9c7avboxsync *
45e9809aff7304721fddb95654901b32195c9c7avboxsync * Note: We only use the device id because the DeviceIntPtr may become invalid while
45e9809aff7304721fddb95654901b32195c9c7avboxsync * the event is in the EQ.
45e9809aff7304721fddb95654901b32195c9c7avboxsync */
45e9809aff7304721fddb95654901b32195c9c7avboxsyncstruct _DeviceEvent
45e9809aff7304721fddb95654901b32195c9c7avboxsync{
45e9809aff7304721fddb95654901b32195c9c7avboxsync unsigned char header; /**< Always ET_Internal */
45e9809aff7304721fddb95654901b32195c9c7avboxsync enum EventType type; /**< One of EventType */
45e9809aff7304721fddb95654901b32195c9c7avboxsync int length; /**< Length in bytes */
45e9809aff7304721fddb95654901b32195c9c7avboxsync Time time; /**< Time in ms */
45e9809aff7304721fddb95654901b32195c9c7avboxsync int deviceid; /**< Device to post this event for */
45e9809aff7304721fddb95654901b32195c9c7avboxsync int sourceid; /**< The physical source device */
45e9809aff7304721fddb95654901b32195c9c7avboxsync union {
45e9809aff7304721fddb95654901b32195c9c7avboxsync uint32_t button; /**< Button number */
45e9809aff7304721fddb95654901b32195c9c7avboxsync uint32_t key; /**< Key code */
45e9809aff7304721fddb95654901b32195c9c7avboxsync } detail;
45e9809aff7304721fddb95654901b32195c9c7avboxsync uint16_t root_x; /**< Pos relative to root window in integral data */
45e9809aff7304721fddb95654901b32195c9c7avboxsync float root_x_frac; /**< Pos relative to root window in frac part */
45e9809aff7304721fddb95654901b32195c9c7avboxsync uint16_t root_y; /**< Pos relative to root window in integral part */
45e9809aff7304721fddb95654901b32195c9c7avboxsync float root_y_frac; /**< Pos relative to root window in frac part */
45e9809aff7304721fddb95654901b32195c9c7avboxsync uint8_t buttons[(MAX_BUTTONS + 7)/8]; /**< Button mask */
45e9809aff7304721fddb95654901b32195c9c7avboxsync struct {
45e9809aff7304721fddb95654901b32195c9c7avboxsync uint8_t mask[(MAX_VALUATORS + 7)/8]; /**< Valuator mask */
45e9809aff7304721fddb95654901b32195c9c7avboxsync uint8_t mode[(MAX_VALUATORS + 7)/8]; /**< Valuator mode (Abs or Rel)*/
45e9809aff7304721fddb95654901b32195c9c7avboxsync uint32_t data[MAX_VALUATORS]; /**< Valuator data */
45e9809aff7304721fddb95654901b32195c9c7avboxsync int32_t data_frac[MAX_VALUATORS]; /**< Fractional part for data */
45e9809aff7304721fddb95654901b32195c9c7avboxsync } valuators;
45e9809aff7304721fddb95654901b32195c9c7avboxsync struct {
45e9809aff7304721fddb95654901b32195c9c7avboxsync uint32_t base; /**< XKB base modifiers */
45e9809aff7304721fddb95654901b32195c9c7avboxsync uint32_t latched; /**< XKB latched modifiers */
45e9809aff7304721fddb95654901b32195c9c7avboxsync uint32_t locked; /**< XKB locked modifiers */
45e9809aff7304721fddb95654901b32195c9c7avboxsync uint32_t effective;/**< XKB effective modifiers */
45e9809aff7304721fddb95654901b32195c9c7avboxsync } mods;
45e9809aff7304721fddb95654901b32195c9c7avboxsync struct {
45e9809aff7304721fddb95654901b32195c9c7avboxsync uint8_t base; /**< XKB base group */
45e9809aff7304721fddb95654901b32195c9c7avboxsync uint8_t latched; /**< XKB latched group */
45e9809aff7304721fddb95654901b32195c9c7avboxsync uint8_t locked; /**< XKB locked group */
45e9809aff7304721fddb95654901b32195c9c7avboxsync uint8_t effective;/**< XKB effective group */
45e9809aff7304721fddb95654901b32195c9c7avboxsync } group;
45e9809aff7304721fddb95654901b32195c9c7avboxsync Window root; /**< Root window of the event */
45e9809aff7304721fddb95654901b32195c9c7avboxsync int corestate; /**< Core key/button state BEFORE the event */
45e9809aff7304721fddb95654901b32195c9c7avboxsync int key_repeat; /**< Internally-generated key repeat event */
45e9809aff7304721fddb95654901b32195c9c7avboxsync};
45e9809aff7304721fddb95654901b32195c9c7avboxsync
45e9809aff7304721fddb95654901b32195c9c7avboxsync
45e9809aff7304721fddb95654901b32195c9c7avboxsync/* Flags used in DeviceChangedEvent to signal if the slave has changed */
45e9809aff7304721fddb95654901b32195c9c7avboxsync#define DEVCHANGE_SLAVE_SWITCH 0x2
45e9809aff7304721fddb95654901b32195c9c7avboxsync/* Flags used in DeviceChangedEvent to signal whether the event was a
45e9809aff7304721fddb95654901b32195c9c7avboxsync * pointer event or a keyboard event */
45e9809aff7304721fddb95654901b32195c9c7avboxsync#define DEVCHANGE_POINTER_EVENT 0x4
45e9809aff7304721fddb95654901b32195c9c7avboxsync#define DEVCHANGE_KEYBOARD_EVENT 0x8
45e9809aff7304721fddb95654901b32195c9c7avboxsync/* device capabilities changed */
45e9809aff7304721fddb95654901b32195c9c7avboxsync#define DEVCHANGE_DEVICE_CHANGE 0x10
45e9809aff7304721fddb95654901b32195c9c7avboxsync
45e9809aff7304721fddb95654901b32195c9c7avboxsync/**
45e9809aff7304721fddb95654901b32195c9c7avboxsync * Sent whenever a device's capabilities have changed.
45e9809aff7304721fddb95654901b32195c9c7avboxsync */
45e9809aff7304721fddb95654901b32195c9c7avboxsyncstruct _DeviceChangedEvent
45e9809aff7304721fddb95654901b32195c9c7avboxsync{
45e9809aff7304721fddb95654901b32195c9c7avboxsync unsigned char header; /**< Always ET_Internal */
45e9809aff7304721fddb95654901b32195c9c7avboxsync enum EventType type; /**< ET_DeviceChanged */
45e9809aff7304721fddb95654901b32195c9c7avboxsync int length; /**< Length in bytes */
45e9809aff7304721fddb95654901b32195c9c7avboxsync Time time; /**< Time in ms */
45e9809aff7304721fddb95654901b32195c9c7avboxsync int deviceid; /**< Device whose capabilities have changed */
45e9809aff7304721fddb95654901b32195c9c7avboxsync int flags; /**< Mask of ::HAS_NEW_SLAVE,
45e9809aff7304721fddb95654901b32195c9c7avboxsync ::POINTER_EVENT, ::KEYBOARD_EVENT */
45e9809aff7304721fddb95654901b32195c9c7avboxsync int masterid; /**< MD when event was generated */
45e9809aff7304721fddb95654901b32195c9c7avboxsync int sourceid; /**< The device that caused the change */
45e9809aff7304721fddb95654901b32195c9c7avboxsync
45e9809aff7304721fddb95654901b32195c9c7avboxsync struct {
45e9809aff7304721fddb95654901b32195c9c7avboxsync int num_buttons; /**< Number of buttons */
45e9809aff7304721fddb95654901b32195c9c7avboxsync Atom names[MAX_BUTTONS];/**< Button names */
45e9809aff7304721fddb95654901b32195c9c7avboxsync } buttons;
45e9809aff7304721fddb95654901b32195c9c7avboxsync
45e9809aff7304721fddb95654901b32195c9c7avboxsync int num_valuators; /**< Number of axes */
45e9809aff7304721fddb95654901b32195c9c7avboxsync struct {
45e9809aff7304721fddb95654901b32195c9c7avboxsync uint32_t min; /**< Minimum value */
45e9809aff7304721fddb95654901b32195c9c7avboxsync uint32_t max; /**< Maximum value */
45e9809aff7304721fddb95654901b32195c9c7avboxsync /* FIXME: frac parts of min/max */
45e9809aff7304721fddb95654901b32195c9c7avboxsync uint32_t resolution; /**< Resolution counts/m */
45e9809aff7304721fddb95654901b32195c9c7avboxsync uint8_t mode; /**< Relative or Absolute */
45e9809aff7304721fddb95654901b32195c9c7avboxsync Atom name; /**< Axis name */
45e9809aff7304721fddb95654901b32195c9c7avboxsync } valuators[MAX_VALUATORS];
45e9809aff7304721fddb95654901b32195c9c7avboxsync
45e9809aff7304721fddb95654901b32195c9c7avboxsync struct {
45e9809aff7304721fddb95654901b32195c9c7avboxsync int min_keycode;
45e9809aff7304721fddb95654901b32195c9c7avboxsync int max_keycode;
45e9809aff7304721fddb95654901b32195c9c7avboxsync } keys;
45e9809aff7304721fddb95654901b32195c9c7avboxsync};
45e9809aff7304721fddb95654901b32195c9c7avboxsync
45e9809aff7304721fddb95654901b32195c9c7avboxsync#if XFreeXDGA
45e9809aff7304721fddb95654901b32195c9c7avboxsync/**
45e9809aff7304721fddb95654901b32195c9c7avboxsync * DGAEvent, used by DGA to intercept and emulate input events.
45e9809aff7304721fddb95654901b32195c9c7avboxsync */
45e9809aff7304721fddb95654901b32195c9c7avboxsyncstruct _DGAEvent
45e9809aff7304721fddb95654901b32195c9c7avboxsync{
45e9809aff7304721fddb95654901b32195c9c7avboxsync unsigned char header; /**< Always ET_Internal */
45e9809aff7304721fddb95654901b32195c9c7avboxsync enum EventType type; /**< ET_DGAEvent */
45e9809aff7304721fddb95654901b32195c9c7avboxsync int length; /**< Length in bytes */
45e9809aff7304721fddb95654901b32195c9c7avboxsync Time time; /**< Time in ms */
45e9809aff7304721fddb95654901b32195c9c7avboxsync int subtype; /**< KeyPress, KeyRelease, ButtonPress,
45e9809aff7304721fddb95654901b32195c9c7avboxsync ButtonRelease, MotionNotify */
45e9809aff7304721fddb95654901b32195c9c7avboxsync int detail; /**< Relative x coordinate */
45e9809aff7304721fddb95654901b32195c9c7avboxsync int dx; /**< Relative x coordinate */
45e9809aff7304721fddb95654901b32195c9c7avboxsync int dy; /**< Relative y coordinate */
45e9809aff7304721fddb95654901b32195c9c7avboxsync int screen; /**< Screen number this event applies to */
45e9809aff7304721fddb95654901b32195c9c7avboxsync uint16_t state; /**< Core modifier/button state */
45e9809aff7304721fddb95654901b32195c9c7avboxsync};
45e9809aff7304721fddb95654901b32195c9c7avboxsync#endif
45e9809aff7304721fddb95654901b32195c9c7avboxsync
45e9809aff7304721fddb95654901b32195c9c7avboxsync/**
45e9809aff7304721fddb95654901b32195c9c7avboxsync * Raw event, contains the data as posted by the device.
45e9809aff7304721fddb95654901b32195c9c7avboxsync */
45e9809aff7304721fddb95654901b32195c9c7avboxsyncstruct _RawDeviceEvent
45e9809aff7304721fddb95654901b32195c9c7avboxsync{
45e9809aff7304721fddb95654901b32195c9c7avboxsync unsigned char header; /**< Always ET_Internal */
45e9809aff7304721fddb95654901b32195c9c7avboxsync enum EventType type; /**< ET_Raw */
45e9809aff7304721fddb95654901b32195c9c7avboxsync int length; /**< Length in bytes */
45e9809aff7304721fddb95654901b32195c9c7avboxsync Time time; /**< Time in ms */
45e9809aff7304721fddb95654901b32195c9c7avboxsync int deviceid; /**< Device to post this event for */
45e9809aff7304721fddb95654901b32195c9c7avboxsync int sourceid; /**< The physical source device */
45e9809aff7304721fddb95654901b32195c9c7avboxsync union {
45e9809aff7304721fddb95654901b32195c9c7avboxsync uint32_t button; /**< Button number */
45e9809aff7304721fddb95654901b32195c9c7avboxsync uint32_t key; /**< Key code */
45e9809aff7304721fddb95654901b32195c9c7avboxsync } detail;
45e9809aff7304721fddb95654901b32195c9c7avboxsync struct {
45e9809aff7304721fddb95654901b32195c9c7avboxsync uint8_t mask[(MAX_VALUATORS + 7)/8]; /**< Valuator mask */
45e9809aff7304721fddb95654901b32195c9c7avboxsync int32_t data[MAX_VALUATORS]; /**< Valuator data */
45e9809aff7304721fddb95654901b32195c9c7avboxsync int32_t data_frac[MAX_VALUATORS]; /**< Fractional part for data */
45e9809aff7304721fddb95654901b32195c9c7avboxsync int32_t data_raw[MAX_VALUATORS]; /**< Valuator data as posted */
45e9809aff7304721fddb95654901b32195c9c7avboxsync int32_t data_raw_frac[MAX_VALUATORS];/**< Fractional part for data_raw */
45e9809aff7304721fddb95654901b32195c9c7avboxsync } valuators;
45e9809aff7304721fddb95654901b32195c9c7avboxsync};
45e9809aff7304721fddb95654901b32195c9c7avboxsync
45e9809aff7304721fddb95654901b32195c9c7avboxsync#ifdef XQUARTZ
45e9809aff7304721fddb95654901b32195c9c7avboxsync#define XQUARTZ_EVENT_MAXARGS 5
45e9809aff7304721fddb95654901b32195c9c7avboxsyncstruct _XQuartzEvent {
45e9809aff7304721fddb95654901b32195c9c7avboxsync unsigned char header; /**< Always ET_Internal */
45e9809aff7304721fddb95654901b32195c9c7avboxsync enum EventType type; /**< Always ET_XQuartz */
45e9809aff7304721fddb95654901b32195c9c7avboxsync int length; /**< Length in bytes */
45e9809aff7304721fddb95654901b32195c9c7avboxsync Time time; /**< Time in ms. */
45e9809aff7304721fddb95654901b32195c9c7avboxsync int subtype; /**< Subtype defined by XQuartz DDX */
45e9809aff7304721fddb95654901b32195c9c7avboxsync uint32_t data[XQUARTZ_EVENT_MAXARGS]; /**< Up to 5 32bit values passed to handler */
45e9809aff7304721fddb95654901b32195c9c7avboxsync};
45e9809aff7304721fddb95654901b32195c9c7avboxsync#endif
45e9809aff7304721fddb95654901b32195c9c7avboxsync
45e9809aff7304721fddb95654901b32195c9c7avboxsync/**
45e9809aff7304721fddb95654901b32195c9c7avboxsync * Event type used inside the X server for input event
45e9809aff7304721fddb95654901b32195c9c7avboxsync * processing.
45e9809aff7304721fddb95654901b32195c9c7avboxsync */
45e9809aff7304721fddb95654901b32195c9c7avboxsyncunion _InternalEvent {
45e9809aff7304721fddb95654901b32195c9c7avboxsync struct {
45e9809aff7304721fddb95654901b32195c9c7avboxsync unsigned char header; /**< Always ET_Internal */
45e9809aff7304721fddb95654901b32195c9c7avboxsync enum EventType type; /**< One of ET_* */
45e9809aff7304721fddb95654901b32195c9c7avboxsync int length; /**< Length in bytes */
45e9809aff7304721fddb95654901b32195c9c7avboxsync Time time; /**< Time in ms. */
45e9809aff7304721fddb95654901b32195c9c7avboxsync } any;
45e9809aff7304721fddb95654901b32195c9c7avboxsync DeviceEvent device_event;
45e9809aff7304721fddb95654901b32195c9c7avboxsync DeviceChangedEvent changed_event;
45e9809aff7304721fddb95654901b32195c9c7avboxsync#if XFreeXDGA
45e9809aff7304721fddb95654901b32195c9c7avboxsync DGAEvent dga_event;
45e9809aff7304721fddb95654901b32195c9c7avboxsync#endif
45e9809aff7304721fddb95654901b32195c9c7avboxsync RawDeviceEvent raw_event;
45e9809aff7304721fddb95654901b32195c9c7avboxsync#ifdef XQUARTZ
45e9809aff7304721fddb95654901b32195c9c7avboxsync XQuartzEvent xquartz_event;
45e9809aff7304721fddb95654901b32195c9c7avboxsync#endif
45e9809aff7304721fddb95654901b32195c9c7avboxsync};
45e9809aff7304721fddb95654901b32195c9c7avboxsync
45e9809aff7304721fddb95654901b32195c9c7avboxsync#endif