diff options
Diffstat (limited to 'hw/dmx/input/dmxbackend.c')
-rw-r--r-- | hw/dmx/input/dmxbackend.c | 359 |
1 files changed, 204 insertions, 155 deletions
diff --git a/hw/dmx/input/dmxbackend.c b/hw/dmx/input/dmxbackend.c index e917a5c42..9463c87d3 100644 --- a/hw/dmx/input/dmxbackend.c +++ b/hw/dmx/input/dmxbackend.c @@ -63,17 +63,17 @@ /* Private area for backend devices. */ typedef struct _myPrivate { DMX_COMMON_PRIVATE; - int myScreen; - DMXScreenInfo *grabbedScreen; - - int lastX, lastY; - int centerX, centerY; - int relative; - int newscreen; - int initialized; - DevicePtr mou, kbd; - int entered; - int offX, offY; + int myScreen; + DMXScreenInfo *grabbedScreen; + + int lastX, lastY; + int centerX, centerY; + int relative; + int newscreen; + int initialized; + DevicePtr mou, kbd; + int entered; + int offX, offY; } myPrivate; #if DMX_BACKEND_DEBUG @@ -101,27 +101,32 @@ typedef struct _myPrivate { #endif /** Create and return a private data structure. */ -pointer dmxBackendCreatePrivate(DeviceIntPtr pDevice) +pointer +dmxBackendCreatePrivate(DeviceIntPtr pDevice) { GETDMXLOCALFROMPDEVICE; myPrivate *priv = calloc(1, sizeof(*priv)); - priv->dmxLocal = dmxLocal; + + priv->dmxLocal = dmxLocal; return priv; } /** Destroy the private data structure. No checking is performed to * verify that the structure was actually created by * #dmxBackendCreatePrivate. */ -void dmxBackendDestroyPrivate(pointer private) +void +dmxBackendDestroyPrivate(pointer private) { free(private); } -static void *dmxBackendTestScreen(DMXScreenInfo *dmxScreen, void *closure) +static void * +dmxBackendTestScreen(DMXScreenInfo * dmxScreen, void *closure) { - long target = (long)closure; + long target = (long) closure; - if (dmxScreen->index == target) return dmxScreen; + if (dmxScreen->index == target) + return dmxScreen; return NULL; } @@ -130,51 +135,59 @@ static void *dmxBackendTestScreen(DMXScreenInfo *dmxScreen, void *closure) * different screens). Since this is a common operation, the results * are cached. The cache is invalidated if \a priv is NULL (this should * be done with each server generation and reconfiguration). */ -static int dmxBackendSameDisplay(myPrivate *priv, long screen) +static int +dmxBackendSameDisplay(myPrivate * priv, long screen) { - static myPrivate *oldpriv = NULL; - static int oldscreen = -1; - static int retcode = 0; + static myPrivate *oldpriv = NULL; + static int oldscreen = -1; + static int retcode = 0; - if (priv == oldpriv && screen == oldscreen) return retcode; + if (priv == oldpriv && screen == oldscreen) + return retcode; if (!priv) { /* Invalidate cache */ - oldpriv = NULL; + oldpriv = NULL; oldscreen = -1; - retcode = 0; + retcode = 0; return 0; } - if (screen == priv->myScreen) retcode = 1; - else if (screen < 0 || screen >= dmxNumScreens) retcode = 0; + if (screen == priv->myScreen) + retcode = 1; + else if (screen < 0 || screen >= dmxNumScreens) + retcode = 0; else if (dmxPropertyIterate(priv->be, - dmxBackendTestScreen, - (void *)screen)) retcode = 2; - else retcode = 0; + dmxBackendTestScreen, (void *) screen)) + retcode = 2; + else + retcode = 0; - oldpriv = priv; + oldpriv = priv; oldscreen = screen; return retcode; } -static void *dmxBackendTestEvents(DMXScreenInfo *dmxScreen, void *closure) +static void * +dmxBackendTestEvents(DMXScreenInfo * dmxScreen, void *closure) { - XEvent *X = (XEvent *)closure; - + XEvent *X = (XEvent *) closure; + if (XCheckNotMaskEvent(dmxScreen->beDisplay, ExposureMask, X)) return dmxScreen; return NULL; } -static void *dmxBackendTestMotionEvent(DMXScreenInfo *dmxScreen, void *closure) +static void * +dmxBackendTestMotionEvent(DMXScreenInfo * dmxScreen, void *closure) { - XEvent *X = (XEvent *)closure; + XEvent *X = (XEvent *) closure; if (XCheckTypedEvent(dmxScreen->beDisplay, MotionNotify, X)) return dmxScreen; return NULL; } -static DMXScreenInfo *dmxBackendGetEvent(myPrivate *priv, XEvent *X) +static DMXScreenInfo * +dmxBackendGetEvent(myPrivate * priv, XEvent * X) { DMXScreenInfo *dmxScreen; @@ -183,52 +196,63 @@ static DMXScreenInfo *dmxBackendGetEvent(myPrivate *priv, XEvent *X) return NULL; } -static DMXScreenInfo *dmxBackendPendingMotionEvent(myPrivate *priv, int save) +static DMXScreenInfo * +dmxBackendPendingMotionEvent(myPrivate * priv, int save) { DMXScreenInfo *dmxScreen; - XEvent N; + XEvent N; if ((dmxScreen = dmxPropertyIterate(priv->be, dmxBackendTestMotionEvent, &N))) { - if (save) XPutBackEvent(dmxScreen->beDisplay, &N); + if (save) + XPutBackEvent(dmxScreen->beDisplay, &N); return dmxScreen; } return NULL; } -static void *dmxBackendTestWindow(DMXScreenInfo *dmxScreen, void *closure) +static void * +dmxBackendTestWindow(DMXScreenInfo * dmxScreen, void *closure) { - Window win = (Window)(long)closure; - if (dmxScreen->scrnWin == win) return dmxScreen; + Window win = (Window) (long) closure; + + if (dmxScreen->scrnWin == win) + return dmxScreen; return NULL; } -static DMXScreenInfo *dmxBackendFindWindow(myPrivate *priv, Window win) +static DMXScreenInfo * +dmxBackendFindWindow(myPrivate * priv, Window win) { return dmxPropertyIterate(priv->be, dmxBackendTestWindow, - (void *)(long)win); + (void *) (long) win); } /* If the cursor is over a set of overlapping screens and one of those * screens takes backend input, then we want that particular screen to * be current, not one of the other ones. */ -static int dmxBackendFindOverlapping(myPrivate *priv, int screen, int x, int y) +static int +dmxBackendFindOverlapping(myPrivate * priv, int screen, int x, int y) { DMXScreenInfo *start = &dmxScreens[screen]; DMXScreenInfo *pt; - if (!start->over) return screen; - - for (pt = start->over; /* condition at end of loop */; pt = pt->over) { + if (!start->over) + return screen; + + for (pt = start->over; /* condition at end of loop */ ; pt = pt->over) { if (pt->index == priv->myScreen - && dmxOnScreen(x, y, &dmxScreens[pt->index])) return pt->index; - if (pt == start) break; + && dmxOnScreen(x, y, &dmxScreens[pt->index])) + return pt->index; + if (pt == start) + break; } return screen; } /* Return non-zero if \a x and \a y are off \a screen. */ -static int dmxBackendOffscreen(int screen, int x, int y) +static int +dmxBackendOffscreen(int screen, int x, int y) { DMXScreenInfo *dmxScreen = &dmxScreens[screen]; @@ -237,16 +261,17 @@ static int dmxBackendOffscreen(int screen, int x, int y) /** This routine is called from #dmxCoreMotion for each motion * event. \a x and \a y are global coordinants. */ -void dmxBackendUpdatePosition(pointer private, int x, int y) +void +dmxBackendUpdatePosition(pointer private, int x, int y) { GETPRIVFROMPRIVATE; - int screen = miPointerGetScreen(inputInfo.pointer)->myNum; - DMXScreenInfo *dmxScreen = &dmxScreens[priv->myScreen]; - int oldRelative = priv->relative; - int topscreen = dmxBackendFindOverlapping(priv, screen, x, y); - int same = dmxBackendSameDisplay(priv, topscreen); - int offscreen = dmxBackendOffscreen(priv->myScreen, x, y); - int offthis = dmxBackendOffscreen(screen, x, y); + int screen = miPointerGetScreen(inputInfo.pointer)->myNum; + DMXScreenInfo *dmxScreen = &dmxScreens[priv->myScreen]; + int oldRelative = priv->relative; + int topscreen = dmxBackendFindOverlapping(priv, screen, x, y); + int same = dmxBackendSameDisplay(priv, topscreen); + int offscreen = dmxBackendOffscreen(priv->myScreen, x, y); + int offthis = dmxBackendOffscreen(screen, x, y); DMXDBG9("dmxBackendUpdatePosition(%d,%d) my=%d mi=%d rel=%d" " topscreen=%d same=%d offscreen=%d offthis=%d\n", @@ -262,13 +287,15 @@ void dmxBackendUpdatePosition(pointer private, int x, int y) DMXDBG0(" Off screen, but not absolute\n"); priv->relative = 0; } - } else { + } + else { if (!priv->relative) { DMXDBG0(" Off screen, but not relative\n"); priv->relative = 1; } } - } else { + } + else { if (topscreen != screen) { DMXDBG2(" Using screen %d instead of %d (from mi)\n", topscreen, screen); @@ -278,7 +305,8 @@ void dmxBackendUpdatePosition(pointer private, int x, int y) DMXDBG0(" On screen, but not absolute\n"); priv->relative = 0; } - } else { + } + else { if (!priv->relative) { DMXDBG0(" Not on screen, but not relative\n"); priv->relative = 1; @@ -287,12 +315,11 @@ void dmxBackendUpdatePosition(pointer private, int x, int y) } if (oldRelative != priv->relative) { - DMXDBG2(" Do switch, relative=%d same=%d\n", - priv->relative, same); + DMXDBG2(" Do switch, relative=%d same=%d\n", priv->relative, same); /* Discard all pre-switch events */ dmxSync(dmxScreen, TRUE); while (dmxBackendPendingMotionEvent(priv, FALSE)); - + if (dmxInput->console && offscreen) { /* Our special case is a console window and a backend window * share a display. In this case, the cursor is either on @@ -309,7 +336,8 @@ void dmxBackendUpdatePosition(pointer private, int x, int y) } DMXDBG0(" Capturing console\n"); dmxConsoleCapture(dmxInput); - } else { + } + else { priv->newscreen = 1; if (priv->relative && !dmxInput->console) { DMXDBG5(" Hide cursor; warp from %d,%d to %d,%d on %d\n", @@ -317,12 +345,13 @@ void dmxBackendUpdatePosition(pointer private, int x, int y) priv->myScreen); dmxConsoleUncapture(dmxInput); dmxHideCursor(dmxScreen); - priv->lastX = priv->centerX; - priv->lastY = priv->centerY; + priv->lastX = priv->centerX; + priv->lastY = priv->centerY; XWarpPointer(priv->display, None, priv->window, 0, 0, 0, 0, priv->lastX, priv->lastY); dmxSync(dmxScreen, TRUE); - } else { + } + else { DMXDBG0(" Check cursor\n"); dmxCheckCursor(); } @@ -332,37 +361,37 @@ void dmxBackendUpdatePosition(pointer private, int x, int y) /** Get events from the X queue on the backend servers and put the * events into the DMX event queue. */ -void dmxBackendCollectEvents(DevicePtr pDev, - dmxMotionProcPtr motion, - dmxEnqueueProcPtr enqueue, - dmxCheckSpecialProcPtr checkspecial, - DMXBlockType block) +void +dmxBackendCollectEvents(DevicePtr pDev, + dmxMotionProcPtr motion, + dmxEnqueueProcPtr enqueue, + dmxCheckSpecialProcPtr checkspecial, DMXBlockType block) { GETPRIVFROMPDEV; GETDMXINPUTFROMPRIV; - XEvent X; - DMXScreenInfo *dmxScreen; - int left = 0; - int entered = priv->entered; - int ignoreLeave = 0; - int v[2]; - int retcode; + XEvent X; + DMXScreenInfo *dmxScreen; + int left = 0; + int entered = priv->entered; + int ignoreLeave = 0; + int v[2]; + int retcode; while ((dmxScreen = dmxBackendGetEvent(priv, &X))) { - switch (X.type) { + switch (X.type) { case EnterNotify: dmxCommonSaveState(priv); if (entered++) continue; priv->entered = 1; - ignoreLeave = 1; + ignoreLeave = 1; DMXDBG5("dmxBackendCollectEvents: Enter %lu %d,%d; GRAB %s %p\n", X.xcrossing.root, X.xcrossing.x, X.xcrossing.y, dmxScreen->name, dmxScreen->beDisplay); XRaiseWindow(dmxScreen->beDisplay, dmxScreen->scrnWin); priv->grabbedScreen = dmxScreen; if ((retcode = XGrabPointer(dmxScreen->beDisplay, - dmxScreen->scrnWin, + dmxScreen->scrnWin, True, 0, GrabModeAsync, GrabModeAsync, None, None, CurrentTime))) { @@ -382,15 +411,14 @@ void dmxBackendCollectEvents(DevicePtr pDev, DMXDBG7("dmxBackendCollectEvents: Leave %lu %d,%d %d %d %s %s\n", X.xcrossing.root, X.xcrossing.x, X.xcrossing.y, X.xcrossing.detail, X.xcrossing.focus, - priv->grabbedScreen ? "UNGRAB" : "", - dmxScreen->name); + priv->grabbedScreen ? "UNGRAB" : "", dmxScreen->name); if (priv->grabbedScreen) { XUngrabPointer(priv->grabbedScreen->beDisplay, CurrentTime); dmxSync(priv->grabbedScreen, TRUE); priv->grabbedScreen = NULL; } break; - case MotionNotify: + case MotionNotify: DMXDBG9("dmxBackendCollectEvents: MotionNotify %d/%d (mi %d)" " newscreen=%d: %d %d (e=%d; last=%d,%d)\n", dmxScreen->index, priv->myScreen, @@ -409,12 +437,17 @@ void dmxBackendCollectEvents(DevicePtr pDev, int newY = X.xmotion.y - dmxScreen->rootY; if (!priv->newscreen) { - int width = dmxScreen->rootWidth; + int width = dmxScreen->rootWidth; int height = dmxScreen->rootHeight; - if (!newX) newX = -1; - if (newX == width - 1) newX = width; - if (!newY) newY = -1; - if (newY == height - 1) newY = height; + + if (!newX) + newX = -1; + if (newX == width - 1) + newX = width; + if (!newY) + newY = -1; + if (newY == height - 1) + newY = height; } priv->newscreen = 0; v[0] = dmxScreen->rootXOrigin + newX; @@ -426,13 +459,15 @@ void dmxBackendCollectEvents(DevicePtr pDev, priv->be->scrnWidth, priv->be->scrnHeight); motion(priv->mou, v, 0, 2, DMX_ABSOLUTE, block); priv->entered = 0; - } else { + } + else { int newX = priv->lastX - X.xmotion.x; int newY = priv->lastY - X.xmotion.y; + priv->lastX = X.xmotion.x; priv->lastY = X.xmotion.y; - v[0] = newX; - v[1] = newY; + v[0] = newX; + v[1] = newY; DMXDBG2(" Relative move: %d, %d\n", v[0], v[1]); motion(priv->mou, v, 0, 2, DMX_RELATIVE, block); } @@ -444,7 +479,7 @@ void dmxBackendCollectEvents(DevicePtr pDev, (dmxScreen->rootYOrigin + X.xmotion.y - dmxScreen->rootY)); } - break; + break; case KeyPress: case KeyRelease: @@ -453,71 +488,77 @@ void dmxBackendCollectEvents(DevicePtr pDev, case ButtonPress: case ButtonRelease: /* fall-through */ - default: - /* Pass the whole event here, because - * this may be an extension event. */ + default: + /* Pass the whole event here, because + * this may be an extension event. */ enqueue(priv->mou, X.type, X.xbutton.button, 0, &X, block); - break; - } + break; + } } } /** Called after input events are processed from the DMX queue. No * event processing actually takes place here, but this is a convenient * place to update the pointer. */ -void dmxBackendProcessInput(pointer private) +void +dmxBackendProcessInput(pointer private) { GETPRIVFROMPRIVATE; DMXDBG6("dmxBackendProcessInput: myScreen=%d relative=%d" " last=%d,%d center=%d,%d\n", priv->myScreen, priv->relative, - priv->lastX, priv->lastY, - priv->centerX, priv->centerY); + priv->lastX, priv->lastY, priv->centerX, priv->centerY); if (priv->relative && !dmxInput->console && (priv->lastX != priv->centerX || priv->lastY != priv->centerY)) { DMXDBG4(" warping pointer from last=%d,%d to center=%d,%d\n", priv->lastX, priv->lastY, priv->centerX, priv->centerY); - priv->lastX = priv->centerX; - priv->lastY = priv->centerY; + priv->lastX = priv->centerX; + priv->lastY = priv->centerY; XWarpPointer(priv->display, None, priv->window, 0, 0, 0, 0, priv->lastX, priv->lastY); dmxSync(&dmxScreens[priv->myScreen], TRUE); } } -static void dmxBackendComputeCenter(myPrivate *priv) +static void +dmxBackendComputeCenter(myPrivate * priv) { int centerX; int centerY; - - centerX = priv->be->rootWidth / 2 + priv->be->rootX; - centerY = priv->be->rootHeight / 2 + priv->be->rootY; - if (centerX > priv->be->rootWidth) centerX = priv->be->rootWidth - 1; - if (centerY > priv->be->rootHeight) centerY = priv->be->rootHeight - 1; - if (centerX < 1) centerX = 1; - if (centerY < 1) centerY = 1; + centerX = priv->be->rootWidth / 2 + priv->be->rootX; + centerY = priv->be->rootHeight / 2 + priv->be->rootY; + + if (centerX > priv->be->rootWidth) + centerX = priv->be->rootWidth - 1; + if (centerY > priv->be->rootHeight) + centerY = priv->be->rootHeight - 1; + if (centerX < 1) + centerX = 1; + if (centerY < 1) + centerY = 1; priv->centerX = centerX; priv->centerY = centerY; } -static DMXScreenInfo *dmxBackendInitPrivate(DevicePtr pDev) +static DMXScreenInfo * +dmxBackendInitPrivate(DevicePtr pDev) { GETPRIVFROMPDEV; - DMXInputInfo *dmxInput = &dmxInputs[dmxLocal->inputIdx]; - DMXScreenInfo *dmxScreen; - int i; + DMXInputInfo *dmxInput = &dmxInputs[dmxLocal->inputIdx]; + DMXScreenInfo *dmxScreen; + int i; /* Fill in myPrivate */ - for (i = 0,dmxScreen = &dmxScreens[0]; i<dmxNumScreens; i++,dmxScreen++) { + for (i = 0, dmxScreen = &dmxScreens[0]; i < dmxNumScreens; i++, dmxScreen++) { if (dmxPropertySameDisplay(dmxScreen, dmxInput->name)) { - priv->display = dmxScreen->beDisplay; - priv->window = dmxScreen->scrnWin; - priv->be = dmxScreen; + priv->display = dmxScreen->beDisplay; + priv->window = dmxScreen->scrnWin; + priv->be = dmxScreen; break; } } @@ -532,80 +573,88 @@ static DMXScreenInfo *dmxBackendInitPrivate(DevicePtr pDev) /** Re-initialized the backend device described by \a pDev (after a * reconfig). */ -void dmxBackendLateReInit(DevicePtr pDev) +void +dmxBackendLateReInit(DevicePtr pDev) { GETPRIVFROMPDEV; - int x, y; + int x, y; DMXDBG1("dmxBackendLateReInit miPointerCurrentScreen() = %p\n", miPointerCurrentScreen()); - dmxBackendSameDisplay(NULL, 0); /* Invalidate cache */ + dmxBackendSameDisplay(NULL, 0); /* Invalidate cache */ dmxBackendInitPrivate(pDev); dmxBackendComputeCenter(priv); dmxGetGlobalPosition(&x, &y); - dmxInvalidateGlobalPosition(); /* To force event processing */ + dmxInvalidateGlobalPosition(); /* To force event processing */ dmxBackendUpdatePosition(priv, x, y); } /** Initialized the backend device described by \a pDev. */ -void dmxBackendInit(DevicePtr pDev) +void +dmxBackendInit(DevicePtr pDev) { GETPRIVFROMPDEV; - DMXScreenInfo *dmxScreen; + DMXScreenInfo *dmxScreen; - dmxBackendSameDisplay(NULL, 0); /* Invalidate cache */ + dmxBackendSameDisplay(NULL, 0); /* Invalidate cache */ - if (dmxLocal->type == DMX_LOCAL_MOUSE) priv->mou = pDev; - if (dmxLocal->type == DMX_LOCAL_KEYBOARD) priv->kbd = pDev; - if (priv->initialized++) return; /* Only do once for mouse/keyboard pair */ + if (dmxLocal->type == DMX_LOCAL_MOUSE) + priv->mou = pDev; + if (dmxLocal->type == DMX_LOCAL_KEYBOARD) + priv->kbd = pDev; + if (priv->initialized++) + return; /* Only do once for mouse/keyboard pair */ dmxScreen = dmxBackendInitPrivate(pDev); /* Finish initialization using computed values or constants. */ dmxBackendComputeCenter(priv); - priv->eventMask = (EnterWindowMask|LeaveWindowMask); - priv->myScreen = dmxScreen->index; - priv->lastX = priv->centerX; - priv->lastY = priv->centerY; - priv->relative = 0; - priv->newscreen = 0; + priv->eventMask = (EnterWindowMask | LeaveWindowMask); + priv->myScreen = dmxScreen->index; + priv->lastX = priv->centerX; + priv->lastY = priv->centerY; + priv->relative = 0; + priv->newscreen = 0; } /** Get information about the backend pointer (for initialization). */ -void dmxBackendMouGetInfo(DevicePtr pDev, DMXLocalInitInfoPtr info) +void +dmxBackendMouGetInfo(DevicePtr pDev, DMXLocalInitInfoPtr info) { const DMXScreenInfo *dmxScreen = dmxBackendInitPrivate(pDev); - info->buttonClass = 1; + info->buttonClass = 1; dmxCommonMouGetMap(pDev, info->map, &info->numButtons); - info->valuatorClass = 1; - info->numRelAxes = 2; - info->minval[0] = 0; - info->minval[1] = 0; - info->maxval[0] = dmxScreen->beWidth; - info->maxval[1] = dmxScreen->beHeight; - info->res[0] = 1; - info->minres[0] = 0; - info->maxres[0] = 1; + info->valuatorClass = 1; + info->numRelAxes = 2; + info->minval[0] = 0; + info->minval[1] = 0; + info->maxval[0] = dmxScreen->beWidth; + info->maxval[1] = dmxScreen->beHeight; + info->res[0] = 1; + info->minres[0] = 0; + info->maxres[0] = 1; info->ptrFeedbackClass = 1; } /** Get information about the backend keyboard (for initialization). */ -void dmxBackendKbdGetInfo(DevicePtr pDev, DMXLocalInitInfoPtr info) +void +dmxBackendKbdGetInfo(DevicePtr pDev, DMXLocalInitInfoPtr info) { dmxCommonKbdGetInfo(pDev, info); - info->keyboard = 1; - info->keyClass = 1; + info->keyboard = 1; + info->keyClass = 1; dmxCommonKbdGetMap(pDev, &info->keySyms, info->modMap); - info->freemap = 1; - info->focusClass = 1; + info->freemap = 1; + info->focusClass = 1; info->kbdFeedbackClass = 1; } /** Process #DMXFunctionType functions. The only function handled here * is to acknowledge a pending server shutdown. */ -int dmxBackendFunctions(pointer private, DMXFunctionType function) +int +dmxBackendFunctions(pointer private, DMXFunctionType function) { switch (function) { case DMX_FUNCTION_TERMINATE: |