/
manymouse.c
87 lines (67 loc) · 2.09 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-2007 Ryan C. Gordon.";
15
16
17
18
19
extern const ManyMouseDriver *ManyMouseDriver_windows;
extern const ManyMouseDriver *ManyMouseDriver_evdev;
extern const ManyMouseDriver *ManyMouseDriver_hidmanager;
extern const ManyMouseDriver *ManyMouseDriver_xinput;
20
21
static const ManyMouseDriver **mice_drivers[] =
22
{
23
24
&ManyMouseDriver_xinput,
&ManyMouseDriver_evdev,
25
&ManyMouseDriver_windows,
26
&ManyMouseDriver_hidmanager,
27
28
29
};
30
static const ManyMouseDriver *driver = NULL;
31
32
int ManyMouse_Init(void)
33
{
34
const int upper = (sizeof (mice_drivers) / sizeof (mice_drivers[0]));
35
int i;
36
int retval = -1;
37
38
/* impossible test to keep manymouse_copyright linked into the binary. */
39
if (manymouse_copyright == NULL)
40
41
return(-1);
42
43
44
if (driver != NULL)
return(-1);
45
for (i = 0; (i < upper) && (driver == NULL); i++)
46
{
47
48
const ManyMouseDriver *this_driver = *(mice_drivers[i]);
if (this_driver != NULL) /* if not built for this platform, skip it. */
49
{
50
51
52
53
54
55
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;
56
57
58
} /* if */
} /* for */
59
return(retval);
60
} /* ManyMouse_Init */
61
62
63
void ManyMouse_Quit(void)
64
65
66
67
{
if (driver != NULL)
driver->quit();
driver = NULL;
68
} /* ManyMouse_Quit */
69
70
71
const char *ManyMouse_DeviceName(unsigned int index)
72
73
74
75
{
if (driver != NULL)
return(driver->name(index));
return(NULL);
76
} /* ManyMouse_PollEvent */
77
78
79
int ManyMouse_PollEvent(ManyMouseEvent *event)
80
81
82
83
{
if (driver != NULL)
return(driver->poll(event));
return(0);
84
} /* ManyMouse_PollEvent */
85
86
/* end of manymouse.c ... */