diff options
author | Colin Hill <colin.james.hill@gmail.com> | 2011-02-16 23:40:13 -0800 |
---|---|---|
committer | Colin Hill <colin.james.hill@gmail.com> | 2011-02-16 23:40:13 -0800 |
commit | b8c35929de5f16ad372081554a35060aa3d0961e (patch) | |
tree | 1bbbb68bf402492e3780e05af119bc446c4eede2 | |
parent | b315b79f3ff75dcfb31ba746483fd6dd7364698c (diff) |
Massive code clean up. Mouse motion/buttons and keyboard works.
-rw-r--r-- | src/Makefile.am | 2 | ||||
-rw-r--r-- | src/driver.c | 15 | ||||
-rw-r--r-- | src/xNestedMouse.c | 272 | ||||
-rw-r--r-- | src/xNestedMouse.h | 10 | ||||
-rw-r--r-- | src/xlibclient.c | 62 |
5 files changed, 20 insertions, 341 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index ef96d47..282127a 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -27,4 +27,4 @@ nested_drv_la_LTLIBRARIES = nested_drv.la nested_drv_la_LDFLAGS = -module -avoid-version $(X11_LIBS) $(XEXT_LIBS) nested_drv_ladir = @moduledir@/drivers -nested_drv_la_SOURCES = driver.c xNestedMouse.c xlibclient.c client.h +nested_drv_la_SOURCES = driver.c input.c xlibclient.c client.h diff --git a/src/driver.c b/src/driver.c index 3730973..0980297 100644 --- a/src/driver.c +++ b/src/driver.c @@ -37,8 +37,7 @@ #include "config.h" #include "client.h" - -#include "xNestedMouse.h" +#include "input.h" #define NESTED_VERSION 0 #define NESTED_NAME "NESTED" @@ -120,12 +119,12 @@ _X_EXPORT DriverRec NESTED = { 0 /* PciProbe */ }; -_X_EXPORT InputDriverRec NESTEDMOUSE = { +_X_EXPORT InputDriverRec NESTEDINPUT = { 1, - "nestedmouse", + "nestedinput", NULL, - NestedMousePreInit, - NestedMouseUnInit, + NestedInputPreInit, + NestedInputUnInit, NULL, 0, }; @@ -171,7 +170,7 @@ typedef struct NestedPrivate { static CARD32 NestedMouseTimer(OsTimerPtr timer, CARD32 time, pointer arg) { - Load_Nested_Mouse(arg); + NestedInputLoadDriver(arg); return 0; } @@ -183,7 +182,7 @@ NestedSetup(pointer module, pointer opts, int *errmaj, int *errmin) { setupDone = TRUE; xf86AddDriver(&NESTED, module, HaveDriverFuncs); - xf86AddInputDriver(&NESTEDMOUSE, module, 0); + xf86AddInputDriver(&NESTEDINPUT, module, 0); return (pointer)1; } else { diff --git a/src/xNestedMouse.c b/src/xNestedMouse.c deleted file mode 100644 index 05b4e27..0000000 --- a/src/xNestedMouse.c +++ /dev/null @@ -1,272 +0,0 @@ -#include <errno.h> -#include <fcntl.h> -#include <stdlib.h> -#include <string.h> -#include <unistd.h> - -#include <xorg/xorg-server.h> -#include <xorg/fb.h> -#include <xorg/micmap.h> -#include <xorg/mipointer.h> -#include <xorg/shadow.h> -#include <xorg/xf86.h> -#include <xorg/xf86Module.h> -#include <xorg/xf86str.h> - -#include "config.h" - -#include "client.h" - -#include "xNestedMouse.h" - -#define SYSCALL(call) while (((call) == -1) && (errno == EINTR)) - -static pointer NestedMousePlug(pointer module, pointer options, int *errmaj, int *errmin); -static void NestedMouseUnplug(pointer p); -static void NestedMouseReadInput(InputInfoPtr pInfo); -static int NestedMouseControl(DeviceIntPtr device,int what); -static int _nested_mouse_init_buttons(DeviceIntPtr device); -static int _nested_mouse_init_axes(DeviceIntPtr device); - -typedef struct _NestedMouseDeviceRec { - char *device; - int version; /* Driver version */ - Atom* labels; - int num_vals; - int axes; -} NestedMouseDeviceRec, *NestedMouseDevicePtr; - -static XF86ModuleVersionInfo NestedMouseVersionRec = { - "nestedmouse", - MODULEVENDORSTRING, - MODINFOSTRING1, - MODINFOSTRING2, - XORG_VERSION_CURRENT, - PACKAGE_VERSION_MAJOR, PACKAGE_VERSION_MINOR, - PACKAGE_VERSION_PATCHLEVEL, - ABI_CLASS_XINPUT, - ABI_XINPUT_VERSION, - MOD_CLASS_XINPUT, - {0, 0, 0, 0} -}; - -_X_EXPORT XF86ModuleData nestedMouseModuleData = { - &NestedMouseVersionRec, - &NestedMousePlug, - &NestedMouseUnplug -}; - -InputInfoPtr -NestedMousePreInit(InputDriverPtr drv, IDevPtr dev, int flags) { - InputInfoPtr pInfo; - NestedMouseDevicePtr pNestedMouse; - - if (!(pInfo = xf86AllocateInput(drv, 0))) - return NULL; - - pNestedMouse = xcalloc(1, sizeof(NestedMouseDeviceRec)); - - if (!pNestedMouse) { - pInfo->private = NULL; - xf86DeleteInput(pInfo, 0); - return NULL; - } - - pInfo->private = pNestedMouse; - pInfo->name = xstrdup(dev->identifier); - pInfo->flags = 0; - pInfo->type_name = XI_MOUSE; /* see XI.h */ - pInfo->conf_idev = dev; - pInfo->read_input = NestedMouseReadInput; /* new data avl */ - pInfo->switch_mode = NULL; /* toggle absolute/relative mode */ - pInfo->device_control = NestedMouseControl; /* enable/disable dev */ - - /* process driver specific options */ - pNestedMouse->device = xf86SetStrOption(dev->commonOptions, - "Device", - "/dev/random"); - - xf86Msg(X_INFO, "%s: Using device %s.\n", pInfo->name, pNestedMouse->device); - - /* process generic options */ - xf86CollectInputOptions(pInfo, NULL, NULL); - xf86ProcessCommonOptions(pInfo, pInfo->options); - - /* Open sockets, init device files, etc. */ - SYSCALL(pInfo->fd = open(pNestedMouse->device, O_RDWR | O_NONBLOCK)); - - 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; - } - - pInfo->flags |= XI86_OPEN_ON_INIT; - pInfo->flags |= XI86_CONFIGURED; - return pInfo; -} - -void -NestedMouseUnInit(InputDriverPtr drv, InputInfoPtr pInfo, int flags) { -} - -static pointer -NestedMousePlug(pointer module, pointer options, int *errmaj, int *errmin) { - //xf86AddInputDriver(&NESTEDMOUSE, module, 0); - return module; -} - -static void -NestedMouseUnplug(pointer p) { -} - -static int -_nested_mouse_init_buttons(DeviceIntPtr device) { - -InputInfoPtr pInfo = device->public.devicePrivate; - CARD8 *map; - int i; - int ret = Success; - const int num_buttons = 2; - - Atom btn_labels[2] = {0}; - - btn_labels[0] = "left"; - btn_labels[1] = "right"; - - map = xcalloc(num_buttons, sizeof(CARD8)); - - for (i = 0; i < num_buttons; i++) - map[i] = i; - - if (!InitButtonClassDeviceStruct(device, num_buttons, btn_labels, map)) { - xf86Msg(X_ERROR, "%s: Failed to register buttons.\n", pInfo->name); - ret = BadAlloc; - } - - - if (!InitKeyboardDeviceStruct(device, NULL, NULL, NULL)) { - xf86Msg(X_ERROR, "%s: Failed to register keyboard.\n", pInfo->name); - ret = BadAlloc; - } - - xfree(map); - return ret; -return -1; -} - -static int -_nested_mouse_init_axes(DeviceIntPtr device) { - InputInfoPtr pInfo = device->public.devicePrivate; - int i; - const int num_axes = 2; - - if (!InitValuatorClassDeviceStruct(device, - num_axes, - GetMotionHistory, - GetMotionHistorySize(), - 0)) - return BadAlloc; - - pInfo->dev->valuator->mode = Relative; - if (!InitAbsoluteClassDeviceStruct(device)) - return BadAlloc; - - for (i = 0; i < 2; i++) { - xf86InitValuatorAxisStruct(device, i, "", -1, -1, 1, 1, 1); - xf86InitValuatorDefaults(device, i); - } - - return Success; - return -1; -} - -static int -NestedMouseControl(DeviceIntPtr device, int what) { - InputInfoPtr pInfo = device->public.devicePrivate; - NestedMouseDevicePtr pNestedMouse = pInfo->private; - - switch (what) { - case DEVICE_INIT: - _nested_mouse_init_buttons(device); - _nested_mouse_init_axes(device); - break; - case DEVICE_ON: - xf86Msg(X_INFO, "%s: On.\n", pInfo->name); - if (device->public.on) - break; - xf86FlushInput(pInfo->fd); - xf86AddEnabledDevice(pInfo); - device->public.on = TRUE; - break; - case DEVICE_OFF: - xf86Msg(X_INFO, "%s: Off.\n", pInfo->name); - if (!device->public.on) - break; - xf86RemoveEnabledDevice(pInfo); - pInfo->fd = -1; - device->public.on = FALSE; - break; - case DEVICE_CLOSE: - /* free what we have to free */ - break; - } - - return Success; -} - -static void -NestedMouseReadInput(InputInfoPtr pInfo) { -} - -//Helper func to load mouse driver at the init of nested video driver -void Load_Nested_Mouse(NestedClientPrivatePtr clientData) { - xf86Msg(X_INFO, "NESTED MOUSE LOADING\n"); - - //xf86AddInputDriver(&NESTEDMOUSE, module, 0); - - // Create input options for our invocation to NewInputDeviceRequest(). - InputOption* options = (InputOption*)xalloc(sizeof(InputOption)); - - options->key = "driver"; - options->value = "nestedmouse"; - - options->next = (InputOption*)xalloc(sizeof(InputOption)); - - options->next->key = "identifier"; - options->next->value = "nestedmouse"; - options->next->next = NULL; - - DeviceIntPtr dev; - int ret = NewInputDeviceRequest(options, NULL, &dev); - - if (ret != Success) { - xf86Msg(X_ERROR, "Failed to load input driver.\n"); - } - - NestedMouseControl(dev, DEVICE_ON); - - 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) { - xf86PostMotionEvent(dev, TRUE, 0, 2, x, y); -} - -void NestedPostMouseButton(void* dev, int button, int isDown) { - xf86PostButtonEvent(dev, 0, button, isDown, 0, 0); -} - -void NestedPostKey(void* dev, unsigned int keycode, int isDown) { - xf86PostKeyboardEvent(dev, keycode, isDown); -} diff --git a/src/xNestedMouse.h b/src/xNestedMouse.h deleted file mode 100644 index 13ffdae..0000000 --- a/src/xNestedMouse.h +++ /dev/null @@ -1,10 +0,0 @@ -#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); -void NestedPostMouseButton(void* dev, int button, int isDown); -void NestedPostKey(void* dev, unsigned int keycode, int isDown); diff --git a/src/xlibclient.c b/src/xlibclient.c index ebddc38..51363d0 100644 --- a/src/xlibclient.c +++ b/src/xlibclient.c @@ -33,8 +33,7 @@ #include <xorg/xf86.h> #include "client.h" - -#include "xNestedMouse.h" +#include "input.h" struct NestedClientPrivate { Display *display; @@ -271,69 +270,32 @@ NestedClientTimerCallback(NestedClientPrivatePtr pPriv) { ((XExposeEvent*)&ev)->height); } + // Post mouse motion events to input driver. 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), - ((XMotionEvent*)&ev)->x, ((XMotionEvent*)&ev)->y, - msg, strlen(msg)); - XDrawString(pPriv->display, pPriv->window, - DefaultGC(pPriv->display, pPriv->screenNumber), - ((XMotionEvent*)&ev)->x_root, - ((XMotionEvent*)&ev)->y_root, msg2, strlen(msg2)); - */ - } - - if (ev.type == EnterNotify) { - xf86DrvMsg(pPriv->scrnIndex, X_INFO, "Cursor entered window!\n"); - } - - if (ev.type == LeaveNotify) { - xf86DrvMsg(pPriv->scrnIndex, X_INFO, "Cursor left window!\n"); + NestedInputPostMouseMotionEvent(pPriv->dev, x, y); } + // Post mouse button press events to input driver. if (ev.type == ButtonPress) { - switch (ev.xbutton.button) { - case Button1: xf86DrvMsg(pPriv->scrnIndex, X_INFO, "Left Mouse Button Pressed\n"); - NestedPostMouseButton(pPriv->dev, 1, TRUE); - break; - case Button2: xf86DrvMsg(pPriv->scrnIndex, X_INFO, "Middle Mouse Button Pressed\n"); - break; - case Button3: xf86DrvMsg(pPriv->scrnIndex, X_INFO, "Right Mouse Button Pressed\n"); - break; - case Button4: xf86DrvMsg(pPriv->scrnIndex, X_INFO, "Wheel Up Pressed\n"); - break; - case Button5: xf86DrvMsg(pPriv->scrnIndex, X_INFO, "Wheel Down Pressed\n"); - } + NestedInputPostButtonEvent(pPriv->dev, ev.xbutton.button, TRUE); } - + + // Post mouse button release events to input driver. if (ev.type == ButtonRelease) { - switch (ev.xbutton.button) { - case Button1: xf86DrvMsg(pPriv->scrnIndex, X_INFO, "Left Mouse Button Released\n"); - NestedPostMouseButton(pPriv->dev, 1, FALSE); - break; - case Button2: xf86DrvMsg(pPriv->scrnIndex, X_INFO, "Middle Mouse Button Released\n"); - break; - case Button3: xf86DrvMsg(pPriv->scrnIndex, X_INFO, "Right Mouse Button Released\n"); - break; - case Button4: xf86DrvMsg(pPriv->scrnIndex, X_INFO, "Wheel Up Released\n"); - break; - case Button5: xf86DrvMsg(pPriv->scrnIndex, X_INFO, "Wheel Down Released\n"); - } + NestedInputPostButtonEvent(pPriv->dev, ev.xbutton.button, FALSE); } + // Post keyboard press events to input driver. if (ev.type == KeyPress) { - xf86DrvMsg(pPriv->scrnIndex, X_INFO, "Key Pressed!--%d\n",ev.xkey.keycode); - NestedPostKey(pPriv->dev, ev.xkey.keycode, TRUE); + NestedInputPostKeyboardEvent(pPriv->dev, ev.xkey.keycode, TRUE); } + // Post keyboard release events to input driver. if (ev.type == KeyRelease) { - xf86DrvMsg(pPriv->scrnIndex, X_INFO, "Key Released!--%d\n",ev.xkey.keycode); - NestedPostKey(pPriv->dev, ev.xkey.keycode, FALSE); + NestedInputPostKeyboardEvent(pPriv->dev, ev.xkey.keycode, FALSE); } } } |