/
manymouse.c
102 lines (81 loc) · 2.78 KB
1
/*
2
* ManyMouse foundation code; apps talks to this and it talks to the lowlevel
3
4
5
6
7
8
* code for various platforms.
*
* Please see the file LICENSE in the source's root directory.
*
* This file written by Ryan C. Gordon.
*/
9
10
#include <stdlib.h>
11
#include "manymouse.h"
12
13
static const char *manymouse_copyright =
14
"ManyMouse " MANYMOUSE_VERSION " copyright (c) 2005-2008 Ryan C. Gordon.";
15
16
17
extern const ManyMouseDriver *ManyMouseDriver_windows;
extern const ManyMouseDriver *ManyMouseDriver_evdev;
18
extern const ManyMouseDriver *ManyMouseDriver_hidmanager;
19
extern const ManyMouseDriver *ManyMouseDriver_hidutilities;
20
extern const ManyMouseDriver *ManyMouseDriver_xinput;
21
22
23
24
25
26
27
28
29
30
31
/*
* These have to be in the favored order...obviously it doesn't matter if the
* Linux driver comes before or after the Windows one, since one won't
* exist on a given platform, but things like Mac OS X's hidmanager (which
* only works on OS X 10.5 and later) should come before Mac OS X's
* hidutilities (which works on older systems, but may stop working in 10.6
* and later). In the Mac OS X case, you want to try the newer tech, and if
* it's not available (on 10.4 or earlier), fall back to trying the legacy
* code.
*/
32
static const ManyMouseDriver **mice_drivers[] =
33
{
34
#if 0 /* FIXME: re-add this when the code is written! */
35
&ManyMouseDriver_xinput,
36
37
#endif
38
&ManyMouseDriver_evdev,
39
&ManyMouseDriver_windows,
40
&ManyMouseDriver_hidmanager,
41
&ManyMouseDriver_hidutilities,
42
43
44
};
45
static const ManyMouseDriver *driver = NULL;
46
47
int ManyMouse_Init(void)
48
{
49
const int upper = (sizeof (mice_drivers) / sizeof (mice_drivers[0]));
50
int i;
51
int retval = -1;
52
53
/* impossible test to keep manymouse_copyright linked into the binary. */
54
if (manymouse_copyright == NULL)
55
56
return(-1);
57
58
59
if (driver != NULL)
return(-1);
60
for (i = 0; (i < upper) && (driver == NULL); i++)
61
{
62
63
const ManyMouseDriver *this_driver = *(mice_drivers[i]);
if (this_driver != NULL) /* if not built for this platform, skip it. */
64
{
65
66
67
68
69
70
const int mice = this_driver->init();
if (mice > retval)
retval = mice; /* may move from "error" to "no mice found". */
if (mice > 0)
driver = this_driver;
71
72
73
} /* if */
} /* for */
74
return(retval);
75
} /* ManyMouse_Init */
76
77
78
void ManyMouse_Quit(void)
79
80
81
82
{
if (driver != NULL)
driver->quit();
driver = NULL;
83
} /* ManyMouse_Quit */
84
85
86
const char *ManyMouse_DeviceName(unsigned int index)
87
88
89
90
{
if (driver != NULL)
return(driver->name(index));
return(NULL);
91
} /* ManyMouse_PollEvent */
92
93
94
int ManyMouse_PollEvent(ManyMouseEvent *event)
95
96
97
98
{
if (driver != NULL)
return(driver->poll(event));
return(0);
99
} /* ManyMouse_PollEvent */
100
101
/* end of manymouse.c ... */