From 2c3764b4901931282e323c42d6fae3cc85e9e030 Mon Sep 17 00:00:00 2001 From: Colin Hill Date: Wed, 16 Feb 2011 13:46:23 -0800 Subject: Made device pointer shared between input and xlibclient.c --- src/client.h | 2 ++ src/driver.c | 24 ++++++++++++++++++------ src/xNestedMouse.c | 40 +++++++++++++++++++++------------------- src/xNestedMouse.h | 9 ++++++++- src/xlibclient.c | 14 +++++++++++++- 5 files changed, 62 insertions(+), 27 deletions(-) diff --git a/src/client.h b/src/client.h index 25e066a..a32c61a 100644 --- a/src/client.h +++ b/src/client.h @@ -58,3 +58,5 @@ void NestedClientTimerCallback(NestedClientPrivatePtr pPriv); void NestedClientCloseScreen(NestedClientPrivatePtr pPriv); +void NestedClientSetDevicePtr(NestedClientPrivatePtr pPriv, void* dev); + diff --git a/src/driver.c b/src/driver.c index 6caa1ec..65f3c73 100644 --- a/src/driver.c +++ b/src/driver.c @@ -120,6 +120,15 @@ _X_EXPORT DriverRec NESTED = { 0 /* PciProbe */ }; +_X_EXPORT InputDriverRec NESTEDMOUSE = { + 1, + "nestedmouse", + NULL, + NestedMousePreInit, + NestedMouseUnInit, + NULL, + 0, +}; static XF86ModuleVersionInfo NestedVersRec = { NESTED_DRIVER_NAME, @@ -147,7 +156,7 @@ typedef struct NestedPrivate { char *displayName; int originX; int originY; - NestedClientPrivatePtr clientData; + NestedClientPrivatePtr clientData; CreateScreenResourcesProcPtr CreateScreenResources; CloseScreenProcPtr CloseScreen; OsTimerPtr timer; @@ -172,10 +181,9 @@ NestedSetup(pointer module, pointer opts, int *errmaj, int *errmin) { if (!setupDone) { setupDone = TRUE; + xf86AddDriver(&NESTED, module, HaveDriverFuncs); - - //pNested->timer = - TimerSet(NULL, 0, 1, NestedMouseTimer, module); + xf86AddInputDriver(&NESTEDMOUSE, module, 0); return (pointer)1; } else { @@ -215,7 +223,6 @@ NestedProbe(DriverPtr drv, int flags) { return FALSE; } - if (numDevSections > 0) { for(i = 0; i < numDevSections; i++) { pScrn = NULL; @@ -398,7 +405,7 @@ static Bool NestedPreInit(ScrnInfoPtr pScrn, int flags) { pScrn->memPhysBase = 0; pScrn->fbOffset = 0; - + return TRUE; } @@ -592,6 +599,8 @@ static Bool NestedScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, /* Save state: * NestedSave(pScrn); */ + + //Load_Nested_Mouse(); pNested->clientData = NestedClientCreateScreen(scrnIndex, pNested->displayName, @@ -602,10 +611,13 @@ static Bool NestedScreenInit(int scrnIndex, ScreenPtr pScreen, int argc, pScrn->depth, pScrn->bitsPerPixel, &redMask, &greenMask, &blueMask); + if (!pNested->clientData) { xf86DrvMsg(scrnIndex, X_ERROR, "Failed to create client screen\n"); return FALSE; } + + TimerSet(NULL, 0, 1, NestedMouseTimer, pNested->clientData); miClearVisualTypes(); if (!miSetVisualTypesAndMasks(pScrn->depth, diff --git a/src/xNestedMouse.c b/src/xNestedMouse.c index 6a13eb7..ba7b3cf 100644 --- a/src/xNestedMouse.c +++ b/src/xNestedMouse.c @@ -12,7 +12,6 @@ #include #include #include -#include "xf86Xinput.h" #include "config.h" @@ -22,8 +21,6 @@ #define SYSCALL(call) while (((call) == -1) && (errno == EINTR)) -static InputInfoPtr NestedMousePreInit(InputDriverPtr drv, IDevPtr dev, int flags); -static void NestedMouseUnInit(InputDriverPtr drv, InputInfoPtr pInfo, int flags); static pointer NestedMousePlug(pointer module, pointer options, int *errmaj, int *errmin); static void NestedMouseUnplug(pointer p); static void NestedMouseReadInput(InputInfoPtr pInfo); @@ -31,16 +28,6 @@ static int NestedMouseControl(DeviceIntPtr device,int what); static int _nested_mouse_init_buttons(DeviceIntPtr device); static int _nested_mouse_init_axes(DeviceIntPtr device); -_X_EXPORT InputDriverRec NESTEDMOUSE = { - 1, - "nestedmouse", - NULL, - NestedMousePreInit, - NestedMouseUnInit, - NULL, - 0, -}; - typedef struct _NestedMouseDeviceRec { char *device; int version; /* Driver version */ @@ -69,7 +56,7 @@ _X_EXPORT XF86ModuleData nestedMouseModuleData = { &NestedMouseUnplug }; -static InputInfoPtr +InputInfoPtr NestedMousePreInit(InputDriverPtr drv, IDevPtr dev, int flags) { InputInfoPtr pInfo; NestedMouseDevicePtr pNestedMouse; @@ -97,7 +84,7 @@ NestedMousePreInit(InputDriverPtr drv, IDevPtr dev, int flags) { /* process driver specific options */ pNestedMouse->device = xf86SetStrOption(dev->commonOptions, "Device", - "/dev/null"); + "/dev/random"); xf86Msg(X_INFO, "%s: Using device %s.\n", pInfo->name, pNestedMouse->device); @@ -111,9 +98,12 @@ NestedMousePreInit(InputDriverPtr drv, IDevPtr dev, int flags) { if (pInfo->fd == -1) { xf86Msg(X_ERROR, "%s: failed to open %s.", pInfo->name, pNestedMouse->device); + pInfo->private = NULL; + xfree(pNestedMouse); xf86DeleteInput(pInfo, 0); + return NULL; } @@ -122,13 +112,13 @@ NestedMousePreInit(InputDriverPtr drv, IDevPtr dev, int flags) { return pInfo; } -static void +void NestedMouseUnInit(InputDriverPtr drv, InputInfoPtr pInfo, int flags) { } static pointer NestedMousePlug(pointer module, pointer options, int *errmaj, int *errmin) { - xf86AddInputDriver(&NESTEDMOUSE, module, 0); + //xf86AddInputDriver(&NESTEDMOUSE, module, 0); return module; } @@ -185,10 +175,10 @@ NestedMouseReadInput(InputInfoPtr pInfo) { } //Helper func to load mouse driver at the init of nested video driver -void Load_Nested_Mouse(pointer module) { +void Load_Nested_Mouse(NestedClientPrivatePtr clientData) { xf86Msg(X_INFO, "NESTED MOUSE LOADING\n"); - xf86AddInputDriver(&NESTEDMOUSE, module, 0); + //xf86AddInputDriver(&NESTEDMOUSE, module, 0); // Create input options for our invocation to NewInputDeviceRequest(). InputOption* options = (InputOption*)xalloc(sizeof(InputOption)); @@ -209,6 +199,18 @@ void Load_Nested_Mouse(pointer module) { xf86Msg(X_ERROR, "Failed to load input driver.\n"); } + InputInfoPtr pInfo = dev->public.devicePrivate; + NestedClientSetDevicePtr(clientData, pInfo->dev); + xf86Msg(X_INFO, "NESTED MOUSE LOADING DONE\n"); } +void NestedPostMouseMotion(void* dev, int x, int y) { + xf86Msg(X_INFO, "Mouse move: %i %i\n", x, y); + + if (dev == NULL) { + xf86Msg(X_ERROR, "Null device.\n"); + } + + xf86PostMotionEvent(dev, 1, 0, 2, 1, 1); +} diff --git a/src/xNestedMouse.h b/src/xNestedMouse.h index 53d4ad5..b4d5ddb 100644 --- a/src/xNestedMouse.h +++ b/src/xNestedMouse.h @@ -1 +1,8 @@ -void Load_Nested_Mouse(pointer module); +#include "xf86Xinput.h" + +void Load_Nested_Mouse(NestedClientPrivatePtr clientData); + +InputInfoPtr NestedMousePreInit(InputDriverPtr drv, IDevPtr dev, int flags); +void NestedMouseUnInit(InputDriverPtr drv, InputInfoPtr pInfo, int flags); + +void NestedPostMouseMotion(void* dev, int x, int y); diff --git a/src/xlibclient.c b/src/xlibclient.c index b044769..101c4b1 100644 --- a/src/xlibclient.c +++ b/src/xlibclient.c @@ -50,6 +50,8 @@ struct NestedClientPrivate { Cursor mycursor; /* Test cursor */ Pixmap bitmapNoData; XColor color1; + + void* dev; }; /* Checks if a display is open */ @@ -211,7 +213,9 @@ xf86DrvMsg(scrnIndex, X_INFO, "blu_mask: 0x%lx\n", pPriv->img->blue_mask); break; } } - + + pPriv->dev = NULL; + return pPriv; } @@ -268,6 +272,10 @@ NestedClientTimerCallback(NestedClientPrivatePtr pPriv) { } if (ev.type == MotionNotify) { + int x = ((XMotionEvent*)&ev)->x; + int y = ((XMotionEvent*)&ev)->y; + + NestedPostMouseMotion(pPriv->dev, x, y); /* XDrawString(pPriv->display, pPriv->window, DefaultGC(pPriv->display, pPriv->screenNumber), @@ -338,3 +346,7 @@ NestedClientCloseScreen(NestedClientPrivatePtr pPriv) { XDestroyImage(pPriv->img); XCloseDisplay(pPriv->display); } + +void NestedClientSetDevicePtr(NestedClientPrivatePtr pPriv, void* dev) { + pPriv->dev = dev; +} -- cgit v1.2.3