#include "X.h"
#include "compiler.h"
#include "xf86.h"
#include "xf86Xinput.h"
#include "xf86OSmouse.h"
#include "xf86Priv.h"
#include "xf86_OSlib.h"
#include "mipointer.h"
static int
SupportedInterfaces(void)
{
return MSE_MISC;
}
static const char *internalNames[] = {
NULL
};
static const char **
BuiltinNames(void)
{
return internalNames;
}
static const char *
DefaultProtocol (void)
{
return "OSMouse";
}
static Bool
CheckProtocol(const char *protocol)
{
int i;
for (i = 0; internalNames[i]; i++)
if (xf86NameCmp(protocol, internalNames[i]) == 0)
return TRUE;
return FALSE;
}
static int
OsMouseProc(DeviceIntPtr pPointer, int what)
{
InputInfoPtr pInfo;
MouseDevPtr pMse;
unsigned char map[9];
int ret;
pInfo = pPointer->public.devicePrivate;
pMse = pInfo->private;
pMse->device = pPointer;
switch (what) {
case DEVICE_INIT:
pPointer->public.on = FALSE;
for (ret = 0; ret <= 8; ret++)
map[ret] = ret;
InitPointerDeviceStruct((DevicePtr)pPointer, map, 8,
miPointerGetMotionEvents, pMse->Ctrl,
miPointerGetMotionBufferSize());
xf86InitValuatorAxisStruct(pPointer, 0, 0, -1, 1, 0, 1);
xf86InitValuatorDefaults(pPointer, 0);
xf86InitValuatorAxisStruct(pPointer, 1, 0, -1, 1, 0, 1);
xf86InitValuatorDefaults(pPointer, 1);
xf86MotionHistoryAllocate(pInfo);
break;
case DEVICE_ON:
pMse->lastButtons = 0;
pMse->emulateState = 0;
pPointer->public.on = TRUE;
XqMseOnOff (pInfo, 1);
break;
case DEVICE_CLOSE:
case DEVICE_OFF:
pPointer->public.on = FALSE;
XqMseOnOff (pInfo, 0);
break;
}
return Success;
}
static Bool
OsMousePreInit(InputInfoPtr pInfo, const char *protocol, int flags)
{
MouseDevPtr pMse;
pMse = pInfo->private;
pMse->protocol = protocol;
xf86Msg(X_CONFIG, "%s: Protocol: %s\n", pInfo->name, protocol);
xf86CollectInputOptions(pInfo, NULL, NULL);
xf86ProcessCommonOptions(pInfo, pInfo->options);
pInfo->fd = -1;
#if 0
pInfo->fd = open ("/dev/mouse", O_RDONLY | O_NONBLOCK);
if (pInfo->fd < 0) {
if (xf86GetAllowMouseOpenFail()) {
xf86Msg(X_WARNING, "%s: cannot open /dev/mouse (%s)\n",
pInfo->name, strerror(errno));
} else {
xf86Msg(X_ERROR, "%s: cannot open /dev/mouse (%s)\n",
pInfo->name, strerror(errno));
xfree(pMse);
return FALSE;
}
}
#endif
pMse->CommonOptions(pInfo);
pInfo->device_control = OsMouseProc;
pInfo->read_input = NULL;
pInfo->flags |= XI86_CONFIGURED;
return TRUE;
}
_X_EXPORT OSMouseInfoPtr
xf86OSMouseInit(int flags)
{
OSMouseInfoPtr p;
p = xcalloc(sizeof(OSMouseInfoRec), 1);
if (!p)
return NULL;
p->SupportedInterfaces = SupportedInterfaces;
p->BuiltinNames = BuiltinNames;
p->DefaultProtocol = DefaultProtocol;
p->CheckProtocol = CheckProtocol;
p->PreInit = OsMousePreInit;
return p;
}