10
10
#include < Message.h>
11
11
#include < View.h> // for B_PRIMARY_MOUSE_BUTTON, etc.
12
12
#include < stdio.h>
13
+ #include < syslog.h>
14
+
15
+ // #define DEBUG_KEYCURSOR
13
16
14
17
// ------------------------------------------------------------------------------
15
18
@@ -42,11 +45,20 @@ KeyCursorDevice::KeyCursorDevice()
42
45
fClickCount = 0 ;
43
46
fClickedButton = 0 ;
44
47
fAcceleration = fPrefs .GetAcceleration () / 1000000 .0f ;
48
+
49
+ status_t res = get_click_speed (&fClickSpeed );
50
+ if (res != B_OK) {
51
+ syslog (LOG_WARNING, " KeyCursorDevice(): using default value for fClickSpeed." );
52
+ fClickSpeed = 100000 ; // 0.1 secs
53
+ }
45
54
}
46
55
47
56
KeyCursorDevice::~KeyCursorDevice ()
48
57
{
49
- // XXX: need to quit thread, etc.
58
+ if (fThreadID != -1 ) {
59
+ // just in case.
60
+ kill_thread (fThreadID );
61
+ }
50
62
}
51
63
52
64
status_t KeyCursorDevice::InitCheck ()
@@ -89,6 +101,7 @@ status_t KeyCursorDevice::Stop(const char* /*device*/, void* /*cookie*/)
89
101
delete_sem (quitSem);
90
102
delete_port (fPortID );
91
103
fPortID = -1 ;
104
+ fThreadID = -1 ;
92
105
}
93
106
return B_OK;
94
107
}
@@ -97,6 +110,16 @@ status_t
97
110
KeyCursorDevice::Control (const char * device, void * cookie, uint32 code, BMessage* message)
98
111
{
99
112
BInputServerDevice::Control (device, cookie, code, message);
113
+ if (code == B_CLICK_SPEED_CHANGED) {
114
+ status_t res = get_click_speed (&fClickSpeed );
115
+ if (res != B_OK or fClickSpeed < 100000 ) {
116
+ syslog (LOG_WARNING, " KeyCursorDevice::Control(): using default value for fClickSpeed." );
117
+ fClickSpeed = 100000 ; // 0.1 secs should be the minumum value according to the BeBook.
118
+ }
119
+ #ifdef DEBUG_KEYCURSOR
120
+ else syslog (LOG_INFO, " KeyCursorDevice: fClickSpeed = %d" , fClickSpeed );
121
+ #endif
122
+ }
100
123
return B_OK;
101
124
}
102
125
@@ -181,21 +204,18 @@ void KeyCursorDevice::ProcessMessage(int32 what, int32 data)
181
204
182
205
case BUTTON_DOWN:
183
206
{
184
- bigtime_t click_speed;
185
- get_click_speed (&click_speed);
186
207
char clicked = (char ) data;
187
-
188
- if (clicked != fClickedButton )
208
+ #ifdef DEBUG_KEYCURSOR
209
+ syslog (LOG_INFO, " clicked = %d" , clicked);
210
+ #endif
211
+ if ((clicked != fClickedButton ) || ((now - fLastClick ) > fClickSpeed ))
189
212
{
213
+ // a different button was clicked, or not fast enough as to count as a double-click.
190
214
fClickCount = 1 ;
191
215
fClickedButton = clicked;
192
216
}
193
- else
194
- {
195
- if ((now - fLastClick ) < click_speed)
196
- fClickCount ++;
197
- else
198
- fClickCount = 1 ;
217
+ else {
218
+ fClickCount ++;
199
219
}
200
220
201
221
fLastClick = now;
@@ -205,8 +225,10 @@ void KeyCursorDevice::ProcessMessage(int32 what, int32 data)
205
225
{
206
226
case 1 : buttonMask = B_PRIMARY_MOUSE_BUTTON; break ;
207
227
case 2 : buttonMask = B_SECONDARY_MOUSE_BUTTON; break ;
208
- case 3 : buttonMask = B_TERTIARY_MOUSE_BUTTON; break ;
209
- default : buttonMask = 0 ; break ;
228
+ default :
229
+ syslog (LOG_ERR, " KeyCursorDevice::ProcessMessage(): Invalid fClickedButton = %d" , fClickedButton );
230
+ buttonMask = 0 ;
231
+ break ;
210
232
}
211
233
212
234
BMessage* event = new BMessage (B_MOUSE_DOWN);
@@ -215,16 +237,15 @@ void KeyCursorDevice::ProcessMessage(int32 what, int32 data)
215
237
event->AddInt32 (" clicks" , fClickCount );
216
238
event->AddInt32 (" x" , 0 );
217
239
event->AddInt32 (" y" , 0 );
240
+ #ifdef DEBUG_KEYCURSOR
241
+ syslog (LOG_INFO, " KeyCursorDevice: fClickCount = %d" , fClickCount );
242
+ #endif
218
243
EnqueueMessage (event);
219
244
}
220
245
break ;
221
246
222
247
case BUTTON_UP:
223
248
{
224
- fClickedButton = 0 ;
225
- fLastClick = 0 ;
226
- fClickCount = 0 ;
227
-
228
249
BMessage* event = new BMessage (B_MOUSE_UP);
229
250
event->AddInt64 (" when" , now);
230
251
event->AddInt32 (" x" , 0 );
@@ -284,10 +305,15 @@ void KeyCursorDevice::GenerateMotionEvent()
284
305
{
285
306
case 1 : buttonMask = B_PRIMARY_MOUSE_BUTTON; break ;
286
307
case 2 : buttonMask = B_SECONDARY_MOUSE_BUTTON; break ;
287
- case 3 : buttonMask = B_TERTIARY_MOUSE_BUTTON; break ;
288
308
default : buttonMask = 0 ; break ;
289
309
}
290
310
311
+ #ifdef DEBUG_KEYCURSOR
312
+ if (fClickedButton ) {
313
+ syslog (LOG_INFO, " KeyCursorDevice: fClickedButton = %d" , fClickedButton );
314
+ }
315
+ #endif
316
+
291
317
BMessage* event = new BMessage (B_MOUSE_MOVED);
292
318
event->AddInt64 (" when" , now);
293
319
event->AddInt32 (" buttons" , buttonMask);
@@ -299,7 +325,6 @@ void KeyCursorDevice::GenerateMotionEvent()
299
325
{
300
326
event = new BMessage (B_MOUSE_WHEEL_CHANGED);
301
327
event->AddInt64 (" when" , now);
302
- // event->AddFloat("be:wheel_delta_x", w);
303
328
event->AddFloat (" be:wheel_delta_y" , w);
304
329
EnqueueMessage (event);
305
330
}
0 commit comments