Home | History | Annotate | Line # | Download | only in src
      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 
     58 typedef 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 
     67 extern KdCardInfo	*kdCardInfo;
     68 
     69 /*
     70  * Configuration information per X screen
     71  */
     72 typedef 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 
     87 typedef 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 
    106 typedef 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 
    139 typedef 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 
    156 typedef 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 
    175 typedef struct _KdPointerInfo KdPointerInfo;
    176 
    177 typedef 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 
    186 struct _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 
    223 extern int KdCurScreen;
    224 
    225 void KdAddPointerDriver (KdPointerDriver *driver);
    226 void KdRemovePointerDriver (KdPointerDriver *driver);
    227 KdPointerInfo *KdNewPointer (void);
    228 void KdFreePointer (KdPointerInfo *);
    229 int KdAddPointer (KdPointerInfo *ki);
    230 int KdAddConfigPointer (char *pointer);
    231 void 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 
    240 typedef struct {
    241     KeySym modsym;
    242     int    modbit;
    243 } KdKeySymModsRec;
    244 
    245 typedef struct _KdKeyboardInfo KdKeyboardInfo;
    246 
    247 typedef 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 
    258 struct _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 
    284 void KdAddKeyboardDriver (KdKeyboardDriver *driver);
    285 void KdRemoveKeyboardDriver (KdKeyboardDriver *driver);
    286 KdKeyboardInfo *KdNewKeyboard (void);
    287 void KdFreeKeyboard (KdKeyboardInfo *ki);
    288 int KdAddConfigKeyboard (char *pointer);
    289 int KdAddKeyboard (KdKeyboardInfo *ki);
    290 void KdRemoveKeyboard (KdKeyboardInfo *ki);
    291 
    292 typedef 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 
    302 typedef enum _KdSyncPolarity {
    303     KdSyncNegative, KdSyncPositive
    304 } KdSyncPolarity;
    305 
    306 typedef 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 
    325 extern const KdMonitorTiming	kdMonitorTimings[];
    326 extern const int		kdNumMonitorTimings;
    327 
    328 typedef 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 
    345 extern DevPrivateKeyRec	kdScreenPrivateKeyRec;
    346 #define kdScreenPrivateKey (&kdScreenPrivateKeyRec)
    347 
    348 extern unsigned long	kdGeneration;
    349 extern Bool		kdEnabled;
    350 extern Bool		kdSwitchPending;
    351 extern Bool		kdEmulateMiddleButton;
    352 extern Bool		kdDisableZaphod;
    353 extern Bool		kdAllowZap;
    354 extern int		kdVirtualTerminal;
    355 extern char		*kdSwitchCmd;
    356 extern 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 */
    365 void
    366 KdSetColormap (ScreenPtr pScreen);
    367 
    368 void
    369 KdEnableColormap (ScreenPtr pScreen);
    370 
    371 void
    372 KdDisableColormap (ScreenPtr pScreen);
    373 
    374 void
    375 KdInstallColormap (ColormapPtr pCmap);
    376 
    377 void
    378 KdUninstallColormap (ColormapPtr pCmap);
    379 
    380 int
    381 KdListInstalledColormaps (ScreenPtr pScreen, Colormap *pCmaps);
    382 
    383 void
    384 KdStoreColors (ColormapPtr pCmap, int ndef, xColorItem *pdefs);
    385 
    386 /* kdrive.c */
    387 extern miPointerScreenFuncRec kdPointerScreenFuncs;
    388 
    389 void
    390 KdSetRootClip (ScreenPtr pScreen, BOOL enable);
    391 
    392 void
    393 KdDisableScreen (ScreenPtr pScreen);
    394 
    395 void
    396 KdDisableScreens (void);
    397 
    398 Bool
    399 KdEnableScreen (ScreenPtr pScreen);
    400 
    401 void
    402 KdEnableScreens (void);
    403 
    404 void
    405 KdSuspend (void);
    406 
    407 void
    408 KdResume (void);
    409 
    410 void
    411 KdProcessSwitch (void);
    412 
    413 Rotation
    414 KdAddRotation (Rotation a, Rotation b);
    415 
    416 Rotation
    417 KdSubRotation (Rotation a, Rotation b);
    418 
    419 void
    420 KdParseScreen (KdScreenInfo *screen,
    421 	       char	    *arg);
    422 
    423 KdPointerInfo *
    424 KdParsePointer (char *arg);
    425 
    426 KdKeyboardInfo *
    427 KdParseKeyboard (char *arg);
    428 
    429 char *
    430 KdParseFindNext (char *cur, char *delim, char *save, char *last);
    431 
    432 void
    433 KdParseRgba (char *rgba);
    434 
    435 void
    436 KdUseMsg (void);
    437 
    438 int
    439 KdProcessArgument (int argc, char **argv, int i);
    440 
    441 void
    442 KdOsInit (KdOsFuncs *pOsFuncs);
    443 
    444 void
    445 KdOsAddInputDrivers (void);
    446 
    447 Bool
    448 KdAllocatePrivates (ScreenPtr pScreen);
    449 
    450 Bool
    451 KdCreateScreenResources (ScreenPtr pScreen);
    452 
    453 Bool
    454 KdCloseScreen (int index, ScreenPtr pScreen);
    455 
    456 Bool
    457 KdSaveScreen (ScreenPtr pScreen, int on);
    458 
    459 Bool
    460 KdScreenInit(int index, ScreenPtr pScreen, int argc, char **argv);
    461 
    462 void
    463 KdInitScreen (ScreenInfo    *pScreenInfo,
    464 	      KdScreenInfo  *screen,
    465 	      int	    argc,
    466 	      char	    **argv);
    467 
    468 void
    469 KdInitCard (ScreenInfo	    *pScreenInfo,
    470 	    KdCardInfo	    *card,
    471 	    int		    argc,
    472 	    char	    **argv);
    473 
    474 void
    475 KdInitOutput (ScreenInfo    *pScreenInfo,
    476 	      int	    argc,
    477 	      char	    **argv);
    478 
    479 void
    480 KdSetSubpixelOrder (ScreenPtr pScreen, Rotation randr);
    481 
    482 void
    483 KdBacktrace (int signum);
    484 
    485 /* kinfo.c */
    486 KdCardInfo *
    487 KdCardInfoAdd (KdCardFuncs  *funcs,
    488 	       void	    *closure);
    489 
    490 KdCardInfo *
    491 KdCardInfoLast (void);
    492 
    493 void
    494 KdCardInfoDispose (KdCardInfo *ci);
    495 
    496 KdScreenInfo *
    497 KdScreenInfoAdd (KdCardInfo *ci);
    498 
    499 void
    500 KdScreenInfoDispose (KdScreenInfo *si);
    501 
    502 
    503 /* kinput.c */
    504 void
    505 KdInitInput(void);
    506 
    507 void
    508 KdAddPointerDriver(KdPointerDriver *);
    509 
    510 void
    511 KdAddKeyboardDriver(KdKeyboardDriver *);
    512 
    513 Bool
    514 KdRegisterFd (int fd, void (*read) (int fd, void *closure), void *closure);
    515 
    516 void
    517 KdUnregisterFds (void *closure, Bool do_close);
    518 
    519 void
    520 KdUnregisterFd (void *closure, int fd, Bool do_close);
    521 
    522 void
    523 KdEnqueueKeyboardEvent(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 
    534 void
    535 KdEnqueuePointerEvent(KdPointerInfo *pi, unsigned long flags, int rx, int ry,
    536                       int rz);
    537 
    538 void
    539 _KdEnqueuePointerEvent(KdPointerInfo *pi, int type, int x, int y, int z,
    540                        int b, int absrel, Bool force);
    541 
    542 void
    543 KdReleaseAllKeys (void);
    544 
    545 void
    546 KdSetLed (KdKeyboardInfo *ki, int led, Bool on);
    547 
    548 void
    549 KdSetPointerMatrix (KdPointerMatrix *pointer);
    550 
    551 void
    552 KdComputePointerMatrix (KdPointerMatrix *pointer, Rotation randr, int width, int height);
    553 
    554 void
    555 KdScreenToPointerCoords (int *x, int *y);
    556 
    557 void
    558 KdBlockHandler (int		screen,
    559 		pointer		blockData,
    560 		pointer		timeout,
    561 		pointer		readmask);
    562 
    563 void
    564 KdWakeupHandler (int		screen,
    565 		 pointer    	data,
    566 		 unsigned long	result,
    567 		 pointer	readmask);
    568 
    569 void
    570 KdDisableInput (void);
    571 
    572 void
    573 KdEnableInput (void);
    574 
    575 void
    576 ProcessInputEvents (void);
    577 
    578 void
    579 KdRingBell (KdKeyboardInfo      *ki,
    580             int                 volume,
    581             int                 pitch,
    582             int                 duration);
    583 
    584 /* kmode.c */
    585 const KdMonitorTiming *
    586 KdFindMode (KdScreenInfo    *screen,
    587 	    Bool	    (*supported) (KdScreenInfo *,
    588 					  const KdMonitorTiming *));
    589 
    590 Bool
    591 KdTuneMode (KdScreenInfo    *screen,
    592 	    Bool	    (*usable) (KdScreenInfo *),
    593 	    Bool	    (*supported) (KdScreenInfo *,
    594 					  const KdMonitorTiming *));
    595 
    596 #ifdef RANDR
    597 Bool
    598 KdRandRGetInfo (ScreenPtr pScreen,
    599 		int randr,
    600 		Bool (*supported) (ScreenPtr pScreen,
    601 				   const KdMonitorTiming *));
    602 
    603 const KdMonitorTiming *
    604 KdRandRGetTiming (ScreenPtr	    pScreen,
    605 		  Bool		    (*supported) (ScreenPtr pScreen,
    606 						  const KdMonitorTiming *),
    607 		  int		    rate,
    608 		  RRScreenSizePtr   pSize);
    609 #endif
    610 
    611 /* kshadow.c */
    612 Bool
    613 KdShadowFbAlloc (KdScreenInfo *screen, Bool rotate);
    614 
    615 void
    616 KdShadowFbFree (KdScreenInfo *screen);
    617 
    618 Bool
    619 KdShadowSet (ScreenPtr pScreen, int randr, ShadowUpdateProc update, ShadowWindowProc window);
    620 
    621 void
    622 KdShadowUnset (ScreenPtr pScreen);
    623 
    624 /* function prototypes to be implemented by the drivers */
    625 void
    626 InitCard (char *name);
    627 
    628 #endif /* _KDRIVE_H_ */
    629