added 3 changesets to branch 'refs/remotes/jessicah-github/synergy' old head: ddfccdf22ae227c75ac0699047f1a1045eaf9f07 new head: 5fb6da4ebeb8bec3739fbe883c7138d6e5826f68 overview: https://github.com/jessicah/haiku/compare/ddfccdf...5fb6da4 ---------------------------------------------------------------------------- 8aaf1ba: synergy: fix establishing remote connection 8381463: synergy: attempt at working keyboard support 5fb6da4: synergy: semi-working keyboard code [ Jessica Hamilton <jessica.l.hamilton@xxxxxxxxx> ] ---------------------------------------------------------------------------- 4 files changed, 252 insertions(+), 48 deletions(-) src/add-ons/input_server/devices/synergy/Jamfile | 7 +- .../devices/synergy/haiku-usynergy.cpp | 265 ++++++++++++++++--- .../devices/synergy/haiku-usynergy.h | 24 +- .../input_server/devices/synergy/uSynergy.c | 4 +- ############################################################################ Commit: 8aaf1ba357ed01caa81ef5c45bf465efbd5b1fac Author: Jessica Hamilton <jessica.l.hamilton@xxxxxxxxx> Date: Mon Sep 29 18:33:25 2014 UTC synergy: fix establishing remote connection ---------------------------------------------------------------------------- diff --git a/src/add-ons/input_server/devices/synergy/haiku-usynergy.cpp b/src/add-ons/input_server/devices/synergy/haiku-usynergy.cpp index c9b7b3f..99e10e6 100644 --- a/src/add-ons/input_server/devices/synergy/haiku-usynergy.cpp +++ b/src/add-ons/input_server/devices/synergy/haiku-usynergy.cpp @@ -4,6 +4,7 @@ #include <cstdlib> #include <strings.h> #include <errno.h> +#include <arpa/inet.h> #include <keyboard_mouse_driver.h> @@ -128,7 +129,6 @@ uSynergyInputServerDevice::Control(const char* name, void* cookie, uint32 comman BMessage* uSynergyInputServerDevice::_BuildMouseMessage(uint32 what, uint64 when, uint32 buttons, float x, float y) const { - CALLED(); BMessage* message = new BMessage(what); if (message == NULL) return NULL; @@ -147,14 +147,11 @@ uSynergyInputServerDevice::_BuildMouseMessage(uint32 what, uint64 when, uint32 b status_t uSynergyInputServerDevice::uSynergyThreadLoop(void* arg) { - CALLED(); uSynergyContext *uSynergyHaikuContext = (uSynergyContext*)arg; uSynergyInputServerDevice *inputDevice = (uSynergyInputServerDevice*)uSynergyHaikuContext->m_cookie; while (inputDevice->threadActive) { uSynergyUpdate(uSynergyHaikuContext); - TRACE("synergy: update triggered\n"); - snooze(1000000); } return B_OK; @@ -168,31 +165,28 @@ uSynergyConnectHaiku(uSynergyCookie cookie) CALLED(); uSynergyInputServerDevice *inputDevice = (uSynergyInputServerDevice*)cookie; - struct hostent *host = gethostbyname("10.20.30.18"); - if (host == NULL) { - TRACE("synergy: host 10.20.30.18 doesn't exist!\n"); - snooze(1000000); - return USYNERGY_FALSE; - } - bzero(&inputDevice->synergyServerData, sizeof(inputDevice->synergyServerData)); - bcopy(host->h_addr, &(inputDevice->synergyServerData.sin_addr.s_addr), host->h_length); - inputDevice->synergyServerData.sin_family = AF_INET; - inputDevice->synergyServerData.sin_port = htons(24800); - inputDevice->synergyServerSocket = socket(AF_INET, SOCK_STREAM, 0); + struct sockaddr_in server; + + server.sin_family = AF_INET; + server.sin_port = htons(24800); + inet_aton("10.20.30.18", &server.sin_addr); + + inputDevice->synergyServerSocket = socket(PF_INET, SOCK_STREAM, 0); if (inputDevice->synergyServerSocket < 0) { - TRACE("SYNERGY: socket couldn't be created\n"); + TRACE("synergy: socket couldn't be created\n"); snooze(1000000); return USYNERGY_FALSE; } - if (connect(inputDevice->synergyServerSocket, (struct sockaddr*)&inputDevice->synergyServerData, sizeof(struct sockaddr*)) < 0 ) { - TRACE("%s: %d\n", "failed to connect to remote host", errno); + if (connect(inputDevice->synergyServerSocket, (struct sockaddr*)&server, sizeof(struct sockaddr)) < 0 ) { + TRACE("synergy: %s: %d\n", "failed to connect to remote host", errno); close(inputDevice->synergyServerSocket); snooze(1000000); // temporary workaround to avoid filling up log too quickly return USYNERGY_FALSE; } else { + TRACE("synergy: connected to remote host!!!\n"); return USYNERGY_TRUE; } } @@ -200,7 +194,6 @@ uSynergyConnectHaiku(uSynergyCookie cookie) uSynergyBool uSynergySendHaiku(uSynergyCookie cookie, const uint8_t *buffer, int length) { - CALLED(); uSynergyInputServerDevice *inputDevice = (uSynergyInputServerDevice*)cookie; if (send(inputDevice->synergyServerSocket, buffer, length, 0) != length) @@ -211,7 +204,6 @@ uSynergySendHaiku(uSynergyCookie cookie, const uint8_t *buffer, int length) uSynergyBool uSynergyReceiveHaiku(uSynergyCookie cookie, uint8_t *buffer, int maxLength, int* outLength) { - CALLED(); uSynergyInputServerDevice *inputDevice = (uSynergyInputServerDevice*)cookie; if ((*outLength = recv(inputDevice->synergyServerSocket, buffer, maxLength, 0)) == -1) @@ -222,14 +214,12 @@ uSynergyReceiveHaiku(uSynergyCookie cookie, uint8_t *buffer, int maxLength, int* void uSynergySleepHaiku(uSynergyCookie cookie, int timeMs) { - CALLED(); snooze(timeMs * 1000); } uint32_t uSynergyGetTimeHaiku() { - CALLED(); return system_time(); } @@ -254,7 +244,6 @@ uSynergyScreenActiveCallbackHaiku(uSynergyCookie cookie, uSynergyBool active) void uSynergyMouseCallbackHaiku(uSynergyCookie cookie, uint16_t x, uint16_t y, int16_t wheelX, int16_t wheelY, uSynergyBool buttonLeft, uSynergyBool buttonRight, uSynergyBool buttonMiddle) { - CALLED(); uSynergyInputServerDevice *inputDevice = (uSynergyInputServerDevice*)cookie; static uint32_t oldButtons = 0; uint32_t buttons = 0; ############################################################################ Commit: 8381463c5095c5f133960e2727fbe9cde3381215 Author: Jessica Hamilton <jessica.l.hamilton@xxxxxxxxx> Date: Mon Sep 29 06:34:09 2014 UTC synergy: attempt at working keyboard support ---------------------------------------------------------------------------- diff --git a/src/add-ons/input_server/devices/synergy/Jamfile b/src/add-ons/input_server/devices/synergy/Jamfile index 554687c..d7a6e5d 100644 --- a/src/add-ons/input_server/devices/synergy/Jamfile +++ b/src/add-ons/input_server/devices/synergy/Jamfile @@ -2,11 +2,12 @@ SubDir HAIKU_TOP src add-ons input_server devices synergy ; SetSubDirSupportedPlatformsBeOSCompatible ; -UsePrivateHeaders input network shared ; +UsePrivateHeaders input interface network shared ; UsePrivateSystemHeaders ; Addon <input>synergy : uSynergy.c haiku-usynergy.cpp + Keymap.cpp - : input_server be network [ TargetLibsupc++ ] ; + : input_server be libshared.a network [ TargetLibsupc++ ] ; diff --git a/src/add-ons/input_server/devices/synergy/haiku-usynergy.cpp b/src/add-ons/input_server/devices/synergy/haiku-usynergy.cpp index 99e10e6..47eadce 100644 --- a/src/add-ons/input_server/devices/synergy/haiku-usynergy.cpp +++ b/src/add-ons/input_server/devices/synergy/haiku-usynergy.cpp @@ -1,3 +1,6 @@ + +#include <Application.h> +#include <Autolock.h> #include <Notification.h> #include <Screen.h> #include <OS.h> @@ -5,6 +8,10 @@ #include <strings.h> #include <errno.h> #include <arpa/inet.h> +#include <sys/socket.h> +#include <sys/types.h> +#include <netinet/in.h> +#include <netdb.h> #include <keyboard_mouse_driver.h> @@ -31,6 +38,9 @@ const static uint32 kSynergyThreadPriority = B_FIRST_REAL_TIME_PRIORITY + 4; uSynergyInputServerDevice::uSynergyInputServerDevice() + : + fUpdateSettings(false), + fKeymapLock("synergy keymap lock") { CALLED(); uSynergyHaikuContext = (uSynergyContext*)malloc(sizeof(uSynergyContext)); @@ -123,6 +133,9 @@ uSynergyInputServerDevice::Stop(const char* name, void* cookie) status_t uSynergyInputServerDevice::Control(const char* name, void* cookie, uint32 command, BMessage* message) { + if (command == B_KEY_MAP_CHANGED) + fUpdateSettings = true; + return B_OK; } @@ -144,6 +157,16 @@ uSynergyInputServerDevice::_BuildMouseMessage(uint32 what, uint64 when, uint32 b return message; } +void +uSynergyInputServerDevice::_UpdateSettings() +{ + BAutolock lock(fKeymapLock); + fKeymap.RetrieveCurrent(); + fModifiers = fKeymap.Map().lock_settings; + fControlKey = fKeymap.KeyForModifier(B_LEFT_CONTROL_KEY); + fCommandKey = fKeymap.KeyForModifier(B_LEFT_COMMAND_KEY); +} + status_t uSynergyInputServerDevice::uSynergyThreadLoop(void* arg) { @@ -152,13 +175,17 @@ uSynergyInputServerDevice::uSynergyThreadLoop(void* arg) while (inputDevice->threadActive) { uSynergyUpdate(uSynergyHaikuContext); + + if (inputDevice->fUpdateSettings) { + inputDevice->_UpdateSettings(); + inputDevice->fUpdateSettings = false; + } } return B_OK; } -extern "C" { uSynergyBool uSynergyConnectHaiku(uSynergyCookie cookie) { @@ -166,11 +193,11 @@ uSynergyConnectHaiku(uSynergyCookie cookie) uSynergyInputServerDevice *inputDevice = (uSynergyInputServerDevice*)cookie; struct sockaddr_in server; - + server.sin_family = AF_INET; server.sin_port = htons(24800); inet_aton("10.20.30.18", &server.sin_addr); - + inputDevice->synergyServerSocket = socket(PF_INET, SOCK_STREAM, 0); if (inputDevice->synergyServerSocket < 0) { @@ -248,10 +275,11 @@ uSynergyMouseCallbackHaiku(uSynergyCookie cookie, uint16_t x, uint16_t y, int16_ static uint32_t oldButtons = 0; uint32_t buttons = 0; static uint16_t oldX = 0, oldY = 0; - static int16_t oldWheelX = 0, oldWheelY = 0; float xVal = (float)x / (float)inputDevice->uSynergyHaikuContext->m_clientWidth; float yVal = (float)y / (float)inputDevice->uSynergyHaikuContext->m_clientHeight; + int64 timestamp = system_time(); + if (buttonLeft == USYNERGY_TRUE) { buttons |= 1 << 0; } @@ -264,39 +292,227 @@ uSynergyMouseCallbackHaiku(uSynergyCookie cookie, uint16_t x, uint16_t y, int16_ if (buttons != oldButtons) { bool pressedButton = buttons > 0; - BMessage* message = inputDevice->_BuildMouseMessage(pressedButton ? B_MOUSE_DOWN : B_MOUSE_UP, system_time(), buttons, xVal, yVal); + BMessage* message = inputDevice->_BuildMouseMessage(pressedButton ? B_MOUSE_DOWN : B_MOUSE_UP, timestamp, buttons, xVal, yVal); if (message != NULL) inputDevice->EnqueueMessage(message); oldButtons = buttons; } if ((x != oldX) || (y != oldY)) { - BMessage* message = inputDevice->_BuildMouseMessage(B_MOUSE_MOVED, system_time(), buttons, xVal, yVal); + BMessage* message = inputDevice->_BuildMouseMessage(B_MOUSE_MOVED, timestamp, buttons, xVal, yVal); if (message != NULL) inputDevice->EnqueueMessage(message); oldX = x; oldY = y; } - if ((oldWheelX != wheelX) || (oldWheelY = wheelY)) { + if (wheelX != 0 && wheelY != 0) { BMessage* message = new BMessage(B_MOUSE_WHEEL_CHANGED); if (message != NULL) { - if (message->AddInt64("when", system_time()) == B_OK + if (message->AddInt64("when", timestamp) == B_OK && message->AddFloat("be:wheel_delta_x", wheelX) == B_OK && message->AddFloat("be:wheel_delta_y", wheelY) == B_OK) inputDevice->EnqueueMessage(message); else delete message; } - oldWheelX = wheelX; - oldWheelY = wheelY; } } void -uSynergyKeyboardCallbackHaiku(uSynergyCookie cookie, uint16_t key, uint16_t modifiers, uSynergyBool down, uSynergyBool repeat) +uSynergyInputServerDevice::_ProcessKeyboard(uint16_t keycode, uint16_t _modifiers, bool isKeyDown, bool isKeyRepeat) { + static uint8 activeDeadKey = 0; + static uint32 lastKeyCode = 0; + static uint32 repeatCount = 1; + static uint8 states[16]; + + int64 timestamp = system_time(); + + TRACE("synergy: keycode = %04x, modifiers = %04x\n", keycode, _modifiers); + + if (isKeyDown && keycode == 0x68) { + // MENU KEY for Tracker + bool noOtherKeyPressed = true; + for (int32 i = 0; i < 16; ++i) { + if (states[i] != 0) { + noOtherKeyPressed = false; + break; + } + } + if (noOtherKeyPressed) { + BMessenger deskbar("application/x-bnd.Be-TSKB"); + if (deskbar.IsValid()) + deskbar.SendMessage('BeMn'); + } + } + + if (keycode < 256) { + if (isKeyDown) + states[(keycode) >> 3] |= (1 << (7 - (keycode & 0x7))); + else + states[(keycode) >> 3] &= (!(1 << (7 - (keycode & 0x7)))); + } +#if false + if (isKeyDown && keycode == 0x34 // DELETE KEY + && (states[fCommandKey >> 3] & (1 << (7 - (fCommandKey & 0x7)))) + && (states[fControlKey >> 3] & (1 << (7 - (fControlKey & 0x7))))) { + //LOG_EVENT("TeamMonitor called\n"); + + // show the team monitor + if (fOwner->fTeamMonitorWindow == NULL) + fOwner->fTeamMonitorWindow = new(std::nothrow) TeamMonitorWindow(); + + if (fOwner->fTeamMonitorWindow != NULL) + fOwner->fTeamMonitorWindow->Enable(); + + ctrlAltDelPressed = true; + } + + if (ctrlAltDelPressed) { + if (fOwner->fTeamMonitorWindow != NULL) { + BMessage message(kMsgCtrlAltDelPressed); + message.AddBool("key down", isKeyDown); + fOwner->fTeamMonitorWindow->PostMessage(&message); + } + + if (!isKeyDown) + ctrlAltDelPressed = false; + } +#endif + BAutolock lock(fKeymapLock); + + uint32 modifiers = fKeymap.Modifier(keycode); + bool isLock + = (modifiers & (B_CAPS_LOCK | B_NUM_LOCK | B_SCROLL_LOCK)) != 0; + if (modifiers != 0 && (!isLock || isKeyDown)) { + uint32 oldModifiers = fModifiers; + + if ((isKeyDown && !isLock) + || (isKeyDown && !(fModifiers & modifiers))) + fModifiers |= modifiers; + else { + fModifiers &= ~modifiers; + + // ensure that we don't clear a combined B_*_KEY when still + // one of the individual B_{LEFT|RIGHT}_*_KEY is pressed + if (fModifiers & (B_LEFT_SHIFT_KEY | B_RIGHT_SHIFT_KEY)) + fModifiers |= B_SHIFT_KEY; + if (fModifiers & (B_LEFT_COMMAND_KEY | B_RIGHT_COMMAND_KEY)) + fModifiers |= B_COMMAND_KEY; + if (fModifiers & (B_LEFT_CONTROL_KEY | B_RIGHT_CONTROL_KEY)) + fModifiers |= B_CONTROL_KEY; + if (fModifiers & (B_LEFT_OPTION_KEY | B_RIGHT_OPTION_KEY)) + fModifiers |= B_OPTION_KEY; + } + + if (fModifiers != oldModifiers) { + BMessage* message = new BMessage(B_MODIFIERS_CHANGED); + if (message == NULL) + return; + + message->AddInt64("when", timestamp); + message->AddInt32("be:old_modifiers", oldModifiers); + message->AddInt32("modifiers", fModifiers); + message->AddData("states", B_UINT8_TYPE, states, 16); + + if (EnqueueMessage(message) != B_OK) + delete message; + } + } + + uint8 newDeadKey = 0; + if (activeDeadKey == 0 || !isKeyDown) + newDeadKey = fKeymap.ActiveDeadKey(keycode, fModifiers); + + char* string = NULL; + char* rawString = NULL; + int32 numBytes = 0, rawNumBytes = 0; + if (newDeadKey == 0) { + fKeymap.GetChars(keycode, fModifiers, activeDeadKey, &string, + &numBytes); + } + fKeymap.GetChars(keycode, 0, 0, &rawString, &rawNumBytes); + + BMessage* msg = new BMessage; + if (msg == NULL) { + delete[] string; + delete[] rawString; + return; + } + + if (numBytes > 0) + msg->what = isKeyDown ? B_KEY_DOWN : B_KEY_UP; + else + msg->what = isKeyDown ? B_UNMAPPED_KEY_DOWN : B_UNMAPPED_KEY_UP; + + msg->AddInt64("when", timestamp); + msg->AddInt32("key", keycode); + msg->AddInt32("modifiers", fModifiers); + msg->AddData("states", B_UINT8_TYPE, states, 16); + if (numBytes > 0) { + for (int i = 0; i < numBytes; i++) + msg->AddInt8("byte", (int8)string[i]); + msg->AddData("bytes", B_STRING_TYPE, string, numBytes + 1); + + if (rawNumBytes <= 0) { + rawNumBytes = 1; + delete[] rawString; + rawString = string; + } else + delete[] string; + + if (isKeyDown && lastKeyCode == keycode) { + repeatCount++; + msg->AddInt32("be:key_repeat", repeatCount); + } else + repeatCount = 1; + } else + delete[] string; + + if (rawNumBytes > 0) + msg->AddInt32("raw_char", (uint32)((uint8)rawString[0] & 0x7f)); + + delete[] rawString; +#if 0 + if (newDeadKey == 0) { + if (isKeyDown && !modifiers && activeDeadKey != 0) { + // a dead key was completed + activeDeadKey = 0; + if (fInputMethodStarted) { + _EnqueueInlineInputMethod(B_INPUT_METHOD_CHANGED, + string, true, msg); + _EnqueueInlineInputMethod(B_INPUT_METHOD_STOPPED); + fInputMethodStarted = false; + msg = NULL; + } + } + } else if (isKeyDown + && _EnqueueInlineInputMethod(B_INPUT_METHOD_STARTED) == B_OK) { + // start of a dead key + char* string = NULL; + int32 numBytes = 0; + fKeymap.GetChars(keycode, fModifiers, 0, &string, &numBytes); + + if (_EnqueueInlineInputMethod(B_INPUT_METHOD_CHANGED, string) + == B_OK) + fInputMethodStarted = true; + + activeDeadKey = newDeadKey; + delete[] string; + } +#endif + if (msg != NULL && EnqueueMessage(msg) != B_OK) + delete msg; + + lastKeyCode = isKeyDown ? keycode : 0; +} + +void +uSynergyKeyboardCallbackHaiku(uSynergyCookie cookie, uint16_t key, uint16_t modifiers, uSynergyBool down, uSynergyBool repeat) +{ + ((uSynergyInputServerDevice*)cookie)->_ProcessKeyboard(key, modifiers, down, repeat); } void @@ -311,7 +527,6 @@ uSynergyClipboardCallbackHaiku(uSynergyCookie cookie, enum uSynergyClipboardForm } -} extern "C" BInputServerDevice* instantiate_input_device() diff --git a/src/add-ons/input_server/devices/synergy/haiku-usynergy.h b/src/add-ons/input_server/devices/synergy/haiku-usynergy.h index b77afc4..7ea94c2 100644 --- a/src/add-ons/input_server/devices/synergy/haiku-usynergy.h +++ b/src/add-ons/input_server/devices/synergy/haiku-usynergy.h @@ -8,24 +8,16 @@ #ifndef USYNERGY_H #define USYNERGY_H -extern "C" -{ -#include <sys/socket.h> -#include <sys/types.h> -#include <netinet/in.h> -#include <netdb.h> -} - #include <InputServerDevice.h> #include <InterfaceDefs.h> #include <Locker.h> #include <ObjectList.h> +#include "Keymap.h" #include "uSynergy.h" -extern "C" -{ + uSynergyBool uSynergyConnectHaiku(uSynergyCookie cookie); uSynergyBool uSynergySendHaiku(uSynergyCookie cookie, const uint8_t *buffer, int length); uSynergyBool uSynergyReceiveHaiku(uSynergyCookie cookie, uint8_t *buffer, int maxLength, int* outLength); @@ -37,7 +29,6 @@ void uSynergyMouseCallbackHaiku(uSynergyCookie cookie, uint16_t x, void uSynergyKeyboardCallbackHaiku(uSynergyCookie cookie, uint16_t key, uint16_t modifiers, uSynergyBool down, uSynergyBool repeat); void uSynergyJoystickCallbackHaiku(uSynergyCookie cookie, uint8_t joyNum, uint16_t buttons, int8_t leftStickX, int8_t leftStickY, int8_t rightStickX, int8_t rightStickY); void uSynergyClipboardCallbackHaiku(uSynergyCookie cookie, enum uSynergyClipboardFormat format, const uint8_t *data, uint32_t size); -} class uSynergyInputServerDevice : public BInputServerDevice { public: @@ -56,12 +47,23 @@ class uSynergyInputServerDevice : public BInputServerDevice { uSynergyContext *uSynergyHaikuContext; BMessage* _BuildMouseMessage(uint32 what, uint64 when, uint32 buttons, float x, float y) const; + void _ProcessKeyboard(uint16_t keycode, uint16_t modifiers, bool isKeyDown, bool isKeyRepeat); + void _UpdateSettings(); public: struct sockaddr_in synergyServerData; int synergyServerSocket; private: static status_t uSynergyThreadLoop(void* arg); + uint32 fModifiers; + uint32 fCommandKey; + uint32 fControlKey; + + volatile bool fUpdateSettings; + + Keymap fKeymap; + BLocker fKeymapLock; + public: /* callbacks for uSynergy */ friend uSynergyBool uSynergyConnectHaiku(uSynergyCookie cookie); ############################################################################ Commit: 5fb6da4ebeb8bec3739fbe883c7138d6e5826f68 Author: Jessica Hamilton <jessica.l.hamilton@xxxxxxxxx> Date: Mon Sep 29 11:13:37 2014 UTC synergy: semi-working keyboard code ---------------------------------------------------------------------------- diff --git a/src/add-ons/input_server/devices/synergy/Jamfile b/src/add-ons/input_server/devices/synergy/Jamfile index d7a6e5d..e11fd00 100644 --- a/src/add-ons/input_server/devices/synergy/Jamfile +++ b/src/add-ons/input_server/devices/synergy/Jamfile @@ -2,6 +2,8 @@ SubDir HAIKU_TOP src add-ons input_server devices synergy ; SetSubDirSupportedPlatformsBeOSCompatible ; +SubDirHdrs $(HAIKU_TOP) src add-ons kernel bus_managers ps2 ; + UsePrivateHeaders input interface network shared ; UsePrivateSystemHeaders ; diff --git a/src/add-ons/input_server/devices/synergy/haiku-usynergy.cpp b/src/add-ons/input_server/devices/synergy/haiku-usynergy.cpp index 47eadce..e9f7f86 100644 --- a/src/add-ons/input_server/devices/synergy/haiku-usynergy.cpp +++ b/src/add-ons/input_server/devices/synergy/haiku-usynergy.cpp @@ -15,6 +15,8 @@ #include <keyboard_mouse_driver.h> +#include "ATKeymap.h" + #include "haiku-usynergy.h" @@ -275,6 +277,7 @@ uSynergyMouseCallbackHaiku(uSynergyCookie cookie, uint16_t x, uint16_t y, int16_ static uint32_t oldButtons = 0; uint32_t buttons = 0; static uint16_t oldX = 0, oldY = 0; + static int16_t oldWheelX = 0, oldWheelY = 0; float xVal = (float)x / (float)inputDevice->uSynergyHaikuContext->m_clientWidth; float yVal = (float)y / (float)inputDevice->uSynergyHaikuContext->m_clientHeight; @@ -306,47 +309,55 @@ uSynergyMouseCallbackHaiku(uSynergyCookie cookie, uint16_t x, uint16_t y, int16_ oldY = y; } - if (wheelX != 0 && wheelY != 0) { + if (wheelX != 0 || wheelY != 0) { BMessage* message = new BMessage(B_MOUSE_WHEEL_CHANGED); if (message != NULL) { if (message->AddInt64("when", timestamp) == B_OK - && message->AddFloat("be:wheel_delta_x", wheelX) == B_OK - && message->AddFloat("be:wheel_delta_y", wheelY) == B_OK) + && message->AddFloat("be:wheel_delta_x", (oldWheelX - wheelX) / 120) == B_OK + && message->AddFloat("be:wheel_delta_y", (oldWheelY - wheelY) / 120) == B_OK) inputDevice->EnqueueMessage(message); else delete message; } + oldWheelX = wheelX; + oldWheelY = wheelY; } } +/* Synergy modifier definitions */ +#define SYNERGY_SHIFT 0x0001 +#define SYNERGY_CONTROL 0x0002 +#define SYNERGY_ALT 0x0004 +#define SYNERGY_META 0x0008 +#define SYNERGY_SUPER 0x0010 +#define SYNERGY_ALTGR 0x0020 +#define SYNERGY_LEVEL5LOCK 0x0040 +#define SYNERGY_CAPSLOCK 0x1000 +#define SYNERGY_NUMLOCK 0x2000 +#define SYNERGY_SCROLLLOCK 0x4000 +#define EXTENDED_KEY 0xe000 + void -uSynergyInputServerDevice::_ProcessKeyboard(uint16_t keycode, uint16_t _modifiers, bool isKeyDown, bool isKeyRepeat) +uSynergyInputServerDevice::_ProcessKeyboard(uint16_t scancode, uint16_t _modifiers, bool isKeyDown, bool isKeyRepeat) { - static uint8 activeDeadKey = 0; - static uint32 lastKeyCode = 0; + static uint32 lastScanCode = 0; static uint32 repeatCount = 1; static uint8 states[16]; - int64 timestamp = system_time(); + bool isExtended = false; - TRACE("synergy: keycode = %04x, modifiers = %04x\n", keycode, _modifiers); + if (scancode & EXTENDED_KEY != 0) { + isExtended = true; + TRACE("synergy: extended key\n"); + } - if (isKeyDown && keycode == 0x68) { - // MENU KEY for Tracker - bool noOtherKeyPressed = true; - for (int32 i = 0; i < 16; ++i) { - if (states[i] != 0) { - noOtherKeyPressed = false; - break; - } - } + int64 timestamp = system_time(); - if (noOtherKeyPressed) { - BMessenger deskbar("application/x-bnd.Be-TSKB"); - if (deskbar.IsValid()) - deskbar.SendMessage('BeMn'); - } - } + //TRACE("synergy: scancode = 0x%02x\n", scancode); + uint32_t keycode = 0; + if (scancode < sizeof(kATKeycodeMap)/sizeof(uint32)) + keycode = kATKeycodeMap[scancode - 1]; + //TRACE("synergy: keycode = 0x%x\n", keycode); if (keycode < 256) { if (isKeyDown) @@ -354,39 +365,50 @@ uSynergyInputServerDevice::_ProcessKeyboard(uint16_t keycode, uint16_t _modifier else states[(keycode) >> 3] &= (!(1 << (7 - (keycode & 0x7)))); } -#if false - if (isKeyDown && keycode == 0x34 // DELETE KEY + + if (isKeyDown && keycode == 0x1E // DELETE KEY && (states[fCommandKey >> 3] & (1 << (7 - (fCommandKey & 0x7)))) && (states[fControlKey >> 3] & (1 << (7 - (fControlKey & 0x7))))) { - //LOG_EVENT("TeamMonitor called\n"); - - // show the team monitor - if (fOwner->fTeamMonitorWindow == NULL) - fOwner->fTeamMonitorWindow = new(std::nothrow) TeamMonitorWindow(); - - if (fOwner->fTeamMonitorWindow != NULL) - fOwner->fTeamMonitorWindow->Enable(); - - ctrlAltDelPressed = true; + TRACE("synergy: TeamMonitor called\n"); } - if (ctrlAltDelPressed) { - if (fOwner->fTeamMonitorWindow != NULL) { - BMessage message(kMsgCtrlAltDelPressed); - message.AddBool("key down", isKeyDown); - fOwner->fTeamMonitorWindow->PostMessage(&message); - } - - if (!isKeyDown) - ctrlAltDelPressed = false; + uint32 modifiers = 0; + TRACE("synergy: modifiers: "); + if (_modifiers & SYNERGY_SHIFT) { + TRACE("SHIFT "); + modifiers |= B_SHIFT_KEY; } -#endif - BAutolock lock(fKeymapLock); + if (_modifiers & SYNERGY_CONTROL) { + TRACE("CONTROL "); + modifiers |= B_CONTROL_KEY; + } + if (_modifiers & SYNERGY_ALT) { + TRACE("COMMAND(ALT) "); + modifiers |= B_COMMAND_KEY; + } + if (_modifiers & SYNERGY_META) { + TRACE("MENU(META) "); + modifiers |= B_MENU_KEY; + } + if (_modifiers & SYNERGY_SUPER) { + TRACE("OPTION(SUPER) "); + modifiers |= B_OPTION_KEY; + } + if (_modifiers & SYNERGY_ALTGR) { + TRACE("RIGHT_OPTION(ALTGR) "); + modifiers |= B_RIGHT_OPTION_KEY; + } + if (_modifiers & SYNERGY_CAPSLOCK) + modifiers |= B_CAPS_LOCK; + if (_modifiers & SYNERGY_NUMLOCK) + modifiers |= B_NUM_LOCK; + if (_modifiers & SYNERGY_SCROLLLOCK) + modifiers |= B_SCROLL_LOCK; + TRACE("\n"); - uint32 modifiers = fKeymap.Modifier(keycode); bool isLock = (modifiers & (B_CAPS_LOCK | B_NUM_LOCK | B_SCROLL_LOCK)) != 0; - if (modifiers != 0 && (!isLock || isKeyDown)) { + if (true) { uint32 oldModifiers = fModifiers; if ((isKeyDown && !isLock) @@ -412,6 +434,8 @@ uSynergyInputServerDevice::_ProcessKeyboard(uint16_t keycode, uint16_t _modifier if (message == NULL) return; + TRACE("synergy: modifiers changed: 0x%04lx => 0x%04lx\n", oldModifiers, fModifiers); + message->AddInt64("when", timestamp); message->AddInt32("be:old_modifiers", oldModifiers); message->AddInt32("modifiers", fModifiers); @@ -422,26 +446,21 @@ uSynergyInputServerDevice::_ProcessKeyboard(uint16_t keycode, uint16_t _modifier } } - uint8 newDeadKey = 0; - if (activeDeadKey == 0 || !isKeyDown) - newDeadKey = fKeymap.ActiveDeadKey(keycode, fModifiers); + if (scancode == 0 || scancode == EXTENDED_KEY) { + TRACE("empty scancode\n"); + return; + } + + BMessage* msg = new BMessage; + if (msg == NULL) + return; char* string = NULL; char* rawString = NULL; int32 numBytes = 0, rawNumBytes = 0; - if (newDeadKey == 0) { - fKeymap.GetChars(keycode, fModifiers, activeDeadKey, &string, - &numBytes); - } + fKeymap.GetChars(keycode, fModifiers, 0, &string, &numBytes); fKeymap.GetChars(keycode, 0, 0, &rawString, &rawNumBytes); - BMessage* msg = new BMessage; - if (msg == NULL) { - delete[] string; - delete[] rawString; - return; - } - if (numBytes > 0) msg->what = isKeyDown ? B_KEY_DOWN : B_KEY_UP; else @@ -452,8 +471,11 @@ uSynergyInputServerDevice::_ProcessKeyboard(uint16_t keycode, uint16_t _modifier msg->AddInt32("modifiers", fModifiers); msg->AddData("states", B_UINT8_TYPE, states, 16); if (numBytes > 0) { - for (int i = 0; i < numBytes; i++) + for (int i = 0; i < numBytes; i++) { + TRACE("%02x:", (int8)string[i]); msg->AddInt8("byte", (int8)string[i]); + } + TRACE("\n"); msg->AddData("bytes", B_STRING_TYPE, string, numBytes + 1); if (rawNumBytes <= 0) { @@ -463,7 +485,7 @@ uSynergyInputServerDevice::_ProcessKeyboard(uint16_t keycode, uint16_t _modifier } else delete[] string; - if (isKeyDown && lastKeyCode == keycode) { + if (isKeyDown && isKeyRepeat) { repeatCount++; msg->AddInt32("be:key_repeat", repeatCount); } else @@ -475,38 +497,11 @@ uSynergyInputServerDevice::_ProcessKeyboard(uint16_t keycode, uint16_t _modifier msg->AddInt32("raw_char", (uint32)((uint8)rawString[0] & 0x7f)); delete[] rawString; -#if 0 - if (newDeadKey == 0) { - if (isKeyDown && !modifiers && activeDeadKey != 0) { - // a dead key was completed - activeDeadKey = 0; - if (fInputMethodStarted) { - _EnqueueInlineInputMethod(B_INPUT_METHOD_CHANGED, - string, true, msg); - _EnqueueInlineInputMethod(B_INPUT_METHOD_STOPPED); - fInputMethodStarted = false; - msg = NULL; - } - } - } else if (isKeyDown - && _EnqueueInlineInputMethod(B_INPUT_METHOD_STARTED) == B_OK) { - // start of a dead key - char* string = NULL; - int32 numBytes = 0; - fKeymap.GetChars(keycode, fModifiers, 0, &string, &numBytes); - - if (_EnqueueInlineInputMethod(B_INPUT_METHOD_CHANGED, string) - == B_OK) - fInputMethodStarted = true; - - activeDeadKey = newDeadKey; - delete[] string; - } -#endif + if (msg != NULL && EnqueueMessage(msg) != B_OK) delete msg; - lastKeyCode = isKeyDown ? keycode : 0; + lastScanCode = isKeyDown ? scancode : 0; } void diff --git a/src/add-ons/input_server/devices/synergy/haiku-usynergy.h b/src/add-ons/input_server/devices/synergy/haiku-usynergy.h index 7ea94c2..1ab944d 100644 --- a/src/add-ons/input_server/devices/synergy/haiku-usynergy.h +++ b/src/add-ons/input_server/devices/synergy/haiku-usynergy.h @@ -47,7 +47,7 @@ class uSynergyInputServerDevice : public BInputServerDevice { uSynergyContext *uSynergyHaikuContext; BMessage* _BuildMouseMessage(uint32 what, uint64 when, uint32 buttons, float x, float y) const; - void _ProcessKeyboard(uint16_t keycode, uint16_t modifiers, bool isKeyDown, bool isKeyRepeat); + void _ProcessKeyboard(uint16_t scancode, uint16_t modifiers, bool isKeyDown, bool isKeyRepeat); void _UpdateSettings(); public: struct sockaddr_in synergyServerData; diff --git a/src/add-ons/input_server/devices/synergy/uSynergy.c b/src/add-ons/input_server/devices/synergy/uSynergy.c index a8d01da..8ebbd46 100644 --- a/src/add-ons/input_server/devices/synergy/uSynergy.c +++ b/src/add-ons/input_server/devices/synergy/uSynergy.c @@ -420,7 +420,7 @@ static void sProcessMessage(uSynergyContext *context, const uint8_t *message) uint32_t format = sNetToNative32(parse_msg); uint32_t size = sNetToNative32(parse_msg+4); parse_msg += 8; - + // Call callback if (context->m_clipboardCallback) context->m_clipboardCallback(context->m_cookie, format, parse_msg, size); @@ -612,7 +612,7 @@ void uSynergySendClipboard(uSynergyContext *context, const char *text) 4 + /* Clipboard format */ 4; /* Clipboard data length */ uint32_t max_length = USYNERGY_REPLY_BUFFER_SIZE - overhead_size; - + // Clip text to max length uint32_t text_length = (uint32_t)strlen(text); if (text_length > max_length)