Fixed a few warnings.
[tangerine.git] / arch / all-hosted / hidd / x11 / x11mouse.c
blobf53cdf4df6a0624e9a41b0eb31e2fd9dcdb5c84e
1 /*
2 Copyright © 1995-2009, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: X11 hidd handling mouse events.
6 Lang: English.
7 */
9 #define __OOP_NOATTRBASES__
11 #include <proto/utility.h>
12 #include <proto/oop.h>
13 #include <oop/oop.h>
15 #include <X11/Xlib.h>
17 #include <hidd/hidd.h>
18 #include <hidd/mouse.h>
20 #include <aros/symbolsets.h>
22 #define DEBUG 0
23 #include <aros/debug.h>
25 #include LC_LIBDEFS_FILE
27 #include "x11.h"
29 /****************************************************************************************/
31 static OOP_AttrBase HiddMouseAB;
33 static struct OOP_ABDescr attrbases[] =
35 { IID_Hidd_Mouse, &HiddMouseAB },
36 { NULL , NULL }
39 /****************************************************************************************/
41 static ULONG xbutton2hidd(XButtonEvent *xb)
43 ULONG button;
45 switch (xb->button)
47 case Button1:
48 button = vHidd_Mouse_Button1;
49 break;
51 case Button2:
52 button = vHidd_Mouse_Button3;
53 break;
55 case Button3:
56 button = vHidd_Mouse_Button2;
57 break;
61 return button;
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);
82 if (o)
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)))
90 ULONG idx;
92 if (IS_HIDDMOUSE_ATTR(tag->ti_Tag, idx))
94 switch (idx)
96 case aoHidd_Mouse_IrqHandler:
97 data->mouse_callback = (VOID (*)())tag->ti_Data;
98 break;
100 case aoHidd_Mouse_IrqHandlerData:
101 data->callbackdata = (APTR)tag->ti_Data;
102 break;
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);
116 return o;
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);
142 e.x = xb->x;
143 e.y = xb->y;
145 if (msg->event->type == ButtonRelease)
147 switch(xb->button)
149 case Button1:
150 case Button2:
151 case Button3:
152 e.button = xbutton2hidd(xb);
153 e.type = vHidd_Mouse_Release;
154 data->mouse_callback(data->callbackdata, &e);
155 break;
158 else if (msg->event->type == ButtonPress)
160 switch(xb->button)
162 case Button1:
163 case Button2:
164 case Button3:
165 e.button = xbutton2hidd(xb);
166 e.type = vHidd_Mouse_Press;
167 data->mouse_callback(data->callbackdata, &e);
168 break;
170 case Button4:
171 e.type = vHidd_Mouse_WheelMotion;
172 e.button = vHidd_Mouse_NoButton;
173 e.x = 0;
174 e.y = -1;
175 data->mouse_callback(data->callbackdata, &e);
176 break;
178 case Button5:
179 e.type = vHidd_Mouse_WheelMotion;
180 e.button = vHidd_Mouse_NoButton;
181 e.x = 0;
182 e.y = 1;
183 data->mouse_callback(data->callbackdata, &e);
184 break;
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 /****************************************************************************************/
200 #undef XSD
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);
215 return TRUE;
218 /****************************************************************************************/
220 ADD2INITLIB(X11Mouse_Init, 0)
221 ADD2EXPUNGELIB(X11Mouse_Expunge, 0)