Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KeyCursor 1.2 #2

Merged
merged 7 commits into from
Jan 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
preflet/objects*
src/objects*
preflet/KeyCursor
src/KeyCursor
90 changes: 90 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# KeyCursor version 1.2

- (original version) by Nathan Schrenk.
- originally posted on BeBits by Eugenia Loli-Queru.
- (this version) by Oscar Lesta.

## What is this?

It's just an update to Nathan Schrenk's mighty KeyCursor input_server add-on.
Read his BeNewsLetter article to find more (included as article.txt).

This one does all the original version did (let you simulate a mouse using the keyboard) plus:

- Now you have a little preferences app that allows you to:
- choose which keys will toggle KeyCursor On/Off
- configure the acceleration factor
- disable KeyCursor usage, so you don't turn it on by accident.

- PageUp and PageDown act as a vertical mouse wheel when KeyCursor its active.

Just try it on Web+, it gives you a smooth scroll effect, kinda. I find it very useful to read the BeBook, mouseless :-)

## Basic usage:

Hit and release the toggle key(s) to activate KeyCursor, then use the arrow keys to move the cursor.

The space bar key acts as the primary button, and if you press SHIFT while "clicking" with the space key, you get a secondary button event.

Hit again the toggle key(s) to deactivate it.

## How to (un) install it?

Easiest way is just using HaikuDepot, or pkgman:

- `pkgman install keycursor`
- `pkgman uninstall keycursor`.

If compiling/installing from sources: Use the provided install.sh/uninstall.sh scripts.

## What else do I need to know?

The Preflet only allows you to configure the "toggle-keys" and not the "click" or "move" keys. That's because the later are just fine for me. The source code it's included, just in case you want to make it more complete.

Interaction with other input filters: works OK with InstantClick and TwoWheels (the ones I use). Your milleage will vary.

To build from sources, just type make at the shell, then use the install scripts.

As requested by previous mantainer, I'll let you know where to get the older versions:

- Eugenia's version:

- http://bezip.de/app/777/
- https://pulkomandy.tk/~beosarchive/unsorted/BDifferent/System/Add-Ons/input_server/KeyCursor-1.0.zip

- Nathan's (original) version:

- https://pulkomandy.tk/~beosarchive/unsorted/ftp.ntua.gr/mirror/BeOS/samples/input_server/KeyCursor.zip

## Thanks to:

- Nathan Schrenk - for the original version, quite handy when things go wrong with your input_server device hacking efforts.
- Thomas Thiriez - I used part of his EasyMove input_server filter addon and prefs app.
- OBOS (now Haiku) devs - I used some bytes from their cvs too.
- Eugenia - for transfering the app to me.

## History/Changelog

Newer versions, if any, will be available here: https://github.com/HaikuArchives/KeyCursor

1.2 Haiku-only from now on...

Fixed the issue where Tracker didn't registered double-clicks [issue#1](https://github.com/HaikuArchives/KeyCursor/issues/1)

Minor changes and cleanups.

1.1 First version:

For BeOS (2004/04/16):
- http://www.bebits.com/apps/1941/
- https://pulkomandy.tk/~beosarchive/unsorted/BDifferent/System/Add-Ons/input_server/KeyCursor-1.1.zip

For Haiku (2021/12/15):
- https://github.com/HaikuArchives/KeyCursor/releases/tag/1.1


### Notes

On BeOS R5, we could have the same binary "KeyCursor" addon placed in "add-ons/input_server/filter" and a symlink with the same name under "add-ons/input_server/devices" and it would work.

On Haiku that doesn't seems to work at all, and KeyCursor only works when those do NOT have the same name (changing the name of either the binary, or the name of the symlink, makes it work).
53 changes: 0 additions & 53 deletions Readme.txt

This file was deleted.

11 changes: 11 additions & 0 deletions install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/sh

rm -f ~/config/non-packaged/add-ons/input_server/devices/KeyCursorDevice
rm -f ~/config/non-packaged/add-ons/input_server/filters/KeyCursorFilter

cp src/KeyCursor ~/config/non-packaged/add-ons/input_server/devices/KeyCursorDevice
ln -s ~/config/non-packaged/add-ons/input_server/devices/KeyCursorDevice ~/config/non-packaged/add-ons/input_server/filters/KeyCursorFilter

# /system/servers/input_server -q
kill -9 `pidof input_server`
sleep 1
2 changes: 1 addition & 1 deletion preflet/ModifierBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const ModifierBox::MaskListType ModifierBox::ModifierList[]=
////////////////////////////////////////////////////////////////////////////////

ModifierBox::ModifierBox(BRect frame, const char* label, uint32 modifier,
uint32 button)
uint32 /*button*/)
: BBox(frame),
fDefaultModifier(0)
{
Expand Down
2 changes: 1 addition & 1 deletion preflet/ModifierBox.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class ModifierBox : public BInvoker, public BBox
struct MaskListType
{
uint32 mask;
char* label;
const char* label;
};

static const MaskListType ModifierList[];
Expand Down
4 changes: 2 additions & 2 deletions preflet/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ DEFINES = I_AM_THE_PREFLET
WARNINGS =
SYMBOLS =
DEBUGGER =
COMPILER_FLAGS =
LINKER_FLAGS = -s
COMPILER_FLAGS = -Wall -Wextra -Wundef -Wshadow -Wmissing-declarations -Wredundant-decls
LINKER_FLAGS =

## include the makefile-engine
include $(BUILDHOME)/etc/makefile-engine
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
65 changes: 45 additions & 20 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,17 +45,26 @@ 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()
{
input_device_ref* devices[2];
input_device_ref devRef = { KEY_CURSOR_DEVICE_NAME,
input_device_ref devRef = { (char*) KEY_CURSOR_DEVICE_NAME,
B_POINTING_DEVICE,
(void*) this };
devices[0] = &devRef;
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
5 changes: 5 additions & 0 deletions src/KeyCursorFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ KeyCursorFilter::KeyCursorFilter()

KeyCursorFilter::~KeyCursorFilter()
{
if (fPrefsThread != -1) {
kill_thread(fPrefsThread);
}
}

status_t KeyCursorFilter::InitCheck()
Expand Down Expand Up @@ -86,6 +89,7 @@ filter_result KeyCursorFilter::Filter(BMessage* message, BList* /*outList*/)
{
case B_UNMAPPED_KEY_DOWN:
case B_UNMAPPED_KEY_UP:
{
// raw modifier state changes only concern us in toggle mode
if (!fToggleMode)
{
Expand Down Expand Up @@ -118,6 +122,7 @@ filter_result KeyCursorFilter::Filter(BMessage* message, BList* /*outList*/)
}
toggleModPressedLast = false;
}
}
break;

case B_KEY_DOWN: // fall through
Expand Down
4 changes: 2 additions & 2 deletions src/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ DEFINES =
WARNINGS = ALL
SYMBOLS =
DEBUGGER =
COMPILER_FLAGS =
LINKER_FLAGS = -s
COMPILER_FLAGS = -Wall -Wextra -Wundef -Wshadow -Wmissing-declarations -Wredundant-decls
LINKER_FLAGS =

## include the makefile-engine
include $(BUILDHOME)/etc/makefile-engine
8 changes: 8 additions & 0 deletions uninstall.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/sh

rm ~/config/non-packaged/add-ons/input_server/devices/KeyCursorDevice
rm ~/config/non-packaged/add-ons/input_server/filters/KeyCursorFilter

# /system/servers/input_server -q
kill -9 `pidof input_server`
sleep 1