Test initialisation of MUIA_List_AdjustWidth and MUIA_List_AdjustHeight, and
[AROS.git] / arch / all-linux / hidd / linuxinput / linuxinput_init.c
blob2515c85c6a8b9423a7de0f5acf8b7b1e626bcec3
1 /*
2 Copyright © 2013, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: LinuxInput hidd initialization code.
6 Lang: English.
7 */
9 #define DEBUG 0
11 #define __OOP_NOATTRBASES__
13 #include <exec/rawfmt.h>
14 #include <aros/symbolsets.h>
15 #include <aros/debug.h>
16 #include <utility/utility.h>
17 #include <oop/oop.h>
18 #include <proto/exec.h>
19 #include <proto/oop.h>
20 #include <hidd/mouse.h>
21 #include <hidd/keyboard.h>
22 #include <hidd/unixio.h>
24 #include LC_LIBDEFS_FILE
26 #include "linuxinput_intern.h"
28 #include <linux/input.h>
30 #define O_RDONLY 0
32 /*
33 * Some attrbases needed as global vars.
34 * These are write-once read-many.
36 OOP_AttrBase HiddKbdAB;
37 OOP_AttrBase HiddMouseAB;
39 static const struct OOP_ABDescr abd[] =
41 { IID_Hidd_Kbd , &HiddKbdAB },
42 { IID_Hidd_Mouse , &HiddMouseAB },
43 { NULL , NULL }
46 VOID Update_EventHandlers(struct LinuxInput_staticdata *lsd)
48 struct EventHandler * eh;
49 ForeachNode(&lsd->eventhandlers, eh)
51 eh->mousehidd = lsd->mousehidd;
52 eh->kbdhidd = lsd->kbdhidd;
53 eh->unixio = lsd->unixio;
57 static inline void _sprintf(UBYTE *buffer, UBYTE *format, ...)
59 va_list args;
61 va_start(args, format);
62 VNewRawDoFmt(format, RAWFMTFUNC_STRING, buffer, args);
63 va_end(args);
66 static VOID Enumerate_InputDevices(struct LinuxInput_staticdata *lsd)
68 int fd, ioerr, read;
69 LONG i = 0;
70 TEXT eventdev[64];
73 while(TRUE)
75 LONG param = 0;
76 struct EventHandler * eh = NULL;
78 _sprintf(eventdev, "/dev/input/event%d", i);
80 D(bug("[LinuxInput] Testing %s\n", eventdev));
82 fd = Hidd_UnixIO_OpenFile(lsd->unixio, eventdev, O_RDONLY, 0, &ioerr);
83 if (fd< 0)
84 break;
86 read = Hidd_UnixIO_IOControlFile(lsd->unixio, fd, EVIOCGBIT(0, EV_MAX), &param,&ioerr);
88 if (read < 0)
89 continue;
91 eh = AllocVec(sizeof(struct EventHandler), MEMF_PUBLIC | MEMF_CLEAR);
92 eh->eventdev = fd;
93 eh->capabilities = CAP_NONE;
95 if ((param & (1 << EV_REP)) && (param& (1 << EV_KEY)))
97 /* Mouse */
98 eh->capabilities |= CAP_KEYBOARD;
99 D(bug("[LinuxInput] Found Keyboard\n"));
102 if ((param & (1 << EV_REL)) && (param& (1 << EV_KEY)))
104 /* Mouse */
105 eh->capabilities |= CAP_MOUSE;
106 D(bug("[LinuxInput] Found Mouse\n"));
110 if (eh->capabilities != CAP_NONE)
111 ADDHEAD(&lsd->eventhandlers, eh);
112 else
113 FreeVec(eh);
115 i++;
119 VOID Init_LinuxInput_inputtask(struct EventHandler * eh);
120 VOID Kill_LinuxInput_inputtask(struct EventHandler * eh);
122 static int Init_Hidd(LIBBASETYPEPTR LIBBASE)
124 struct EventHandler * eh;
126 InitSemaphore(&LIBBASE->lsd.sema);
127 NEWLIST(&LIBBASE->lsd.eventhandlers);
130 * We cannot cooperate with any other driver at the moment.
131 * Attempting to do so results in duplicating events (one from
132 * X11 and another from us).
134 if (OOP_FindClass("hidd.gfx.x11"))
135 return FALSE;
137 D(bug("[LinuxInput] Opening UnixIO... "));
138 LIBBASE->lsd.unixio = OOP_NewObject(NULL, CLID_Hidd_UnixIO, NULL);
139 if (!LIBBASE->lsd.unixio)
141 D(bug("Failed\n"));
142 return FALSE;
144 D(bug("OK\n"));
146 Enumerate_InputDevices(&LIBBASE->lsd);
147 if (IsListEmpty(&LIBBASE->lsd.eventhandlers))
148 return FALSE;
150 if (!OOP_ObtainAttrBases(abd))
151 return FALSE;
153 Update_EventHandlers(&LIBBASE->lsd);
155 ForeachNode(&LIBBASE->lsd.eventhandlers, eh)
157 Init_LinuxInput_inputtask(eh);
160 D(bug("[LinuxInput] Finished Init_Hidd"));
162 return TRUE;
165 static int Expunge_Hidd(LIBBASETYPEPTR LIBBASE)
167 int ioerr;
168 struct EventHandler * eh;
170 ForeachNode(&LIBBASE->lsd.eventhandlers, eh)
172 Kill_LinuxInput_inputtask(eh);
173 Hidd_UnixIO_CloseFile(LIBBASE->lsd.unixio, eh->eventdev, &ioerr);
176 OOP_ReleaseAttrBases(abd);
178 if (LIBBASE->lsd.unixio)
179 OOP_DisposeObject(LIBBASE->lsd.unixio);
181 return TRUE;
184 ADD2INITLIB(Init_Hidd, 1)
185 ADD2EXPUNGELIB(Expunge_Hidd, 1)