1 /*
2 (c) Copyright 2001-2009 The world wide DirectFB Open Source Community (directfb.org)
3 (c) Copyright 2000-2004 Convergence (integrated media) GmbH
4
5 All rights reserved.
6
7 Written by Denis Oliver Kropp <dok@directfb.org>,
8 Andreas Hundt <andi@fischlustig.de>,
9 Sven Neumann <neo@directfb.org>,
10 Ville Syrjälä <syrjala@sci.fi> and
11 Claudio Ciccani <klan@users.sf.net>.
12
13 This library is free software; you can redistribute it and/or
14 modify it under the terms of the GNU Lesser General Public
15 License as published by the Free Software Foundation; either
16 version 2 of the License, or (at your option) any later version.
17
18 This library is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 Lesser General Public License for more details.
22
23 You should have received a copy of the GNU Lesser General Public
24 License along with this library; if not, write to the
25 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
26 Boston, MA 02111-1307, USA.
27 */
28
29 #include <config.h>
30
31 #include <directfb.h>
32
33 #include <direct/debug.h>
34 #include <direct/messages.h>
35 #include <direct/util.h>
36
37 #include <core/gfxcard.h>
38 #include <core/state.h>
39
40 #include <misc/util.h>
41
42 #include <unique/context.h>
43 #include <unique/device.h>
44 #include <unique/internal.h>
45
46
47 D_DEBUG_DOMAIN( UniQuE_Wheel, "UniQuE/Wheel", "UniQuE's Wheel Device Class" );
48
49
50 typedef struct {
51 int magic;
52 } WheelData;
53
54 /**************************************************************************************************/
55
56 static DFBResult
wheel_initialize(UniqueDevice * device,void * data,void * ctx)57 wheel_initialize( UniqueDevice *device,
58 void *data,
59 void *ctx )
60 {
61 WheelData *wheel = data;
62
63 D_MAGIC_ASSERT( device, UniqueDevice );
64
65 D_DEBUG_AT( UniQuE_Wheel, "wheel_initialize( %p, %p, %p )\n", device, data, ctx );
66
67 D_MAGIC_SET( wheel, WheelData );
68
69 return DFB_OK;
70 }
71
72 static void
wheel_shutdown(UniqueDevice * device,void * data,void * ctx)73 wheel_shutdown( UniqueDevice *device,
74 void *data,
75 void *ctx )
76 {
77 WheelData *wheel = data;
78
79 D_MAGIC_ASSERT( device, UniqueDevice );
80 D_MAGIC_ASSERT( wheel, WheelData );
81
82 D_DEBUG_AT( UniQuE_Wheel, "wheel_shutdown( %p, %p, %p )\n", device, data, ctx );
83
84 D_MAGIC_CLEAR( wheel );
85 }
86
87 static void
wheel_connected(UniqueDevice * device,void * data,void * ctx,CoreInputDevice * source)88 wheel_connected( UniqueDevice *device,
89 void *data,
90 void *ctx,
91 CoreInputDevice *source )
92 {
93 WheelData *wheel = data;
94
95 (void) wheel;
96
97 D_MAGIC_ASSERT( device, UniqueDevice );
98 D_MAGIC_ASSERT( wheel, WheelData );
99
100 D_ASSERT( source != NULL );
101
102 D_DEBUG_AT( UniQuE_Wheel, "wheel_connected( %p, %p, %p, %p )\n",
103 device, data, ctx, source );
104 }
105
106 static void
wheel_disconnected(UniqueDevice * device,void * data,void * ctx,CoreInputDevice * source)107 wheel_disconnected( UniqueDevice *device,
108 void *data,
109 void *ctx,
110 CoreInputDevice *source )
111 {
112 WheelData *wheel = data;
113
114 (void) wheel;
115
116 D_MAGIC_ASSERT( device, UniqueDevice );
117 D_MAGIC_ASSERT( wheel, WheelData );
118
119 D_ASSERT( source != NULL );
120
121 D_DEBUG_AT( UniQuE_Wheel, "wheel_disconnected( %p, %p, %p, %p )\n",
122 device, data, ctx, source );
123 }
124
125 static void
wheel_process_event(UniqueDevice * device,void * data,void * ctx,const DFBInputEvent * event)126 wheel_process_event( UniqueDevice *device,
127 void *data,
128 void *ctx,
129 const DFBInputEvent *event )
130 {
131 UniqueInputEvent evt;
132 WheelData *wheel = data;
133
134 (void) wheel;
135
136 D_MAGIC_ASSERT( device, UniqueDevice );
137 D_MAGIC_ASSERT( wheel, WheelData );
138
139 D_ASSERT( event != NULL );
140
141 D_DEBUG_AT( UniQuE_Wheel, "wheel_process_event( %p, %p, %p, %p ) <- type 0x%08x\n",
142 device, data, ctx, event, event->type );
143
144 switch (event->type) {
145 case DIET_AXISMOTION:
146 switch (event->axis) {
147 case DIAI_Z:
148 evt.type = UIET_WHEEL;
149
150 evt.wheel.device_id = event->device_id;
151
152 if (event->flags & DIEF_AXISREL)
153 evt.wheel.value = -event->axisrel;
154 else if (event->flags & DIEF_AXISABS)
155 evt.wheel.value = event->axisabs;
156 else
157 break;
158
159 unique_device_dispatch( device, &evt );
160 break;
161
162 default:
163 break;
164 }
165 break;
166
167 default:
168 break;
169 }
170 }
171
172
173 const UniqueDeviceClass unique_wheel_device_class = {
174 data_size: sizeof(WheelData),
175
176 Initialize: wheel_initialize,
177 Shutdown: wheel_shutdown,
178 Connected: wheel_connected,
179 Disconnected: wheel_disconnected,
180 ProcessEvent: wheel_process_event
181 };
182
183