Added missing properties.
[tangerine.git] / arch / all-x11 / hidd / x11mouse.c
blob1aacbd76edc4003d4204b786900aa3f826ad743e
1 /*
2 Copyright © 1995-2006, 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 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);
81 if (o)
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)))
89 ULONG idx;
91 if (IS_HIDDMOUSE_ATTR(tag->ti_Tag, idx))
93 switch (idx)
95 case aoHidd_Mouse_IrqHandler:
96 data->mouse_callback = (VOID (*)())tag->ti_Data;
97 break;
99 case aoHidd_Mouse_IrqHandlerData:
100 data->callbackdata = (APTR)tag->ti_Data;
101 break;
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);
115 return o;
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);
128 e.x = xb->x;
129 e.y = xb->y;
131 if (msg->event->type == ButtonRelease)
133 switch(xb->button)
135 case Button1:
136 case Button2:
137 case Button3:
138 e.button = xbutton2hidd(xb);
139 e.type = vHidd_Mouse_Release;
140 data->mouse_callback(data->callbackdata, &e);
141 break;
144 else if (msg->event->type == ButtonPress)
146 switch(xb->button)
148 case Button1:
149 case Button2:
150 case Button3:
151 e.button = xbutton2hidd(xb);
152 e.type = vHidd_Mouse_Press;
153 data->mouse_callback(data->callbackdata, &e);
154 break;
156 case Button4:
157 e.type = vHidd_Mouse_WheelMotion;
158 e.button = vHidd_Mouse_NoButton;
159 e.x = 0;
160 e.y = -1;
161 data->mouse_callback(data->callbackdata, &e);
162 break;
164 case Button5:
165 e.type = vHidd_Mouse_WheelMotion;
166 e.button = vHidd_Mouse_NoButton;
167 e.x = 0;
168 e.y = 1;
169 data->mouse_callback(data->callbackdata, &e);
170 break;
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 /****************************************************************************************/
186 #undef XSD
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);
201 return TRUE;
204 /****************************************************************************************/
206 ADD2INITLIB(X11Mouse_Init, 0)
207 ADD2EXPUNGELIB(X11Mouse_Expunge, 0)