1/* 2 * Copyright © 1999 Keith Packard 3 * 4 * Permission to use, copy, modify, distribute, and sell this software and its 5 * documentation for any purpose is hereby granted without fee, provided that 6 * the above copyright notice appear in all copies and that both that 7 * copyright notice and this permission notice appear in supporting 8 * documentation, and that the name of Keith Packard not be used in 9 * advertising or publicity pertaining to distribution of the software without 10 * specific, written prior permission. Keith Packard makes no 11 * representations about the suitability of this software for any purpose. It 12 * is provided "as is" without express or implied warranty. 13 * 14 * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, 15 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO 16 * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR 17 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, 18 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER 19 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 20 * PERFORMANCE OF THIS SOFTWARE. 21 */ 22 23#ifndef _KDRIVE_H_ 24#define _KDRIVE_H_ 25 26#include <stdio.h> 27#include <string.h> 28#include <X11/X.h> 29#include <X11/Xproto.h> 30#include <X11/Xos.h> 31#include "scrnintstr.h" 32#include "pixmapstr.h" 33#include "windowstr.h" 34#include "servermd.h" 35#include "colormapst.h" 36#include "gcstruct.h" 37#include "input.h" 38#include "mipointer.h" 39#include "mi.h" 40#include "dix.h" 41#include "fb.h" 42#include "fboverlay.h" 43#include "shadow.h" 44#include "randrstr.h" 45#include "globals.h" 46 47#include "xkbstr.h" 48 49#define KD_DPMS_NORMAL 0 50#define KD_DPMS_STANDBY 1 51#define KD_DPMS_SUSPEND 2 52#define KD_DPMS_POWERDOWN 3 53#define KD_DPMS_MAX KD_DPMS_POWERDOWN 54 55#define Status int 56 57typedef struct _KdCardInfo { 58 struct _KdCardFuncs *cfuncs; 59 void *closure; 60 void *driver; 61 struct _KdScreenInfo *screenList; 62 int selected; 63 struct _KdCardInfo *next; 64} KdCardInfo; 65 66extern KdCardInfo *kdCardInfo; 67 68/* 69 * Configuration information per X screen 70 */ 71typedef struct _KdFrameBuffer { 72 CARD8 *frameBuffer; 73 int depth; 74 int bitsPerPixel; 75 int pixelStride; 76 int byteStride; 77 Bool shadow; 78 unsigned long visuals; 79 Pixel redMask, greenMask, blueMask; 80 void *closure; 81} KdFrameBuffer; 82 83#define RR_Rotate_All (RR_Rotate_0|RR_Rotate_90|RR_Rotate_180|RR_Rotate_270) 84#define RR_Reflect_All (RR_Reflect_X|RR_Reflect_Y) 85 86typedef struct _KdScreenInfo { 87 struct _KdScreenInfo *next; 88 KdCardInfo *card; 89 ScreenPtr pScreen; 90 void *driver; 91 Rotation randr; /* rotation and reflection */ 92 int x; 93 int y; 94 int width; 95 int height; 96 int rate; 97 int width_mm; 98 int height_mm; 99 int subpixel_order; 100 Bool dumb; 101 Bool softCursor; 102 int mynum; 103 DDXPointRec origin; 104 KdFrameBuffer fb; 105} KdScreenInfo; 106 107typedef struct _KdCardFuncs { 108 Bool (*cardinit) (KdCardInfo *); /* detect and map device */ 109 Bool (*scrinit) (KdScreenInfo *); /* initialize screen information */ 110 Bool (*initScreen) (ScreenPtr); /* initialize ScreenRec */ 111 Bool (*finishInitScreen) (ScreenPtr pScreen); 112 Bool (*createRes) (ScreenPtr); /* create screen resources */ 113 void (*scrfini) (KdScreenInfo *); /* close down screen */ 114 void (*cardfini) (KdCardInfo *); /* close down */ 115 116 Bool (*initCursor) (ScreenPtr); /* detect and map cursor */ 117 118 Bool (*initAccel) (ScreenPtr); 119 void (*enableAccel) (ScreenPtr); 120 void (*disableAccel) (ScreenPtr); 121 void (*finiAccel) (ScreenPtr); 122 123 void (*getColors) (ScreenPtr, int, xColorItem *); 124 void (*putColors) (ScreenPtr, int, xColorItem *); 125 126 void (*closeScreen) (ScreenPtr); /* close ScreenRec */ 127} KdCardFuncs; 128 129#define KD_MAX_PSEUDO_DEPTH 8 130#define KD_MAX_PSEUDO_SIZE (1 << KD_MAX_PSEUDO_DEPTH) 131 132typedef struct { 133 KdScreenInfo *screen; 134 KdCardInfo *card; 135 136 Bool enabled; 137 Bool closed; 138 int bytesPerPixel; 139 140 int dpmsState; 141 142 ColormapPtr pInstalledmap; /* current colormap */ 143 xColorItem systemPalette[KD_MAX_PSEUDO_SIZE]; /* saved windows colors */ 144 145 CreateScreenResourcesProcPtr CreateScreenResources; 146 CloseScreenProcPtr CloseScreen; 147} KdPrivScreenRec, *KdPrivScreenPtr; 148 149typedef enum _kdPointerState { 150 start, 151 button_1_pend, 152 button_1_down, 153 button_2_down, 154 button_3_pend, 155 button_3_down, 156 synth_2_down_13, 157 synth_2_down_3, 158 synth_2_down_1, 159 num_input_states 160} KdPointerState; 161 162#define KD_MAX_BUTTON 32 163 164#define KD_KEYBOARD 1 165#define KD_MOUSE 2 166#define KD_TOUCHSCREEN 3 167 168typedef struct _KdPointerInfo KdPointerInfo; 169 170typedef struct _KdPointerDriver { 171 const char *name; 172 Status(*Init) (KdPointerInfo *); 173 Status(*Enable) (KdPointerInfo *); 174 void (*Disable) (KdPointerInfo *); 175 void (*Fini) (KdPointerInfo *); 176 struct _KdPointerDriver *next; 177} KdPointerDriver; 178 179struct _KdPointerInfo { 180 DeviceIntPtr dixdev; 181 char *name; 182 char *path; 183 char *protocol; 184 InputOption *options; 185 int inputClass; 186 187 CARD8 map[KD_MAX_BUTTON + 1]; 188 int nButtons; 189 int nAxes; 190 191 Bool emulateMiddleButton; 192 unsigned long emulationTimeout; 193 int emulationDx, emulationDy; 194 195 Bool timeoutPending; 196 KdPointerState mouseState; 197 Bool eventHeld; 198 struct { 199 int type; 200 int x; 201 int y; 202 int z; 203 int flags; 204 int absrel; 205 } heldEvent; 206 unsigned char buttonState; 207 Bool transformCoordinates; 208 int pressureThreshold; 209 210 KdPointerDriver *driver; 211 void *driverPrivate; 212 213 struct _KdPointerInfo *next; 214}; 215 216void KdAddPointerDriver(KdPointerDriver * driver); 217void KdRemovePointerDriver(KdPointerDriver * driver); 218KdPointerInfo *KdNewPointer(void); 219void KdFreePointer(KdPointerInfo *); 220int KdAddPointer(KdPointerInfo * ki); 221int KdAddConfigPointer(char *pointer); 222void KdRemovePointer(KdPointerInfo * ki); 223 224#define KD_KEY_COUNT 248 225#define KD_MIN_KEYCODE 8 226#define KD_MAX_KEYCODE 255 227#define KD_MAX_WIDTH 4 228#define KD_MAX_LENGTH (KD_MAX_KEYCODE - KD_MIN_KEYCODE + 1) 229 230typedef struct { 231 KeySym modsym; 232 int modbit; 233} KdKeySymModsRec; 234 235typedef struct _KdKeyboardInfo KdKeyboardInfo; 236 237typedef struct _KdKeyboardDriver { 238 const char *name; 239 Bool (*Init) (KdKeyboardInfo *); 240 Bool (*Enable) (KdKeyboardInfo *); 241 void (*Leds) (KdKeyboardInfo *, int); 242 void (*Bell) (KdKeyboardInfo *, int, int, int); 243 void (*Disable) (KdKeyboardInfo *); 244 void (*Fini) (KdKeyboardInfo *); 245 struct _KdKeyboardDriver *next; 246} KdKeyboardDriver; 247 248struct _KdKeyboardInfo { 249 struct _KdKeyboardInfo *next; 250 DeviceIntPtr dixdev; 251 void *closure; 252 char *name; 253 char *path; 254 int inputClass; 255 char *xkbRules; 256 char *xkbModel; 257 char *xkbLayout; 258 char *xkbVariant; 259 char *xkbOptions; 260 int LockLed; 261 262 int minScanCode; 263 int maxScanCode; 264 265 int leds; 266 int bellPitch; 267 int bellDuration; 268 InputOption *options; 269 270 KdKeyboardDriver *driver; 271 void *driverPrivate; 272}; 273 274void KdAddKeyboardDriver(KdKeyboardDriver * driver); 275void KdRemoveKeyboardDriver(KdKeyboardDriver * driver); 276KdKeyboardInfo *KdNewKeyboard(void); 277void KdFreeKeyboard(KdKeyboardInfo * ki); 278int KdAddConfigKeyboard(char *pointer); 279int KdAddKeyboard(KdKeyboardInfo * ki); 280void KdRemoveKeyboard(KdKeyboardInfo * ki); 281 282typedef struct _KdPointerMatrix { 283 int matrix[2][3]; 284} KdPointerMatrix; 285 286extern DevPrivateKeyRec kdScreenPrivateKeyRec; 287 288#define kdScreenPrivateKey (&kdScreenPrivateKeyRec) 289 290extern Bool kdEmulateMiddleButton; 291extern Bool kdDisableZaphod; 292 293#define KdGetScreenPriv(pScreen) ((KdPrivScreenPtr) \ 294 dixLookupPrivate(&(pScreen)->devPrivates, kdScreenPrivateKey)) 295#define KdSetScreenPriv(pScreen,v) \ 296 dixSetPrivate(&(pScreen)->devPrivates, kdScreenPrivateKey, v) 297#define KdScreenPriv(pScreen) KdPrivScreenPtr pScreenPriv = KdGetScreenPriv(pScreen) 298 299/* kcmap.c */ 300void 301 KdEnableColormap(ScreenPtr pScreen); 302 303void 304 KdDisableColormap(ScreenPtr pScreen); 305 306void 307 KdInstallColormap(ColormapPtr pCmap); 308 309void 310 KdUninstallColormap(ColormapPtr pCmap); 311 312int 313 KdListInstalledColormaps(ScreenPtr pScreen, Colormap * pCmaps); 314 315void 316 KdStoreColors(ColormapPtr pCmap, int ndef, xColorItem * pdefs); 317 318/* kdrive.c */ 319extern miPointerScreenFuncRec kdPointerScreenFuncs; 320 321void 322 KdDisableScreen(ScreenPtr pScreen); 323 324Bool 325 KdEnableScreen(ScreenPtr pScreen); 326 327void 328 KdEnableScreens(void); 329 330void 331 KdProcessSwitch(void); 332 333Rotation KdAddRotation(Rotation a, Rotation b); 334 335Rotation KdSubRotation(Rotation a, Rotation b); 336 337void 338 KdParseScreen(KdScreenInfo * screen, const char *arg); 339 340const char * 341KdParseFindNext(const char *cur, const char *delim, char *save, char *last); 342 343void 344 KdUseMsg(void); 345 346int 347 KdProcessArgument(int argc, char **argv, int i); 348 349void 350 KdOsAddInputDrivers(void); 351 352void 353 KdInitCard(ScreenInfo * pScreenInfo, KdCardInfo * card, int argc, char **argv); 354 355void 356 KdInitOutput(ScreenInfo * pScreenInfo, int argc, char **argv); 357 358void 359 KdSetSubpixelOrder(ScreenPtr pScreen, Rotation randr); 360 361void 362 KdBacktrace(int signum); 363 364/* kinfo.c */ 365KdCardInfo *KdCardInfoAdd(KdCardFuncs * funcs, void *closure); 366 367KdCardInfo *KdCardInfoLast(void); 368 369void 370 KdCardInfoDispose(KdCardInfo * ci); 371 372KdScreenInfo *KdScreenInfoAdd(KdCardInfo * ci); 373 374void 375 KdScreenInfoDispose(KdScreenInfo * si); 376 377/* kinput.c */ 378void 379 KdInitInput(void); 380void 381 KdCloseInput(void); 382 383void 384KdEnqueueKeyboardEvent(KdKeyboardInfo * ki, unsigned char scan_code, 385 unsigned char is_up); 386 387#define KD_BUTTON_1 0x01 388#define KD_BUTTON_2 0x02 389#define KD_BUTTON_3 0x04 390#define KD_BUTTON_4 0x08 391#define KD_BUTTON_5 0x10 392#define KD_BUTTON_8 0x80 393#define KD_POINTER_DESKTOP 0x40000000 394#define KD_MOUSE_DELTA 0x80000000 395 396void 397KdEnqueuePointerEvent(KdPointerInfo * pi, unsigned long flags, int rx, int ry, 398 int rz); 399 400void 401 KdSetPointerMatrix(KdPointerMatrix *pointer); 402 403void 404KdComputePointerMatrix(KdPointerMatrix *pointer, Rotation randr, int width, 405 int height); 406 407void 408KdBlockHandler(ScreenPtr pScreen, void *timeout); 409 410void 411KdWakeupHandler(ScreenPtr pScreen, int result); 412 413void 414 KdDisableInput(void); 415 416void 417 KdEnableInput(void); 418 419/* kshadow.c */ 420Bool 421 KdShadowFbAlloc(KdScreenInfo * screen, Bool rotate); 422 423void 424 KdShadowFbFree(KdScreenInfo * screen); 425 426Bool 427 428KdShadowSet(ScreenPtr pScreen, int randr, ShadowUpdateProc update, 429 ShadowWindowProc window); 430 431void 432 KdShadowUnset(ScreenPtr pScreen); 433 434/* function prototypes to be implemented by the drivers */ 435void 436 InitCard(char *name); 437 438#endif /* _KDRIVE_H_ */ 439