Skip to content

Latest commit

 

History

History
100 lines (81 loc) · 2.8 KB

manymouse.c

File metadata and controls

100 lines (81 loc) · 2.8 KB
 
Jun 27, 2005
Jun 27, 2005
1
/*
Jun 27, 2005
Jun 27, 2005
2
* ManyMouse foundation code; apps talks to this and it talks to the lowlevel
Jun 27, 2005
Jun 27, 2005
3
4
* code for various platforms.
*
Jul 28, 2008
Jul 28, 2008
5
* Please see the file LICENSE.txt in the source's root directory.
Jun 27, 2005
Jun 27, 2005
6
7
8
*
* This file written by Ryan C. Gordon.
*/
Jun 26, 2005
Jun 26, 2005
10
#include <stdlib.h>
Jun 27, 2005
Jun 27, 2005
11
#include "manymouse.h"
Jun 28, 2005
Jun 28, 2005
13
static const char *manymouse_copyright =
Jul 12, 2011
Jul 12, 2011
14
"ManyMouse " MANYMOUSE_VERSION " copyright (c) 2005-2011 Ryan C. Gordon.";
Jun 28, 2005
Jun 28, 2005
15
Jul 27, 2007
Jul 27, 2007
16
17
extern const ManyMouseDriver *ManyMouseDriver_windows;
extern const ManyMouseDriver *ManyMouseDriver_evdev;
Feb 8, 2008
Feb 8, 2008
18
extern const ManyMouseDriver *ManyMouseDriver_hidmanager;
Feb 7, 2008
Feb 7, 2008
19
extern const ManyMouseDriver *ManyMouseDriver_hidutilities;
Apr 18, 2011
Apr 18, 2011
20
extern const ManyMouseDriver *ManyMouseDriver_xinput2;
Feb 8, 2008
Feb 8, 2008
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.
*/
Jul 27, 2007
Jul 27, 2007
32
static const ManyMouseDriver **mice_drivers[] =
Apr 18, 2011
Apr 18, 2011
34
&ManyMouseDriver_xinput2,
Jun 27, 2005
Jun 27, 2005
35
&ManyMouseDriver_evdev,
Mar 24, 2006
Mar 24, 2006
36
&ManyMouseDriver_windows,
Feb 8, 2008
Feb 8, 2008
37
&ManyMouseDriver_hidmanager,
Feb 7, 2008
Feb 7, 2008
38
&ManyMouseDriver_hidutilities,
Jun 27, 2005
Jun 27, 2005
42
static const ManyMouseDriver *driver = NULL;
Jun 27, 2005
Jun 27, 2005
44
int ManyMouse_Init(void)
Jul 27, 2007
Jul 27, 2007
46
const int upper = (sizeof (mice_drivers) / sizeof (mice_drivers[0]));
Mar 24, 2006
Mar 24, 2006
48
int retval = -1;
Jun 28, 2005
Jun 28, 2005
50
/* impossible test to keep manymouse_copyright linked into the binary. */
Mar 24, 2006
Mar 24, 2006
51
if (manymouse_copyright == NULL)
Apr 26, 2011
Apr 26, 2011
52
return -1;
Jun 28, 2005
Jun 28, 2005
53
54
if (driver != NULL)
Apr 26, 2011
Apr 26, 2011
55
return -1;
Jul 27, 2007
Jul 27, 2007
57
for (i = 0; (i < upper) && (driver == NULL); i++)
Jul 27, 2007
Jul 27, 2007
59
60
const ManyMouseDriver *this_driver = *(mice_drivers[i]);
if (this_driver != NULL) /* if not built for this platform, skip it. */
Jul 27, 2007
Jul 27, 2007
62
63
64
65
66
67
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;
68
69
70
} /* if */
} /* for */
Apr 26, 2011
Apr 26, 2011
71
return retval;
Jun 27, 2005
Jun 27, 2005
72
} /* ManyMouse_Init */
Jun 27, 2005
Jun 27, 2005
75
void ManyMouse_Quit(void)
76
77
{
if (driver != NULL)
Apr 26, 2011
Apr 26, 2011
78
{
79
driver->quit();
Apr 26, 2011
Apr 26, 2011
80
81
driver = NULL;
} /* if */
Jun 27, 2005
Jun 27, 2005
82
} /* ManyMouse_Quit */
Apr 26, 2011
Apr 26, 2011
84
85
const char *ManyMouse_DriverName(void)
{
Apr 26, 2011
Apr 26, 2011
86
return (driver) ? driver->driver_name : NULL;
Apr 26, 2011
Apr 26, 2011
87
} /* ManyMouse_DriverName */
Jun 27, 2005
Jun 27, 2005
89
const char *ManyMouse_DeviceName(unsigned int index)
Jun 26, 2005
Jun 26, 2005
90
{
Apr 26, 2011
Apr 26, 2011
91
92
return (driver) ? driver->name(index) : NULL;
} /* ManyMouse_DeviceName */
Jun 26, 2005
Jun 26, 2005
93
Jun 27, 2005
Jun 27, 2005
94
int ManyMouse_PollEvent(ManyMouseEvent *event)
Apr 26, 2011
Apr 26, 2011
96
return (driver) ? driver->poll(event) : 0;
Jun 27, 2005
Jun 27, 2005
97
} /* ManyMouse_PollEvent */
Jun 27, 2005
Jun 27, 2005
99
/* end of manymouse.c ... */