Imported Upstream version 1.15.1
[deb_xorg-server.git] / hw / kdrive / src / kdrive.h
CommitLineData
a09e091a
JB
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 width;
93 int height;
94 int rate;
95 int width_mm;
96 int height_mm;
97 int subpixel_order;
98 Bool dumb;
99 Bool softCursor;
100 int mynum;
101 DDXPointRec origin;
102 KdFrameBuffer fb;
103} KdScreenInfo;
104
105typedef 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 */
118
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 *);
124
125 Bool (*initAccel) (ScreenPtr);
126 void (*enableAccel) (ScreenPtr);
127 void (*disableAccel) (ScreenPtr);
128 void (*finiAccel) (ScreenPtr);
129
130 void (*getColors) (ScreenPtr, int, xColorItem *);
131 void (*putColors) (ScreenPtr, int, xColorItem *);
132
133} KdCardFuncs;
134
135#define KD_MAX_PSEUDO_DEPTH 8
136#define KD_MAX_PSEUDO_SIZE (1 << KD_MAX_PSEUDO_DEPTH)
137
138typedef struct {
139 KdScreenInfo *screen;
140 KdCardInfo *card;
141
142 Bool enabled;
143 Bool closed;
144 int bytesPerPixel;
145
146 int dpmsState;
147
148 ColormapPtr pInstalledmap; /* current colormap */
149 xColorItem systemPalette[KD_MAX_PSEUDO_SIZE]; /* saved windows colors */
150
151 CreateScreenResourcesProcPtr CreateScreenResources;
152 CloseScreenProcPtr CloseScreen;
153} KdPrivScreenRec, *KdPrivScreenPtr;
154
155typedef enum _kdPointerState {
156 start,
157 button_1_pend,
158 button_1_down,
159 button_2_down,
160 button_3_pend,
161 button_3_down,
162 synth_2_down_13,
163 synth_2_down_3,
164 synth_2_down_1,
165 num_input_states
166} KdPointerState;
167
168#define KD_MAX_BUTTON 32
169
170#define KD_KEYBOARD 1
171#define KD_MOUSE 2
172#define KD_TOUCHSCREEN 3
173
174typedef struct _KdPointerInfo KdPointerInfo;
175
176typedef struct _KdPointerDriver {
177 const char *name;
178 Status(*Init) (KdPointerInfo *);
179 Status(*Enable) (KdPointerInfo *);
180 void (*Disable) (KdPointerInfo *);
181 void (*Fini) (KdPointerInfo *);
182 struct _KdPointerDriver *next;
183} KdPointerDriver;
184
185struct _KdPointerInfo {
186 DeviceIntPtr dixdev;
187 char *name;
188 char *path;
189 char *protocol;
190 InputOption *options;
191 int inputClass;
192
193 CARD8 map[KD_MAX_BUTTON + 1];
194 int nButtons;
195 int nAxes;
196
197 Bool emulateMiddleButton;
198 unsigned long emulationTimeout;
199 int emulationDx, emulationDy;
200
201 Bool timeoutPending;
202 KdPointerState mouseState;
203 Bool eventHeld;
204 struct {
205 int type;
206 int x;
207 int y;
208 int z;
209 int flags;
210 int absrel;
211 } heldEvent;
212 unsigned char buttonState;
213 Bool transformCoordinates;
214 int pressureThreshold;
215
216 KdPointerDriver *driver;
217 void *driverPrivate;
218
219 struct _KdPointerInfo *next;
220};
221
222extern int KdCurScreen;
223
224void KdAddPointerDriver(KdPointerDriver * driver);
225void KdRemovePointerDriver(KdPointerDriver * driver);
226KdPointerInfo *KdNewPointer(void);
227void KdFreePointer(KdPointerInfo *);
228int KdAddPointer(KdPointerInfo * ki);
229int KdAddConfigPointer(char *pointer);
230void KdRemovePointer(KdPointerInfo * ki);
231
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)
237
238typedef struct {
239 KeySym modsym;
240 int modbit;
241} KdKeySymModsRec;
242
243typedef struct _KdKeyboardInfo KdKeyboardInfo;
244
245typedef struct _KdKeyboardDriver {
246 const char *name;
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;
254} KdKeyboardDriver;
255
256struct _KdKeyboardInfo {
257 struct _KdKeyboardInfo *next;
258 DeviceIntPtr dixdev;
259 void *closure;
260 char *name;
261 char *path;
262 int inputClass;
263 char *xkbRules;
264 char *xkbModel;
265 char *xkbLayout;
266 char *xkbVariant;
267 char *xkbOptions;
268 int LockLed;
269
270 int minScanCode;
271 int maxScanCode;
272
273 int leds;
274 int bellPitch;
275 int bellDuration;
276 InputOption *options;
277
278 KdKeyboardDriver *driver;
279 void *driverPrivate;
280};
281
282void KdAddKeyboardDriver(KdKeyboardDriver * driver);
283void KdRemoveKeyboardDriver(KdKeyboardDriver * driver);
284KdKeyboardInfo *KdNewKeyboard(void);
285void KdFreeKeyboard(KdKeyboardInfo * ki);
286int KdAddConfigKeyboard(char *pointer);
287int KdAddKeyboard(KdKeyboardInfo * ki);
288void KdRemoveKeyboard(KdKeyboardInfo * ki);
289
290typedef struct _KdOsFuncs {
291 int (*Init) (void);
292 void (*Enable) (void);
293 Bool (*SpecialKey) (KeySym);
294 void (*Disable) (void);
295 void (*Fini) (void);
296 void (*pollEvents) (void);
297 void (*Bell) (int, int, int);
298} KdOsFuncs;
299
300typedef enum _KdSyncPolarity {
301 KdSyncNegative, KdSyncPositive
302} KdSyncPolarity;
303
304typedef struct _KdMonitorTiming {
305 /* label */
306 int horizontal;
307 int vertical;
308 int rate;
309 /* pixel clock */
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 */
321} KdMonitorTiming;
322
323extern const KdMonitorTiming kdMonitorTimings[];
324extern const int kdNumMonitorTimings;
325
326typedef struct _KdPointerMatrix {
327 int matrix[2][3];
328} KdPointerMatrix;
329
330/*
331 * This is the only completely portable way to
332 * compute this info.
333 */
334
335#ifndef BitsPerPixel
336#define BitsPerPixel(d) (\
337 PixmapWidthPaddingInfo[d].notPower2 ? \
338 (PixmapWidthPaddingInfo[d].bytesPerPixel * 8) : \
339 ((1 << PixmapWidthPaddingInfo[d].padBytesLog2) * 8 / \
340 (PixmapWidthPaddingInfo[d].padRoundUp+1)))
341#endif
342
343extern DevPrivateKeyRec kdScreenPrivateKeyRec;
344
345#define kdScreenPrivateKey (&kdScreenPrivateKeyRec)
346
347extern unsigned long kdGeneration;
348extern Bool kdEnabled;
349extern Bool kdSwitchPending;
350extern Bool kdEmulateMiddleButton;
351extern Bool kdDisableZaphod;
352extern Bool kdAllowZap;
353extern int kdVirtualTerminal;
354extern char *kdSwitchCmd;
355extern KdOsFuncs *kdOsFuncs;
356
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)
362
363/* kcmap.c */
364void
365 KdSetColormap(ScreenPtr pScreen);
366
367void
368 KdEnableColormap(ScreenPtr pScreen);
369
370void
371 KdDisableColormap(ScreenPtr pScreen);
372
373void
374 KdInstallColormap(ColormapPtr pCmap);
375
376void
377 KdUninstallColormap(ColormapPtr pCmap);
378
379int
380 KdListInstalledColormaps(ScreenPtr pScreen, Colormap * pCmaps);
381
382void
383 KdStoreColors(ColormapPtr pCmap, int ndef, xColorItem * pdefs);
384
385/* kdrive.c */
386extern miPointerScreenFuncRec kdPointerScreenFuncs;
387
388void
389 KdDisableScreen(ScreenPtr pScreen);
390
391void
392 KdDisableScreens(void);
393
394Bool
395 KdEnableScreen(ScreenPtr pScreen);
396
397void
398 KdEnableScreens(void);
399
400void
401 KdSuspend(void);
402
403void
404 KdResume(void);
405
406void
407 KdProcessSwitch(void);
408
409Rotation KdAddRotation(Rotation a, Rotation b);
410
411Rotation KdSubRotation(Rotation a, Rotation b);
412
413void
414 KdParseScreen(KdScreenInfo * screen, const char *arg);
415
416KdPointerInfo *KdParsePointer(const char *arg);
417
418KdKeyboardInfo *KdParseKeyboard(const char *arg);
419
420const char *
421KdParseFindNext(const char *cur, const char *delim, char *save, char *last);
422
423void
424 KdParseRgba(char *rgba);
425
426void
427 KdUseMsg(void);
428
429int
430 KdProcessArgument(int argc, char **argv, int i);
431
432void
433 KdOsInit(KdOsFuncs * pOsFuncs);
434
435void
436 KdOsAddInputDrivers(void);
437
438Bool
439 KdAllocatePrivates(ScreenPtr pScreen);
440
441Bool
442 KdCreateScreenResources(ScreenPtr pScreen);
443
444Bool
445 KdCloseScreen(ScreenPtr pScreen);
446
447Bool
448 KdSaveScreen(ScreenPtr pScreen, int on);
449
450Bool
451 KdScreenInit(ScreenPtr pScreen, int argc, char **argv);
452
453void
454
455KdInitScreen(ScreenInfo * pScreenInfo,
456 KdScreenInfo * screen, int argc, char **argv);
457
458void
459 KdInitCard(ScreenInfo * pScreenInfo, KdCardInfo * card, int argc, char **argv);
460
461void
462 KdInitOutput(ScreenInfo * pScreenInfo, int argc, char **argv);
463
464void
465 KdSetSubpixelOrder(ScreenPtr pScreen, Rotation randr);
466
467void
468 KdBacktrace(int signum);
469
470/* kinfo.c */
471KdCardInfo *KdCardInfoAdd(KdCardFuncs * funcs, void *closure);
472
473KdCardInfo *KdCardInfoLast(void);
474
475void
476 KdCardInfoDispose(KdCardInfo * ci);
477
478KdScreenInfo *KdScreenInfoAdd(KdCardInfo * ci);
479
480void
481 KdScreenInfoDispose(KdScreenInfo * si);
482
483/* kinput.c */
484void
485 KdInitInput(void);
486void
487 KdCloseInput(void);
488
489Bool
490 KdRegisterFd(int fd, void (*read) (int fd, void *closure), void *closure);
491
492void
493 KdUnregisterFds(void *closure, Bool do_close);
494
495void
496 KdUnregisterFd(void *closure, int fd, Bool do_close);
497
498void
499
500KdEnqueueKeyboardEvent(KdKeyboardInfo * ki, unsigned char scan_code,
501 unsigned char is_up);
502
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
511
512void
513
514KdEnqueuePointerEvent(KdPointerInfo * pi, unsigned long flags, int rx, int ry,
515 int rz);
516
517void
518
519_KdEnqueuePointerEvent(KdPointerInfo * pi, int type, int x, int y, int z,
520 int b, int absrel, Bool force);
521
522void
523 KdReleaseAllKeys(void);
524
525void
526 KdSetLed(KdKeyboardInfo * ki, int led, Bool on);
527
528void
529 KdSetPointerMatrix(KdPointerMatrix * pointer);
530
531void
532
533KdComputePointerMatrix(KdPointerMatrix * pointer, Rotation randr, int width,
534 int height);
535
536void
537 KdScreenToPointerCoords(int *x, int *y);
538
539void
540
541KdBlockHandler(ScreenPtr pScreen, pointer timeout, pointer readmask);
542
543void
544
545KdWakeupHandler(ScreenPtr pScreen, unsigned long result, pointer readmask);
546
547void
548 KdDisableInput(void);
549
550void
551 KdEnableInput(void);
552
553void
554 KdRingBell(KdKeyboardInfo * ki, int volume, int pitch, int duration);
555
556/* kmode.c */
557const KdMonitorTiming *KdFindMode(KdScreenInfo * screen,
558 Bool (*supported) (KdScreenInfo *,
559 const KdMonitorTiming *));
560
561Bool
562
563KdTuneMode(KdScreenInfo * screen,
564 Bool (*usable) (KdScreenInfo *),
565 Bool (*supported) (KdScreenInfo *, const KdMonitorTiming *));
566
567#ifdef RANDR
568Bool
569
570KdRandRGetInfo(ScreenPtr pScreen,
571 int randr,
572 Bool (*supported) (ScreenPtr pScreen, const KdMonitorTiming *));
573
574const KdMonitorTiming *KdRandRGetTiming(ScreenPtr pScreen,
575 Bool (*supported) (ScreenPtr pScreen,
576 const KdMonitorTiming
577 *), int rate,
578 RRScreenSizePtr pSize);
579#endif
580
581/* kshadow.c */
582Bool
583 KdShadowFbAlloc(KdScreenInfo * screen, Bool rotate);
584
585void
586 KdShadowFbFree(KdScreenInfo * screen);
587
588Bool
589
590KdShadowSet(ScreenPtr pScreen, int randr, ShadowUpdateProc update,
591 ShadowWindowProc window);
592
593void
594 KdShadowUnset(ScreenPtr pScreen);
595
596/* function prototypes to be implemented by the drivers */
597void
598 InitCard(char *name);
599
600#endif /* _KDRIVE_H_ */