2 Copyright © 1995-2009, 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 EnterFunc(bug("[X11Mouse] New()\n"));
71 ObtainSemaphoreShared( &XSD(cl
)->sema
);
73 if (XSD(cl
)->mousehidd
)
74 has_mouse_hidd
= TRUE
;
76 ReleaseSemaphore( &XSD(cl
)->sema
);
78 if (has_mouse_hidd
) /* Cannot open twice */
79 return NULL
; /* Should have some error code here */
81 o
= (OOP_Object
*)OOP_DoSuperMethod(cl
, o
, (OOP_Msg
)msg
);
84 struct x11mouse_data
*data
= OOP_INST_DATA(cl
, o
);
85 struct TagItem
*tag
, *tstate
;
87 tstate
= msg
->attrList
;
88 while ((tag
= NextTagItem((const struct TagItem
**)&tstate
)))
92 if (IS_HIDDMOUSE_ATTR(tag
->ti_Tag
, idx
))
96 case aoHidd_Mouse_IrqHandler
:
97 data
->mouse_callback
= (VOID (*)())tag
->ti_Data
;
100 case aoHidd_Mouse_IrqHandlerData
:
101 data
->callbackdata
= (APTR
)tag
->ti_Data
;
106 } /* while (tags to process) */
108 /* Install the mouse hidd */
110 ObtainSemaphore( &XSD(cl
)->sema
);
111 XSD(cl
)->mousehidd
= o
;
112 ReleaseSemaphore( &XSD(cl
)->sema
);
119 /****************************************************************************************/
121 VOID
X11Mouse__Root__Dispose(OOP_Class
*cl
, OOP_Object
*o
, struct pRoot_Dispose
*msg
)
123 EnterFunc(bug("[X11Mouse] Dispose()\n"));
125 ObtainSemaphore( &XSD(cl
)->sema
);
126 XSD(cl
)->mousehidd
= NULL
;
127 ReleaseSemaphore( &XSD(cl
)->sema
);
128 OOP_DoSuperMethod(cl
, o
, msg
);
131 /****************************************************************************************/
133 VOID
X11Mouse__Hidd_X11Mouse__HandleEvent(OOP_Class
*cl
, OOP_Object
*o
, struct pHidd_X11Mouse_HandleEvent
*msg
)
136 struct x11mouse_data
*data
= OOP_INST_DATA(cl
, o
);
137 struct pHidd_Mouse_Event e
;
139 DB2(bug("[X11Mouse] HandleEvent()\n"));
140 XButtonEvent
*xb
= &(msg
->event
->xbutton
);
145 if (msg
->event
->type
== ButtonRelease
)
152 e
.button
= xbutton2hidd(xb
);
153 e
.type
= vHidd_Mouse_Release
;
154 data
->mouse_callback(data
->callbackdata
, &e
);
158 else if (msg
->event
->type
== ButtonPress
)
165 e
.button
= xbutton2hidd(xb
);
166 e
.type
= vHidd_Mouse_Press
;
167 data
->mouse_callback(data
->callbackdata
, &e
);
171 e
.type
= vHidd_Mouse_WheelMotion
;
172 e
.button
= vHidd_Mouse_NoButton
;
175 data
->mouse_callback(data
->callbackdata
, &e
);
179 e
.type
= vHidd_Mouse_WheelMotion
;
180 e
.button
= vHidd_Mouse_NoButton
;
183 data
->mouse_callback(data
->callbackdata
, &e
);
188 else if (msg
->event
->type
== MotionNotify
)
190 e
.button
= vHidd_Mouse_NoButton
;
191 e
.type
= vHidd_Mouse_Motion
;
193 data
->mouse_callback(data
->callbackdata
, &e
);
198 /****************************************************************************************/
201 #define XSD(cl) (&LIBBASE->xsd)
203 /****************************************************************************************/
205 static int X11Mouse_Init(LIBBASETYPEPTR LIBBASE
)
207 return OOP_ObtainAttrBases(attrbases
);
210 /****************************************************************************************/
212 static int X11Mouse_Expunge(LIBBASETYPEPTR LIBBASE
)
214 OOP_ReleaseAttrBases(attrbases
);
218 /****************************************************************************************/
220 ADD2INITLIB(X11Mouse_Init
, 0)
221 ADD2EXPUNGELIB(X11Mouse_Expunge
, 0)