1010#include < Message.h>
1111#include < View.h> // for B_PRIMARY_MOUSE_BUTTON, etc.
1212#include < stdio.h>
13+ #include < syslog.h>
14+
15+ // #define DEBUG_KEYCURSOR
1316
1417// ------------------------------------------------------------------------------
1518
@@ -42,11 +45,20 @@ KeyCursorDevice::KeyCursorDevice()
4245 fClickCount = 0 ;
4346 fClickedButton = 0 ;
4447 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+ }
4554}
4655
4756KeyCursorDevice::~KeyCursorDevice ()
4857{
49- // XXX: need to quit thread, etc.
58+ if (fThreadID != -1 ) {
59+ // just in case.
60+ kill_thread (fThreadID );
61+ }
5062}
5163
5264status_t KeyCursorDevice::InitCheck ()
@@ -89,6 +101,7 @@ status_t KeyCursorDevice::Stop(const char* /*device*/, void* /*cookie*/)
89101 delete_sem (quitSem);
90102 delete_port (fPortID );
91103 fPortID = -1 ;
104+ fThreadID = -1 ;
92105 }
93106 return B_OK;
94107}
@@ -97,6 +110,16 @@ status_t
97110KeyCursorDevice::Control (const char * device, void * cookie, uint32 code, BMessage* message)
98111{
99112 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+ }
100123 return B_OK;
101124}
102125
@@ -181,21 +204,18 @@ void KeyCursorDevice::ProcessMessage(int32 what, int32 data)
181204
182205 case BUTTON_DOWN:
183206 {
184- bigtime_t click_speed;
185- get_click_speed (&click_speed);
186207 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 ))
189212 {
213+ // a different button was clicked, or not fast enough as to count as a double-click.
190214 fClickCount = 1 ;
191215 fClickedButton = clicked;
192216 }
193- else
194- {
195- if ((now - fLastClick ) < click_speed)
196- fClickCount ++;
197- else
198- fClickCount = 1 ;
217+ else {
218+ fClickCount ++;
199219 }
200220
201221 fLastClick = now;
@@ -205,8 +225,10 @@ void KeyCursorDevice::ProcessMessage(int32 what, int32 data)
205225 {
206226 case 1 : buttonMask = B_PRIMARY_MOUSE_BUTTON; break ;
207227 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 ;
210232 }
211233
212234 BMessage* event = new BMessage (B_MOUSE_DOWN);
@@ -215,16 +237,15 @@ void KeyCursorDevice::ProcessMessage(int32 what, int32 data)
215237 event->AddInt32 (" clicks" , fClickCount );
216238 event->AddInt32 (" x" , 0 );
217239 event->AddInt32 (" y" , 0 );
240+ #ifdef DEBUG_KEYCURSOR
241+ syslog (LOG_INFO, " KeyCursorDevice: fClickCount = %d" , fClickCount );
242+ #endif
218243 EnqueueMessage (event);
219244 }
220245 break ;
221246
222247 case BUTTON_UP:
223248 {
224- fClickedButton = 0 ;
225- fLastClick = 0 ;
226- fClickCount = 0 ;
227-
228249 BMessage* event = new BMessage (B_MOUSE_UP);
229250 event->AddInt64 (" when" , now);
230251 event->AddInt32 (" x" , 0 );
@@ -284,10 +305,15 @@ void KeyCursorDevice::GenerateMotionEvent()
284305 {
285306 case 1 : buttonMask = B_PRIMARY_MOUSE_BUTTON; break ;
286307 case 2 : buttonMask = B_SECONDARY_MOUSE_BUTTON; break ;
287- case 3 : buttonMask = B_TERTIARY_MOUSE_BUTTON; break ;
288308 default : buttonMask = 0 ; break ;
289309 }
290310
311+ #ifdef DEBUG_KEYCURSOR
312+ if (fClickedButton ) {
313+ syslog (LOG_INFO, " KeyCursorDevice: fClickedButton = %d" , fClickedButton );
314+ }
315+ #endif
316+
291317 BMessage* event = new BMessage (B_MOUSE_MOVED);
292318 event->AddInt64 (" when" , now);
293319 event->AddInt32 (" buttons" , buttonMask);
@@ -299,7 +325,6 @@ void KeyCursorDevice::GenerateMotionEvent()
299325 {
300326 event = new BMessage (B_MOUSE_WHEEL_CHANGED);
301327 event->AddInt64 (" when" , now);
302- // event->AddFloat("be:wheel_delta_x", w);
303328 event->AddFloat (" be:wheel_delta_y" , w);
304329 EnqueueMessage (event);
305330 }
0 commit comments