kdrive.h revision 706f2543
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 "mibstore.h" 36#include "colormapst.h" 37#include "gcstruct.h" 38#include "input.h" 39#include "mipointer.h" 40#include "mi.h" 41#include "dix.h" 42#include "fb.h" 43#include "fboverlay.h" 44#include "shadow.h" 45#include "randrstr.h" 46#include "globals.h" 47 48#include "xkbstr.h" 49 50#define KD_DPMS_NORMAL 0 51#define KD_DPMS_STANDBY 1 52#define KD_DPMS_SUSPEND 2 53#define KD_DPMS_POWERDOWN 3 54#define KD_DPMS_MAX KD_DPMS_POWERDOWN 55 56#define Status int 57 58typedef struct _KdCardInfo { 59 struct _KdCardFuncs *cfuncs; 60 void *closure; 61 void *driver; 62 struct _KdScreenInfo *screenList; 63 int selected; 64 struct _KdCardInfo *next; 65} KdCardInfo; 66 67extern KdCardInfo *kdCardInfo; 68 69/* 70 * Configuration information per X screen 71 */ 72typedef struct _KdFrameBuffer { 73 CARD8 *frameBuffer; 74 int depth; 75 int bitsPerPixel; 76 int pixelStride; 77 int byteStride; 78 Bool shadow; 79 unsigned long visuals; 80 Pixel redMask, greenMask, blueMask; 81 void *closure; 82} KdFrameBuffer; 83 84#define RR_Rotate_All (RR_Rotate_0|RR_Rotate_90|RR_Rotate_180|RR_Rotate_270) 85#define RR_Reflect_All (RR_Reflect_X|RR_Reflect_Y) 86 87typedef struct _KdScreenInfo { 88 struct _KdScreenInfo *next; 89 KdCardInfo *card; 90 ScreenPtr pScreen; 91 void *driver; 92 Rotation randr; /* rotation and reflection */ 93 int width; 94 int height; 95 int rate; 96 int width_mm; 97 int height_mm; 98 int subpixel_order; 99 Bool dumb; 100 Bool softCursor; 101 int mynum; 102 DDXPointRec origin; 103 KdFrameBuffer fb; 104} KdScreenInfo; 105 106typedef struct _KdCardFuncs { 107 Bool (*cardinit) (KdCardInfo *); /* detect and map device */ 108 Bool (*scrinit) (KdScreenInfo *);/* initialize screen information */ 109 Bool (*initScreen) (ScreenPtr); /* initialize ScreenRec */ 110 Bool (*finishInitScreen) (ScreenPtr pScreen); 111 Bool (*createRes) (ScreenPtr); /* create screen resources */ 112 void (*preserve) (KdCardInfo *); /* save graphics card state */ 113 Bool (*enable) (ScreenPtr); /* set up for rendering */ 114 Bool (*dpms) (ScreenPtr, int); /* set DPMS screen saver */ 115 void (*disable) (ScreenPtr); /* turn off rendering */ 116 void (*restore) (KdCardInfo *); /* restore graphics card state */ 117 void (*scrfini) (KdScreenInfo *);/* close down screen */ 118 void (*cardfini) (KdCardInfo *); /* close down */ 119 120 Bool (*initCursor) (ScreenPtr); /* detect and map cursor */ 121 void (*enableCursor) (ScreenPtr); /* enable cursor */ 122 void (*disableCursor) (ScreenPtr); /* disable cursor */ 123 void (*finiCursor) (ScreenPtr); /* close down */ 124 void (*recolorCursor) (ScreenPtr, int, xColorItem *); 125 126 Bool (*initAccel) (ScreenPtr); 127 void (*enableAccel) (ScreenPtr); 128 void (*disableAccel) (ScreenPtr); 129 void (*finiAccel) (ScreenPtr); 130 131 void (*getColors) (ScreenPtr, int, xColorItem *); 132 void (*putColors) (ScreenPtr, int, xColorItem *); 133 134} KdCardFuncs; 135 136#define KD_MAX_PSEUDO_DEPTH 8 137#define KD_MAX_PSEUDO_SIZE (1 << KD_MAX_PSEUDO_DEPTH) 138 139typedef struct { 140 KdScreenInfo *screen; 141 KdCardInfo *card; 142 143 Bool enabled; 144 Bool closed; 145 int bytesPerPixel; 146 147 int dpmsState; 148 149 ColormapPtr pInstalledmap; /* current colormap */ 150 xColorItem systemPalette[KD_MAX_PSEUDO_SIZE];/* saved windows colors */ 151 152 CreateScreenResourcesProcPtr CreateScreenResources; 153 CloseScreenProcPtr CloseScreen; 154} KdPrivScreenRec, *KdPrivScreenPtr; 155 156typedef enum _kdPointerState { 157 start, 158 button_1_pend, 159 button_1_down, 160 button_2_down, 161 button_3_pend, 162 button_3_down, 163 synth_2_down_13, 164 synth_2_down_3, 165 synth_2_down_1, 166 num_input_states 167} KdPointerState; 168 169#define KD_MAX_BUTTON 32 170 171#define KD_KEYBOARD 1 172#define KD_MOUSE 2 173#define KD_TOUCHSCREEN 3 174 175typedef struct _KdPointerInfo KdPointerInfo; 176 177typedef struct _KdPointerDriver { 178 char *name; 179 Status (*Init) (KdPointerInfo *); 180 Status (*Enable) (KdPointerInfo *); 181 void (*Disable) (KdPointerInfo *); 182 void (*Fini) (KdPointerInfo *); 183 struct _KdPointerDriver *next; 184} KdPointerDriver; 185 186struct _KdPointerInfo { 187 DeviceIntPtr dixdev; 188 char *name; 189 char *path; 190 char *protocol; 191 InputOption *options; 192 int inputClass; 193 194 CARD8 map[KD_MAX_BUTTON + 1]; 195 int nButtons; 196 int nAxes; 197 198 Bool emulateMiddleButton; 199 unsigned long emulationTimeout; 200 int emulationDx, emulationDy; 201 202 Bool timeoutPending; 203 KdPointerState mouseState; 204 Bool eventHeld; 205 struct { 206 int type; 207 int x; 208 int y; 209 int z; 210 int flags; 211 int absrel; 212 } heldEvent; 213 unsigned char buttonState; 214 Bool transformCoordinates; 215 int pressureThreshold; 216 217 KdPointerDriver *driver; 218 void *driverPrivate; 219 220 struct _KdPointerInfo *next; 221}; 222 223extern int KdCurScreen; 224 225void KdAddPointerDriver (KdPointerDriver *driver); 226void KdRemovePointerDriver (KdPointerDriver *driver); 227KdPointerInfo *KdNewPointer (void); 228void KdFreePointer (KdPointerInfo *); 229int KdAddPointer (KdPointerInfo *ki); 230int KdAddConfigPointer (char *pointer); 231void KdRemovePointer (KdPointerInfo *ki); 232 233 234#define KD_KEY_COUNT 248 235#define KD_MIN_KEYCODE 8 236#define KD_MAX_KEYCODE 255 237#define KD_MAX_WIDTH 4 238#define KD_MAX_LENGTH (KD_MAX_KEYCODE - KD_MIN_KEYCODE + 1) 239 240typedef struct { 241 KeySym modsym; 242 int modbit; 243} KdKeySymModsRec; 244 245typedef struct _KdKeyboardInfo KdKeyboardInfo; 246 247typedef struct _KdKeyboardDriver { 248 char *name; 249 Bool (*Init) (KdKeyboardInfo *); 250 Bool (*Enable) (KdKeyboardInfo *); 251 void (*Leds) (KdKeyboardInfo *, int); 252 void (*Bell) (KdKeyboardInfo *, int, int, int); 253 void (*Disable) (KdKeyboardInfo *); 254 void (*Fini) (KdKeyboardInfo *); 255 struct _KdKeyboardDriver *next; 256} KdKeyboardDriver; 257 258struct _KdKeyboardInfo { 259 struct _KdKeyboardInfo *next; 260 DeviceIntPtr dixdev; 261 void *closure; 262 char *name; 263 char *path; 264 int inputClass; 265 char *xkbRules; 266 char *xkbModel; 267 char *xkbLayout; 268 char *xkbVariant; 269 char *xkbOptions; 270 int LockLed; 271 272 int minScanCode; 273 int maxScanCode; 274 275 int leds; 276 int bellPitch; 277 int bellDuration; 278 InputOption *options; 279 280 KdKeyboardDriver *driver; 281 void *driverPrivate; 282}; 283 284void KdAddKeyboardDriver (KdKeyboardDriver *driver); 285void KdRemoveKeyboardDriver (KdKeyboardDriver *driver); 286KdKeyboardInfo *KdNewKeyboard (void); 287void KdFreeKeyboard (KdKeyboardInfo *ki); 288int KdAddConfigKeyboard (char *pointer); 289int KdAddKeyboard (KdKeyboardInfo *ki); 290void KdRemoveKeyboard (KdKeyboardInfo *ki); 291 292typedef struct _KdOsFuncs { 293 int (*Init) (void); 294 void (*Enable) (void); 295 Bool (*SpecialKey) (KeySym); 296 void (*Disable) (void); 297 void (*Fini) (void); 298 void (*pollEvents) (void); 299 void (*Bell) (int, int, int); 300} KdOsFuncs; 301 302typedef enum _KdSyncPolarity { 303 KdSyncNegative, KdSyncPositive 304} KdSyncPolarity; 305 306typedef struct _KdMonitorTiming { 307 /* label */ 308 int horizontal; 309 int vertical; 310 int rate; 311 /* pixel clock */ 312 int clock; /* in KHz */ 313 /* horizontal timing */ 314 int hfp; /* front porch */ 315 int hbp; /* back porch */ 316 int hblank; /* blanking */ 317 KdSyncPolarity hpol; /* polarity */ 318 /* vertical timing */ 319 int vfp; /* front porch */ 320 int vbp; /* back porch */ 321 int vblank; /* blanking */ 322 KdSyncPolarity vpol; /* polarity */ 323} KdMonitorTiming; 324 325extern const KdMonitorTiming kdMonitorTimings[]; 326extern const int kdNumMonitorTimings; 327 328typedef struct _KdPointerMatrix { 329 int matrix[2][3]; 330} KdPointerMatrix; 331 332/* 333 * This is the only completely portable way to 334 * compute this info. 335 */ 336 337#ifndef BitsPerPixel 338#define BitsPerPixel(d) (\ 339 PixmapWidthPaddingInfo[d].notPower2 ? \ 340 (PixmapWidthPaddingInfo[d].bytesPerPixel * 8) : \ 341 ((1 << PixmapWidthPaddingInfo[d].padBytesLog2) * 8 / \ 342 (PixmapWidthPaddingInfo[d].padRoundUp+1))) 343#endif 344 345extern DevPrivateKeyRec kdScreenPrivateKeyRec; 346#define kdScreenPrivateKey (&kdScreenPrivateKeyRec) 347 348extern unsigned long kdGeneration; 349extern Bool kdEnabled; 350extern Bool kdSwitchPending; 351extern Bool kdEmulateMiddleButton; 352extern Bool kdDisableZaphod; 353extern Bool kdAllowZap; 354extern int kdVirtualTerminal; 355extern char *kdSwitchCmd; 356extern KdOsFuncs *kdOsFuncs; 357 358#define KdGetScreenPriv(pScreen) ((KdPrivScreenPtr) \ 359 dixLookupPrivate(&(pScreen)->devPrivates, kdScreenPrivateKey)) 360#define KdSetScreenPriv(pScreen,v) \ 361 dixSetPrivate(&(pScreen)->devPrivates, kdScreenPrivateKey, v) 362#define KdScreenPriv(pScreen) KdPrivScreenPtr pScreenPriv = KdGetScreenPriv(pScreen) 363 364/* kcmap.c */ 365void 366KdSetColormap (ScreenPtr pScreen); 367 368void 369KdEnableColormap (ScreenPtr pScreen); 370 371void 372KdDisableColormap (ScreenPtr pScreen); 373 374void 375KdInstallColormap (ColormapPtr pCmap); 376 377void 378KdUninstallColormap (ColormapPtr pCmap); 379 380int 381KdListInstalledColormaps (ScreenPtr pScreen, Colormap *pCmaps); 382 383void 384KdStoreColors (ColormapPtr pCmap, int ndef, xColorItem *pdefs); 385 386/* kdrive.c */ 387extern miPointerScreenFuncRec kdPointerScreenFuncs; 388 389void 390KdSetRootClip (ScreenPtr pScreen, BOOL enable); 391 392void 393KdDisableScreen (ScreenPtr pScreen); 394 395void 396KdDisableScreens (void); 397 398Bool 399KdEnableScreen (ScreenPtr pScreen); 400 401void 402KdEnableScreens (void); 403 404void 405KdSuspend (void); 406 407void 408KdResume (void); 409 410void 411KdProcessSwitch (void); 412 413Rotation 414KdAddRotation (Rotation a, Rotation b); 415 416Rotation 417KdSubRotation (Rotation a, Rotation b); 418 419void 420KdParseScreen (KdScreenInfo *screen, 421 char *arg); 422 423KdPointerInfo * 424KdParsePointer (char *arg); 425 426KdKeyboardInfo * 427KdParseKeyboard (char *arg); 428 429char * 430KdParseFindNext (char *cur, char *delim, char *save, char *last); 431 432void 433KdParseRgba (char *rgba); 434 435void 436KdUseMsg (void); 437 438int 439KdProcessArgument (int argc, char **argv, int i); 440 441void 442KdOsInit (KdOsFuncs *pOsFuncs); 443 444void 445KdOsAddInputDrivers (void); 446 447Bool 448KdAllocatePrivates (ScreenPtr pScreen); 449 450Bool 451KdCreateScreenResources (ScreenPtr pScreen); 452 453Bool 454KdCloseScreen (int index, ScreenPtr pScreen); 455 456Bool 457KdSaveScreen (ScreenPtr pScreen, int on); 458 459Bool 460KdScreenInit(int index, ScreenPtr pScreen, int argc, char **argv); 461 462void 463KdInitScreen (ScreenInfo *pScreenInfo, 464 KdScreenInfo *screen, 465 int argc, 466 char **argv); 467 468void 469KdInitCard (ScreenInfo *pScreenInfo, 470 KdCardInfo *card, 471 int argc, 472 char **argv); 473 474void 475KdInitOutput (ScreenInfo *pScreenInfo, 476 int argc, 477 char **argv); 478 479void 480KdSetSubpixelOrder (ScreenPtr pScreen, Rotation randr); 481 482void 483KdBacktrace (int signum); 484 485/* kinfo.c */ 486KdCardInfo * 487KdCardInfoAdd (KdCardFuncs *funcs, 488 void *closure); 489 490KdCardInfo * 491KdCardInfoLast (void); 492 493void 494KdCardInfoDispose (KdCardInfo *ci); 495 496KdScreenInfo * 497KdScreenInfoAdd (KdCardInfo *ci); 498 499void 500KdScreenInfoDispose (KdScreenInfo *si); 501 502 503/* kinput.c */ 504void 505KdInitInput(void); 506 507void 508KdAddPointerDriver(KdPointerDriver *); 509 510void 511KdAddKeyboardDriver(KdKeyboardDriver *); 512 513Bool 514KdRegisterFd (int fd, void (*read) (int fd, void *closure), void *closure); 515 516void 517KdUnregisterFds (void *closure, Bool do_close); 518 519void 520KdUnregisterFd (void *closure, int fd, Bool do_close); 521 522void 523KdEnqueueKeyboardEvent(KdKeyboardInfo *ki, unsigned char scan_code, 524 unsigned char is_up); 525 526#define KD_BUTTON_1 0x01 527#define KD_BUTTON_2 0x02 528#define KD_BUTTON_3 0x04 529#define KD_BUTTON_4 0x08 530#define KD_BUTTON_5 0x10 531#define KD_BUTTON_8 0x80 532#define KD_MOUSE_DELTA 0x80000000 533 534void 535KdEnqueuePointerEvent(KdPointerInfo *pi, unsigned long flags, int rx, int ry, 536 int rz); 537 538void 539_KdEnqueuePointerEvent(KdPointerInfo *pi, int type, int x, int y, int z, 540 int b, int absrel, Bool force); 541 542void 543KdReleaseAllKeys (void); 544 545void 546KdSetLed (KdKeyboardInfo *ki, int led, Bool on); 547 548void 549KdSetPointerMatrix (KdPointerMatrix *pointer); 550 551void 552KdComputePointerMatrix (KdPointerMatrix *pointer, Rotation randr, int width, int height); 553 554void 555KdScreenToPointerCoords (int *x, int *y); 556 557void 558KdBlockHandler (int screen, 559 pointer blockData, 560 pointer timeout, 561 pointer readmask); 562 563void 564KdWakeupHandler (int screen, 565 pointer data, 566 unsigned long result, 567 pointer readmask); 568 569void 570KdDisableInput (void); 571 572void 573KdEnableInput (void); 574 575void 576ProcessInputEvents (void); 577 578void 579KdRingBell (KdKeyboardInfo *ki, 580 int volume, 581 int pitch, 582 int duration); 583 584/* kmode.c */ 585const KdMonitorTiming * 586KdFindMode (KdScreenInfo *screen, 587 Bool (*supported) (KdScreenInfo *, 588 const KdMonitorTiming *)); 589 590Bool 591KdTuneMode (KdScreenInfo *screen, 592 Bool (*usable) (KdScreenInfo *), 593 Bool (*supported) (KdScreenInfo *, 594 const KdMonitorTiming *)); 595 596#ifdef RANDR 597Bool 598KdRandRGetInfo (ScreenPtr pScreen, 599 int randr, 600 Bool (*supported) (ScreenPtr pScreen, 601 const KdMonitorTiming *)); 602 603const KdMonitorTiming * 604KdRandRGetTiming (ScreenPtr pScreen, 605 Bool (*supported) (ScreenPtr pScreen, 606 const KdMonitorTiming *), 607 int rate, 608 RRScreenSizePtr pSize); 609#endif 610 611/* kshadow.c */ 612Bool 613KdShadowFbAlloc (KdScreenInfo *screen, Bool rotate); 614 615void 616KdShadowFbFree (KdScreenInfo *screen); 617 618Bool 619KdShadowSet (ScreenPtr pScreen, int randr, ShadowUpdateProc update, ShadowWindowProc window); 620 621void 622KdShadowUnset (ScreenPtr pScreen); 623 624/* function prototypes to be implemented by the drivers */ 625void 626InitCard (char *name); 627 628#endif /* _KDRIVE_H_ */ 629