wip prep commit in lieu of gfx subsystem update changes.
[AROS.git] / arch / all-hosted / hidd / x11 / x11_mouseclass.c
blob734cdb5d4b21582b37648feffdf7947a008cac20
1 /*
2 Copyright © 1995-2017, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: X11 hidd handling mouse events.
6 Lang: English.
7 */
9 #include "x11_debug.h"
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 },
26 { NULL , NULL }
29 /****************************************************************************************/
31 static ULONG xbutton2hidd(XButtonEvent *xb)
33 ULONG button = vHidd_Mouse_NoButton;
35 switch (xb->button)
37 case Button1:
38 button = vHidd_Mouse_Button1;
39 break;
41 case Button2:
42 button = vHidd_Mouse_Button3;
43 break;
45 case Button3:
46 button = vHidd_Mouse_Button2;
47 break;
51 return button;
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);
72 if (o)
74 struct x11mouse_data *data = OOP_INST_DATA(cl, o);
75 struct TagItem *tag, *tstate;
77 tstate = msg->attrList;
78 while ((tag = NextTagItem(&tstate)))
80 ULONG idx;
82 if (IS_HIDDMOUSE_ATTR(tag->ti_Tag, idx))
84 switch (idx)
86 case aoHidd_Mouse_IrqHandler:
87 data->mouse_callback = (VOID (*)())tag->ti_Data;
88 break;
90 case aoHidd_Mouse_IrqHandlerData:
91 data->callbackdata = (APTR)tag->ti_Data;
92 break;
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);
106 return o;
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);
132 e.x = xb->x;
133 e.y = xb->y;
135 if (msg->event->type == ButtonRelease)
137 switch(xb->button)
139 case Button1:
140 case Button2:
141 case Button3:
142 e.button = xbutton2hidd(xb);
143 e.type = vHidd_Mouse_Release;
144 data->mouse_callback(data->callbackdata, &e);
145 break;
148 else if (msg->event->type == ButtonPress)
150 switch(xb->button)
152 case Button1:
153 case Button2:
154 case Button3:
155 e.button = xbutton2hidd(xb);
156 e.type = vHidd_Mouse_Press;
157 data->mouse_callback(data->callbackdata, &e);
158 break;
160 case Button4:
161 e.type = vHidd_Mouse_WheelMotion;
162 e.button = vHidd_Mouse_NoButton;
163 e.x = 0;
164 e.y = -1;
165 data->mouse_callback(data->callbackdata, &e);
166 break;
168 case Button5:
169 e.type = vHidd_Mouse_WheelMotion;
170 e.button = vHidd_Mouse_NoButton;
171 e.x = 0;
172 e.y = 1;
173 data->mouse_callback(data->callbackdata, &e);
174 break;
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 /****************************************************************************************/
190 #undef XSD
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);
205 return TRUE;
208 /****************************************************************************************/
210 ADD2INITLIB(X11Mouse_Init, 0)
211 ADD2EXPUNGELIB(X11Mouse_Expunge, 0)