2 Copyright (C) 2004-2013, The AROS Development Team. All rights reserved.
6 #define __OOP_NOATTRBASES__
8 #include <aros/debug.h>
10 #include <hidd/mouse.h>
12 #include <utility/tagitem.h>
13 #include <proto/alib.h>
14 #include <proto/exec.h>
15 #include <proto/utility.h>
16 #include <proto/oop.h>
20 #define SysBase (CSD(cl)->cs_SysBase)
21 #define UtilityBase (CSD(cl)->cs_UtilityBase)
23 /*****************************************************************************************
26 --background_mouseclass--
32 Instances of this class are virtual devices being clients of the
33 pointing input subsystem. In order to receive input events, you
34 have to create an object of this class and supply a callback using
35 aoHidd_Mouse_IrqHandler attribute. After this your callback will be
36 called every time the event arrives until you dispose your object.
38 Every client receives events from all pointing devices merged into
41 *****************************************************************************************/
43 /*****************************************************************************************
46 aoHidd_Mouse_IrqHandler
55 Specifies a pointing device interrupt handler. The handler will called be every time a
56 keyboard event happens. A "C" calling convention is used, declare the handler
59 void MouseIRQ(APTR data, struct pHidd_Mouse_Event *event);
61 Handler parameters are:
62 data - Anything you specify using aoHidd_Mouse_IrqHandlerData
63 event - A pointer to a read-only event descriptor structure with the following
65 button - button code, or vHidd_Mouse_NoButton of the event describes a simple
67 x, y - event coordinates. Need to be always valid, even if the event describes
68 a button pressed without actual motion.
69 In case of mouse wheel event these fields specify horizontal and vertical
70 wheel delta respectively.
71 type - type of event (button press, button release, wheel or motion).
72 flags - event flags. Currently only one value of vHidd_Mouse_Relative is defined.
73 If this flag is not set, coordinates are assumed to be absolute.
74 This member is actually present in the structure only if the driver
75 supplies TRUE value for aoHidd_Mouse_Extended attribute.
77 The handler is called inside interrupts, so usual restrictions apply to it.
80 CLID_Hidd_Mouse class always provides extended form of event structure
81 (struct pHidd_Mouse_ExtEvent). Drivers will not always provide it, depending
82 on their aoHidd_Mouse_Extended attribute value.
89 aoHidd_Mouse_IrqHandlerData, aoHidd_Mouse_Extended
93 *****************************************************************************************/
95 /*****************************************************************************************
98 aoHidd_Mouse_IrqHandlerData
107 Specifies a user-defined value that will be passed to interrupt handler as a first
108 parameter. The purpose of this is to pass some static data to the handler.
109 The system will not assume anything about this value.
111 Defaults to NULL if not specified.
120 aoHidd_Mouse_IrqHandler
124 *****************************************************************************************/
126 /*****************************************************************************************
132 [..G], struct pHidd_Mouse_Event
138 Obtains current pointing devices state.
140 This attribute was historically implemented only in PS/2 mouse driver, but the
141 implementation was broken and incomplete. At the moment this attribute is considered
142 reserved. Do not use it, the specification may change in future.
149 Not implemented, considered reserved.
155 *****************************************************************************************/
157 /*****************************************************************************************
160 aoHidd_Mouse_RelativeCoords
169 Asks the driver it the device provides relative (like mouse) or absolute (like
170 touchscreen or tabled) coordinates.
172 Drivers which provide extended event structure may not implement this attribute
173 because they may provide mixed set of events. In this case coordinates type
174 is determined by flags member of struct pHidd_Mouse_ExtEvent.
176 CLID_Hidd_Mouse class does not implement this attribute since it provides mixed
186 aoHidd_Mouse_IrqHandler, aoHidd_Mouse_Extended
190 *****************************************************************************************/
192 /*****************************************************************************************
195 aoHidd_Mouse_Extended
204 Asks the driver if it provides extended event descriptor structure
205 (struct pHidd_Mouse_ExtEvent).
207 If value of this attribute is FALSE, the flags member is actually missing from
208 the structure, not just zeroed out! So do not use it at all in this case.
210 CLID_Hidd_Mouse class always return TRUE for this attribute.
219 aoHidd_Mouse_IrqHandler
223 ******************************************************************************************/
225 OOP_Object
*Mouse__Root__New(OOP_Class
*cl
, OOP_Object
*o
, struct pRoot_New
*msg
)
227 struct mouse_data
*data
;
228 struct TagItem
*tag
, *tstate
;
230 o
= (OOP_Object
*)OOP_DoSuperMethod(cl
, o
, (OOP_Msg
)msg
);
234 data
= OOP_INST_DATA(cl
, o
);
235 data
->callback
= NULL
;
236 data
->callbackdata
= NULL
;
238 tstate
= msg
->attrList
;
239 D(bug("tstate: %p\n", tstate
));
241 while ((tag
= NextTagItem(&tstate
)))
245 D(bug("Got tag %d, data %x\n", tag
->ti_Tag
, tag
->ti_Data
));
247 if (IS_HIDDMOUSE_ATTR(tag
->ti_Tag
, idx
))
249 D(bug("Mouse hidd tag\n"));
252 case aoHidd_Mouse_IrqHandler
:
253 data
->callback
= (APTR
)tag
->ti_Data
;
254 D(bug("Got callback %p\n", (APTR
)tag
->ti_Data
));
257 case aoHidd_Mouse_IrqHandlerData
:
258 data
->callbackdata
= (APTR
)tag
->ti_Data
;
259 D(bug("Got data %p\n", (APTR
)tag
->ti_Data
));
263 } /* while (tags to process) */
265 /* Add to interrupts list if we have a callback */
269 ADDTAIL(&CSD(cl
)->callbacks
, data
);
276 VOID
Mouse__Root__Dispose(OOP_Class
*cl
, OOP_Object
*o
, OOP_Msg msg
)
278 struct mouse_data
*data
= OOP_INST_DATA(cl
, o
);
283 REMOVE((struct Node
*)data
);
286 OOP_DoSuperMethod(cl
, o
, msg
);
289 VOID
Mouse__Root__Get(OOP_Class
*cl
, OOP_Object
*o
, struct pRoot_Get
*msg
)
293 if (IS_HIDDMOUSE_ATTR(msg
->attrID
, idx
))
297 /* case aoHidd_Mouse_State:
299 TODO: Implement this, by ORing buttons from all registered mice (?)
303 case aoHidd_Mouse_Extended
:
304 *msg
->storage
= TRUE
;
309 OOP_DoSuperMethod(cl
, o
, (OOP_Msg
)msg
);
313 * In future we could support enumeration of devices and specifying
314 * which device we wish to read events from (in case if we want to implement
315 * amigainput.library or something like it)
318 /*****************************************************************************************
321 moHidd_Mouse_AddHardwareDriver
324 OOP_Object *OOP_DoMethod(OOP_Object *obj, struct pHidd_Mouse_AddHardwareDriver *Msg);
326 OOP_Object *HIDD_Mouse_AddHardwareDriver(OOP_Object *obj, OOP_Class *driverClass, struct TagItem *tags)
332 Creates a hardware driver object and registers it in the system.
334 It does not matter on which instance of CLID_Hidd_Mouse class this method is
335 used. Hardware driver objects are shared between all of them.
337 Since V2 this interface is obsolete and deprecated. Use moHW_AddDriver
338 method on CLID_HW_Mouse class in order to install the driver.
341 obj - Any object of CLID_Hidd_Mouse class.
342 driverClass - A pointer to OOP class of the driver. In order to create an object
343 of some previously registered public class, use
344 oop.library/OOP_FindClass().
345 tags - An optional taglist which will be passed to driver class' New() method.
348 A pointer to driver object.
351 Do not dispose the returned object yourself, use HIDD_Mouse_RemHardwareDriver() for it.
358 moHidd_Mouse_RemHardwareDriver
361 This method supplies own interrupt handler to the driver, do not override this.
363 *****************************************************************************************/
365 OOP_Object
*Mouse__Hidd_Mouse__AddHardwareDriver(OOP_Class
*cl
, OOP_Object
*o
, struct pHidd_Mouse_AddHardwareDriver
*Msg
)
367 return HW_AddDriver(CSD(cl
)->hwObject
, Msg
->driverClass
, Msg
->tags
);
370 /*****************************************************************************************
373 moHidd_Mouse_RemHardwareDriver
376 void OOP_DoMethod(OOP_Object *obj, struct pHidd_Mouse_RemHardwareDriver *Msg);
378 void HIDD_Mouse_RemHardwareDriver(OOP_Object *obj, OOP_Object *driver);
384 Unregisters and disposes pointing device hardware driver object.
386 It does not matter on which instance of CLID_Hidd_Mouse class this method is
387 used. Hardware driver objects are shared between all of them.
389 Since V2 this interface is obsolete and deprecated. Use moHW_RemoveDriver
390 method on CLID_HW_Kbd class in order to remove the driver.
393 obj - Any object of CLID_Hidd_Mouse class.
394 driver - A pointer to a driver object, returned by HIDD_Mouse_AddHardwareDriver().
406 moHidd_Mouse_AddHardwareDriver
410 *****************************************************************************************/
412 void Mouse__Hidd_Mouse__RemHardwareDriver(OOP_Class
*cl
, OOP_Object
*o
, struct pHidd_Mouse_RemHardwareDriver
*Msg
)
414 HW_RemoveDriver(CSD(cl
)->hwObject
, Msg
->driverObject
);