dont try to convert the pixfmt while calculating the "shade"
[AROS.git] / arch / all-linux / hidd / linuxinput / linuxinput_init.c
blobb3d901c631a018385b15f916bc40b025bc16678d
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>
23 #include <hidd/unixio_inline.h>
25 #include LC_LIBDEFS_FILE
27 #include "linuxinput_intern.h"
29 #include <linux/input.h>
31 #define O_RDONLY 0
33 /*
34 * Some attrbases needed as global vars.
35 * These are write-once read-many.
37 OOP_AttrBase HiddKbdAB;
38 OOP_AttrBase HiddMouseAB;
40 static const struct OOP_ABDescr abd[] =
42 { IID_Hidd_Kbd , &HiddKbdAB },
43 { IID_Hidd_Mouse , &HiddMouseAB },
44 { NULL , NULL }
47 VOID Update_EventHandlers(struct LinuxInput_staticdata *lsd)
49 struct EventHandler * eh;
50 ForeachNode(&lsd->eventhandlers, eh)
52 eh->mousehidd = lsd->mousehidd;
53 eh->kbdhidd = lsd->kbdhidd;
54 eh->unixio = lsd->unixio;
58 static inline void _sprintf(UBYTE *buffer, UBYTE *format, ...)
60 va_list args;
62 va_start(args, format);
63 VNewRawDoFmt(format, RAWFMTFUNC_STRING, buffer, args);
64 va_end(args);
67 static VOID Enumerate_InputDevices(struct LinuxInput_staticdata *lsd)
69 int fd, ioerr, read;
70 LONG i = 0;
71 TEXT eventdev[64];
74 while(TRUE)
76 LONG param = 0;
77 struct EventHandler * eh = NULL;
79 _sprintf(eventdev, "/dev/input/event%d", i);
81 D(bug("[LinuxInput] Testing %s\n", eventdev));
83 fd = Hidd_UnixIO_OpenFile(lsd->unixio, eventdev, O_RDONLY, 0, &ioerr);
84 if (fd< 0)
85 break;
87 read = Hidd_UnixIO_IOControlFile(lsd->unixio, fd, EVIOCGBIT(0, EV_MAX), &param,&ioerr);
89 if (read < 0)
90 continue;
92 eh = AllocVec(sizeof(struct EventHandler), MEMF_PUBLIC | MEMF_CLEAR);
93 eh->eventdev = fd;
94 eh->capabilities = CAP_NONE;
96 if ((param & (1 << EV_REP)) && (param& (1 << EV_KEY)))
98 /* Mouse */
99 eh->capabilities |= CAP_KEYBOARD;
100 D(bug("[LinuxInput] Found Keyboard\n"));
103 if ((param & (1 << EV_REL)) && (param& (1 << EV_KEY)))
105 /* Mouse */
106 eh->capabilities |= CAP_MOUSE;
107 D(bug("[LinuxInput] Found Mouse\n"));
111 if (eh->capabilities != CAP_NONE)
112 ADDHEAD(&lsd->eventhandlers, eh);
113 else
114 FreeVec(eh);
116 i++;
120 VOID Init_LinuxInput_inputtask(struct EventHandler * eh);
121 VOID Kill_LinuxInput_inputtask(struct EventHandler * eh);
123 static int Init_Hidd(LIBBASETYPEPTR LIBBASE)
125 struct EventHandler * eh;
127 InitSemaphore(&LIBBASE->lsd.sema);
128 NEWLIST(&LIBBASE->lsd.eventhandlers);
131 * We cannot cooperate with any other driver at the moment.
132 * Attempting to do so results in duplicating events (one from
133 * X11 and another from us).
135 if (OOP_FindClass("hidd.gfx.x11"))
136 return FALSE;
138 D(bug("[LinuxInput] Opening UnixIO... "));
139 LIBBASE->lsd.unixio = OOP_NewObject(NULL, CLID_Hidd_UnixIO, NULL);
140 if (!LIBBASE->lsd.unixio)
142 D(bug("Failed\n"));
143 return FALSE;
145 D(bug("OK\n"));
147 Enumerate_InputDevices(&LIBBASE->lsd);
148 if (IsListEmpty(&LIBBASE->lsd.eventhandlers))
149 return FALSE;
151 if (!OOP_ObtainAttrBases(abd))
152 return FALSE;
154 Update_EventHandlers(&LIBBASE->lsd);
156 ForeachNode(&LIBBASE->lsd.eventhandlers, eh)
158 Init_LinuxInput_inputtask(eh);
161 D(bug("[LinuxInput] Finished Init_Hidd"));
163 return TRUE;
166 static int Expunge_Hidd(LIBBASETYPEPTR LIBBASE)
168 int ioerr;
169 struct EventHandler * eh;
171 ForeachNode(&LIBBASE->lsd.eventhandlers, eh)
173 Kill_LinuxInput_inputtask(eh);
174 Hidd_UnixIO_CloseFile(LIBBASE->lsd.unixio, eh->eventdev, &ioerr);
177 OOP_ReleaseAttrBases(abd);
179 if (LIBBASE->lsd.unixio)
180 OOP_DisposeObject(LIBBASE->lsd.unixio);
182 return TRUE;
185 ADD2INITLIB(Init_Hidd, 1)
186 ADD2EXPUNGELIB(Expunge_Hidd, 1)