2 * Copyright © 1999 Keith Packard
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.
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.
29 #include <X11/Xproto.h>
31 #include "scrnintstr.h"
32 #include "pixmapstr.h"
33 #include "windowstr.h"
35 #include "colormapst.h"
38 #include "mipointer.h"
42 #include "fboverlay.h"
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
57 typedef struct _KdCardInfo
{
58 struct _KdCardFuncs
*cfuncs
;
61 struct _KdScreenInfo
*screenList
;
63 struct _KdCardInfo
*next
;
66 extern KdCardInfo
*kdCardInfo
;
69 * Configuration information per X screen
71 typedef struct _KdFrameBuffer
{
78 unsigned long visuals
;
79 Pixel redMask
, greenMask
, blueMask
;
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)
86 typedef struct _KdScreenInfo
{
87 struct _KdScreenInfo
*next
;
91 Rotation randr
; /* rotation and reflection */
105 typedef struct _KdCardFuncs
{
106 Bool (*cardinit
) (KdCardInfo
*); /* detect and map device */
107 Bool (*scrinit
) (KdScreenInfo
*); /* initialize screen information */
108 Bool (*initScreen
) (ScreenPtr
); /* initialize ScreenRec */
109 Bool (*finishInitScreen
) (ScreenPtr pScreen
);
110 Bool (*createRes
) (ScreenPtr
); /* create screen resources */
111 void (*preserve
) (KdCardInfo
*); /* save graphics card state */
112 Bool (*enable
) (ScreenPtr
); /* set up for rendering */
113 Bool (*dpms
) (ScreenPtr
, int); /* set DPMS screen saver */
114 void (*disable
) (ScreenPtr
); /* turn off rendering */
115 void (*restore
) (KdCardInfo
*); /* restore graphics card state */
116 void (*scrfini
) (KdScreenInfo
*); /* close down screen */
117 void (*cardfini
) (KdCardInfo
*); /* close down */
119 Bool (*initCursor
) (ScreenPtr
); /* detect and map cursor */
120 void (*enableCursor
) (ScreenPtr
); /* enable cursor */
121 void (*disableCursor
) (ScreenPtr
); /* disable cursor */
122 void (*finiCursor
) (ScreenPtr
); /* close down */
123 void (*recolorCursor
) (ScreenPtr
, int, xColorItem
*);
125 Bool (*initAccel
) (ScreenPtr
);
126 void (*enableAccel
) (ScreenPtr
);
127 void (*disableAccel
) (ScreenPtr
);
128 void (*finiAccel
) (ScreenPtr
);
130 void (*getColors
) (ScreenPtr
, int, xColorItem
*);
131 void (*putColors
) (ScreenPtr
, int, xColorItem
*);
135 #define KD_MAX_PSEUDO_DEPTH 8
136 #define KD_MAX_PSEUDO_SIZE (1 << KD_MAX_PSEUDO_DEPTH)
139 KdScreenInfo
*screen
;
148 ColormapPtr pInstalledmap
; /* current colormap */
149 xColorItem systemPalette
[KD_MAX_PSEUDO_SIZE
]; /* saved windows colors */
151 CreateScreenResourcesProcPtr CreateScreenResources
;
152 CloseScreenProcPtr CloseScreen
;
153 } KdPrivScreenRec
, *KdPrivScreenPtr
;
155 typedef enum _kdPointerState
{
168 #define KD_MAX_BUTTON 32
170 #define KD_KEYBOARD 1
172 #define KD_TOUCHSCREEN 3
174 typedef struct _KdPointerInfo KdPointerInfo
;
176 typedef struct _KdPointerDriver
{
178 Status(*Init
) (KdPointerInfo
*);
179 Status(*Enable
) (KdPointerInfo
*);
180 void (*Disable
) (KdPointerInfo
*);
181 void (*Fini
) (KdPointerInfo
*);
182 struct _KdPointerDriver
*next
;
185 struct _KdPointerInfo
{
190 InputOption
*options
;
193 CARD8 map
[KD_MAX_BUTTON
+ 1];
197 Bool emulateMiddleButton
;
198 unsigned long emulationTimeout
;
199 int emulationDx
, emulationDy
;
202 KdPointerState mouseState
;
212 unsigned char buttonState
;
213 Bool transformCoordinates
;
214 int pressureThreshold
;
216 KdPointerDriver
*driver
;
219 struct _KdPointerInfo
*next
;
222 extern int KdCurScreen
;
224 void KdAddPointerDriver(KdPointerDriver
* driver
);
225 void KdRemovePointerDriver(KdPointerDriver
* driver
);
226 KdPointerInfo
*KdNewPointer(void);
227 void KdFreePointer(KdPointerInfo
*);
228 int KdAddPointer(KdPointerInfo
* ki
);
229 int KdAddConfigPointer(char *pointer
);
230 void KdRemovePointer(KdPointerInfo
* ki
);
232 #define KD_KEY_COUNT 248
233 #define KD_MIN_KEYCODE 8
234 #define KD_MAX_KEYCODE 255
235 #define KD_MAX_WIDTH 4
236 #define KD_MAX_LENGTH (KD_MAX_KEYCODE - KD_MIN_KEYCODE + 1)
243 typedef struct _KdKeyboardInfo KdKeyboardInfo
;
245 typedef struct _KdKeyboardDriver
{
247 Bool (*Init
) (KdKeyboardInfo
*);
248 Bool (*Enable
) (KdKeyboardInfo
*);
249 void (*Leds
) (KdKeyboardInfo
*, int);
250 void (*Bell
) (KdKeyboardInfo
*, int, int, int);
251 void (*Disable
) (KdKeyboardInfo
*);
252 void (*Fini
) (KdKeyboardInfo
*);
253 struct _KdKeyboardDriver
*next
;
256 struct _KdKeyboardInfo
{
257 struct _KdKeyboardInfo
*next
;
276 InputOption
*options
;
278 KdKeyboardDriver
*driver
;
282 void KdAddKeyboardDriver(KdKeyboardDriver
* driver
);
283 void KdRemoveKeyboardDriver(KdKeyboardDriver
* driver
);
284 KdKeyboardInfo
*KdNewKeyboard(void);
285 void KdFreeKeyboard(KdKeyboardInfo
* ki
);
286 int KdAddConfigKeyboard(char *pointer
);
287 int KdAddKeyboard(KdKeyboardInfo
* ki
);
288 void KdRemoveKeyboard(KdKeyboardInfo
* ki
);
290 typedef struct _KdOsFuncs
{
292 void (*Enable
) (void);
293 Bool (*SpecialKey
) (KeySym
);
294 void (*Disable
) (void);
296 void (*pollEvents
) (void);
297 void (*Bell
) (int, int, int);
300 typedef enum _KdSyncPolarity
{
301 KdSyncNegative
, KdSyncPositive
304 typedef struct _KdMonitorTiming
{
310 int clock
; /* in KHz */
311 /* horizontal timing */
312 int hfp
; /* front porch */
313 int hbp
; /* back porch */
314 int hblank
; /* blanking */
315 KdSyncPolarity hpol
; /* polarity */
316 /* vertical timing */
317 int vfp
; /* front porch */
318 int vbp
; /* back porch */
319 int vblank
; /* blanking */
320 KdSyncPolarity vpol
; /* polarity */
323 extern const KdMonitorTiming kdMonitorTimings
[];
324 extern const int kdNumMonitorTimings
;
326 typedef struct _KdPointerMatrix
{
331 * This is the only completely portable way to
336 #define BitsPerPixel(d) (\
337 PixmapWidthPaddingInfo[d].notPower2 ? \
338 (PixmapWidthPaddingInfo[d].bytesPerPixel * 8) : \
339 ((1 << PixmapWidthPaddingInfo[d].padBytesLog2) * 8 / \
340 (PixmapWidthPaddingInfo[d].padRoundUp+1)))
343 extern DevPrivateKeyRec kdScreenPrivateKeyRec
;
345 #define kdScreenPrivateKey (&kdScreenPrivateKeyRec)
347 extern unsigned long kdGeneration
;
348 extern Bool kdEnabled
;
349 extern Bool kdSwitchPending
;
350 extern Bool kdEmulateMiddleButton
;
351 extern Bool kdDisableZaphod
;
352 extern Bool kdAllowZap
;
353 extern int kdVirtualTerminal
;
354 extern char *kdSwitchCmd
;
355 extern KdOsFuncs
*kdOsFuncs
;
357 #define KdGetScreenPriv(pScreen) ((KdPrivScreenPtr) \
358 dixLookupPrivate(&(pScreen)->devPrivates, kdScreenPrivateKey))
359 #define KdSetScreenPriv(pScreen,v) \
360 dixSetPrivate(&(pScreen)->devPrivates, kdScreenPrivateKey, v)
361 #define KdScreenPriv(pScreen) KdPrivScreenPtr pScreenPriv = KdGetScreenPriv(pScreen)
365 KdSetColormap(ScreenPtr pScreen
);
368 KdEnableColormap(ScreenPtr pScreen
);
371 KdDisableColormap(ScreenPtr pScreen
);
374 KdInstallColormap(ColormapPtr pCmap
);
377 KdUninstallColormap(ColormapPtr pCmap
);
380 KdListInstalledColormaps(ScreenPtr pScreen
, Colormap
* pCmaps
);
383 KdStoreColors(ColormapPtr pCmap
, int ndef
, xColorItem
* pdefs
);
386 extern miPointerScreenFuncRec kdPointerScreenFuncs
;
389 KdDisableScreen(ScreenPtr pScreen
);
392 KdDisableScreens(void);
395 KdEnableScreen(ScreenPtr pScreen
);
398 KdEnableScreens(void);
407 KdProcessSwitch(void);
409 Rotation
KdAddRotation(Rotation a
, Rotation b
);
411 Rotation
KdSubRotation(Rotation a
, Rotation b
);
414 KdParseScreen(KdScreenInfo
* screen
, const char *arg
);
416 KdPointerInfo
*KdParsePointer(const char *arg
);
418 KdKeyboardInfo
*KdParseKeyboard(const char *arg
);
421 KdParseFindNext(const char *cur
, const char *delim
, char *save
, char *last
);
424 KdParseRgba(char *rgba
);
430 KdProcessArgument(int argc
, char **argv
, int i
);
433 KdOsInit(KdOsFuncs
* pOsFuncs
);
436 KdOsAddInputDrivers(void);
439 KdAllocatePrivates(ScreenPtr pScreen
);
442 KdCreateScreenResources(ScreenPtr pScreen
);
445 KdCloseScreen(ScreenPtr pScreen
);
448 KdSaveScreen(ScreenPtr pScreen
, int on
);
451 KdScreenInit(ScreenPtr pScreen
, int argc
, char **argv
);
455 KdInitScreen(ScreenInfo
* pScreenInfo
,
456 KdScreenInfo
* screen
, int argc
, char **argv
);
459 KdInitCard(ScreenInfo
* pScreenInfo
, KdCardInfo
* card
, int argc
, char **argv
);
462 KdInitOutput(ScreenInfo
* pScreenInfo
, int argc
, char **argv
);
465 KdSetSubpixelOrder(ScreenPtr pScreen
, Rotation randr
);
468 KdBacktrace(int signum
);
471 KdCardInfo
*KdCardInfoAdd(KdCardFuncs
* funcs
, void *closure
);
473 KdCardInfo
*KdCardInfoLast(void);
476 KdCardInfoDispose(KdCardInfo
* ci
);
478 KdScreenInfo
*KdScreenInfoAdd(KdCardInfo
* ci
);
481 KdScreenInfoDispose(KdScreenInfo
* si
);
490 KdRegisterFd(int fd
, void (*read
) (int fd
, void *closure
), void *closure
);
493 KdUnregisterFds(void *closure
, Bool do_close
);
496 KdUnregisterFd(void *closure
, int fd
, Bool do_close
);
500 KdEnqueueKeyboardEvent(KdKeyboardInfo
* ki
, unsigned char scan_code
,
501 unsigned char is_up
);
503 #define KD_BUTTON_1 0x01
504 #define KD_BUTTON_2 0x02
505 #define KD_BUTTON_3 0x04
506 #define KD_BUTTON_4 0x08
507 #define KD_BUTTON_5 0x10
508 #define KD_BUTTON_8 0x80
509 #define KD_POINTER_DESKTOP 0x40000000
510 #define KD_MOUSE_DELTA 0x80000000
514 KdEnqueuePointerEvent(KdPointerInfo
* pi
, unsigned long flags
, int rx
, int ry
,
519 _KdEnqueuePointerEvent(KdPointerInfo
* pi
, int type
, int x
, int y
, int z
,
520 int b
, int absrel
, Bool force
);
523 KdReleaseAllKeys(void);
526 KdSetLed(KdKeyboardInfo
* ki
, int led
, Bool on
);
529 KdSetPointerMatrix(KdPointerMatrix
* pointer
);
533 KdComputePointerMatrix(KdPointerMatrix
* pointer
, Rotation randr
, int width
,
537 KdScreenToPointerCoords(int *x
, int *y
);
541 KdBlockHandler(ScreenPtr pScreen
, pointer timeout
, pointer readmask
);
545 KdWakeupHandler(ScreenPtr pScreen
, unsigned long result
, pointer readmask
);
548 KdDisableInput(void);
554 KdRingBell(KdKeyboardInfo
* ki
, int volume
, int pitch
, int duration
);
557 const KdMonitorTiming
*KdFindMode(KdScreenInfo
* screen
,
558 Bool (*supported
) (KdScreenInfo
*,
559 const KdMonitorTiming
*));
563 KdTuneMode(KdScreenInfo
* screen
,
564 Bool (*usable
) (KdScreenInfo
*),
565 Bool (*supported
) (KdScreenInfo
*, const KdMonitorTiming
*));
570 KdRandRGetInfo(ScreenPtr pScreen
,
572 Bool (*supported
) (ScreenPtr pScreen
, const KdMonitorTiming
*));
574 const KdMonitorTiming
*KdRandRGetTiming(ScreenPtr pScreen
,
575 Bool (*supported
) (ScreenPtr pScreen
,
576 const KdMonitorTiming
578 RRScreenSizePtr pSize
);
583 KdShadowFbAlloc(KdScreenInfo
* screen
, Bool rotate
);
586 KdShadowFbFree(KdScreenInfo
* screen
);
590 KdShadowSet(ScreenPtr pScreen
, int randr
, ShadowUpdateProc update
,
591 ShadowWindowProc window
);
594 KdShadowUnset(ScreenPtr pScreen
);
596 /* function prototypes to be implemented by the drivers */
598 InitCard(char *name
);
600 #endif /* _KDRIVE_H_ */