2 Copyright © 1995-2017, The AROS Development Team. All rights reserved.
5 Desc: X11 hidd handling mouse events.
11 #define __OOP_NOATTRBASES__
13 #include <proto/utility.h>
14 #include <hidd/mouse.h>
16 #include "x11_types.h"
17 #include LC_LIBDEFS_FILE
19 /****************************************************************************************/
21 static OOP_AttrBase HiddMouseAB
;
23 static struct OOP_ABDescr attrbases
[] =
25 { IID_Hidd_Mouse
, &HiddMouseAB
},
29 /****************************************************************************************/
31 static ULONG
xbutton2hidd(XButtonEvent
*xb
)
33 ULONG button
= vHidd_Mouse_NoButton
;
38 button
= vHidd_Mouse_Button1
;
42 button
= vHidd_Mouse_Button3
;
46 button
= vHidd_Mouse_Button2
;
54 /****************************************************************************************/
56 OOP_Object
* X11Mouse__Root__New(OOP_Class
*cl
, OOP_Object
*o
, struct pRoot_New
*msg
)
58 BOOL has_mouse_hidd
= FALSE
;
60 EnterFunc(bug("[X11Mouse] New()\n"));
61 ObtainSemaphoreShared( &XSD(cl
)->sema
);
63 if (XSD(cl
)->mousehidd
)
64 has_mouse_hidd
= TRUE
;
66 ReleaseSemaphore( &XSD(cl
)->sema
);
68 if (has_mouse_hidd
) /* Cannot open twice */
69 return NULL
; /* Should have some error code here */
71 o
= (OOP_Object
*)OOP_DoSuperMethod(cl
, o
, (OOP_Msg
)msg
);
74 struct x11mouse_data
*data
= OOP_INST_DATA(cl
, o
);
75 struct TagItem
*tag
, *tstate
;
77 tstate
= msg
->attrList
;
78 while ((tag
= NextTagItem(&tstate
)))
82 if (IS_HIDDMOUSE_ATTR(tag
->ti_Tag
, idx
))
86 case aoHidd_Mouse_IrqHandler
:
87 data
->mouse_callback
= (VOID (*)())tag
->ti_Data
;
90 case aoHidd_Mouse_IrqHandlerData
:
91 data
->callbackdata
= (APTR
)tag
->ti_Data
;
96 } /* while (tags to process) */
98 /* Install the mouse hidd */
100 ObtainSemaphore( &XSD(cl
)->sema
);
101 XSD(cl
)->mousehidd
= o
;
102 ReleaseSemaphore( &XSD(cl
)->sema
);
109 /****************************************************************************************/
111 VOID
X11Mouse__Root__Dispose(OOP_Class
*cl
, OOP_Object
*o
, OOP_Msg msg
)
113 EnterFunc(bug("[X11Mouse] Dispose()\n"));
115 ObtainSemaphore( &XSD(cl
)->sema
);
116 XSD(cl
)->mousehidd
= NULL
;
117 ReleaseSemaphore( &XSD(cl
)->sema
);
118 OOP_DoSuperMethod(cl
, o
, msg
);
121 /****************************************************************************************/
123 VOID
X11Mouse__Hidd_Mouse_X11__HandleEvent(OOP_Class
*cl
, OOP_Object
*o
, struct pHidd_Mouse_X11_HandleEvent
*msg
)
126 struct x11mouse_data
*data
= OOP_INST_DATA(cl
, o
);
127 struct pHidd_Mouse_Event e
;
129 DB2(bug("[X11Mouse] HandleEvent()\n"));
130 XButtonEvent
*xb
= &(msg
->event
->xbutton
);
135 if (msg
->event
->type
== ButtonRelease
)
142 e
.button
= xbutton2hidd(xb
);
143 e
.type
= vHidd_Mouse_Release
;
144 data
->mouse_callback(data
->callbackdata
, &e
);
148 else if (msg
->event
->type
== ButtonPress
)
155 e
.button
= xbutton2hidd(xb
);
156 e
.type
= vHidd_Mouse_Press
;
157 data
->mouse_callback(data
->callbackdata
, &e
);
161 e
.type
= vHidd_Mouse_WheelMotion
;
162 e
.button
= vHidd_Mouse_NoButton
;
165 data
->mouse_callback(data
->callbackdata
, &e
);
169 e
.type
= vHidd_Mouse_WheelMotion
;
170 e
.button
= vHidd_Mouse_NoButton
;
173 data
->mouse_callback(data
->callbackdata
, &e
);
178 else if (msg
->event
->type
== MotionNotify
)
180 e
.button
= vHidd_Mouse_NoButton
;
181 e
.type
= vHidd_Mouse_Motion
;
183 data
->mouse_callback(data
->callbackdata
, &e
);
188 /****************************************************************************************/
191 #define XSD(cl) (&LIBBASE->xsd)
193 /****************************************************************************************/
195 static int X11Mouse_Init(LIBBASETYPEPTR LIBBASE
)
197 return OOP_ObtainAttrBases(attrbases
);
200 /****************************************************************************************/
202 static int X11Mouse_Expunge(LIBBASETYPEPTR LIBBASE
)
204 OOP_ReleaseAttrBases(attrbases
);
208 /****************************************************************************************/
210 ADD2INITLIB(X11Mouse_Init
, 0)
211 ADD2EXPUNGELIB(X11Mouse_Expunge
, 0)