diff options
author | faith <faith> | 2001-12-14 20:46:02 +0000 |
---|---|---|
committer | faith <faith> | 2001-12-14 20:46:02 +0000 |
commit | ebd078008c8bb30edfb287770744266f283ceb83 (patch) | |
tree | 12e46e7335139459e1b1115ee59565cdc808e9ec | |
parent | e6ede3f595916a6dea71bb90ab24a0e61c66ed53 (diff) |
Encapsulate devPrivates accessdmx-0-1-20020112
Use global list instead of single set of globals for inputs and consoles
(this allows more than one -inputfrom).
Remove globals from dmxbeinput.c
Remove unused variables from dmxbeinput.c
Provide support for using non-backend for input (not done yet)
Move dmxLog* functions out of dmx.h into dmxlog.h
Remove globals from dmxconsole.c
Make parsing and initialization of dmxScreens, dmxInputs, and dmxConsoles similar.
Enhance support for nonstandard depths (all depths <= 32 compute a reasonable bpp).
Simplify command-line parsing and defaults.
Close all displays we open in AbortDDX.
Simplify input initialization.
Enhance logging functions for input/output and event reporting.
Protect X server namespace in some areas by using dmx prefix.
-rw-r--r-- | xc/programs/Xserver/hw/dmx/Imakefile | 2 | ||||
-rw-r--r-- | xc/programs/Xserver/hw/dmx/dmx.h | 85 | ||||
-rw-r--r-- | xc/programs/Xserver/hw/dmx/dmxbeinput.c | 171 | ||||
-rw-r--r-- | xc/programs/Xserver/hw/dmx/dmxbeinput.h | 7 | ||||
-rw-r--r-- | xc/programs/Xserver/hw/dmx/dmxbekeyboard.c | 70 | ||||
-rw-r--r-- | xc/programs/Xserver/hw/dmx/dmxbekeyboard.h | 5 | ||||
-rw-r--r-- | xc/programs/Xserver/hw/dmx/dmxbepointer.c | 46 | ||||
-rw-r--r-- | xc/programs/Xserver/hw/dmx/dmxbepointer.h | 2 | ||||
-rw-r--r-- | xc/programs/Xserver/hw/dmx/dmxconsole.c | 450 | ||||
-rw-r--r-- | xc/programs/Xserver/hw/dmx/dmxconsole.h | 12 | ||||
-rw-r--r-- | xc/programs/Xserver/hw/dmx/dmxdummy.c | 28 | ||||
-rw-r--r-- | xc/programs/Xserver/hw/dmx/dmxdummy.h | 6 | ||||
-rw-r--r-- | xc/programs/Xserver/hw/dmx/dmxinit.c | 298 | ||||
-rw-r--r-- | xc/programs/Xserver/hw/dmx/dmxinput.c | 47 | ||||
-rw-r--r-- | xc/programs/Xserver/hw/dmx/dmxinput.h | 18 | ||||
-rw-r--r-- | xc/programs/Xserver/hw/dmx/dmxlog.c | 64 | ||||
-rw-r--r-- | xc/programs/Xserver/hw/dmx/dmxlog.h | 60 | ||||
-rw-r--r-- | xc/programs/Xserver/hw/dmx/dmxpriv.c | 59 | ||||
-rw-r--r-- | xc/programs/Xserver/hw/dmx/dmxpriv.h | 41 |
19 files changed, 909 insertions, 562 deletions
diff --git a/xc/programs/Xserver/hw/dmx/Imakefile b/xc/programs/Xserver/hw/dmx/Imakefile index e10363d7c..2732b1bf5 100644 --- a/xc/programs/Xserver/hw/dmx/Imakefile +++ b/xc/programs/Xserver/hw/dmx/Imakefile @@ -14,6 +14,7 @@ SRCS = dmxinit.c \ $(INPUTSRCS) \ dmxdpms.c \ dmxlog.c \ + dmxpriv.c \ stubs.c \ miinitext.c @@ -25,6 +26,7 @@ OBJS = dmxinit.o \ $(INPUTOBJS) \ dmxdpms.o \ dmxlog.o \ + dmxpriv.o \ stubs.o \ miinitext.o diff --git a/xc/programs/Xserver/hw/dmx/dmx.h b/xc/programs/Xserver/hw/dmx/dmx.h index 68939e732..aaf51941b 100644 --- a/xc/programs/Xserver/hw/dmx/dmx.h +++ b/xc/programs/Xserver/hw/dmx/dmx.h @@ -51,10 +51,10 @@ typedef enum { } PositionType; typedef struct _DMXScreenInfo { - char *name; - - int index; - Display *display; + const char *name; /* Name from command line or config file */ + int index; /* Index into dmxScreens global */ + + Display *display; Window window; int width; @@ -95,37 +95,50 @@ typedef struct _DMXScreenInfo { CloseScreenProcPtr CloseScreen; } DMXScreenInfo; -typedef enum { - InputFromDummy = 0, - InputFromBackEnd, - InputFromConsole, - InputFromFrontEnd -} InputSourceType; - -typedef enum { - dmxDebug, - dmxInfo, - dmxWarning, - dmxError, - dmxFatal -} dmxLogLevel; - -extern dmxLogLevel dmxSetLogLevel(dmxLogLevel newLevel); -extern dmxLogLevel dmxGetLogLevel(void); -extern void dmxLog(dmxLogLevel logLevel, const char *format, ...); -extern void dmxLogOutput(DMXScreenInfo *dmxScreen, const char *format, ...); -extern void dmxLogInput(DMXScreenInfo *dmxScreen, const char *format, ...); -extern void dmxLogArgs(dmxLogLevel logLevel, int argc, char **argv); -extern void dmxLogVisual(DMXScreenInfo *dmxScreen, XVisualInfo *vi, - int defaultVisual); -void dmxLogAdditional(DMXScreenInfo *dmxScreen, const char *format, ...); - +typedef struct _DMXConsoleInfo { + const char *name; /* Name from command line or config file */ + int index; /* Index into dmxScreens global */ + + Display *display; + Window window; + XlibGC gc; + long eventMask; + + int width; + int height; + double xScale; + double yScale; + int lastScreen; + + CloseScreenProcPtr CloseScreen; +} DMXConsoleInfo; + +struct _DMXInputInfo; +typedef void (*ProcessInputEventsProc)(struct _DMXInputInfo *); + +typedef struct _DMXInputInfo { + const char *name; /* Name from command line or config file */ + int index; /* Index into dmxScreens global */ + + Display *display; + Window window; + int width; + int height; + long *pEventMask; + long eventMask; + ProcessInputEventsProc processInputEvents; + DMXScreenInfo *dmxScreen; + DMXConsoleInfo *dmxConsole; + int initPointerX; + int initPointerY; + int lastX; + int lastY; +} DMXInputInfo; + +/* Global variables available to all Xserver/hw/dmx routines. */ extern int dmxNumScreens; extern DMXScreenInfo *dmxScreens; - -extern int dmxEventMask; -extern int dmxInputScreen; -extern InputSourceType dmxInputSource; - -#define DEFAULT_INPUT_SOURCE InputFromBackEnd - +extern int dmxNumInputs; +extern DMXInputInfo *dmxInputs; +extern int dmxNumConsoles; +extern DMXConsoleInfo *dmxConsoles; diff --git a/xc/programs/Xserver/hw/dmx/dmxbeinput.c b/xc/programs/Xserver/hw/dmx/dmxbeinput.c index 6cfd51214..4acab4c1c 100644 --- a/xc/programs/Xserver/hw/dmx/dmxbeinput.c +++ b/xc/programs/Xserver/hw/dmx/dmxbeinput.c @@ -45,6 +45,7 @@ #include "scrnintstr.h" #include "dmx.h" +#include "dmxlog.h" #include "dmxinput.h" #include "dmxbeinput.h" #include "dmxbepointer.h" @@ -52,62 +53,55 @@ #include "XInput.h" -static long backEndEventMask = 0; -static CARD32 lastEventTime = 0; - -static int lastX = -1, lastY = -1; - -static Bool -dmxEventPredicate(Display *display, XEvent *event, char *args) { +static Bool dmxEventPredicate(Display *display, XEvent *event, char *args) { return TRUE; } -static void -dmxCollectEvents(void) +static void dmxCollectEvents(DMXInputInfo *dmxInput) { XEvent X; xEvent x; - int curX, curY; + int curX, curY; - if (lastX < 0 || lastY < 0) { - lastX = dmxInputRec.dmxScreen->width / 2; - lastY = dmxInputRec.dmxScreen->height / 2; + if (dmxInput->lastX < 0 || dmxInput->lastY < 0) { + dmxInput->lastX = dmxInput->width / 2; + dmxInput->lastY = dmxInput->height / 2; } - while (XCheckIfEvent(dmxInputRec.display, &X, dmxEventPredicate, NULL)) { + while (XCheckIfEvent(dmxInput->display, &X, dmxEventPredicate, NULL)) { switch (X.type) { case KeyPress: x.u.u.type = KeyPress; x.u.u.detail = X.xkey.keycode; - x.u.keyButtonPointer.time = lastEventTime = GetTimeInMillis(); + x.u.keyButtonPointer.time = GetTimeInMillis(); mieqEnqueue(&x); break; case KeyRelease: x.u.u.type = KeyRelease; x.u.u.detail = X.xkey.keycode; - x.u.keyButtonPointer.time = lastEventTime = GetTimeInMillis(); + x.u.keyButtonPointer.time = GetTimeInMillis(); mieqEnqueue(&x); break; case ButtonPress: x.u.u.type = ButtonPress; x.u.u.detail = X.xbutton.button; - x.u.keyButtonPointer.time = lastEventTime = GetTimeInMillis(); + x.u.keyButtonPointer.time = GetTimeInMillis(); mieqEnqueue(&x); break; case ButtonRelease: x.u.u.type = ButtonRelease; x.u.u.detail = X.xbutton.button; - x.u.keyButtonPointer.time = lastEventTime = GetTimeInMillis(); + x.u.keyButtonPointer.time = GetTimeInMillis(); mieqEnqueue(&x); break; case MotionNotify: x.u.u.type = MotionNotify; miPointerPosition(&curX, &curY); - x.u.keyButtonPointer.rootX = curX + (X.xmotion.x - lastX); - x.u.keyButtonPointer.rootY = curY + (X.xmotion.y - lastY); + x.u.keyButtonPointer.rootX = curX + (X.xmotion.x-dmxInput->lastX); + x.u.keyButtonPointer.rootY = curY + (X.xmotion.y-dmxInput->lastY); #if DEBUG dmxLog(dmxDebug, "dmxCollectEvents: cursor position is (%4d, %3d)\n", @@ -118,9 +112,9 @@ dmxCollectEvents(void) lastX, lastY, X.xmotion.x, X.xmotion.y, x.u.keyButtonPointer.rootX, x.u.keyButtonPointer.rootY); #endif - lastX = X.xmotion.x; - lastY = X.xmotion.y; - x.u.keyButtonPointer.time = lastEventTime = GetTimeInMillis(); + dmxInput->lastX = X.xmotion.x; + dmxInput->lastY = X.xmotion.y; + x.u.keyButtonPointer.time = GetTimeInMillis(); mieqEnqueue(&x); miPointerAbsoluteCursor(x.u.keyButtonPointer.rootX, @@ -136,59 +130,120 @@ dmxCollectEvents(void) #endif default: - dmxLog(dmxWarning, "Unhandled event: %d\n", X.type); + dmxLog(dmxWarning, "Unhandled event (%d): %s\n", + X.type, dmxEventName(X.type)); break; } } } -static void -dmxBlockHandler(pointer blockData, OSTimePtr pTimeout, pointer pReadMask) +static void dmxBlockHandler(pointer blockData, OSTimePtr pTimeout, + pointer pReadMask) { } -static void -dmxWakeupHandler(pointer blockData, int result, pointer pReadMask) +static void dmxWakeupHandler(pointer blockData, int result, pointer pReadMask) { - dmxCollectEvents(); + DMXInputInfo *dmxInput = blockData; + + dmxCollectEvents(dmxInput); } -static void -dmxBackEndProcessInputEvents(void) +static void dmxBackEndProcessInputEvents(DMXInputInfo *dmxInput) { mieqProcessInputEvents(); miPointerUpdate(); - if ((lastX != dmxInputRec.dmxScreen->width / 2) || - (lastY != dmxInputRec.dmxScreen->height / 2)) { - lastX = dmxInputRec.dmxScreen->width / 2; - lastY = dmxInputRec.dmxScreen->height / 2; - XWarpPointer(dmxInputRec.display, - dmxInputRec.window, - dmxInputRec.window, - 0, 0, 0, 0, lastX, lastY); + if ((dmxInput->lastX != dmxInput->width / 2) + || (dmxInput->lastY != dmxInput->height / 2)) { + dmxInput->lastX = dmxInput->width / 2; + dmxInput->lastY = dmxInput->height / 2; + XWarpPointer(dmxInput->display, dmxInput->window, dmxInput->window, + 0, 0, 0, 0, dmxInput->lastX, dmxInput->lastY); } } -void -dmxBackEndInitInput(int argc, char **argv) +/* dmxBackEndInitDisplay initializes a display for input that is not + * used as an output display. This function should fill in the same + * information as does dmxBackEndInitFromScreen. */ + +static void dmxBackEndInitDisplay(DMXInputInfo *dmxInput) +{ + XWindowAttributes attribs; + + if (!(dmxInput->display = XOpenDisplay(dmxInput->name))) + dmxLog(dmxFatal, + "dmxBackEndInitDisplay: Unable to open display %s\n", + dmxInput->name); + + XGetWindowAttributes(dmxInput->display, + DefaultRootWindow(dmxInput->display), &attribs); + + /* FIXME: this doesn't work -- open a + * window instead. */ + dmxInput->window = DefaultRootWindow(dmxInput->display); + dmxInput->width = attribs.width; + dmxInput->height = attribs.height; + dmxInput->dmxScreen = NULL; + dmxInput->dmxConsole = NULL; + dmxLogInput(dmxInput, "Using %dx%d display %s for input\n", + dmxInput->width, dmxInput->height, dmxInput->name); + dmxLog(dmxWarning, + "Using non-backend X server for input is currently unsupported\n"); +} + +/* dmxBackEndInitFromScreen copies information from an already + * initialized display (i.e., one of the backend displays). This + * function should fill in the same information as does + * dmxBackEndInitDisplay. */ + +static void dmxBackEndInitFromScreen(DMXInputInfo *dmxInput, + DMXScreenInfo *dmxScreen) +{ + dmxInput->display = dmxScreen->display; + dmxInput->window = dmxScreen->window; + dmxInput->width = dmxScreen->width; + dmxInput->height = dmxScreen->height; + dmxInput->dmxScreen = dmxScreen; + dmxInput->dmxConsole = NULL; +} + +void dmxBackEndInitInput(DMXInputInfo *dmxInput) { DeviceIntPtr pKeyboard, pPointer; XExtensionVersion *ext; XDeviceInfo *devices; + DMXScreenInfo *dmxScreen; int num; int i; - dmxLog(dmxDebug, "dmxBackEndInitInput\n"); - dmxLogArgs(dmxDebug, argc, argv); + /* Fill in dmxInput either from an existing display or by opening a + * new display. */ + for (i = 0,dmxScreen = &dmxScreens[0]; i<dmxNumScreens; i++,dmxScreen++) { + if (!strcmp(dmxInput->name, dmxScreen->name)) { + dmxBackEndInitFromScreen(dmxInput, dmxScreen); + break; + } + } + if (i >= dmxNumScreens) dmxBackEndInitDisplay(dmxInput); + + /* Finish dmxInput initialization using computed values or constants. */ + dmxInput->initPointerX = dmxInput->width / 2; + dmxInput->initPointerY = dmxInput->height / 2; + dmxInput->pEventMask = &dmxInput->eventMask; + dmxInput->processInputEvents = dmxBackEndProcessInputEvents; + dmxInput->eventMask = 0; + dmxInput->lastX = -1; + dmxInput->lastY = -1; - ext = XGetExtensionVersion(dmxScreens[dmxInputScreen].display, INAME); + /* Print out information about the XInput Extension. */ + ext = XGetExtensionVersion(dmxInput->display, INAME); if (ext && ext != (XExtensionVersion *)NoSuchExtension) { - dmxLogInput(&dmxScreens[dmxInputScreen], "%s version %d.%d\n", + dmxLogInput(dmxInput, "%s version %d.%d\n", INAME, ext->major_version, ext->minor_version); - devices = XListInputDevices(dmxScreens[dmxInputScreen].display, &num); + devices = XListInputDevices(dmxInput->display, &num); if (num) - dmxLogInput(&dmxScreens[dmxInputScreen], "Extended devices:\n"); + dmxLogInput(dmxInput, "Extended devices:\n"); for (i = 0; i < num; i++) { const char *kind = "Unknown"; switch (devices[i].use) { @@ -196,27 +251,27 @@ dmxBackEndInitInput(int argc, char **argv) case IsXKeyboard: kind = "XKeybaord"; break; case IsXExtensionDevice: kind = "XExtensionDevice"; break; } - dmxLogInput(&dmxScreens[dmxInputScreen], " \"%s\": %s\n", + dmxLogInput(dmxInput, " \"%s\": %s\n", devices[i].name ? devices[i].name : "<noname>", kind); } XFreeDeviceList(devices); } + /* Register devices. */ pPointer = AddInputDevice(dmxPointerProc, TRUE); pKeyboard = AddInputDevice(dmxKeyboardProc, TRUE); RegisterPointerDevice(pPointer); RegisterKeyboardDevice(pKeyboard); miRegisterPointerDevice(screenInfo.screens[0], pPointer); mieqInit(&pKeyboard->public, &pPointer->public); - dmxInputRec.display = dmxScreens[dmxInputScreen].display; - dmxInputRec.window = dmxScreens[dmxInputScreen].window; - dmxInputRec.pEventMask = &backEndEventMask; - dmxInputRec.processInputEvents = dmxBackEndProcessInputEvents; - dmxInputRec.dmxScreen = &dmxScreens[dmxInputScreen]; - dmxInputRec.initPointerX = dmxScreens[dmxInputScreen].width / 2; - dmxInputRec.initPointerY = dmxScreens[dmxInputScreen].height / 2; - AddEnabledDevice(XConnectionNumber(dmxInputRec.display)); - RegisterBlockAndWakeupHandlers(dmxBlockHandler, dmxWakeupHandler, NULL); -} + pKeyboard->public.devicePrivate = dmxInput; + pPointer->public.devicePrivate = dmxInput; + AddEnabledDevice(XConnectionNumber(dmxInput->display)); + RegisterBlockAndWakeupHandlers(dmxBlockHandler, dmxWakeupHandler, + dmxInput); + + dmxLogInput(dmxInput, "Keyboard: %s; Pointer: %s\n", + pKeyboard->name, pPointer->name); +} diff --git a/xc/programs/Xserver/hw/dmx/dmxbeinput.h b/xc/programs/Xserver/hw/dmx/dmxbeinput.h index 1a3b6be76..dd3b598fe 100644 --- a/xc/programs/Xserver/hw/dmx/dmxbeinput.h +++ b/xc/programs/Xserver/hw/dmx/dmxbeinput.h @@ -30,8 +30,13 @@ * Authors: * David H. Dawes <dawes@xfree86.org> * Kevin E. Martin <kem@redhat.com> + * Rickard E. (Rik) Faith <faith@redhat.com> * */ -extern void dmxBackEndInitInput(int argc, char **argv); +#ifndef _DMXBEINPUT_H_ +#define _DMXBEINPUT_H_ +extern void dmxBackEndInitInput(DMXInputInfo *dmxInput); + +#endif diff --git a/xc/programs/Xserver/hw/dmx/dmxbekeyboard.c b/xc/programs/Xserver/hw/dmx/dmxbekeyboard.c index d90601f3d..353ce58be 100644 --- a/xc/programs/Xserver/hw/dmx/dmxbekeyboard.c +++ b/xc/programs/Xserver/hw/dmx/dmxbekeyboard.c @@ -43,6 +43,7 @@ is" without express or implied warranty. * Authors: * David H. Dawes <dawes@xfree86.org> * Kevin E. Martin <kem@redhat.com> + * Rickard E. (Rik) Faith <faith@redhat.com> * */ @@ -63,6 +64,7 @@ is" without express or implied warranty. #include "servermd.h" #include "dmx.h" +#include "dmxlog.h" #include "dmxinput.h" #include "dmxbekeyboard.h" @@ -98,14 +100,15 @@ is" without express or implied warranty. extern Bool noXkbExtension; #endif -void -dmxBell(int volume, DeviceIntPtr pDev, pointer ctrl, int cls) +static void dmxBell(int volume, DeviceIntPtr pDev, pointer ctrl, int cls) { - XBell(dmxInputRec.display, volume); + DMXInputInfo *dmxInput = pDev->public.devicePrivate; + Display *dsp = dmxInput->display; + + XBell(dsp, volume); } -void -dmxChangeKeyboardControl(DeviceIntPtr pDev, KeybdCtrl *ctrl) +static void dmxChangeKeyboardControl(DeviceIntPtr pDev, KeybdCtrl *ctrl) { #if 0 unsigned long value_mask; @@ -142,29 +145,30 @@ dmxChangeKeyboardControl(DeviceIntPtr pDev, KeybdCtrl *ctrl) #endif } -int -dmxKeyboardProc(DeviceIntPtr pDevice, int onoff) +int dmxKeyboardProc(DeviceIntPtr pDevice, int onoff) { + DMXInputInfo *dmxInput = pDevice->public.devicePrivate; + Display *dsp = dmxInput->display; + Window win = dmxInput->window; + DevicePtr pDev = &pDevice->public; XModifierKeymap *modifier_keymap; - KeySym *keymap; - int mapWidth; - int min_keycode, max_keycode; - KeySymsRec keySyms; - CARD8 modmap[MAP_LENGTH]; - int i, j; - XKeyboardState values; - DevicePtr pDev = (DevicePtr)pDevice; + KeySym *keymap; + int mapWidth; + int min_keycode, max_keycode; + KeySymsRec keySyms; + CARD8 modmap[MAP_LENGTH]; + int i, j; + XKeyboardState values; switch (onoff) { case DEVICE_INIT: - modifier_keymap = - XGetModifierMapping(dmxInputRec.display); - XDisplayKeycodes(dmxInputRec.display, &min_keycode, &max_keycode); + modifier_keymap = XGetModifierMapping(dsp); + XDisplayKeycodes(dsp, &min_keycode, &max_keycode); #ifdef _XSERVER64 { KeySym64 *keymap64; int i, len; - keymap64 = XGetKeyboardMapping(dmxInputRec.display, + keymap64 = XGetKeyboardMapping(dsp, min_keycode, max_keycode - min_keycode + 1, &mapWidth); @@ -175,7 +179,7 @@ dmxKeyboardProc(DeviceIntPtr pDevice, int onoff) XFree(keymap64); } #else - keymap = XGetKeyboardMapping(dmxInputRec.display, + keymap = XGetKeyboardMapping(dsp, min_keycode, max_keycode - min_keycode + 1, &mapWidth); @@ -201,7 +205,7 @@ dmxKeyboardProc(DeviceIntPtr pDevice, int onoff) if (1 || noXkbExtension) { XkbError: #endif - XGetKeyboardControl(dmxInputRec.display, &values); + XGetKeyboardControl(dsp, &values); memmove((char *) defaultKeyboardControl.autoRepeats, (char *) values.auto_repeats, sizeof(values.auto_repeats)); @@ -219,20 +223,19 @@ XkbError: XkbDescPtr xkb; int op, event, error, major, minor; - if (XkbQueryExtension(dmxInputRec.display, + if (XkbQueryExtension(dsp, &op, &event, &error, &major, &minor) == 0) { dmxLog(dmxError, "Unable to initialize XKEYBOARD extension.\n"); goto XkbError; } - xkb = XkbGetKeyboard(dmxInputRec.display, - XkbGBN_AllComponentsMask, XkbUseCoreKbd); + xkb = XkbGetKeyboard(dsp, + XkbGBN_AllComponentsMask, XkbUseCoreKbd); if (xkb == NULL || xkb->geom == NULL) { dmxLog(dmxError, "Couldn't get keyboard.\n"); goto XkbError; } - XkbGetControls(dmxInputRec.display, - XkbAllControlsMask, xkb); + XkbGetControls(dsp, XkbAllControlsMask, xkb); memset(&names, 0, sizeof(XkbComponentNamesRec)); rules = XKB_DFLT_RULES_FILE; @@ -269,8 +272,9 @@ XkbError: } XkbSetRulesDflts(rules, model, layout, variants, options); - XkbInitKeyboardDeviceStruct((pointer)pDev, &names, &keySyms, modmap, - dmxBell, dmxChangeKeyboardControl); + XkbInitKeyboardDeviceStruct((pointer)pDev, &names, &keySyms, + modmap, dmxBell, + dmxChangeKeyboardControl); XkbDDXChangeControls((pointer)pDev, xkb->ctrls, xkb->ctrls); XkbFreeKeyboard(xkb, 0, False); } @@ -283,16 +287,14 @@ XkbError: break; case DEVICE_ON: pDev->on = TRUE; - *dmxInputRec.pEventMask |= DMX_KEYBOARD_EVENT_MASK; - XSelectInput(dmxInputRec.display, dmxInputRec.window, - *dmxInputRec.pEventMask); + *dmxInput->pEventMask |= DMX_KEYBOARD_EVENT_MASK; + XSelectInput(dsp, win, *dmxInput->pEventMask); break; case DEVICE_OFF: case DEVICE_CLOSE: pDev->on = FALSE; - *dmxInputRec.pEventMask &= ~DMX_KEYBOARD_EVENT_MASK; - XSelectInput(dmxInputRec.display, dmxInputRec.window, - *dmxInputRec.pEventMask); + *dmxInput->pEventMask &= ~DMX_KEYBOARD_EVENT_MASK; + XSelectInput(dsp, win, *dmxInput->pEventMask); break; } return Success; diff --git a/xc/programs/Xserver/hw/dmx/dmxbekeyboard.h b/xc/programs/Xserver/hw/dmx/dmxbekeyboard.h index 0e7076928..f6fd48f38 100644 --- a/xc/programs/Xserver/hw/dmx/dmxbekeyboard.h +++ b/xc/programs/Xserver/hw/dmx/dmxbekeyboard.h @@ -43,6 +43,7 @@ is" without express or implied warranty. * Authors: * David H. Dawes <dawes@xfree86.org> * Kevin E. Martin <kem@redhat.com> + * Rickard E. (Rik) Faith <faith@redhat.com> * */ @@ -52,8 +53,6 @@ is" without express or implied warranty. #define DMX_KEYBOARD_EVENT_MASK \ (KeyPressMask | KeyReleaseMask | KeymapStateMask) -void dmxBell(int volume, DeviceIntPtr pDev, pointer ctrl, int cls); -void dmxChangeKeyboardControl(DeviceIntPtr pDev, KeybdCtrl *ctrl); -int dmxKeyboardProc(DeviceIntPtr pDevice, int onoff); +extern int dmxKeyboardProc(DeviceIntPtr pDevice, int onoff); #endif /* _DMXBEKEYBOARD_H */ diff --git a/xc/programs/Xserver/hw/dmx/dmxbepointer.c b/xc/programs/Xserver/hw/dmx/dmxbepointer.c index f4b4431c1..dc5be91fb 100644 --- a/xc/programs/Xserver/hw/dmx/dmxbepointer.c +++ b/xc/programs/Xserver/hw/dmx/dmxbepointer.c @@ -43,6 +43,7 @@ is" without express or implied warranty. * Authors: * David H. Dawes <dawes@xfree86.org> * Kevin E. Martin <kem@redhat.com> + * Rickard E. (Rik) Faith <faith@redhat.com> * */ @@ -56,6 +57,7 @@ is" without express or implied warranty. #include "Xproto.h" #include "screenint.h" #include "input.h" +#include "inputstr.h" #include "misc.h" #include "scrnintstr.h" #include "servermd.h" @@ -66,24 +68,28 @@ is" without express or implied warranty. #include "dmxbepointer.h" -void -dmxChangePointerControl(DeviceIntPtr pDev, PtrCtrl *ctrl) +static void dmxChangePointerControl(DeviceIntPtr pDev, PtrCtrl *ctrl) { - XChangePointerControl(dmxInputRec.display, True, True, + DMXInputInfo *dmxInput = pDev->public.devicePrivate; + Display *dsp = dmxInput->display; + + XChangePointerControl(dsp, True, True, ctrl->num, ctrl->den, ctrl->threshold); } -int -dmxPointerProc(DeviceIntPtr pDevice, int onoff) +int dmxPointerProc(DeviceIntPtr pDevice, int onoff) { - CARD8 map[MAXBUTTONS]; - int nmap; - int i; - DevicePtr pDev = (DevicePtr)pDevice; + DMXInputInfo *dmxInput = pDevice->public.devicePrivate; + Display *dsp = dmxInput->display; + Window win = dmxInput->window; + DevicePtr pDev = &pDevice->public; + CARD8 map[MAXBUTTONS]; + int nmap; + int i; switch (onoff) { - case DEVICE_INIT: - nmap = XGetPointerMapping(dmxInputRec.display, map, MAXBUTTONS); + case DEVICE_INIT: + nmap = XGetPointerMapping(dsp, map, MAXBUTTONS); for (i = 0; i <= nmap; i++) map[i] = i; /* buttons are already mapped */ InitPointerDeviceStruct(pDev, map, nmap, @@ -93,22 +99,18 @@ dmxPointerProc(DeviceIntPtr pDevice, int onoff) break; case DEVICE_ON: pDev->on = TRUE; - *dmxInputRec.pEventMask |= DMX_POINTER_EVENT_MASK; - XWarpPointer(dmxInputRec.display, - dmxInputRec.window, - dmxInputRec.window, + *dmxInput->pEventMask |= DMX_POINTER_EVENT_MASK; + XWarpPointer(dsp, win, win, 0, 0, 0, 0, - dmxInputRec.initPointerX, - dmxInputRec.initPointerY); - XSelectInput(dmxInputRec.display, dmxInputRec.window, - *dmxInputRec.pEventMask); + dmxInput->initPointerX, + dmxInput->initPointerY); + XSelectInput(dsp, win, *dmxInput->pEventMask); break; case DEVICE_OFF: case DEVICE_CLOSE: pDev->on = FALSE; - *dmxInputRec.pEventMask &= ~DMX_POINTER_EVENT_MASK; - XSelectInput(dmxInputRec.display, dmxInputRec.window, - *dmxInputRec.pEventMask); + *dmxInput->pEventMask &= ~DMX_POINTER_EVENT_MASK; + XSelectInput(dsp, win, *dmxInput->pEventMask); break; } return Success; diff --git a/xc/programs/Xserver/hw/dmx/dmxbepointer.h b/xc/programs/Xserver/hw/dmx/dmxbepointer.h index 3e09526fa..7b396e928 100644 --- a/xc/programs/Xserver/hw/dmx/dmxbepointer.h +++ b/xc/programs/Xserver/hw/dmx/dmxbepointer.h @@ -43,6 +43,7 @@ is" without express or implied warranty. * Authors: * David H. Dawes <dawes@xfree86.org> * Kevin E. Martin <kem@redhat.com> + * Rickard E. (Rik) Faith <faith@redhat.com> * */ @@ -54,7 +55,6 @@ is" without express or implied warranty. #define DMX_POINTER_EVENT_MASK \ (ButtonPressMask | ButtonReleaseMask | PointerMotionMask) -void dmxChangePointerControl(DeviceIntPtr pDev, PtrCtrl *ctrl); int dmxPointerProc(DeviceIntPtr pDevice, int onoff); #endif /* _DMXBEPOINTER_H */ diff --git a/xc/programs/Xserver/hw/dmx/dmxconsole.c b/xc/programs/Xserver/hw/dmx/dmxconsole.c index 45561db44..87ca1e20d 100644 --- a/xc/programs/Xserver/hw/dmx/dmxconsole.c +++ b/xc/programs/Xserver/hw/dmx/dmxconsole.c @@ -30,6 +30,7 @@ * Authors: * David H. Dawes <dawes@xfree86.org> * Kevin E. Martin <kem@redhat.com> + * Rickard E. (Rik) Faith <faith@redhat.com> * */ @@ -43,6 +44,7 @@ #include "mi.h" #include "dmx.h" +#include "dmxlog.h" #include "dmxinput.h" #include "dmxconsole.h" #include "dmxbepointer.h" @@ -58,44 +60,28 @@ #define CONSOLE_SCREEN_BG_COLOR "white" #define CONSOLE_SCREEN_FG_COLOR "black" -Window dmxConsoleWindow; -XlibGC dmxConsoleGC; - -static long consoleEventMask = 0; -static double xScale = 1.0; -static double yScale = 1.0; -static int dmxWidth = 0; -static int dmxHeight = 0; - -static void dmxConsoleWakeupHandler(pointer, int, pointer); -static Bool dmxCloseConsole(int i, ScreenPtr pScreen); - -#ifdef CROSS_SCREENS_HERE -static int lastScreen = -1; -#endif - -static CARD32 lastEventTime = 0; - -static CloseScreenProcPtr closeScreen = NULL; - -static void -DrawConsole(void) +static void dmxDrawConsole(DMXConsoleInfo *dmxConsole) { - int i; + Display *dsp = dmxConsole->display; + Window win = dmxConsole->window; + XlibGC gc = dmxConsole->gc; + double xScale = dmxConsole->xScale; + double yScale = dmxConsole->yScale; + int i; unsigned long mask; - XGCValues gcvals; + XGCValues gcvals; unsigned long savedPixel; - XClearWindow(dmxConsoleDisplay, dmxConsoleWindow); + XClearWindow(dsp, win); /* Draw screen backgrounds. */ mask = GCForeground | GCBackground; - XGetGCValues(dmxConsoleDisplay, dmxConsoleGC, mask, &gcvals); + XGetGCValues(dsp, gc, mask, &gcvals); savedPixel = gcvals.foreground; gcvals.foreground = gcvals.background; - XChangeGC(dmxConsoleDisplay, dmxConsoleGC, GCForeground, &gcvals); + XChangeGC(dsp, gc, GCForeground, &gcvals); for (i = 0; i < dmxNumScreens; i++) { - XFillRectangle(dmxConsoleDisplay, dmxConsoleWindow, dmxConsoleGC, + XFillRectangle(dsp, win, gc, (int)(xScale * dixScreenOrigins[i].x), (int)(yScale * dixScreenOrigins[i].y), (int)(xScale * screenInfo.screens[i]->width), @@ -104,169 +90,24 @@ DrawConsole(void) /* Draw screen outlines. */ gcvals.foreground = savedPixel; - XChangeGC(dmxConsoleDisplay, dmxConsoleGC, GCForeground, &gcvals); + XChangeGC(dsp, gc, GCForeground, &gcvals); for (i = 0; i < dmxNumScreens; i++) { - XDrawRectangle(dmxConsoleDisplay, dmxConsoleWindow, dmxConsoleGC, + XDrawRectangle(dsp, win, gc, (int)(xScale * dixScreenOrigins[i].x), (int)(yScale * dixScreenOrigins[i].y), (int)(xScale * screenInfo.screens[i]->width), (int)(yScale * screenInfo.screens[i]->height)); } - XSync(dmxConsoleDisplay, False); -} - -Bool -dmxOpenConsole(const char *name) -{ - int screen; - int consWidth, consHeight; - int i; - unsigned long mask; - XSetWindowAttributes attribs; - XGCValues gcvals; - XColor color; - - if (!(dmxConsoleDisplay = XOpenDisplay(name))) { - ErrorF("dmxOpenConsole: Warning: cannot open console display \"%s\"\n", - name); - return FALSE; - } - - screen = DefaultScreen(dmxConsoleDisplay); - consWidth = DisplayWidth(dmxConsoleDisplay, screen) * - CONSOLE_NUM / CONSOLE_DEN; - consHeight = DisplayHeight(dmxConsoleDisplay, screen) * - CONSOLE_NUM / CONSOLE_DEN; - - for (i = 0; i < dmxNumScreens; i++) { - if (dixScreenOrigins[i].x + screenInfo.screens[i]->width > dmxWidth) - dmxWidth = dixScreenOrigins[i].x + screenInfo.screens[i]->width; - if (dixScreenOrigins[i].y + screenInfo.screens[i]->height > dmxHeight) - dmxHeight = dixScreenOrigins[i].y + screenInfo.screens[i]->height; - } - - if ((double)consWidth / (double)dmxWidth < - (double)consHeight / (double)dmxHeight) - xScale = yScale = (double)consWidth / (double)dmxWidth; - else - xScale = yScale = (double)consHeight / (double)dmxHeight; - - consWidth = (int)(xScale * dmxWidth); - consHeight = (int)(yScale * dmxHeight); - - mask = CWBackPixel | CWEventMask | CWColormap | CWOverrideRedirect; - attribs.colormap = DefaultColormap(dmxConsoleDisplay, screen); - if (XParseColor(dmxConsoleDisplay, attribs.colormap, - CONSOLE_BG_COLOR, &color) && - XAllocColor(dmxConsoleDisplay, attribs.colormap, &color)) { - attribs.background_pixel = color.pixel; - } else - attribs.background_pixel = WhitePixel(dmxConsoleDisplay, screen); - attribs.event_mask = (ButtonPressMask | - ButtonReleaseMask | - PointerMotionMask | - EnterWindowMask | - LeaveWindowMask | - KeyPressMask | - KeyReleaseMask | - FocusChangeMask | - ExposureMask | - ResizeRedirectMask); - attribs.override_redirect = FALSE; - - dmxConsoleWindow = XCreateWindow(dmxConsoleDisplay, - DefaultRootWindow(dmxConsoleDisplay), - 0, 0, consWidth, consHeight, - 0, - DefaultDepth(dmxConsoleDisplay, screen), - InputOutput, - DefaultVisual(dmxConsoleDisplay, screen), - mask, &attribs); - - XStoreName(dmxConsoleDisplay, dmxConsoleWindow, DMX_CONSOLE_NAME); - - /* XXX Set a cursor for the window. */ - - /* Map the window. */ - XMapWindow(dmxConsoleDisplay, dmxConsoleWindow); - - /* Create GC */ - mask = (GCFunction | GCPlaneMask | GCClipMask | GCForeground | - GCBackground | GCLineWidth | GCLineStyle | GCCapStyle | - GCFillStyle); - gcvals.function = GXcopy; - gcvals.plane_mask = AllPlanes; - gcvals.clip_mask = None; - if (XParseColor(dmxConsoleDisplay, attribs.colormap, - CONSOLE_SCREEN_FG_COLOR, &color) && - XAllocColor(dmxConsoleDisplay, attribs.colormap, &color)) { - gcvals.foreground = color.pixel; - } else - gcvals.foreground = BlackPixel(dmxConsoleDisplay, screen); - if (XParseColor(dmxConsoleDisplay, attribs.colormap, - CONSOLE_SCREEN_BG_COLOR, &color) && - XAllocColor(dmxConsoleDisplay, attribs.colormap, &color)) { - gcvals.background = color.pixel; - } else - gcvals.background = WhitePixel(dmxConsoleDisplay, screen); - gcvals.line_width = 0; - gcvals.line_style = LineSolid; - gcvals.cap_style = CapNotLast; - gcvals.fill_style = FillSolid; - - dmxConsoleGC = XCreateGC(dmxConsoleDisplay, dmxConsoleWindow, - mask, &gcvals); - - DrawConsole(); - consoleEventMask = ExposureMask | ResizeRedirectMask; - AddEnabledDevice(XConnectionNumber(dmxConsoleDisplay)); - /* A handler to check events. */ - RegisterBlockAndWakeupHandlers((BlockHandlerProcPtr)NoopDDA, - dmxConsoleWakeupHandler, NULL); - - /* Wrap screen 0's CloseScreen */ - closeScreen = screenInfo.screens[0]->CloseScreen; - screenInfo.screens[0]->CloseScreen = dmxCloseConsole; - - return TRUE; -} - -static void -dmxConsoleProcessInputEvents(void) -{ - mieqProcessInputEvents(); - miPointerUpdate(); -} - -void -dmxConsoleInitInput(int argc, char **argv) -{ - DeviceIntPtr pKeyboard, pPointer; - - pPointer = AddInputDevice(dmxPointerProc, TRUE); - pKeyboard = AddInputDevice(dmxKeyboardProc, TRUE); - RegisterPointerDevice(pPointer); - RegisterKeyboardDevice(pKeyboard); - miRegisterPointerDevice(screenInfo.screens[0], pPointer); - mieqInit(&pKeyboard->public, &pPointer->public); - dmxInputRec.display = dmxConsoleDisplay; - dmxInputRec.window = dmxConsoleWindow; - dmxInputRec.pEventMask = &consoleEventMask; - dmxInputRec.processInputEvents = dmxConsoleProcessInputEvents; - dmxInputRec.dmxScreen = NULL; - dmxInputRec.initPointerX = (int)(xScale * dmxScreens[0].width / 2); - dmxInputRec.initPointerY = (int)(yScale * dmxScreens[0].height / 2); - consoleEventMask |= (EnterWindowMask | LeaveWindowMask); + XSync(dsp, False); } -static int -FindPointerScreen(int x, int y) +static int dmxFindPointerScreen(DMXConsoleInfo *dmxConsole, int x, int y) { int i; int x1, y1; - x1 = (int)(x / xScale); - y1 = (int)(y / yScale); + x1 = (int)(x / dmxConsole->xScale); + y1 = (int)(y / dmxConsole->yScale); for (i = 0; i < dmxNumScreens; i++) { if ((x1 >= dixScreenOrigins[i].x) && @@ -278,37 +119,35 @@ FindPointerScreen(int x, int y) return -1; } -static void -CollectCursorEvents(void) +static void dmxCollectCursorEvents(DMXConsoleInfo *dmxConsole) { - XEvent X; - xEvent x; - int screen; + Display *dsp = dmxConsole->display; + Window win = dmxConsole->window; + int width = dmxConsole->width; + int height = dmxConsole->height; + XEvent X; + xEvent x; + int screen; XSetWindowAttributes attribs; - while (XCheckWindowEvent(dmxConsoleDisplay, dmxConsoleWindow, - consoleEventMask, &X)) { + while (XCheckWindowEvent(dsp, win, dmxConsole->eventMask, &X)) { #if DEBUG > 2 ErrorF("Console event type %d\n", X.type); #endif switch(X.type) { case Expose: - if (X.xexpose.count == 0) { - DrawConsole(); - } + if (X.xexpose.count == 0) dmxDrawConsole(dmxConsole); break; case ResizeRequest: - xScale = (double)X.xresizerequest.width / (double)dmxWidth; - yScale = (double)X.xresizerequest.height / (double)dmxHeight; + dmxConsole->xScale = (double)X.xresizerequest.width / width; + dmxConsole->yScale = (double)X.xresizerequest.height / height; attribs.override_redirect = True; - XChangeWindowAttributes(dmxConsoleDisplay, dmxConsoleWindow, - CWOverrideRedirect, &attribs); - XResizeWindow(dmxConsoleDisplay, dmxConsoleWindow, - X.xresizerequest.width, X.xresizerequest.height); - DrawConsole(); + XChangeWindowAttributes(dsp, win, CWOverrideRedirect, &attribs); + XResizeWindow(dsp, win, + X.xresizerequest.width, X.xresizerequest.height); + dmxDrawConsole(dmxConsole); attribs.override_redirect = False; - XChangeWindowAttributes(dmxConsoleDisplay, dmxConsoleWindow, - CWOverrideRedirect, &attribs); + XChangeWindowAttributes(dsp, win, CWOverrideRedirect, &attribs); break; case EnterNotify: case LeaveNotify: @@ -317,35 +156,36 @@ CollectCursorEvents(void) case KeyPress: x.u.u.type = KeyPress; x.u.u.detail = X.xkey.keycode; - x.u.keyButtonPointer.time = lastEventTime = GetTimeInMillis(); + x.u.keyButtonPointer.time = GetTimeInMillis(); mieqEnqueue(&x); break; case KeyRelease: x.u.u.type = KeyRelease; x.u.u.detail = X.xkey.keycode; - x.u.keyButtonPointer.time = lastEventTime = GetTimeInMillis(); + x.u.keyButtonPointer.time = GetTimeInMillis(); mieqEnqueue(&x); break; case ButtonPress: x.u.u.type = ButtonPress; x.u.u.detail = X.xbutton.button; - x.u.keyButtonPointer.time = lastEventTime = GetTimeInMillis(); + x.u.keyButtonPointer.time = GetTimeInMillis(); mieqEnqueue(&x); break; case ButtonRelease: x.u.u.type = ButtonRelease; x.u.u.detail = X.xbutton.button; - x.u.keyButtonPointer.time = lastEventTime = GetTimeInMillis(); + x.u.keyButtonPointer.time = GetTimeInMillis(); mieqEnqueue(&x); break; case MotionNotify: #ifdef CROSS_SCREENS_HERE x.u.u.type = MotionNotify; - screen = FindPointerScreen(X.xmotion.x, X.xmotion.y); + screen = dmxFindPointerScreen(dmxConsole, + X.xmotion.x, X.xmotion.y); if (screen == -1) { lastScreen = -1; break; @@ -360,7 +200,7 @@ CollectCursorEvents(void) X.xmotion.x, X.xmotion.y, x.u.keyButtonPointer.rootX, x.u.keyButtonPointer.rootY); #endif - x.u.keyButtonPointer.time = lastEventTime = GetTimeInMillis(); + x.u.keyButtonPointer.time = GetTimeInMillis(); if (screen != lastScreen) { /* @@ -391,7 +231,8 @@ CollectCursorEvents(void) } #else /* This checks if the pointer is in a "dead" area. */ - screen = FindPointerScreen(X.xmotion.x, X.xmotion.y); + screen = dmxFindPointerScreen(dmxConsole, + X.xmotion.x, X.xmotion.y); if (screen == -1) { break; } @@ -405,17 +246,19 @@ CollectCursorEvents(void) */ screen = miPointerCurrentScreen()->myNum; x.u.u.type = MotionNotify; - x.u.keyButtonPointer.rootX = (int)(X.xmotion.x / xScale) - - dixScreenOrigins[screen].x; - x.u.keyButtonPointer.rootY = (int)(X.xmotion.y / yScale) - - dixScreenOrigins[screen].y; + x.u.keyButtonPointer.rootX = ((int)(X.xmotion.x + / dmxConsole->xScale) + - dixScreenOrigins[screen].x); + x.u.keyButtonPointer.rootY = ((int)(X.xmotion.y + / dmxConsole->yScale) + - dixScreenOrigins[screen].y); #if DEBUG > 1 ErrorF("CollectCursorEvents: cons X, Y is (%4d, %3d), " "FE X, Y is (%4d, %3d)\n", X.xmotion.x, X.xmotion.y, x.u.keyButtonPointer.rootX, x.u.keyButtonPointer.rootY); #endif - x.u.keyButtonPointer.time = lastEventTime = GetTimeInMillis(); + x.u.keyButtonPointer.time = GetTimeInMillis(); mieqEnqueue(&x); miPointerAbsoluteCursor(x.u.keyButtonPointer.rootX, @@ -431,24 +274,189 @@ CollectCursorEvents(void) } } - -void -dmxConsoleWakeupHandler(pointer blockData, int result, pointer pReadMask) +static void dmxConsoleWakeupHandler(pointer blockData, int result, + pointer pReadMask) { - CollectCursorEvents(); + DMXConsoleInfo *dmxConsole = blockData; + + dmxCollectCursorEvents(dmxConsole); } -void -dmxCloseConsoleDisplay() +void dmxCloseConsole(DMXConsoleInfo *dmxConsole) { - XCloseDisplay(dmxConsoleDisplay); + if (dmxConsole->display) XCloseDisplay(dmxConsole->display); + dmxConsole->display = NULL; } -static Bool -dmxCloseConsole(int index, ScreenPtr pScreen) +static Bool dmxCloseConsoleScreen(int index, ScreenPtr pScreen) { - pScreen->CloseScreen = closeScreen; - dmxCloseConsoleDisplay(); + DMXConsoleInfo *dmxConsole = &dmxConsoles[0]; /* FIXME: use devprivate */ + + pScreen->CloseScreen = dmxConsole->CloseScreen; + dmxCloseConsole(dmxConsole); return pScreen->CloseScreen(index, pScreen); } +Bool dmxOpenConsole(DMXConsoleInfo *dmxConsole) +{ + Display *dsp; + Window win; + int screen; + int consWidth, consHeight; + int i; + unsigned long mask; + XSetWindowAttributes attribs; + XGCValues gcvals; + XColor color; + + if (!(dsp = dmxConsole->display = XOpenDisplay(dmxConsole->name))) { + dmxLog(dmxWarning, "dmxOpenConsole: cannot open console display %s\n", + dmxConsole->name); + return FALSE; + } + + /* Set up defaults */ + dmxConsole->xScale = 1.0; + dmxConsole->yScale = 1.0; + dmxConsole->lastScreen = -1; + + screen = DefaultScreen(dsp); + consWidth = DisplayWidth(dsp, screen) * CONSOLE_NUM / CONSOLE_DEN; + consHeight = DisplayHeight(dsp, screen) * CONSOLE_NUM / CONSOLE_DEN; + + for (i = 0; i < dmxNumScreens; i++) { + if (dixScreenOrigins[i].x + screenInfo.screens[i]->width + > dmxConsole->width) + dmxConsole->width = (dixScreenOrigins[i].x + + screenInfo.screens[i]->width); + + if (dixScreenOrigins[i].y + screenInfo.screens[i]->height + > dmxConsole->height) + dmxConsole->height = (dixScreenOrigins[i].y + + screenInfo.screens[i]->height); + } + + if ((double)consWidth / (double)dmxConsole->width < + (double)consHeight / (double)dmxConsole->height) + dmxConsole->xScale + = dmxConsole->yScale + = (double)consWidth / (double)dmxConsole->width; + else + dmxConsole->xScale + = dmxConsole->yScale + = (double)consHeight / (double)dmxConsole->height; + + consWidth = (int)(dmxConsole->xScale * dmxConsole->width); + consHeight = (int)(dmxConsole->yScale * dmxConsole->height); + + mask = CWBackPixel | CWEventMask | CWColormap | CWOverrideRedirect; + attribs.colormap = DefaultColormap(dsp, screen); + if (XParseColor(dsp, attribs.colormap, CONSOLE_BG_COLOR, &color) + && XAllocColor(dsp, attribs.colormap, &color)) { + attribs.background_pixel = color.pixel; + } else + attribs.background_pixel = WhitePixel(dsp, screen); + attribs.event_mask = (ButtonPressMask | + ButtonReleaseMask | + PointerMotionMask | + EnterWindowMask | + LeaveWindowMask | + KeyPressMask | + KeyReleaseMask | + FocusChangeMask | + ExposureMask | + ResizeRedirectMask); + attribs.override_redirect = FALSE; + + win = dmxConsole->window = XCreateWindow(dsp, + DefaultRootWindow(dsp), + 0, 0, consWidth, consHeight, + 0, + DefaultDepth(dsp, screen), + InputOutput, + DefaultVisual(dsp, screen), + mask, &attribs); + + XStoreName(dsp, win, DMX_CONSOLE_NAME); + + /* XXX Set a cursor for the window. */ + + /* Map the window. */ + XMapWindow(dsp, win); + + /* Create GC */ + mask = (GCFunction | GCPlaneMask | GCClipMask | GCForeground | + GCBackground | GCLineWidth | GCLineStyle | GCCapStyle | + GCFillStyle); + gcvals.function = GXcopy; + gcvals.plane_mask = AllPlanes; + gcvals.clip_mask = None; + if (XParseColor(dsp, attribs.colormap, CONSOLE_SCREEN_FG_COLOR, &color) + && XAllocColor(dsp, attribs.colormap, &color)) { + gcvals.foreground = color.pixel; + } else + gcvals.foreground = BlackPixel(dsp, screen); + if (XParseColor(dsp, attribs.colormap, CONSOLE_SCREEN_BG_COLOR, &color) + && XAllocColor(dsp, attribs.colormap, &color)) { + gcvals.background = color.pixel; + } else + gcvals.background = WhitePixel(dsp, screen); + gcvals.line_width = 0; + gcvals.line_style = LineSolid; + gcvals.cap_style = CapNotLast; + gcvals.fill_style = FillSolid; + + dmxConsole->gc = XCreateGC(dsp, win, mask, &gcvals); + + dmxDrawConsole(dmxConsole); + dmxConsole->eventMask = ExposureMask | ResizeRedirectMask; + AddEnabledDevice(XConnectionNumber(dsp)); + /* A handler to check events. */ + RegisterBlockAndWakeupHandlers((BlockHandlerProcPtr)NoopDDA, + dmxConsoleWakeupHandler, dmxConsole); + + /* Wrap screen 0's CloseScreen */ + dmxConsole->CloseScreen = screenInfo.screens[0]->CloseScreen; + screenInfo.screens[0]->CloseScreen = dmxCloseConsoleScreen; + + return TRUE; +} + +static void dmxConsoleProcessInputEvents(DMXInputInfo *dmxInput) +{ + mieqProcessInputEvents(); + miPointerUpdate(); +} + +/* dmxConsoleInitInput initilized input from the console. Checking for + * dmxNumConsoles is done in InitOutput. */ +void dmxConsoleInitInput(DMXInputInfo *dmxInput) +{ + DMXConsoleInfo *dmxConsole = &dmxConsoles[0]; /* FIXME */ + DeviceIntPtr pKeyboard, pPointer; + + pPointer = AddInputDevice(dmxPointerProc, TRUE); + pKeyboard = AddInputDevice(dmxKeyboardProc, TRUE); + RegisterPointerDevice(pPointer); + RegisterKeyboardDevice(pKeyboard); + miRegisterPointerDevice(screenInfo.screens[0], pPointer); + mieqInit(&pKeyboard->public, &pPointer->public); + + pKeyboard->public.devicePrivate = dmxInput; + pPointer->public.devicePrivate = dmxInput; + + dmxInput->display = dmxConsole->display; + dmxInput->window = dmxConsole->window; + dmxInput->pEventMask = &dmxConsole->eventMask; + dmxInput->processInputEvents = dmxConsoleProcessInputEvents; + dmxInput->dmxScreen = NULL; + dmxInput->dmxConsole = dmxConsole; + dmxInput->initPointerX = (int)(dmxConsole->xScale + * dmxScreens[0].width / 2); + dmxInput->initPointerY = (int)(dmxConsole->yScale + * dmxScreens[0].width / 2); + dmxConsole->eventMask |= (EnterWindowMask | LeaveWindowMask); + + dmxLogInput(dmxInput, "Keyboard: %s; Pointer: %s\n", + pKeyboard->name, pPointer->name); +} diff --git a/xc/programs/Xserver/hw/dmx/dmxconsole.h b/xc/programs/Xserver/hw/dmx/dmxconsole.h index f3f933141..68ba95ea4 100644 --- a/xc/programs/Xserver/hw/dmx/dmxconsole.h +++ b/xc/programs/Xserver/hw/dmx/dmxconsole.h @@ -30,11 +30,15 @@ * Authors: * David H. Dawes <dawes@xfree86.org> * Kevin E. Martin <kem@redhat.com> + * Rickard E. (Rik) Faith <faith@redhat.com> * */ -extern Display *dmxConsoleDisplay; -extern Bool dmxOpenConsole(const char *name); -extern void dmxConsoleInitInput(int argc, char **argv); -extern void dmxCloseConsoleDisplay(void); +#ifndef _DMXCONSOLE_H_ +#define _DMXCONSOLE_H_ +extern Bool dmxOpenConsole(DMXConsoleInfo *dmxConsole); +extern void dmxConsoleInitInput(DMXInputInfo *dmxInput); +extern void dmxCloseConsole(DMXConsoleInfo *dmxConsole); + +#endif diff --git a/xc/programs/Xserver/hw/dmx/dmxdummy.c b/xc/programs/Xserver/hw/dmx/dmxdummy.c index b40d86e08..2240c41f5 100644 --- a/xc/programs/Xserver/hw/dmx/dmxdummy.c +++ b/xc/programs/Xserver/hw/dmx/dmxdummy.c @@ -30,6 +30,7 @@ * Authors: * David H. Dawes <dawes@xfree86.org> * Kevin E. Martin <kem@redhat.com> + * Rickard E. (Rik) Faith <faith@redhat.com> * */ @@ -43,6 +44,7 @@ #include "scrnintstr.h" #include "dmx.h" +#include "dmxlog.h" #include "dmxinput.h" #include "dmxdummy.h" @@ -64,10 +66,9 @@ static KeySymsRec keysyms = { /* XXX Does this need to be initialised? */ static CARD8 modmap[MAP_LENGTH]; -static int -MouseOnOff(DeviceIntPtr pDevice, int what) +static int MouseOnOff(DeviceIntPtr pDevice, int what) { - DevicePtr pDev = (DevicePtr)pDevice; + DevicePtr pDev = &pDevice->public; switch (what) { case DEVICE_INIT: @@ -89,10 +90,9 @@ MouseOnOff(DeviceIntPtr pDevice, int what) } -static int -KeyboardOnOff(DeviceIntPtr pDevice, int what) +static int KeyboardOnOff(DeviceIntPtr pDevice, int what) { - DevicePtr pDev = (DevicePtr)pDevice; + DevicePtr pDev = &pDevice->public; switch (what) { case DEVICE_INIT: @@ -113,13 +113,11 @@ KeyboardOnOff(DeviceIntPtr pDevice, int what) return Success; } -static void -dmxDummyProcessInputEvents(void) +static void dmxDummyProcessInputEvents(DMXInputInfo *dmxInput) { } -void -dmxDummyInitInput(int argc, char **argv) +void dmxDummyInitInput(DMXInputInfo *dmxInput) { DeviceIntPtr pKeyboard, pPointer; @@ -129,8 +127,12 @@ dmxDummyInitInput(int argc, char **argv) RegisterKeyboardDevice(pKeyboard); miRegisterPointerDevice(screenInfo.screens[0], pPointer); mieqInit(&pKeyboard->public, &pPointer->public); - bzero(&dmxInputRec, sizeof(dmxInputRec)); - dmxInputRec.processInputEvents = dmxDummyProcessInputEvents; -} + pKeyboard->public.devicePrivate = dmxInput; + pPointer->public.devicePrivate = dmxInput; + + dmxInput->processInputEvents = dmxDummyProcessInputEvents; + dmxLogInput(dmxInput, "Keyboard: %s; Pointer: %s\n", + pKeyboard->name, pPointer->name); +} diff --git a/xc/programs/Xserver/hw/dmx/dmxdummy.h b/xc/programs/Xserver/hw/dmx/dmxdummy.h index 2853cdf8f..249bc1b8f 100644 --- a/xc/programs/Xserver/hw/dmx/dmxdummy.h +++ b/xc/programs/Xserver/hw/dmx/dmxdummy.h @@ -33,5 +33,9 @@ * */ -extern void dmxDummyInitInput(int argc, char **argv); +#ifndef _DMXDUMMY_H_ +#define _DMXDUMMY_H_ +extern void dmxDummyInitInput(DMXInputInfo *dmxInput); + +#endif diff --git a/xc/programs/Xserver/hw/dmx/dmxinit.c b/xc/programs/Xserver/hw/dmx/dmxinit.c index 6855c8cd3..6a68b1ab1 100644 --- a/xc/programs/Xserver/hw/dmx/dmxinit.c +++ b/xc/programs/Xserver/hw/dmx/dmxinit.c @@ -39,31 +39,109 @@ #include "globals.h" #include "dmx.h" +#include "dmxlog.h" #include "dmxinput.h" #include "dmxscrinit.h" #include "dmxcursor.h" #include "dmxconsole.h" +#include "dmxpriv.h" #include "dixstruct.h" #include "panoramiXsrv.h" +/* Global variables available to all Xserver/hw/dmx routines. */ int dmxNumScreens; DMXScreenInfo *dmxScreens; -char **dmxDisplays = NULL; -int dmxNumDisplays = 0; +int dmxNumInputs; +DMXInputInfo *dmxInputs; -Display *dmxConsoleDisplay = NULL; -InputSourceType dmxInputSource = DEFAULT_INPUT_SOURCE; -int dmxInputScreen = 0; -InputRec dmxInputRec; - -static char *consoleName = NULL; -static char *inputName = NULL; +int dmxNumConsoles; +DMXConsoleInfo *dmxConsoles; +/* Access to the X server's connection block -- used to determine which + * visuals Xinerama ultimately decided to export. */ extern char *ConnectionInfo; extern int connBlockScreenStart; +/* dmxAddInputName adds a display name to the dmxScreens + * structure. Note: can't use xalloc/xfree here because OsInit() hasn't + * been called yet. Use malloc/free instead. */ + +static void dmxAddDisplayName(const char *name) +{ + DMXScreenInfo *dmxScreen; + + if (!(dmxScreens = realloc(dmxScreens, + (dmxNumScreens+1) * sizeof(*dmxScreens)))) + dmxLog(dmxFatal, + "dmxAddDisplayName: realloc failed for screen %d (%s)\n", + dmxNumScreens, name); + + dmxScreen = &dmxScreens[dmxNumScreens]; + memset(dmxScreen, 0, sizeof(*dmxScreen)); + dmxScreen->name = name; + dmxScreen->index = dmxNumScreens; + ++dmxNumScreens; +} + +/* dmxAddInputName adds a display name to the dmxInputs structure. Note: + * can't use xalloc/xfree here because OsInit() hasn't been called yet. + * Use malloc/free instead. Note also that some names are special: + * "dummy", "console". */ + +static void dmxAddInputName(const char *name) +{ + DMXInputInfo *dmxInput; + + if (!(dmxInputs = realloc(dmxInputs, + (dmxNumInputs+1) * sizeof(*dmxInputs)))) + dmxLog(dmxFatal, + "dmxAddInputName: realloc failed for input %d (%s)\n", + dmxNumInputs, name); + + dmxInput = &dmxInputs[dmxNumInputs]; + memset(dmxInput, 0, sizeof(*dmxInput)); + dmxInput->name = name; + dmxInput->index = dmxNumInputs; + ++dmxNumInputs; +} + +/* dmxAddConsoleName adds a display name to the dmxConsoles + * structure. Note: can't use xalloc/xfree here because OsInit() hasn't + * been called yet. Use malloc/free instead. Note also that only one + * console is supported at this time, and some code will assume that + * dmxConsoles[0] is the only console. */ + +static void dmxAddConsoleName(const char *name) +{ + DMXConsoleInfo *dmxConsole; + + if (dmxNumConsoles) + dmxLog(dmxFatal, + "dmxAddConsoleName: only one console supported at this time\n"); + + if (!(dmxConsoles = realloc(dmxConsoles, + (dmxNumConsoles+1) * sizeof(*dmxConsoles)))) + dmxLog(dmxFatal, + "dmxAddConsoleName: realloc failed for input %d (%s)\n", + dmxNumConsoles, name); + + dmxConsole = &dmxConsoles[dmxNumConsoles]; + memset(dmxConsole, 0, sizeof(*dmxConsole)); + dmxConsole->name = name; + dmxConsole->index = dmxNumConsoles; + ++dmxNumConsoles; +} + +static void dmxOpenDisplay(DMXScreenInfo *dmxScreen) +{ + if (!(dmxScreen->display = XOpenDisplay(dmxScreen->name))) + dmxLog(dmxFatal, + "dmxOpenDisplay: Unable to open display %s\n", + dmxScreen->name); +} + static void dmxPrintScreenInfo(DMXScreenInfo *dmxScreen) { XWindowAttributes attribs; @@ -147,12 +225,10 @@ static void dmxGetScreenAttribs(DMXScreenInfo *dmxScreen) * depth 8. * More work needs to be done * here. */ - switch (dmxScreen->depth) { - case 4: dmxScreen->bpp = 8; break; /* FIXME? */ - case 15: dmxScreen->bpp = 16; break; - case 24: dmxScreen->bpp = 32; break; - default: dmxScreen->bpp = dmxScreen->depth; break; - } + + if (dmxScreen->depth <= 8) dmxScreen->bpp = 8; + else if (dmxScreen->depth <= 16) dmxScreen->bpp = 16; + else dmxScreen->bpp = 32; dmxPrintScreenInfo(dmxScreen); dmxLogOutput(dmxScreen, "Using %dx%d at depth=%d, bpp=%d\n", @@ -254,27 +330,13 @@ static Bool dmxSetPixmapFormats(ScreenInfo *pScreenInfo, static void dmxDisplayInit(ScreenInfo *pScreenInfo, DMXScreenInfo *dmxScreen, int argc, char *charv[]) { - dmxScreen->display = XOpenDisplay(dmxScreen->name); - - if (!dmxScreen->display) - dmxLog(dmxFatal, - "Unable to open display \"%s\".\n", - XDisplayName(dmxScreen->name)); - + dmxOpenDisplay(dmxScreen); dmxGetScreenAttribs(dmxScreen); dmxGetVisualInfo(dmxScreen); dmxGetColormaps(dmxScreen); dmxGetPixmapFormats(dmxScreen); } -static void dmxDisplayClose(DMXScreenInfo *dmxScreen) -{ - if (!dmxScreen->display) - return; - - XCloseDisplay(dmxScreen->display); -} - static void dmxConnectionBlockCallback(void) { xWindowRoot *root = (xWindowRoot *)(ConnectionInfo+connBlockScreenStart); @@ -311,33 +373,27 @@ static void dmxConnectionBlockCallback(void) void InitOutput(ScreenInfo *pScreenInfo, int argc, char *argv[]) { - int i; + int i; + static unsigned long dmxGeneration = 0; + + /* Allocate private indices. */ + if (dmxGeneration != serverGeneration) { + dmxAllocateScreenPrivIndex(); + dmxGeneration = serverGeneration; + dmxLog(dmxInfo, "Generation %lu\n", dmxGeneration); + } - /* Parse config file to determine the screens to which we need to - connect. Next, connect to each of them in sequence. Until then, - we will simply connect to the default display (of which there is - only one, of course). */ + /* ddxProcessArgument has been called at this point, so dmxScreens + * has been initialized with names and index data. If there were no + * -display command lines, then use the default display. */ - /* dmxDisplays and dmxNumDisplays will be initialised if one or more - -display command line options were specified. Otherwise, assume - just one display -- the default display. */ - - if (dmxNumDisplays == 0) { - dmxNumDisplays = 1; - dmxDisplays = malloc(sizeof(char *)); - if (!dmxDisplays) - dmxLog(dmxFatal, "InitOutput: malloc failed\n"); - dmxDisplays[0] = NULL; - } + if (dmxNumScreens == 0) dmxAddDisplayName("default"); /* FIXME -- + * unimplemented */ - dmxNumScreens = dmxNumDisplays; - dmxScreens = xnfalloc(dmxNumDisplays * sizeof(*dmxScreens)); + /* Open each display and gather information about it. */ - for (i = 0; i < dmxNumScreens; i++) { - dmxScreens[i].index = i; - dmxScreens[i].name = dmxDisplays[i]; + for (i = 0; i < dmxNumScreens; i++) dmxDisplayInit(pScreenInfo, &dmxScreens[i], argc, argv); - } /* Register a Xinerama callback which will run from within * PanoramiXCreateConnection Block. We can use the callback to @@ -345,24 +401,23 @@ void InitOutput(ScreenInfo *pScreenInfo, int argc, char *argv[]) * determined by PanoramiXConsolidate. */ XineramaRegisterConnectionBlockCallback(dmxConnectionBlockCallback); - /* Since we only have a single screen thus far, we only need to set - the pixmap formats to match that screen. */ + the pixmap formats to match that screen. FIXME: this isn't true.*/ if (!dmxSetPixmapFormats(pScreenInfo, &dmxScreens[0])) return; - /* - * XXX Might want to install a signal handler to allow cleaning up after - * unexpected signals. The DIX/OS layer already handles SIGINT and - * SIGTERM, so everything is OK for expected signals. + /* FIXME: Might want to install a signal handler to allow cleaning + * up after unexpected signals. The DIX/OS layer already handles + * SIGINT and SIGTERM, so everything is OK for expected signals. */ - for (i = 0; i < dmxNumScreens; i++) - AddScreen(dmxScreenInit, argc, argv); + for (i = 0; i < dmxNumScreens; i++) AddScreen(dmxScreenInit, argc, argv); - /* - * Position the screen origins. Assume for now that they are in a single - * row with the lowest number screen at the left. + /* FIXME: add a function to parse this + * information from a commandline/config + * file. */ + /* Position the screen origins. Assume for now that they are in a + * single row with the lowest number screen at the left. */ dmxScreens[0].where = PosAbsolute; dmxScreens[0].whereX = 0; @@ -372,39 +427,33 @@ void InitOutput(ScreenInfo *pScreenInfo, int argc, char *argv[]) dmxScreens[i].whereRefScreen = i - 1; } dmxInitOrigins(); - if (consoleName && dmxOpenConsole(consoleName)) { - /* Default to taking input from the console when it's enabled. */ - dmxInputSource = InputFromConsole; + + + /* Create reasonable defaults when some command-line parameters are + * not specified. */ + + if (dmxNumConsoles) { /* If console, use that as default input. */ + if (dmxOpenConsole(&dmxConsoles[0])) { + if (!dmxNumInputs) dmxAddInputName("console"); + } else { /* If error, don't use console. */ + free(dmxConsoles); + dmxConsoles = NULL; + dmxNumConsoles = 0; + } } - /* - * Override the defaults for the input source if inputName is set. - */ - if (inputName) { - Bool match = FALSE; - - if (consoleName && - (!strcmp(inputName, "console") || - !strcmp(inputName, consoleName))) { - dmxInputSource = InputFromConsole; - match = TRUE; - } else if (!strcmp(inputName, "dummy")) { - dmxInputSource = InputFromDummy; - match = TRUE; - } else { - for (i = 0; i < dmxNumScreens; i++) { - if (!strcmp(inputName, dmxScreens[i].name)) { - dmxInputSource = InputFromBackEnd; - dmxInputScreen = i; - match = TRUE; - break; - } - } - } - if (!match) { - dmxLog(dmxWarning, "Can't find a matching input source \"%s\"\n", - inputName); - } + for (i = 0; i < dmxNumInputs; i++) { + /* If no console, can't take input from it. */ + if (!strcmp(dmxInputs[i].name, "console") && !dmxNumConsoles) + dmxLog(dmxFatal, + "Cannot take input from console without using -console\n"); + } + + /* If no input, use first backend + * display or dummy. */ + if (!dmxNumInputs) { + if (dmxNumScreens) dmxAddInputName(dmxScreens[0].name); + else dmxAddInputName("dummy"); } } @@ -412,8 +461,28 @@ void AbortDDX(void) { int i; - for (i = 0; i < dmxNumScreens; i++) - dmxDisplayClose(&dmxScreens[i]); + for (i=0; i < dmxNumScreens; i++) { + DMXScreenInfo *dmxScreen = &dmxScreens[i]; + + if (dmxScreen->display) XCloseDisplay(dmxScreen->display); + dmxScreen->display = NULL; + } + + for (i = 0; i < dmxNumInputs; i++) { + DMXInputInfo *dmxInput = &dmxInputs[i]; + + if (!dmxInput->dmxScreen + && !dmxInput->dmxConsole + && dmxInput->display) XCloseDisplay(dmxInput->display); + dmxInput->display = NULL; + } + + for (i = 0; i < dmxNumConsoles; i++) { + DMXConsoleInfo *dmxConsole = &dmxConsoles[i]; + + if (dmxConsole->display) XCloseDisplay(dmxConsole->display); + dmxConsole->display = NULL; + } } void ddxGiveUp(void) @@ -432,33 +501,17 @@ void OsVendorFatalError(void) } /* Process our command line arguments. */ -int -ddxProcessArgument(int argc, char *argv[], int i) +int ddxProcessArgument(int argc, char *argv[], int i) { - /* - * Note: can't use xalloc/xfree here because OsInit() hasn't been called - * yet. Use malloc/free instead. - */ - if (!strcmp(argv[i], "-display")) { - if (++i < argc) { - dmxNumDisplays++; - dmxDisplays = realloc(dmxDisplays, dmxNumDisplays * sizeof(char *)); - if (!dmxDisplays) - dmxLog(dmxFatal, "ddxProcessArgument: realloc failed\n"); - dmxDisplays[dmxNumDisplays - 1] = argv[i]; - return 2; - } - } else if (!strcmp(argv[i], "-console")) { - if (++i < argc) { - consoleName = argv[i]; - return 2; - } + if (++i < argc) dmxAddDisplayName(argv[i]); + return 2; } else if (!strcmp(argv[i], "-inputfrom")) { - if (++i < argc) { - inputName = argv[i]; - return 2; - } + if (++i < argc) dmxAddInputName(argv[i]); + return 2; + } else if (!strcmp(argv[i], "-console")) { + if (++i < argc) dmxAddConsoleName(argv[i]); + return 2; } return 0; } @@ -472,11 +525,10 @@ void ddxUseMsg(void) ErrorF("\n"); } -CARD32 -GetTimeInMillis() +CARD32 GetTimeInMillis(void) { struct timeval tp; gettimeofday(&tp, 0); - return(tp.tv_sec * 1000) + (tp.tv_usec / 1000); + return tp.tv_sec * 1000 + tp.tv_usec / 1000; } diff --git a/xc/programs/Xserver/hw/dmx/dmxinput.c b/xc/programs/Xserver/hw/dmx/dmxinput.c index f57cef998..c07a6cb22 100644 --- a/xc/programs/Xserver/hw/dmx/dmxinput.c +++ b/xc/programs/Xserver/hw/dmx/dmxinput.c @@ -30,6 +30,7 @@ * Authors: * David H. Dawes <dawes@xfree86.org> * Kevin E. Martin <kem@redhat.com> + * Rickard E. (Rik) Faith <faith@redhat.com> * */ @@ -37,41 +38,41 @@ #include "input.h" #include "dmx.h" +#include "dmxlog.h" #include "dmxinput.h" #include "dmxdummy.h" #include "dmxbeinput.h" #include "dmxconsole.h" -Bool -LegalModifier(unsigned int key, DevicePtr pDev) +Bool LegalModifier(unsigned int key, DevicePtr pDev) { return TRUE; } -void -InitInput(int argc, char **argv) +void InitInput(int argc, char **argv) { - switch (dmxInputSource) { - case InputFromDummy: - dmxDummyInitInput(argc, argv); - break; - case InputFromBackEnd: - dmxBackEndInitInput(argc, argv); - break; - case InputFromConsole: - dmxConsoleInitInput(argc, argv); - break; - case InputFromFrontEnd: - dmxLog(dmxFatal, "InitInput: InputFromFrontEnd not implemented\n"); - break; + int i; + DMXInputInfo *dmxInput; + + if (!dmxNumInputs) + dmxLog(dmxFatal, "InitInput: no inputs specified\n"); + + for (i = 0, dmxInput = &dmxInputs[0]; i < dmxNumInputs; i++, dmxInput++) { + dmxLogInput(dmxInput, "\n"); + if (!strcmp(dmxInput->name, "console")) dmxConsoleInitInput(dmxInput); + else if (!strcmp(dmxInput->name, "dummy")) dmxDummyInitInput(dmxInput); + else dmxBackEndInitInput(dmxInput); } } -void -ProcessInputEvents() +void ProcessInputEvents() { - if (dmxInputRec.processInputEvents) - dmxInputRec.processInputEvents(); -} - + int i; + DMXInputInfo *dmxInput; + /* FIXME: if possible, don't poll every + * input */ + for (i = 0, dmxInput = &dmxInputs[0]; i < dmxNumInputs; i++, dmxInput++) + if (dmxInput->processInputEvents) + dmxInput->processInputEvents(dmxInput); +} diff --git a/xc/programs/Xserver/hw/dmx/dmxinput.h b/xc/programs/Xserver/hw/dmx/dmxinput.h index a40bb7935..4b70248eb 100644 --- a/xc/programs/Xserver/hw/dmx/dmxinput.h +++ b/xc/programs/Xserver/hw/dmx/dmxinput.h @@ -30,21 +30,11 @@ * Authors: * David H. Dawes <dawes@xfree86.org> * Kevin E. Martin <kem@redhat.com> + * Rickard E. (Rik) Faith <faith@redhat.com> * */ -typedef void (*InitInputProc)(int argc, char **argv); -typedef void (*ProcessInputEventsProc)(void); - -typedef struct { - Display *display; - Window window; - long *pEventMask; - ProcessInputEventsProc processInputEvents; - DMXScreenInfo *dmxScreen; - int initPointerX; - int initPointerY; -} InputRec, *InputPtr; - -extern InputRec dmxInputRec; +#ifndef _DMXINPUT_H_ +#define _DMXINPUT_H_ +#endif diff --git a/xc/programs/Xserver/hw/dmx/dmxlog.c b/xc/programs/Xserver/hw/dmx/dmxlog.c index 6b6ac6ad7..cd18b2d43 100644 --- a/xc/programs/Xserver/hw/dmx/dmxlog.c +++ b/xc/programs/Xserver/hw/dmx/dmxlog.c @@ -33,6 +33,7 @@ */ #include "dmx.h" +#include "dmxlog.h" /* This isn't declared in any header files. It should probably be in * Xserver/include/os.h */ @@ -64,8 +65,8 @@ void dmxCloseLogFile(void) } #endif -static void dmxHeader(dmxLogLevel logLevel, DMXScreenInfo *dmxScreen, - const char *note) +static void dmxHeader(dmxLogLevel logLevel, DMXInputInfo *dmxInput, + DMXScreenInfo *dmxScreen) { const char *type = "??"; @@ -77,9 +78,16 @@ static void dmxHeader(dmxLogLevel logLevel, DMXScreenInfo *dmxScreen, case dmxFatal: type = "Fatal Error"; break; } - if (dmxScreen && note) { - ErrorF("(%s) dmx[%s%d/%s]: ", type, - note, dmxScreen->index, dmxScreen->name); + if (dmxInput && dmxScreen) { + ErrorF("(%s) dmx[i%d/%s;o%d/%s]: ", type, + dmxInput->index, dmxInput->name, + dmxScreen->index, dmxScreen->name); + } else if (dmxScreen) { + ErrorF("(%s) dmx[o%d/%s]: ", type, + dmxScreen->index, dmxScreen->name); + } else if (dmxInput) { + ErrorF("(%s) dmx[i%d/%s]: ", type, + dmxInput->index, dmxInput->name); } else { ErrorF("(%s) dmx: ", type); } @@ -107,17 +115,17 @@ void dmxLogOutput(DMXScreenInfo *dmxScreen, const char *format, ...) { va_list args; - dmxHeader(dmxInfo, dmxScreen, "o"); + dmxHeader(dmxInfo, NULL, dmxScreen); va_start(args, format); dmxMessage(dmxInfo, format, args); va_end(args); } -void dmxLogInput(DMXScreenInfo *dmxScreen, const char *format, ...) +void dmxLogInput(DMXInputInfo *dmxInput, const char *format, ...) { va_list args; - dmxHeader(dmxInfo, dmxScreen, "i"); + dmxHeader(dmxInfo, dmxInput, NULL); va_start(args, format); dmxMessage(dmxInfo, format, args); va_end(args); @@ -168,3 +176,43 @@ void dmxLogVisual(DMXScreenInfo *dmxScreen, XVisualInfo *vi, int defaultVisual) defaultVisual ? " *" : ""); } } + +const char *dmxEventName(int type) +{ + switch (type) { + case KeyPress: return "KeyPress"; + case KeyRelease: return "KeyRelease"; + case ButtonPress: return "ButtonPress"; + case ButtonRelease: return "ButtonRelease"; + case MotionNotify: return "MotionNotify"; + case EnterNotify: return "EnterNotify"; + case LeaveNotify: return "LeaveNotify"; + case FocusIn: return "FocusIn"; + case FocusOut: return "FocusOut"; + case KeymapNotify: return "KeymapNotify"; + case Expose: return "Expose"; + case GraphicsExpose: return "GraphicsExpose"; + case NoExpose: return "NoExpose"; + case VisibilityNotify: return "VisibilityNotify"; + case CreateNotify: return "CreateNotify"; + case DestroyNotify: return "DestroyNotify"; + case UnmapNotify: return "UnmapNotify"; + case MapNotify: return "MapNotify"; + case MapRequest: return "MapRequest"; + case ReparentNotify: return "ReparentNotify"; + case ConfigureNotify: return "ConfigureNotify"; + case ConfigureRequest: return "ConfigureRequest"; + case GravityNotify: return "GravityNotify"; + case ResizeRequest: return "ResizeRequest"; + case CirculateNotify: return "CirculateNotify"; + case CirculateRequest: return "CirculateRequest"; + case PropertyNotify: return "PropertyNotify"; + case SelectionClear: return "SelectionClear"; + case SelectionRequest: return "SelectionRequest"; + case SelectionNotify: return "SelectionNotify"; + case ColormapNotify: return "ColormapNotify"; + case ClientMessage: return "ClientMessage"; + case MappingNotify: return "MappingNotify"; + default: return "<unknown>"; + } +} diff --git a/xc/programs/Xserver/hw/dmx/dmxlog.h b/xc/programs/Xserver/hw/dmx/dmxlog.h new file mode 100644 index 000000000..5ad92f462 --- /dev/null +++ b/xc/programs/Xserver/hw/dmx/dmxlog.h @@ -0,0 +1,60 @@ +/* $XFree86$ */ +/* + * Copyright 2001 Red Hat Inc., Durham, North Carolina. + * + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation on the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial + * portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NON-INFRINGEMENT. IN NO EVENT SHALL RED HAT AND/OR THEIR SUPPLIERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +/* + * Authors: + * Rickard E. (Rik) Faith <faith@redhat.com> + * + */ + +#ifndef _DMXLOG_H_ +#define _DMXLOG_H_ + +/* Logging levels -- output is tunable with dmxSetLogLevel. */ +typedef enum { + dmxDebug, + dmxInfo, + dmxWarning, + dmxError, + dmxFatal +} dmxLogLevel; + +/* Logging functions used by Xserver/hw/dmx routines. */ +extern dmxLogLevel dmxSetLogLevel(dmxLogLevel newLevel); +extern dmxLogLevel dmxGetLogLevel(void); +extern void dmxLog(dmxLogLevel logLevel, const char *format, ...); +extern void dmxLogOutput(DMXScreenInfo *dmxScreen, const char *format, ...); +extern void dmxLogInput(DMXInputInfo *dmxInput, const char *format, ...); +extern void dmxLogArgs(dmxLogLevel logLevel, int argc, char **argv); +extern void dmxLogVisual(DMXScreenInfo *dmxScreen, XVisualInfo *vi, + int defaultVisual); +extern void dmxLogAdditional(DMXScreenInfo *dmxScreen, + const char *format, ...); +extern const char *dmxEventName(int type); + +#endif diff --git a/xc/programs/Xserver/hw/dmx/dmxpriv.c b/xc/programs/Xserver/hw/dmx/dmxpriv.c new file mode 100644 index 000000000..59df767a7 --- /dev/null +++ b/xc/programs/Xserver/hw/dmx/dmxpriv.c @@ -0,0 +1,59 @@ +/* $XFree86$ */ +/* + * Copyright 2001 Red Hat Inc., Durham, North Carolina. + * + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation on the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial + * portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NON-INFRINGEMENT. IN NO EVENT SHALL RED HAT AND/OR THEIR SUPPLIERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +/* + * Authors: + * Rickard E. (Rik) Faith <faith@redhat.com> + */ + +#include "dmx.h" +#include "dmxlog.h" +#include "dmxpriv.h" + +static int dmxScreenPrivIndex = -1; + +void dmxSetScreenPriv(ScreenPtr pScreen, pointer ptr) +{ + if (dmxScreenPrivIndex == -1) + dmxLog(dmxFatal, "dmxAddScreenPriv: privates not initialized\n"); + pScreen->devPrivates[dmxScreenPrivIndex].ptr = ptr; + +} + +pointer dmxGetScreenPriv(ScreenPtr pScreen) +{ + if (dmxScreenPrivIndex == -1) return NULL; + return pScreen->devPrivates[dmxScreenPrivIndex].ptr; +} + +void dmxAllocateScreenPrivIndex(void) +{ + if ((dmxScreenPrivIndex = AllocateScreenPrivateIndex()) < 0) + dmxLog(dmxFatal, + "dmxAllocateScreenPrivIndex: cannot allocate private index\n"); +} diff --git a/xc/programs/Xserver/hw/dmx/dmxpriv.h b/xc/programs/Xserver/hw/dmx/dmxpriv.h new file mode 100644 index 000000000..b05cbf2f9 --- /dev/null +++ b/xc/programs/Xserver/hw/dmx/dmxpriv.h @@ -0,0 +1,41 @@ +/* $XFree86$ */ +/* + * Copyright 2001 Red Hat Inc., Durham, North Carolina. + * + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation on the rights to use, copy, modify, merge, + * publish, distribute, sublicense, and/or sell copies of the Software, + * and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial + * portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NON-INFRINGEMENT. IN NO EVENT SHALL RED HAT AND/OR THEIR SUPPLIERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +/* + * Authors: + * Rickard E. (Rik) Faith <faith@redhat.com> + */ + +#ifndef _DMXPRIV_H_ +#define _DMXPRIV_H_ + +extern void dmxAllocateScreenPrivIndex(void); +extern void dmxSetScreenPriv(ScreenPtr pScreen, pointer ptr); +extern pointer dmxGetScreenPriv(ScreenPtr pScreen); + +#endif |