2 Copyright © 1995-2006, The AROS Development Team. All rights reserved.
5 Desc: X11 hidd handling mouse events.
9 #define __OOP_NOATTRBASES__
11 #include <proto/utility.h>
12 #include <proto/oop.h>
17 #include <hidd/hidd.h>
18 #include <hidd/mouse.h>
20 #include <aros/symbolsets.h>
23 #include <aros/debug.h>
25 #include LC_LIBDEFS_FILE
29 /****************************************************************************************/
31 static OOP_AttrBase HiddMouseAB
;
33 static struct OOP_ABDescr attrbases
[] =
35 { IID_Hidd_Mouse
, &HiddMouseAB
},
39 /****************************************************************************************/
41 static ULONG
xbutton2hidd(XButtonEvent
*xb
)
48 button
= vHidd_Mouse_Button1
;
52 button
= vHidd_Mouse_Button3
;
56 button
= vHidd_Mouse_Button2
;
64 /****************************************************************************************/
66 OOP_Object
* X11Mouse__Root__New(OOP_Class
*cl
, OOP_Object
*o
, struct pRoot_New
*msg
)
68 BOOL has_mouse_hidd
= FALSE
;
70 ObtainSemaphoreShared( &XSD(cl
)->sema
);
72 if (XSD(cl
)->mousehidd
)
73 has_mouse_hidd
= TRUE
;
75 ReleaseSemaphore( &XSD(cl
)->sema
);
77 if (has_mouse_hidd
) /* Cannot open twice */
78 return NULL
; /* Should have some error code here */
80 o
= (OOP_Object
*)OOP_DoSuperMethod(cl
, o
, (OOP_Msg
)msg
);
83 struct x11mouse_data
*data
= OOP_INST_DATA(cl
, o
);
84 struct TagItem
*tag
, *tstate
;
86 tstate
= msg
->attrList
;
87 while ((tag
= NextTagItem((const struct TagItem
**)&tstate
)))
91 if (IS_HIDDMOUSE_ATTR(tag
->ti_Tag
, idx
))
95 case aoHidd_Mouse_IrqHandler
:
96 data
->mouse_callback
= (VOID (*)())tag
->ti_Data
;
99 case aoHidd_Mouse_IrqHandlerData
:
100 data
->callbackdata
= (APTR
)tag
->ti_Data
;
105 } /* while (tags to process) */
107 /* Install the mouse hidd */
109 ObtainSemaphore( &XSD(cl
)->sema
);
110 XSD(cl
)->mousehidd
= o
;
111 ReleaseSemaphore( &XSD(cl
)->sema
);
118 /****************************************************************************************/
120 VOID
X11Mouse__Hidd_X11Mouse__HandleEvent(OOP_Class
*cl
, OOP_Object
*o
, struct pHidd_X11Mouse_HandleEvent
*msg
)
123 struct x11mouse_data
*data
= OOP_INST_DATA(cl
, o
);
124 struct pHidd_Mouse_Event e
;
126 XButtonEvent
*xb
= &(msg
->event
->xbutton
);
131 if (msg
->event
->type
== ButtonRelease
)
138 e
.button
= xbutton2hidd(xb
);
139 e
.type
= vHidd_Mouse_Release
;
140 data
->mouse_callback(data
->callbackdata
, &e
);
144 else if (msg
->event
->type
== ButtonPress
)
151 e
.button
= xbutton2hidd(xb
);
152 e
.type
= vHidd_Mouse_Press
;
153 data
->mouse_callback(data
->callbackdata
, &e
);
157 e
.type
= vHidd_Mouse_WheelMotion
;
158 e
.button
= vHidd_Mouse_NoButton
;
161 data
->mouse_callback(data
->callbackdata
, &e
);
165 e
.type
= vHidd_Mouse_WheelMotion
;
166 e
.button
= vHidd_Mouse_NoButton
;
169 data
->mouse_callback(data
->callbackdata
, &e
);
174 else if (msg
->event
->type
== MotionNotify
)
176 e
.button
= vHidd_Mouse_NoButton
;
177 e
.type
= vHidd_Mouse_Motion
;
179 data
->mouse_callback(data
->callbackdata
, &e
);
184 /****************************************************************************************/
187 #define XSD(cl) (&LIBBASE->xsd)
189 /****************************************************************************************/
191 static int X11Mouse_Init(LIBBASETYPEPTR LIBBASE
)
193 return OOP_ObtainAttrBases(attrbases
);
196 /****************************************************************************************/
198 static int X11Mouse_Expunge(LIBBASETYPEPTR LIBBASE
)
200 OOP_ReleaseAttrBases(attrbases
);
204 /****************************************************************************************/
206 ADD2INITLIB(X11Mouse_Init
, 0)
207 ADD2EXPUNGELIB(X11Mouse_Expunge
, 0)