Skip to content

Commit

Permalink
Fix issue (#1) where Tracker ignored multiple-clicks.
Browse files Browse the repository at this point in the history
Also:
- use get_click_speed() to use the user preference for that.
- kill thread on destructor.
  • Loading branch information
OscarL authored and pulkomandy committed Jan 9, 2023
1 parent 5250379 commit 8d0464e
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 19 deletions.
1 change: 1 addition & 0 deletions src/KeyCursor.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ class KeyCursorDevice : public BInputServerDevice

bigtime_t fTickInterval;
bigtime_t fLastClick;
bigtime_t fClickSpeed;
thread_id fThreadID;
port_id fPortID;
float fAcceleration;
Expand Down
63 changes: 44 additions & 19 deletions src/KeyCursorDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
#include <Message.h>
#include <View.h> // for B_PRIMARY_MOUSE_BUTTON, etc.
#include <stdio.h>
#include <syslog.h>

// #define DEBUG_KEYCURSOR

//------------------------------------------------------------------------------

Expand Down Expand Up @@ -42,11 +45,20 @@ KeyCursorDevice::KeyCursorDevice()
fClickCount = 0;
fClickedButton = 0;
fAcceleration = fPrefs.GetAcceleration() / 1000000.0f;

status_t res = get_click_speed(&fClickSpeed);
if (res != B_OK) {
syslog(LOG_WARNING, "KeyCursorDevice(): using default value for fClickSpeed.");
fClickSpeed = 100000; // 0.1 secs
}
}

KeyCursorDevice::~KeyCursorDevice()
{
// XXX: need to quit thread, etc.
if (fThreadID != -1) {
// just in case.
kill_thread(fThreadID);
}
}

status_t KeyCursorDevice::InitCheck()
Expand Down Expand Up @@ -89,6 +101,7 @@ status_t KeyCursorDevice::Stop(const char* /*device*/, void* /*cookie*/)
delete_sem(quitSem);
delete_port(fPortID);
fPortID = -1;
fThreadID = -1;
}
return B_OK;
}
Expand All @@ -97,6 +110,16 @@ status_t
KeyCursorDevice::Control(const char* device, void* cookie, uint32 code, BMessage* message)
{
BInputServerDevice::Control(device, cookie, code, message);
if (code == B_CLICK_SPEED_CHANGED) {
status_t res = get_click_speed(&fClickSpeed);
if (res != B_OK or fClickSpeed < 100000) {
syslog(LOG_WARNING, "KeyCursorDevice::Control(): using default value for fClickSpeed.");
fClickSpeed = 100000; // 0.1 secs should be the minumum value according to the BeBook.
}
#ifdef DEBUG_KEYCURSOR
else syslog(LOG_INFO, "KeyCursorDevice: fClickSpeed = %d", fClickSpeed);
#endif
}
return B_OK;
}

Expand Down Expand Up @@ -181,21 +204,18 @@ void KeyCursorDevice::ProcessMessage(int32 what, int32 data)

case BUTTON_DOWN:
{
bigtime_t click_speed;
get_click_speed(&click_speed);
char clicked = (char) data;

if (clicked != fClickedButton)
#ifdef DEBUG_KEYCURSOR
syslog(LOG_INFO, "clicked = %d", clicked);
#endif
if ((clicked != fClickedButton) || ((now - fLastClick) > fClickSpeed))
{
// a different button was clicked, or not fast enough as to count as a double-click.
fClickCount = 1;
fClickedButton = clicked;
}
else
{
if ((now - fLastClick) < click_speed)
fClickCount++;
else
fClickCount = 1;
else {
fClickCount++;
}

fLastClick = now;
Expand All @@ -205,8 +225,10 @@ void KeyCursorDevice::ProcessMessage(int32 what, int32 data)
{
case 1: buttonMask = B_PRIMARY_MOUSE_BUTTON; break;
case 2: buttonMask = B_SECONDARY_MOUSE_BUTTON; break;
case 3: buttonMask = B_TERTIARY_MOUSE_BUTTON; break;
default: buttonMask = 0; break;
default:
syslog(LOG_ERR, "KeyCursorDevice::ProcessMessage(): Invalid fClickedButton = %d", fClickedButton);
buttonMask = 0;
break;
}

BMessage* event = new BMessage(B_MOUSE_DOWN);
Expand All @@ -215,16 +237,15 @@ void KeyCursorDevice::ProcessMessage(int32 what, int32 data)
event->AddInt32("clicks", fClickCount);
event->AddInt32("x", 0);
event->AddInt32("y", 0);
#ifdef DEBUG_KEYCURSOR
syslog(LOG_INFO, "KeyCursorDevice: fClickCount = %d", fClickCount);
#endif
EnqueueMessage(event);
}
break;

case BUTTON_UP:
{
fClickedButton = 0;
fLastClick = 0;
fClickCount = 0;

BMessage* event = new BMessage(B_MOUSE_UP);
event->AddInt64("when", now);
event->AddInt32("x", 0);
Expand Down Expand Up @@ -284,10 +305,15 @@ void KeyCursorDevice::GenerateMotionEvent()
{
case 1 : buttonMask = B_PRIMARY_MOUSE_BUTTON; break;
case 2 : buttonMask = B_SECONDARY_MOUSE_BUTTON; break;
case 3 : buttonMask = B_TERTIARY_MOUSE_BUTTON; break;
default: buttonMask = 0; break;
}

#ifdef DEBUG_KEYCURSOR
if (fClickedButton) {
syslog(LOG_INFO, "KeyCursorDevice: fClickedButton = %d", fClickedButton);
}
#endif

BMessage* event = new BMessage(B_MOUSE_MOVED);
event->AddInt64("when", now);
event->AddInt32("buttons", buttonMask);
Expand All @@ -299,7 +325,6 @@ void KeyCursorDevice::GenerateMotionEvent()
{
event = new BMessage(B_MOUSE_WHEEL_CHANGED);
event->AddInt64("when", now);
// event->AddFloat("be:wheel_delta_x", w);
event->AddFloat("be:wheel_delta_y", w);
EnqueueMessage(event);
}
Expand Down

0 comments on commit 8d0464e

Please sign in to comment.