105b261ecSmrg/* 235c4bbdfSmrg * Copyright © 1999 Keith Packard 305b261ecSmrg * 405b261ecSmrg * Permission to use, copy, modify, distribute, and sell this software and its 505b261ecSmrg * documentation for any purpose is hereby granted without fee, provided that 605b261ecSmrg * the above copyright notice appear in all copies and that both that 705b261ecSmrg * copyright notice and this permission notice appear in supporting 805b261ecSmrg * documentation, and that the name of Keith Packard not be used in 905b261ecSmrg * advertising or publicity pertaining to distribution of the software without 1005b261ecSmrg * specific, written prior permission. Keith Packard makes no 1105b261ecSmrg * representations about the suitability of this software for any purpose. It 1205b261ecSmrg * is provided "as is" without express or implied warranty. 1305b261ecSmrg * 1405b261ecSmrg * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, 1505b261ecSmrg * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO 1605b261ecSmrg * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR 1705b261ecSmrg * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, 1805b261ecSmrg * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER 1905b261ecSmrg * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 2005b261ecSmrg * PERFORMANCE OF THIS SOFTWARE. 2105b261ecSmrg */ 2205b261ecSmrg 2305b261ecSmrg#ifndef _KDRIVE_H_ 2405b261ecSmrg#define _KDRIVE_H_ 2505b261ecSmrg 2605b261ecSmrg#include <stdio.h> 276747b715Smrg#include <string.h> 2805b261ecSmrg#include <X11/X.h> 2905b261ecSmrg#include <X11/Xproto.h> 3005b261ecSmrg#include <X11/Xos.h> 3105b261ecSmrg#include "scrnintstr.h" 3205b261ecSmrg#include "pixmapstr.h" 3305b261ecSmrg#include "windowstr.h" 3405b261ecSmrg#include "servermd.h" 3505b261ecSmrg#include "colormapst.h" 3605b261ecSmrg#include "gcstruct.h" 3705b261ecSmrg#include "input.h" 3805b261ecSmrg#include "mipointer.h" 3905b261ecSmrg#include "mi.h" 4005b261ecSmrg#include "dix.h" 4105b261ecSmrg#include "fb.h" 4205b261ecSmrg#include "fboverlay.h" 4305b261ecSmrg#include "shadow.h" 4405b261ecSmrg#include "randrstr.h" 454642e01fSmrg#include "globals.h" 4605b261ecSmrg 476747b715Smrg#include "xkbstr.h" 4805b261ecSmrg 4905b261ecSmrg#define KD_DPMS_NORMAL 0 5005b261ecSmrg#define KD_DPMS_STANDBY 1 5105b261ecSmrg#define KD_DPMS_SUSPEND 2 5205b261ecSmrg#define KD_DPMS_POWERDOWN 3 5305b261ecSmrg#define KD_DPMS_MAX KD_DPMS_POWERDOWN 5405b261ecSmrg 5505b261ecSmrg#define Status int 5605b261ecSmrg 5705b261ecSmrgtypedef struct _KdCardInfo { 5835c4bbdfSmrg struct _KdCardFuncs *cfuncs; 5935c4bbdfSmrg void *closure; 6035c4bbdfSmrg void *driver; 6135c4bbdfSmrg struct _KdScreenInfo *screenList; 6235c4bbdfSmrg int selected; 6335c4bbdfSmrg struct _KdCardInfo *next; 6405b261ecSmrg} KdCardInfo; 6505b261ecSmrg 6635c4bbdfSmrgextern KdCardInfo *kdCardInfo; 6705b261ecSmrg 6805b261ecSmrg/* 6905b261ecSmrg * Configuration information per X screen 7005b261ecSmrg */ 7105b261ecSmrgtypedef struct _KdFrameBuffer { 7235c4bbdfSmrg CARD8 *frameBuffer; 7335c4bbdfSmrg int depth; 7435c4bbdfSmrg int bitsPerPixel; 7535c4bbdfSmrg int pixelStride; 7635c4bbdfSmrg int byteStride; 7735c4bbdfSmrg Bool shadow; 7835c4bbdfSmrg unsigned long visuals; 7935c4bbdfSmrg Pixel redMask, greenMask, blueMask; 8035c4bbdfSmrg void *closure; 8105b261ecSmrg} KdFrameBuffer; 8205b261ecSmrg 8305b261ecSmrg#define RR_Rotate_All (RR_Rotate_0|RR_Rotate_90|RR_Rotate_180|RR_Rotate_270) 8405b261ecSmrg#define RR_Reflect_All (RR_Reflect_X|RR_Reflect_Y) 8505b261ecSmrg 8605b261ecSmrgtypedef struct _KdScreenInfo { 8735c4bbdfSmrg struct _KdScreenInfo *next; 8835c4bbdfSmrg KdCardInfo *card; 8935c4bbdfSmrg ScreenPtr pScreen; 9035c4bbdfSmrg void *driver; 9135c4bbdfSmrg Rotation randr; /* rotation and reflection */ 9235c4bbdfSmrg int x; 9335c4bbdfSmrg int y; 9435c4bbdfSmrg int width; 9535c4bbdfSmrg int height; 9635c4bbdfSmrg int rate; 9735c4bbdfSmrg int width_mm; 9835c4bbdfSmrg int height_mm; 9935c4bbdfSmrg int subpixel_order; 10035c4bbdfSmrg Bool dumb; 10135c4bbdfSmrg Bool softCursor; 10235c4bbdfSmrg int mynum; 10335c4bbdfSmrg DDXPointRec origin; 10435c4bbdfSmrg KdFrameBuffer fb; 10505b261ecSmrg} KdScreenInfo; 10605b261ecSmrg 10705b261ecSmrgtypedef struct _KdCardFuncs { 10835c4bbdfSmrg Bool (*cardinit) (KdCardInfo *); /* detect and map device */ 10935c4bbdfSmrg Bool (*scrinit) (KdScreenInfo *); /* initialize screen information */ 11035c4bbdfSmrg Bool (*initScreen) (ScreenPtr); /* initialize ScreenRec */ 11135c4bbdfSmrg Bool (*finishInitScreen) (ScreenPtr pScreen); 11235c4bbdfSmrg Bool (*createRes) (ScreenPtr); /* create screen resources */ 11335c4bbdfSmrg void (*scrfini) (KdScreenInfo *); /* close down screen */ 11435c4bbdfSmrg void (*cardfini) (KdCardInfo *); /* close down */ 11535c4bbdfSmrg 11635c4bbdfSmrg Bool (*initCursor) (ScreenPtr); /* detect and map cursor */ 11735c4bbdfSmrg 11835c4bbdfSmrg Bool (*initAccel) (ScreenPtr); 11935c4bbdfSmrg void (*enableAccel) (ScreenPtr); 12035c4bbdfSmrg void (*disableAccel) (ScreenPtr); 12135c4bbdfSmrg void (*finiAccel) (ScreenPtr); 12235c4bbdfSmrg 12335c4bbdfSmrg void (*getColors) (ScreenPtr, int, xColorItem *); 12435c4bbdfSmrg void (*putColors) (ScreenPtr, int, xColorItem *); 12535c4bbdfSmrg 12635c4bbdfSmrg void (*closeScreen) (ScreenPtr); /* close ScreenRec */ 12705b261ecSmrg} KdCardFuncs; 12805b261ecSmrg 12905b261ecSmrg#define KD_MAX_PSEUDO_DEPTH 8 13005b261ecSmrg#define KD_MAX_PSEUDO_SIZE (1 << KD_MAX_PSEUDO_DEPTH) 13105b261ecSmrg 13205b261ecSmrgtypedef struct { 13335c4bbdfSmrg KdScreenInfo *screen; 13435c4bbdfSmrg KdCardInfo *card; 13505b261ecSmrg 13635c4bbdfSmrg Bool enabled; 13735c4bbdfSmrg Bool closed; 13835c4bbdfSmrg int bytesPerPixel; 13905b261ecSmrg 14035c4bbdfSmrg int dpmsState; 14105b261ecSmrg 14235c4bbdfSmrg ColormapPtr pInstalledmap; /* current colormap */ 14335c4bbdfSmrg xColorItem systemPalette[KD_MAX_PSEUDO_SIZE]; /* saved windows colors */ 14405b261ecSmrg 14535c4bbdfSmrg CreateScreenResourcesProcPtr CreateScreenResources; 14635c4bbdfSmrg CloseScreenProcPtr CloseScreen; 14705b261ecSmrg} KdPrivScreenRec, *KdPrivScreenPtr; 14805b261ecSmrg 14905b261ecSmrgtypedef enum _kdPointerState { 15005b261ecSmrg start, 15105b261ecSmrg button_1_pend, 15205b261ecSmrg button_1_down, 15305b261ecSmrg button_2_down, 15405b261ecSmrg button_3_pend, 15505b261ecSmrg button_3_down, 15605b261ecSmrg synth_2_down_13, 15705b261ecSmrg synth_2_down_3, 15805b261ecSmrg synth_2_down_1, 15905b261ecSmrg num_input_states 16005b261ecSmrg} KdPointerState; 16105b261ecSmrg 16205b261ecSmrg#define KD_MAX_BUTTON 32 16305b261ecSmrg 16405b261ecSmrg#define KD_KEYBOARD 1 16505b261ecSmrg#define KD_MOUSE 2 16605b261ecSmrg#define KD_TOUCHSCREEN 3 16705b261ecSmrg 16805b261ecSmrgtypedef struct _KdPointerInfo KdPointerInfo; 16905b261ecSmrg 17005b261ecSmrgtypedef struct _KdPointerDriver { 17135c4bbdfSmrg const char *name; 17235c4bbdfSmrg Status(*Init) (KdPointerInfo *); 17335c4bbdfSmrg Status(*Enable) (KdPointerInfo *); 17435c4bbdfSmrg void (*Disable) (KdPointerInfo *); 17535c4bbdfSmrg void (*Fini) (KdPointerInfo *); 17605b261ecSmrg struct _KdPointerDriver *next; 17705b261ecSmrg} KdPointerDriver; 17805b261ecSmrg 17905b261ecSmrgstruct _KdPointerInfo { 18035c4bbdfSmrg DeviceIntPtr dixdev; 18135c4bbdfSmrg char *name; 18235c4bbdfSmrg char *path; 18335c4bbdfSmrg char *protocol; 18435c4bbdfSmrg InputOption *options; 18535c4bbdfSmrg int inputClass; 18635c4bbdfSmrg 18735c4bbdfSmrg CARD8 map[KD_MAX_BUTTON + 1]; 18835c4bbdfSmrg int nButtons; 18935c4bbdfSmrg int nAxes; 19035c4bbdfSmrg 19135c4bbdfSmrg Bool emulateMiddleButton; 19235c4bbdfSmrg unsigned long emulationTimeout; 19335c4bbdfSmrg int emulationDx, emulationDy; 19435c4bbdfSmrg 19535c4bbdfSmrg Bool timeoutPending; 19635c4bbdfSmrg KdPointerState mouseState; 19735c4bbdfSmrg Bool eventHeld; 19805b261ecSmrg struct { 19905b261ecSmrg int type; 20005b261ecSmrg int x; 20105b261ecSmrg int y; 20205b261ecSmrg int z; 20305b261ecSmrg int flags; 20405b261ecSmrg int absrel; 2056747b715Smrg } heldEvent; 20635c4bbdfSmrg unsigned char buttonState; 20735c4bbdfSmrg Bool transformCoordinates; 20835c4bbdfSmrg int pressureThreshold; 20905b261ecSmrg 21035c4bbdfSmrg KdPointerDriver *driver; 21135c4bbdfSmrg void *driverPrivate; 21205b261ecSmrg 21305b261ecSmrg struct _KdPointerInfo *next; 21405b261ecSmrg}; 21505b261ecSmrg 21635c4bbdfSmrgvoid KdAddPointerDriver(KdPointerDriver * driver); 21735c4bbdfSmrgvoid KdRemovePointerDriver(KdPointerDriver * driver); 21835c4bbdfSmrgKdPointerInfo *KdNewPointer(void); 21935c4bbdfSmrgvoid KdFreePointer(KdPointerInfo *); 22035c4bbdfSmrgint KdAddPointer(KdPointerInfo * ki); 22135c4bbdfSmrgint KdAddConfigPointer(char *pointer); 22235c4bbdfSmrgvoid KdRemovePointer(KdPointerInfo * ki); 22305b261ecSmrg 22405b261ecSmrg#define KD_KEY_COUNT 248 22505b261ecSmrg#define KD_MIN_KEYCODE 8 22605b261ecSmrg#define KD_MAX_KEYCODE 255 22705b261ecSmrg#define KD_MAX_WIDTH 4 22805b261ecSmrg#define KD_MAX_LENGTH (KD_MAX_KEYCODE - KD_MIN_KEYCODE + 1) 22905b261ecSmrg 23005b261ecSmrgtypedef struct { 23105b261ecSmrg KeySym modsym; 23235c4bbdfSmrg int modbit; 23305b261ecSmrg} KdKeySymModsRec; 23405b261ecSmrg 23505b261ecSmrgtypedef struct _KdKeyboardInfo KdKeyboardInfo; 23605b261ecSmrg 23705b261ecSmrgtypedef struct _KdKeyboardDriver { 23835c4bbdfSmrg const char *name; 23935c4bbdfSmrg Bool (*Init) (KdKeyboardInfo *); 24035c4bbdfSmrg Bool (*Enable) (KdKeyboardInfo *); 24135c4bbdfSmrg void (*Leds) (KdKeyboardInfo *, int); 24235c4bbdfSmrg void (*Bell) (KdKeyboardInfo *, int, int, int); 24335c4bbdfSmrg void (*Disable) (KdKeyboardInfo *); 24435c4bbdfSmrg void (*Fini) (KdKeyboardInfo *); 24505b261ecSmrg struct _KdKeyboardDriver *next; 24605b261ecSmrg} KdKeyboardDriver; 24705b261ecSmrg 24805b261ecSmrgstruct _KdKeyboardInfo { 24905b261ecSmrg struct _KdKeyboardInfo *next; 25035c4bbdfSmrg DeviceIntPtr dixdev; 25135c4bbdfSmrg void *closure; 25235c4bbdfSmrg char *name; 25335c4bbdfSmrg char *path; 25435c4bbdfSmrg int inputClass; 25535c4bbdfSmrg char *xkbRules; 25635c4bbdfSmrg char *xkbModel; 25735c4bbdfSmrg char *xkbLayout; 25835c4bbdfSmrg char *xkbVariant; 25935c4bbdfSmrg char *xkbOptions; 26035c4bbdfSmrg int LockLed; 26135c4bbdfSmrg 26235c4bbdfSmrg int minScanCode; 26335c4bbdfSmrg int maxScanCode; 26435c4bbdfSmrg 26535c4bbdfSmrg int leds; 26635c4bbdfSmrg int bellPitch; 26735c4bbdfSmrg int bellDuration; 26835c4bbdfSmrg InputOption *options; 26935c4bbdfSmrg 27035c4bbdfSmrg KdKeyboardDriver *driver; 27135c4bbdfSmrg void *driverPrivate; 27205b261ecSmrg}; 27305b261ecSmrg 27435c4bbdfSmrgvoid KdAddKeyboardDriver(KdKeyboardDriver * driver); 27535c4bbdfSmrgvoid KdRemoveKeyboardDriver(KdKeyboardDriver * driver); 27635c4bbdfSmrgKdKeyboardInfo *KdNewKeyboard(void); 27735c4bbdfSmrgvoid KdFreeKeyboard(KdKeyboardInfo * ki); 27835c4bbdfSmrgint KdAddConfigKeyboard(char *pointer); 27935c4bbdfSmrgint KdAddKeyboard(KdKeyboardInfo * ki); 28035c4bbdfSmrgvoid KdRemoveKeyboard(KdKeyboardInfo * ki); 28105b261ecSmrg 28205b261ecSmrgtypedef struct _KdPointerMatrix { 28335c4bbdfSmrg int matrix[2][3]; 28405b261ecSmrg} KdPointerMatrix; 28505b261ecSmrg 28635c4bbdfSmrgextern DevPrivateKeyRec kdScreenPrivateKeyRec; 28705b261ecSmrg 2886747b715Smrg#define kdScreenPrivateKey (&kdScreenPrivateKeyRec) 2896747b715Smrg 29035c4bbdfSmrgextern Bool kdEmulateMiddleButton; 29135c4bbdfSmrgextern Bool kdDisableZaphod; 29205b261ecSmrg 29305b261ecSmrg#define KdGetScreenPriv(pScreen) ((KdPrivScreenPtr) \ 2944642e01fSmrg dixLookupPrivate(&(pScreen)->devPrivates, kdScreenPrivateKey)) 2954642e01fSmrg#define KdSetScreenPriv(pScreen,v) \ 2964642e01fSmrg dixSetPrivate(&(pScreen)->devPrivates, kdScreenPrivateKey, v) 29705b261ecSmrg#define KdScreenPriv(pScreen) KdPrivScreenPtr pScreenPriv = KdGetScreenPriv(pScreen) 29805b261ecSmrg 29905b261ecSmrg/* kcmap.c */ 30005b261ecSmrgvoid 30135c4bbdfSmrg KdEnableColormap(ScreenPtr pScreen); 30205b261ecSmrg 30305b261ecSmrgvoid 30435c4bbdfSmrg KdDisableColormap(ScreenPtr pScreen); 30505b261ecSmrg 30605b261ecSmrgvoid 30735c4bbdfSmrg KdInstallColormap(ColormapPtr pCmap); 30805b261ecSmrg 30905b261ecSmrgvoid 31035c4bbdfSmrg KdUninstallColormap(ColormapPtr pCmap); 31105b261ecSmrg 31205b261ecSmrgint 31335c4bbdfSmrg KdListInstalledColormaps(ScreenPtr pScreen, Colormap * pCmaps); 31405b261ecSmrg 31505b261ecSmrgvoid 31635c4bbdfSmrg KdStoreColors(ColormapPtr pCmap, int ndef, xColorItem * pdefs); 31705b261ecSmrg 31805b261ecSmrg/* kdrive.c */ 31905b261ecSmrgextern miPointerScreenFuncRec kdPointerScreenFuncs; 32005b261ecSmrg 32105b261ecSmrgvoid 32235c4bbdfSmrg KdDisableScreen(ScreenPtr pScreen); 32305b261ecSmrg 32405b261ecSmrgBool 32535c4bbdfSmrg KdEnableScreen(ScreenPtr pScreen); 32605b261ecSmrg 32705b261ecSmrgvoid 32835c4bbdfSmrg KdEnableScreens(void); 32905b261ecSmrg 33005b261ecSmrgvoid 33135c4bbdfSmrg KdProcessSwitch(void); 33205b261ecSmrg 33335c4bbdfSmrgRotation KdAddRotation(Rotation a, Rotation b); 33405b261ecSmrg 33535c4bbdfSmrgRotation KdSubRotation(Rotation a, Rotation b); 33605b261ecSmrg 33705b261ecSmrgvoid 33835c4bbdfSmrg KdParseScreen(KdScreenInfo * screen, const char *arg); 33905b261ecSmrg 34035c4bbdfSmrgconst char * 34135c4bbdfSmrgKdParseFindNext(const char *cur, const char *delim, char *save, char *last); 34205b261ecSmrg 34305b261ecSmrgvoid 34435c4bbdfSmrg KdUseMsg(void); 34505b261ecSmrg 34605b261ecSmrgint 34735c4bbdfSmrg KdProcessArgument(int argc, char **argv, int i); 34805b261ecSmrg 34905b261ecSmrgvoid 35035c4bbdfSmrg KdOsAddInputDrivers(void); 35105b261ecSmrg 35205b261ecSmrgvoid 35335c4bbdfSmrg KdInitCard(ScreenInfo * pScreenInfo, KdCardInfo * card, int argc, char **argv); 35405b261ecSmrg 35505b261ecSmrgvoid 35635c4bbdfSmrg KdInitOutput(ScreenInfo * pScreenInfo, int argc, char **argv); 3576747b715Smrg 35805b261ecSmrgvoid 35935c4bbdfSmrg KdSetSubpixelOrder(ScreenPtr pScreen, Rotation randr); 36005b261ecSmrg 36105b261ecSmrgvoid 36235c4bbdfSmrg KdBacktrace(int signum); 3636747b715Smrg 36405b261ecSmrg/* kinfo.c */ 36535c4bbdfSmrgKdCardInfo *KdCardInfoAdd(KdCardFuncs * funcs, void *closure); 36605b261ecSmrg 36735c4bbdfSmrgKdCardInfo *KdCardInfoLast(void); 36805b261ecSmrg 36905b261ecSmrgvoid 37035c4bbdfSmrg KdCardInfoDispose(KdCardInfo * ci); 37105b261ecSmrg 37235c4bbdfSmrgKdScreenInfo *KdScreenInfoAdd(KdCardInfo * ci); 37305b261ecSmrg 37405b261ecSmrgvoid 37535c4bbdfSmrg KdScreenInfoDispose(KdScreenInfo * si); 37605b261ecSmrg 37705b261ecSmrg/* kinput.c */ 37805b261ecSmrgvoid 37935c4bbdfSmrg KdInitInput(void); 38005b261ecSmrgvoid 38135c4bbdfSmrg KdCloseInput(void); 38205b261ecSmrg 38305b261ecSmrgvoid 38435c4bbdfSmrgKdEnqueueKeyboardEvent(KdKeyboardInfo * ki, unsigned char scan_code, 38535c4bbdfSmrg unsigned char is_up); 38605b261ecSmrg 38705b261ecSmrg#define KD_BUTTON_1 0x01 38805b261ecSmrg#define KD_BUTTON_2 0x02 38905b261ecSmrg#define KD_BUTTON_3 0x04 39005b261ecSmrg#define KD_BUTTON_4 0x08 39105b261ecSmrg#define KD_BUTTON_5 0x10 39205b261ecSmrg#define KD_BUTTON_8 0x80 39335c4bbdfSmrg#define KD_POINTER_DESKTOP 0x40000000 39405b261ecSmrg#define KD_MOUSE_DELTA 0x80000000 39505b261ecSmrg 39605b261ecSmrgvoid 39735c4bbdfSmrgKdEnqueuePointerEvent(KdPointerInfo * pi, unsigned long flags, int rx, int ry, 39805b261ecSmrg int rz); 39905b261ecSmrg 40005b261ecSmrgvoid 40135c4bbdfSmrg KdSetPointerMatrix(KdPointerMatrix *pointer); 40205b261ecSmrg 40305b261ecSmrgvoid 40435c4bbdfSmrgKdComputePointerMatrix(KdPointerMatrix *pointer, Rotation randr, int width, 40535c4bbdfSmrg int height); 4064642e01fSmrg 40705b261ecSmrgvoid 4081b5d61b8SmrgKdBlockHandler(ScreenPtr pScreen, void *timeout); 40905b261ecSmrg 41005b261ecSmrgvoid 4111b5d61b8SmrgKdWakeupHandler(ScreenPtr pScreen, int result); 41205b261ecSmrg 41305b261ecSmrgvoid 41435c4bbdfSmrg KdDisableInput(void); 41505b261ecSmrg 41605b261ecSmrgvoid 41735c4bbdfSmrg KdEnableInput(void); 41805b261ecSmrg 41905b261ecSmrg/* kshadow.c */ 42005b261ecSmrgBool 42135c4bbdfSmrg KdShadowFbAlloc(KdScreenInfo * screen, Bool rotate); 42205b261ecSmrg 42305b261ecSmrgvoid 42435c4bbdfSmrg KdShadowFbFree(KdScreenInfo * screen); 42505b261ecSmrg 42605b261ecSmrgBool 42735c4bbdfSmrg 42835c4bbdfSmrgKdShadowSet(ScreenPtr pScreen, int randr, ShadowUpdateProc update, 42935c4bbdfSmrg ShadowWindowProc window); 4306747b715Smrg 43105b261ecSmrgvoid 43235c4bbdfSmrg KdShadowUnset(ScreenPtr pScreen); 43305b261ecSmrg 43405b261ecSmrg/* function prototypes to be implemented by the drivers */ 43505b261ecSmrgvoid 43635c4bbdfSmrg InitCard(char *name); 43705b261ecSmrg 43835c4bbdfSmrg#endif /* _KDRIVE_H_ */ 439