added 1 changeset to branch 'refs/remotes/jessicah-github/synergy' old head: 81423a30f7034de7790bb5ae451a6cb2434be37f new head: edb1801a56cc86d8dccb1cd87e87a9a484db93ec overview: https://github.com/jessicah/haiku/compare/81423a3...edb1801 ---------------------------------------------------------------------------- edb1801: synergy: remove unneeded files, and fix reference to Keymap.cpp [ Jessica Hamilton <jessica.l.hamilton@xxxxxxxxx> ] ---------------------------------------------------------------------------- Commit: edb1801a56cc86d8dccb1cd87e87a9a484db93ec Author: Jessica Hamilton <jessica.l.hamilton@xxxxxxxxx> Date: Wed Oct 1 11:07:27 2014 UTC ---------------------------------------------------------------------------- 11 files changed, 4 insertions(+), 3041 deletions(-) src/add-ons/input_server/devices/synergy/Jamfile | 4 + .../devices/synergy/KeyboardInputDevice.cpp | 800 ----------------- .../devices/synergy/KeyboardInputDevice.h | 108 --- .../input_server/devices/synergy/Keymap.cpp | 117 --- .../input_server/devices/synergy/Keymap.h | 27 - .../devices/synergy/MouseInputDevice.cpp | 870 ------------------- .../devices/synergy/MouseInputDevice.h | 53 -- .../devices/synergy/TeamListItem.cpp | 200 ----- .../input_server/devices/synergy/TeamListItem.h | 61 -- .../devices/synergy/TeamMonitorWindow.cpp | 747 ---------------- .../devices/synergy/TeamMonitorWindow.h | 58 -- ---------------------------------------------------------------------------- diff --git a/src/add-ons/input_server/devices/synergy/Jamfile b/src/add-ons/input_server/devices/synergy/Jamfile index d4e24de..a913b59 100644 --- a/src/add-ons/input_server/devices/synergy/Jamfile +++ b/src/add-ons/input_server/devices/synergy/Jamfile @@ -3,6 +3,7 @@ SubDir HAIKU_TOP src add-ons input_server devices synergy ; SetSubDirSupportedPlatformsBeOSCompatible ; SubDirHdrs $(HAIKU_TOP) src add-ons kernel bus_managers ps2 ; +SubDirHdrs $(HAIKU_TOP) src add-ons input_server devices keyboard ; UsePrivateHeaders input interface network shared storage translation ; UsePrivateSystemHeaders ; @@ -13,3 +14,6 @@ Addon <input>synergy : Keymap.cpp : input_server be libshared.a network translation [ TargetLibsupc++ ] ; + +SEARCH on [ FGristFiles Keymap.cpp ] + = [ FDirName $(SUBDIR) $(DOTDOT) keyboard ] ; diff --git a/src/add-ons/input_server/devices/synergy/KeyboardInputDevice.cpp b/src/add-ons/input_server/devices/synergy/KeyboardInputDevice.cpp deleted file mode 100644 index d33fe6c..0000000 --- a/src/add-ons/input_server/devices/synergy/KeyboardInputDevice.cpp +++ /dev/null @@ -1,800 +0,0 @@ -/* - * Copyright 2004-2006, Jérôme Duval. All rights reserved. - * Copyright 2005-2010, Axel Dörfler, axeld@xxxxxxxxxxxxxxxx. - * Copyright 2008-2009, Stephan Aßmus, superstippi@xxxxxx. - * - * Distributed under the terms of the MIT License. - */ - - -#include "KeyboardInputDevice.h" - -#include <errno.h> -#include <new> -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> - -#include <Application.h> -#include <Autolock.h> -#include <Directory.h> -#include <Entry.h> -#include <NodeMonitor.h> -#include <Path.h> -#include <String.h> - -#include <keyboard_mouse_driver.h> - - -#undef TRACE - -//#define TRACE_KEYBOARD_DEVICE -#ifdef TRACE_KEYBOARD_DEVICE - -static int32 sFunctionDepth = -1; - -class FunctionTracer { -public: - FunctionTracer(const void* pointer, const char* className, - const char* functionName) - : - fFunctionName(), - fPrepend(), - fPointer(pointer) - { - sFunctionDepth++; - fPrepend.Append(' ', sFunctionDepth * 2); - fFunctionName << className << "::" << functionName << "()"; - - debug_printf("%p -> %s%s {\n", fPointer, fPrepend.String(), - fFunctionName.String()); - } - - ~FunctionTracer() - { - debug_printf("%p -> %s}\n", fPointer, fPrepend.String()); - sFunctionDepth--; - } - - static int32 Depth() { return sFunctionDepth; } - -private: - BString fFunctionName; - BString fPrepend; - const void* fPointer; -}; - -# define KD_CALLED(x...) \ - FunctionTracer _ft(this, "KeyboardDevice", __FUNCTION__) -# define KID_CALLED(x...) \ - FunctionTracer _ft(this, "KeyboardInputDevice", __FUNCTION__) -# define TRACE(x...) \ - do { BString _to; \ - _to.Append(' ', (FunctionTracer::Depth() + 1) * 2); \ - debug_printf("%p -> %s", this, _to.String()); \ - debug_printf(x); } while (0) -# define LOG_EVENT(text...) debug_printf(text) -# define LOG_ERR(text...) TRACE(text) -#else -# define TRACE(x...) do {} while (0) -# define KD_CALLED(x...) TRACE(x) -# define KID_CALLED(x...) TRACE(x) -# define LOG_ERR(text...) debug_printf(text) -# define LOG_EVENT(text...) TRACE(x) -#endif - - -const static uint32 kKeyboardThreadPriority = B_FIRST_REAL_TIME_PRIORITY + 4; -const static char* kKeyboardDevicesDirectory = "/dev/input/keyboard"; - - -extern "C" BInputServerDevice* -instantiate_input_device() -{ - return new(std::nothrow) KeyboardInputDevice(); -} - - -static char* -get_short_name(const char* longName) -{ - BString string(longName); - BString name; - - int32 slash = string.FindLast("/"); - string.CopyInto(name, slash + 1, string.Length() - slash); - int32 index = atoi(name.String()) + 1; - - int32 previousSlash = string.FindLast("/", slash); - string.CopyInto(name, previousSlash + 1, slash - previousSlash - 1); - - // some special handling so that we get "USB" and "AT" instead of "usb"/"at" - if (name.Length() < 4) - name.ToUpper(); - else - name.Capitalize(); - - name << " Keyboard " << index; - - return strdup(name.String()); -} - - -// #pragma mark - - - -KeyboardDevice::KeyboardDevice(KeyboardInputDevice* owner, const char* path) - : - BHandler("keyboard device"), - fOwner(owner), - fFD(-1), - fThread(-1), - fActive(false), - fInputMethodStarted(false), - fKeyboardID(0), - fUpdateSettings(false), - fSettingsCommand(0), - fKeymapLock("keymap lock") -{ - KD_CALLED(); - - strlcpy(fPath, path, B_PATH_NAME_LENGTH); - fDeviceRef.name = get_short_name(path); - fDeviceRef.type = B_KEYBOARD_DEVICE; - fDeviceRef.cookie = this; - - if (be_app->Lock()) { - be_app->AddHandler(this); - be_app->Unlock(); - } -} - - -KeyboardDevice::~KeyboardDevice() -{ - KD_CALLED(); - TRACE("delete\n"); - - if (fActive) - Stop(); - - free(fDeviceRef.name); - - if (be_app->Lock()) { - be_app->RemoveHandler(this); - be_app->Unlock(); - } -} - - -void -KeyboardDevice::MessageReceived(BMessage* message) -{ - KD_CALLED(); - - if (message->what != B_INPUT_METHOD_EVENT) { - BHandler::MessageReceived(message); - return; - } - - int32 opcode; - if (message->FindInt32("be:opcode", &opcode) != B_OK) - return; - - if (opcode == B_INPUT_METHOD_STOPPED) - fInputMethodStarted = false; -} - - -status_t -KeyboardDevice::Start() -{ - KD_CALLED(); - TRACE("name: %s\n", fDeviceRef.name); - - fFD = open(fPath, O_RDWR); - // let the control thread handle any error on opening the device - - char threadName[B_OS_NAME_LENGTH]; - snprintf(threadName, B_OS_NAME_LENGTH, "%s watcher", fDeviceRef.name); - - fThread = spawn_thread(_ControlThreadEntry, threadName, - kKeyboardThreadPriority, this); - if (fThread < B_OK) - return fThread; - - fActive = true; - resume_thread(fThread); - - return fFD >= 0 ? B_OK : B_ERROR; -} - - -void -KeyboardDevice::Stop() -{ - KD_CALLED(); - TRACE("name: %s\n", fDeviceRef.name); - - fActive = false; - - close(fFD); - fFD = -1; - - if (fThread >= 0) { - suspend_thread(fThread); - resume_thread(fThread); - status_t dummy; - wait_for_thread(fThread, &dummy); - } -} - - -status_t -KeyboardDevice::UpdateSettings(uint32 opcode) -{ - KD_CALLED(); - - if (fThread < 0) - return B_ERROR; - - // schedule updating the settings from within the control thread - fSettingsCommand = opcode; - fUpdateSettings = true; - - return B_OK; -} - - -// #pragma mark - control thread - - -/*static*/ int32 -KeyboardDevice::_ControlThreadEntry(void* arg) -{ - KeyboardDevice* device = (KeyboardDevice*)arg; - return device->_ControlThread(); -} - - -int32 -KeyboardDevice::_ControlThread() -{ - KD_CALLED(); - TRACE("fPath: %s\n", fPath); - - if (fFD < B_OK) { - LOG_ERR("KeyboardDevice: error when opening %s: %s\n", - fPath, strerror(errno)); - _ControlThreadCleanup(); - // TOAST! - return B_ERROR; - } - - _UpdateSettings(0); - - raw_key_info keyInfo; - uint8 activeDeadKey = 0; - uint32 lastKeyCode = 0; - uint32 repeatCount = 1; - uint8 states[16]; - bool ctrlAltDelPressed = false; - - memset(states, 0, sizeof(states)); - - if (fKeyboardID == 0) { - if (ioctl(fFD, KB_GET_KEYBOARD_ID, &fKeyboardID) == 0) { - BMessage message(IS_SET_KEYBOARD_ID); - message.AddInt16("id", fKeyboardID); - be_app->PostMessage(&message); - } - } - - while (fActive) { - status_t status = ioctl(fFD, KB_READ, &keyInfo, sizeof(keyInfo)); - if (status == B_BUSY) { - // probably the debugger is listening to key events, wait and try - // again - snooze(100000); - continue; - } else if (status != B_OK) { - _ControlThreadCleanup(); - // TOAST! - return 0; - } - - // Update the settings from this thread if necessary - if (fUpdateSettings) { - _UpdateSettings(fSettingsCommand); - fUpdateSettings = false; - } - - uint32 keycode = keyInfo.keycode; - bool isKeyDown = keyInfo.is_keydown; - - LOG_EVENT("KB_READ: %Ld, %02x, %02lx\n", keyInfo.timestamp, isKeyDown, - keycode); - - if (keycode == 0) - continue; - - 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-vnd.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 (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; - } - - 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) - continue; - - message->AddInt64("when", keyInfo.timestamp); - message->AddInt32("be:old_modifiers", oldModifiers); - message->AddInt32("modifiers", fModifiers); - message->AddData("states", B_UINT8_TYPE, states, 16); - - if (fOwner->EnqueueMessage(message) != B_OK) - delete message; - - if (isLock) - _UpdateLEDs(); - } - } - - 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; - continue; - } - - 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", keyInfo.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 (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; - } - - if (msg != NULL && fOwner->EnqueueMessage(msg) != B_OK) - delete msg; - - lastKeyCode = isKeyDown ? keycode : 0; - } - - return 0; -} - - -void -KeyboardDevice::_ControlThreadCleanup() -{ - // NOTE: Only executed when the control thread detected an error - // and from within the control thread! - - if (fActive) { - fThread = -1; - fOwner->_RemoveDevice(fPath); - } else { - // In case active is already false, another thread - // waits for this thread to quit, and may already hold - // locks that _RemoveDevice() wants to acquire. In another - // words, the device is already being removed, so we simply - // quit here. - } -} - - -void -KeyboardDevice::_UpdateSettings(uint32 opcode) -{ - KD_CALLED(); - - if (opcode == 0 || opcode == B_KEY_REPEAT_RATE_CHANGED) { - if (get_key_repeat_rate(&fSettings.key_repeat_rate) != B_OK) { - LOG_ERR("error when get_key_repeat_rate\n"); - } else if (ioctl(fFD, KB_SET_KEY_REPEAT_RATE, - &fSettings.key_repeat_rate) != B_OK) { - LOG_ERR("error when KB_SET_KEY_REPEAT_RATE, fd:%d\n", fFD); - } - } - - if (opcode == 0 || opcode == B_KEY_REPEAT_DELAY_CHANGED) { - if (get_key_repeat_delay(&fSettings.key_repeat_delay) != B_OK) { - LOG_ERR("error when get_key_repeat_delay\n"); - } else if (ioctl(fFD, KB_SET_KEY_REPEAT_DELAY, - &fSettings.key_repeat_delay) != B_OK) { - LOG_ERR("error when KB_SET_KEY_REPEAT_DELAY, fd:%d\n", fFD); - } - } - - if (opcode == 0 || opcode == B_KEY_MAP_CHANGED - || opcode == B_KEY_LOCKS_CHANGED) { - BAutolock lock(fKeymapLock); - fKeymap.RetrieveCurrent(); - fModifiers = fKeymap.Map().lock_settings; - _UpdateLEDs(); - fControlKey = fKeymap.KeyForModifier(B_LEFT_CONTROL_KEY); - fCommandKey = fKeymap.KeyForModifier(B_LEFT_COMMAND_KEY); - } -} - - -void -KeyboardDevice::_UpdateLEDs() -{ - if (fFD < 0) - return; - - char lockIO[3] = {0, 0, 0}; - - if ((fModifiers & B_NUM_LOCK) != 0) - lockIO[0] = 1; - if ((fModifiers & B_CAPS_LOCK) != 0) - lockIO[1] = 1; - if ((fModifiers & B_SCROLL_LOCK) != 0) - lockIO[2] = 1; - - ioctl(fFD, KB_SET_LEDS, &lockIO); -} - - -status_t -KeyboardDevice::_EnqueueInlineInputMethod(int32 opcode, - const char* string, bool confirmed, BMessage* keyDown) -{ - BMessage* message = new BMessage(B_INPUT_METHOD_EVENT); - if (message == NULL) - return B_NO_MEMORY; - - message->AddInt32("be:opcode", opcode); - message->AddBool("be:inline_only", true); - - if (string != NULL) - message->AddString("be:string", string); - if (confirmed) - message->AddBool("be:confirmed", true); - if (keyDown) - message->AddMessage("be:translated", keyDown); - if (opcode == B_INPUT_METHOD_STARTED) - message->AddMessenger("be:reply_to", this); - - status_t status = fOwner->EnqueueMessage(message); - if (status != B_OK) - delete message; - - return status; -} - - -// #pragma mark - - - -KeyboardInputDevice::KeyboardInputDevice() - : - fDevices(2, true), - fDeviceListLock("KeyboardInputDevice list"), - fTeamMonitorWindow(NULL) -{ - KID_CALLED(); - - StartMonitoringDevice(kKeyboardDevicesDirectory); - _RecursiveScan(kKeyboardDevicesDirectory); -} - - -KeyboardInputDevice::~KeyboardInputDevice() -{ - KID_CALLED(); - - if (fTeamMonitorWindow) { - fTeamMonitorWindow->PostMessage(B_QUIT_REQUESTED); - fTeamMonitorWindow = NULL; - } - - StopMonitoringDevice(kKeyboardDevicesDirectory); - fDevices.MakeEmpty(); -} - - -status_t -KeyboardInputDevice::SystemShuttingDown() -{ - KID_CALLED(); - if (fTeamMonitorWindow) - fTeamMonitorWindow->PostMessage(SYSTEM_SHUTTING_DOWN); - - return B_OK; -} - - -status_t -KeyboardInputDevice::InitCheck() -{ - KID_CALLED(); - return BInputServerDevice::InitCheck(); -} - - -status_t -KeyboardInputDevice::Start(const char* name, void* cookie) -{ - KID_CALLED(); - TRACE("name %s\n", name); - - KeyboardDevice* device = (KeyboardDevice*)cookie; - - return device->Start(); -} - - -status_t -KeyboardInputDevice::Stop(const char* name, void* cookie) -{ - KID_CALLED(); - TRACE("name %s\n", name); - - KeyboardDevice* device = (KeyboardDevice*)cookie; - - device->Stop(); - return B_OK; -} - - -status_t -KeyboardInputDevice::Control(const char* name, void* cookie, - uint32 command, BMessage* message) -{ - KID_CALLED(); - TRACE("KeyboardInputDevice::Control(%s, code: %lu)\n", name, command); - - if (command == B_NODE_MONITOR) - _HandleMonitor(message); - else if (command >= B_KEY_MAP_CHANGED - && command <= B_KEY_REPEAT_RATE_CHANGED) { - KeyboardDevice* device = (KeyboardDevice*)cookie; - device->UpdateSettings(command); - } - return B_OK; -} - - -status_t -KeyboardInputDevice::_HandleMonitor(BMessage* message) -{ - KID_CALLED(); - - const char* path; - int32 opcode; - if (message->FindInt32("opcode", &opcode) != B_OK - || (opcode != B_ENTRY_CREATED && opcode != B_ENTRY_REMOVED) - || message->FindString("path", &path) != B_OK) - return B_BAD_VALUE; - - if (opcode == B_ENTRY_CREATED) - return _AddDevice(path); - -#if 0 - return _RemoveDevice(path); -#else - // Don't handle B_ENTRY_REMOVED, let the control thread take care of it. - return B_OK; -#endif -} - - -KeyboardDevice* -KeyboardInputDevice::_FindDevice(const char* path) const -{ - for (int i = fDevices.CountItems() - 1; i >= 0; i--) { - KeyboardDevice* device = fDevices.ItemAt(i); - if (strcmp(device->Path(), path) == 0) - return device; - } - - return NULL; -} - - -status_t -KeyboardInputDevice::_AddDevice(const char* path) -{ - KID_CALLED(); - TRACE("path: %s\n", path); - - BAutolock _(fDeviceListLock); - - _RemoveDevice(path); - - KeyboardDevice* device = new(std::nothrow) KeyboardDevice(this, path); - if (device == NULL) - return B_NO_MEMORY; - - input_device_ref* devices[2]; - devices[0] = device->DeviceRef(); - devices[1] = NULL; - - fDevices.AddItem(device); - - return RegisterDevices(devices); -} - - -status_t -KeyboardInputDevice::_RemoveDevice(const char* path) -{ - BAutolock _(fDeviceListLock); - - KeyboardDevice* device = _FindDevice(path); - if (device == NULL) - return B_ENTRY_NOT_FOUND; - - KID_CALLED(); - TRACE("path: %s\n", path); - - input_device_ref* devices[2]; - devices[0] = device->DeviceRef(); - devices[1] = NULL; - - UnregisterDevices(devices); - - fDevices.RemoveItem(device); - - return B_OK; -} - - -void -KeyboardInputDevice::_RecursiveScan(const char* directory) -{ - KID_CALLED(); - TRACE("directory: %s\n", directory); - - BEntry entry; - BDirectory dir(directory); - while (dir.GetNextEntry(&entry) == B_OK) { - BPath path; - entry.GetPath(&path); - if (entry.IsDirectory()) - _RecursiveScan(path.Path()); - else - _AddDevice(path.Path()); - } -} diff --git a/src/add-ons/input_server/devices/synergy/KeyboardInputDevice.h b/src/add-ons/input_server/devices/synergy/KeyboardInputDevice.h deleted file mode 100644 index 14a77c2..0000000 --- a/src/add-ons/input_server/devices/synergy/KeyboardInputDevice.h +++ /dev/null @@ -1,108 +0,0 @@ -/* - * Copyright 2004-2008, Jérôme Duval. All rights reserved. - * Copyright 2005-2010, Axel Dörfler, axeld@xxxxxxxxxxxxxxxx. - * Copyright 2008, Stephan Aßmus, superstippi@xxxxxx. - * - * Distributed under the terms of the MIT License. - */ -#ifndef KEYBOARD_INPUT_DEVICE_H -#define KEYBOARD_INPUT_DEVICE_H - - -#include <Handler.h> -#include <InputServerDevice.h> -#include <Locker.h> - -#include <InputServerTypes.h> -#include <ObjectList.h> - -#include "Keymap.h" -#include "TeamMonitorWindow.h" -#include "kb_mouse_settings.h" - - -class KeyboardInputDevice; - -class KeyboardDevice : public BHandler { -public: - KeyboardDevice(KeyboardInputDevice* owner, - const char* path); - virtual ~KeyboardDevice(); - - virtual void MessageReceived(BMessage* message); - status_t Start(); - void Stop(); - - status_t UpdateSettings(uint32 opcode = 0); - - const char* Path() const { return fPath; } - input_device_ref* DeviceRef() { return &fDeviceRef; } - -private: - static int32 _ControlThreadEntry(void* arg); - int32 _ControlThread(); - void _ControlThreadCleanup(); - void _UpdateSettings(uint32 opcode); - void _UpdateLEDs(); - status_t _EnqueueInlineInputMethod(int32 opcode, - const char* string = NULL, - bool confirmed = false, - BMessage* keyDown = NULL); - -private: - KeyboardInputDevice* fOwner; - input_device_ref fDeviceRef; - char fPath[B_PATH_NAME_LENGTH]; - int fFD; - thread_id fThread; - kb_settings fSettings; - volatile bool fActive; - volatile bool fInputMethodStarted; - uint32 fModifiers; - uint32 fCommandKey; - uint32 fControlKey; - uint16 fKeyboardID; - - volatile bool fUpdateSettings; - volatile uint32 fSettingsCommand; - - Keymap fKeymap; - BLocker fKeymapLock; -}; - - -class KeyboardInputDevice : public BInputServerDevice { -public: - KeyboardInputDevice(); - virtual ~KeyboardInputDevice(); - - virtual status_t InitCheck(); - - virtual status_t Start(const char* name, void* cookie); - virtual status_t Stop(const char* name, void* cookie); - - virtual status_t Control(const char* name, void* cookie, - uint32 command, BMessage* message); - - virtual status_t SystemShuttingDown(); - -private: - friend struct KeyboardDevice; - // TODO: needed by the control thread to remove a dead device - // find a better way... - - status_t _HandleMonitor(BMessage* message); - void _RecursiveScan(const char* directory); - - KeyboardDevice* _FindDevice(const char* path) const; - status_t _AddDevice(const char* path); - status_t _RemoveDevice(const char* path); - - BObjectList<KeyboardDevice> fDevices; - BLocker fDeviceListLock; - TeamMonitorWindow* fTeamMonitorWindow; -}; - -extern "C" BInputServerDevice* instantiate_input_device(); - -#endif // KEYBOARD_INPUT_DEVICE_H diff --git a/src/add-ons/input_server/devices/synergy/Keymap.cpp b/src/add-ons/input_server/devices/synergy/Keymap.cpp deleted file mode 100644 index f003b02..0000000 --- a/src/add-ons/input_server/devices/synergy/Keymap.cpp +++ /dev/null @@ -1,117 +0,0 @@ -/* - * Copyright 2004-2012, Haiku, Inc. All rights reserved. - * Distributed under the terms of the MIT License. - * - * Authors: - * Jérôme Duval - */ - - -#include "Keymap.h" - -#include <ByteOrder.h> -#include <File.h> -#include <InputServerTypes.h> -#include <Message.h> -#include <input_globals.h> - -#include <errno.h> -#include <new> -#include <stdlib.h> -#include <stdio.h> -#include <string.h> - - -static void -print_key(char* chars, int32 offset, bool last = false) -{ - int size = chars[offset++]; - - switch (size) { - case 0: - // Not mapped - fputs("N/A", stdout); - break; - - case 1: - // single-byte UTF-8/ASCII character - fputc(chars[offset], stdout); - break; - - default: - { - // 2-, 3-, or 4-byte UTF-8 character - char* str = new (std::nothrow) char[size + 1]; - if (str == NULL) - break; - - strncpy(str, &(chars[offset]), size); - str[size] = 0; - fputs(str, stdout); - delete [] str; - break; - } - } - - if (!last) - fputs("\t", stdout); -} - - -// #pragma mark - - - -Keymap::Keymap() -{ - RetrieveCurrent(); -} - - -Keymap::~Keymap() -{ -} - - -void -Keymap::DumpKeymap() -{ - if (fKeys.version != 3) - return; - - // Print a chart of the normal, shift, control, option, option+shift, - // Caps, Caps+shift, Caps+option, and Caps+option+shift keys. - puts("Key #\tn\ts\tc\to\tos\tC\tCs\tCo\tCos\n"); - - for (uint8 i = 0; i < 128; i++) { - printf(" 0x%02x\t", i); - print_key(fChars, fKeys.normal_map[i]); - print_key(fChars, fKeys.shift_map[i]); - print_key(fChars, fKeys.control_map[i]); - print_key(fChars, fKeys.option_map[i]); - print_key(fChars, fKeys.option_shift_map[i]); - print_key(fChars, fKeys.caps_map[i]); - print_key(fChars, fKeys.caps_shift_map[i]); - print_key(fChars, fKeys.option_caps_map[i]); - print_key(fChars, fKeys.option_caps_shift_map[i], true); - fputs("\n", stdout); - } -} - - -status_t -Keymap::RetrieveCurrent() -{ - Unset(); - - key_map* keys; - _get_key_map(&keys, &fChars, (ssize_t*)&fCharsSize); - if (!keys) { - fprintf(stderr, "error while getting current keymap!\n"); - return B_ERROR; - } - - memcpy(&fKeys, keys, sizeof(fKeys)); - free(keys); - return B_OK; -} - diff --git a/src/add-ons/input_server/devices/synergy/Keymap.h b/src/add-ons/input_server/devices/synergy/Keymap.h deleted file mode 100644 index 9007ef3..0000000 --- a/src/add-ons/input_server/devices/synergy/Keymap.h +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright 2004-2010, Haiku. - * Distributed under the terms of the MIT License. - * - * Authors: - * Jérôme Duval - */ -#ifndef KEYMAP_H -#define KEYMAP_H - - -#include <Keymap.h> -#include <Entry.h> - - -class Keymap : public BKeymap { -public: - Keymap(); - ~Keymap(); - - void DumpKeymap(); - - status_t RetrieveCurrent(); -}; - - -#endif // KEYMAP_H diff --git a/src/add-ons/input_server/devices/synergy/MouseInputDevice.cpp b/src/add-ons/input_server/devices/synergy/MouseInputDevice.cpp deleted file mode 100644 index 4e81432..0000000 --- a/src/add-ons/input_server/devices/synergy/MouseInputDevice.cpp +++ /dev/null @@ -1,870 +0,0 @@ -/* - * Copyright 2004-2011, Haiku. - * Distributed under the terms of the MIT License. - * - * Authors: - * Stefano Ceccherini (stefano.ceccherini@xxxxxxxxx) - * Jérôme Duval - * Axel Dörfler, axeld@xxxxxxxxxxxxxxxx - * Clemens Zeidler, haiku@xxxxxxxxxxxxxxxxxx - * Stephan Aßmus, superstippi@xxxxxx - */ - - -#include "MouseInputDevice.h" - -#include <errno.h> -#include <new> -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> - -#include <Autolock.h> -#include <Debug.h> -#include <Directory.h> -#include <Entry.h> -#include <File.h> -#include <FindDirectory.h> -#include <NodeMonitor.h> -#include <Path.h> -#include <String.h> -#include <View.h> - -#include <kb_mouse_settings.h> -#include <keyboard_mouse_driver.h> -#include <touchpad_settings.h> - - -#undef TRACE -//#define TRACE_MOUSE_DEVICE -#ifdef TRACE_MOUSE_DEVICE - - class FunctionTracer { - public: - FunctionTracer(const void* pointer, const char* className, - const char* functionName, - int32& depth) - : fFunctionName(), - fPrepend(), - fFunctionDepth(depth), - fPointer(pointer) - { - fFunctionDepth++; - fPrepend.Append(' ', fFunctionDepth * 2); - fFunctionName << className << "::" << functionName << "()"; - - debug_printf("%p -> %s%s {\n", fPointer, fPrepend.String(), - fFunctionName.String()); - } - - ~FunctionTracer() - { - debug_printf("%p -> %s}\n", fPointer, fPrepend.String()); - fFunctionDepth--; - } - - private: - BString fFunctionName; - BString fPrepend; - int32& fFunctionDepth; - const void* fPointer; - }; - - - static int32 sFunctionDepth = -1; -# define MD_CALLED(x...) FunctionTracer _ft(this, "MouseDevice", \ - __FUNCTION__, sFunctionDepth) -# define MID_CALLED(x...) FunctionTracer _ft(this, "MouseInputDevice", \ - __FUNCTION__, sFunctionDepth) -# define TRACE(x...) do { BString _to; \ - _to.Append(' ', (sFunctionDepth + 1) * 2); \ - debug_printf("%p -> %s", this, _to.String()); \ - debug_printf(x); } while (0) -# define LOG_EVENT(text...) do {} while (0) -# define LOG_ERR(text...) TRACE(text) -#else -# define TRACE(x...) do {} while (0) -# define MD_CALLED(x...) TRACE(x) -# define MID_CALLED(x...) TRACE(x) -# define LOG_ERR(x...) debug_printf(x) -# define LOG_EVENT(x...) TRACE(x) -#endif - - -const static uint32 kMouseThreadPriority = B_FIRST_REAL_TIME_PRIORITY + 4; -const static char* kMouseDevicesDirectory = "/dev/input/mouse"; -const static char* kTouchpadDevicesDirectory = "/dev/input/touchpad"; - - -class MouseDevice { -public: - MouseDevice(MouseInputDevice& target, - const char* path); - ~MouseDevice(); - - status_t Start(); - void Stop(); - - status_t UpdateSettings(); - status_t UpdateTouchpadSettings(const BMessage* message); - - const char* Path() const { return fPath.String(); } - input_device_ref* DeviceRef() { return &fDeviceRef; } - -private: - char* _BuildShortName() const; - - static status_t _ControlThreadEntry(void* arg); - void _ControlThread(); - void _ControlThreadCleanup(); - void _UpdateSettings(); - - status_t _GetTouchpadSettingsPath(BPath& path); - status_t _ReadTouchpadSettingsMsg(BMessage* message); - status_t _UpdateTouchpadSettings(); - - BMessage* _BuildMouseMessage(uint32 what, - uint64 when, uint32 buttons, - int32 deltaX, int32 deltaY) const; - void _ComputeAcceleration( - const mouse_movement& movements, - int32& deltaX, int32& deltaY, - float& historyDeltaX, - float& historyDeltaY) const; - uint32 _RemapButtons(uint32 buttons) const; - -private: - MouseInputDevice& fTarget; - BString fPath; - int fDevice; - - input_device_ref fDeviceRef; - mouse_settings fSettings; - bool fDeviceRemapsButtons; - - thread_id fThread; - volatile bool fActive; - volatile bool fUpdateSettings; - - bool fIsTouchpad; - touchpad_settings fTouchpadSettings; - BMessage* fTouchpadSettingsMessage; - BLocker fTouchpadSettingsLock; -}; - - -extern "C" BInputServerDevice* -instantiate_input_device() -{ - return new(std::nothrow) MouseInputDevice(); -} - - -// #pragma mark - - - -MouseDevice::MouseDevice(MouseInputDevice& target, const char* driverPath) - : - fTarget(target), - fPath(driverPath), - fDevice(-1), - fDeviceRemapsButtons(false), - fThread(-1), - fActive(false), - fUpdateSettings(false), - fIsTouchpad(false), - fTouchpadSettingsMessage(NULL), - fTouchpadSettingsLock("Touchpad settings lock") -{ - MD_CALLED(); - - fDeviceRef.name = _BuildShortName(); - fDeviceRef.type = B_POINTING_DEVICE; - fDeviceRef.cookie = this; - -#ifdef HAIKU_TARGET_PLATFORM_HAIKU - fSettings.map.button[0] = B_PRIMARY_MOUSE_BUTTON; - fSettings.map.button[1] = B_SECONDARY_MOUSE_BUTTON; - fSettings.map.button[2] = B_TERTIARY_MOUSE_BUTTON; -#endif -}; - - -MouseDevice::~MouseDevice() -{ - MD_CALLED(); - TRACE("delete\n"); - - if (fActive) - Stop(); - - free(fDeviceRef.name); - delete fTouchpadSettingsMessage; -} - - -status_t -MouseDevice::Start() -{ - MD_CALLED(); - - fDevice = open(fPath.String(), O_RDWR); - // let the control thread handle any error on opening the device - - char threadName[B_OS_NAME_LENGTH]; - snprintf(threadName, B_OS_NAME_LENGTH, "%s watcher", fDeviceRef.name); - - fThread = spawn_thread(_ControlThreadEntry, threadName, - kMouseThreadPriority, (void*)this); - - status_t status; - if (fThread < 0) - status = fThread; - else { - fActive = true; - status = resume_thread(fThread); - } - - if (status < B_OK) { - LOG_ERR("%s: can't spawn/resume watching thread: %s\n", - fDeviceRef.name, strerror(status)); - if (fDevice >= 0) - close(fDevice); - - return status; - } - - return fDevice >= 0 ? B_OK : B_ERROR; -} - - -void -MouseDevice::Stop() -{ - MD_CALLED(); - - fActive = false; - // this will stop the thread as soon as it reads the next packet - - close(fDevice); - fDevice = -1; - - if (fThread >= 0) { - // unblock the thread, which might wait on a semaphore. - suspend_thread(fThread); - resume_thread(fThread); - - status_t dummy; - wait_for_thread(fThread, &dummy); - } -} - - -status_t -MouseDevice::UpdateSettings() -{ - MD_CALLED(); - - if (fThread < 0) - return B_ERROR; - - // trigger updating the settings in the control thread - fUpdateSettings = true; - - return B_OK; -} - - -status_t -MouseDevice::UpdateTouchpadSettings(const BMessage* message) -{ - if (!fIsTouchpad) - return B_BAD_TYPE; - if (fThread < 0) - return B_ERROR; - - BAutolock _(fTouchpadSettingsLock); - - // trigger updating the settings in the control thread - fUpdateSettings = true; - - delete fTouchpadSettingsMessage; - fTouchpadSettingsMessage = new BMessage(*message); - if (fTouchpadSettingsMessage == NULL) - return B_NO_MEMORY; - - return B_OK; -} - - -char* -MouseDevice::_BuildShortName() const -{ - BString string(fPath); - BString name; - - int32 slash = string.FindLast("/"); - string.CopyInto(name, slash + 1, string.Length() - slash); - int32 index = atoi(name.String()) + 1; - - int32 previousSlash = string.FindLast("/", slash); - string.CopyInto(name, previousSlash + 1, slash - previousSlash - 1); - - if (name == "ps2") - name = "PS/2"; - - if (name.Length() < 4) - name.ToUpper(); - else - name.Capitalize(); - - if (string.FindFirst("touchpad") >= 0) { - name << " Touchpad "; - } else { - if (string.FindFirst("intelli") >= 0) - name.Prepend("Extended "); - - name << " Mouse "; - } - name << index; - - return strdup(name.String()); -} - - -// #pragma mark - control thread - - -status_t -MouseDevice::_ControlThreadEntry(void* arg) -{ - MouseDevice* device = (MouseDevice*)arg; - device->_ControlThread(); - return B_OK; -} - - -void -MouseDevice::_ControlThread() -{ - MD_CALLED(); - - if (fDevice < 0) { - _ControlThreadCleanup(); - // TOAST! - return; - } - - // touchpad settings - if (ioctl(fDevice, MS_IS_TOUCHPAD, NULL) == B_OK) { - TRACE("is touchpad %s\n", fPath.String()); - fIsTouchpad = true; - - fTouchpadSettings = kDefaultTouchpadSettings; - - BPath path; - status_t status = _GetTouchpadSettingsPath(path); - BFile settingsFile(path.Path(), B_READ_ONLY); - if (status == B_OK && settingsFile.InitCheck() == B_OK) { - if (settingsFile.Read(&fTouchpadSettings, sizeof(touchpad_settings)) - != sizeof(touchpad_settings)) { - TRACE("failed to load settings\n"); - } - } - _UpdateTouchpadSettings(); - } - - _UpdateSettings(); - - uint32 lastButtons = 0; - float historyDeltaX = 0.0; - float historyDeltaY = 0.0; - - static const bigtime_t kTransferDelay = 1000000 / 125; - // 125 transfers per second should be more than enough -#define USE_REGULAR_INTERVAL 1 -#if USE_REGULAR_INTERVAL - bigtime_t nextTransferTime = system_time() + kTransferDelay; -#endif - - while (fActive) { - mouse_movement movements; - -#if USE_REGULAR_INTERVAL - snooze_until(nextTransferTime, B_SYSTEM_TIMEBASE); - nextTransferTime += kTransferDelay; -#endif - - if (ioctl(fDevice, MS_READ, &movements, sizeof(movements)) != B_OK) { - LOG_ERR("Mouse device exiting, %s\n", strerror(errno)); - _ControlThreadCleanup(); - // TOAST! - return; - } - - // take care of updating the settings first, if necessary - if (fUpdateSettings) { - fUpdateSettings = false; - if (fIsTouchpad) { - BAutolock _(fTouchpadSettingsLock); - if (fTouchpadSettingsMessage != NULL) { - _ReadTouchpadSettingsMsg(fTouchpadSettingsMessage); - _UpdateTouchpadSettings(); - delete fTouchpadSettingsMessage; - fTouchpadSettingsMessage = NULL; - } else - _UpdateSettings(); - } else - _UpdateSettings(); - } - - uint32 buttons = lastButtons ^ movements.buttons; - - uint32 remappedButtons = _RemapButtons(movements.buttons); - int32 deltaX, deltaY; - _ComputeAcceleration(movements, deltaX, deltaY, historyDeltaX, - historyDeltaY); - - LOG_EVENT("%s: buttons: 0x%lx, x: %ld, y: %ld, clicks:%ld, " - "wheel_x:%ld, wheel_y:%ld\n", - fDeviceRef.name, movements.buttons, - movements.xdelta, movements.ydelta, movements.clicks, - movements.wheel_xdelta, movements.wheel_ydelta); - LOG_EVENT("%s: x: %ld, y: %ld (%.4f, %.4f)\n", fDeviceRef.name, - deltaX, deltaY, historyDeltaX, historyDeltaY); - - // Send single messages for each event - - if (buttons != 0) { - bool pressedButton = (buttons & movements.buttons) > 0; - BMessage* message = _BuildMouseMessage( - pressedButton ? B_MOUSE_DOWN : B_MOUSE_UP, - movements.timestamp, remappedButtons, deltaX, deltaY); - if (message != NULL) { - if (pressedButton) { - message->AddInt32("clicks", movements.clicks); - LOG_EVENT("B_MOUSE_DOWN\n"); - } else - LOG_EVENT("B_MOUSE_UP\n"); - - fTarget.EnqueueMessage(message); - lastButtons = movements.buttons; - } - } - - if (movements.xdelta != 0 || movements.ydelta != 0) { - BMessage* message = _BuildMouseMessage(B_MOUSE_MOVED, - movements.timestamp, remappedButtons, deltaX, deltaY); - if (message != NULL) - fTarget.EnqueueMessage(message); - } - - if (movements.wheel_ydelta != 0 || movements.wheel_xdelta != 0) { - BMessage* message = new BMessage(B_MOUSE_WHEEL_CHANGED); - if (message == NULL) - continue; - - if (message->AddInt64("when", movements.timestamp) == B_OK - && message->AddFloat("be:wheel_delta_x", - movements.wheel_xdelta) == B_OK - && message->AddFloat("be:wheel_delta_y", - movements.wheel_ydelta) == B_OK) - fTarget.EnqueueMessage(message); - else - delete message; - } - -#if !USE_REGULAR_INTERVAL - snooze(kTransferDelay); -#endif - } -} - - -void -MouseDevice::_ControlThreadCleanup() -{ - // NOTE: Only executed when the control thread detected an error - // and from within the control thread! - - if (fActive) { - fThread = -1; - fTarget._RemoveDevice(fPath.String()); - } else { - // In case active is already false, another thread - // waits for this thread to quit, and may already hold - // locks that _RemoveDevice() wants to acquire. In other - // words, the device is already being removed, so we simply - // quit here. - } -} - - -void -MouseDevice::_UpdateSettings() -{ - MD_CALLED(); - - // retrieve current values - - if (get_mouse_map(&fSettings.map) != B_OK) - LOG_ERR("error when get_mouse_map\n"); - else { - fDeviceRemapsButtons - = ioctl(fDevice, MS_SET_MAP, &fSettings.map) == B_OK; - } - - if (get_click_speed(&fSettings.click_speed) != B_OK) - LOG_ERR("error when get_click_speed\n"); - else - ioctl(fDevice, MS_SET_CLICKSPEED, &fSettings.click_speed); - - if (get_mouse_speed(&fSettings.accel.speed) != B_OK) - LOG_ERR("error when get_mouse_speed\n"); - else { - if (get_mouse_acceleration(&fSettings.accel.accel_factor) != B_OK) - LOG_ERR("error when get_mouse_acceleration\n"); - else { - mouse_accel accel; - ioctl(fDevice, MS_GET_ACCEL, &accel); - accel.speed = fSettings.accel.speed; - accel.accel_factor = fSettings.accel.accel_factor; - ioctl(fDevice, MS_SET_ACCEL, &fSettings.accel); - } - } - - if (get_mouse_type(&fSettings.type) != B_OK) - LOG_ERR("error when get_mouse_type\n"); - else - ioctl(fDevice, MS_SET_TYPE, &fSettings.type); -} - - -status_t -MouseDevice::_GetTouchpadSettingsPath(BPath& path) -{ - status_t status = find_directory(B_USER_SETTINGS_DIRECTORY, &path); - if (status < B_OK) - return status; - return path.Append(TOUCHPAD_SETTINGS_FILE); -} - - -status_t -MouseDevice::_ReadTouchpadSettingsMsg(BMessage* message) -{ - message->FindBool("scroll_twofinger", &fTouchpadSettings.scroll_twofinger); - message->FindBool("scroll_twofinger_horizontal", - &fTouchpadSettings.scroll_twofinger_horizontal); - message->FindFloat("scroll_rightrange", - &fTouchpadSettings.scroll_rightrange); - message->FindFloat("scroll_bottomrange", - &fTouchpadSettings.scroll_bottomrange); - - message->FindInt16("scroll_xstepsize", - (int16*)&fTouchpadSettings.scroll_xstepsize); - message->FindInt16("scroll_ystepsize", - (int16*)&fTouchpadSettings.scroll_ystepsize); - message->FindInt8("scroll_acceleration", - (int8*)&fTouchpadSettings.scroll_acceleration); - message->FindInt8("tapgesture_sensibility", - (int8*)&fTouchpadSettings.tapgesture_sensibility); - - return B_OK; -} - - -status_t -MouseDevice::_UpdateTouchpadSettings() -{ - if (fIsTouchpad) { - ioctl(fDevice, MS_SET_TOUCHPAD_SETTINGS, &fTouchpadSettings); - return B_OK; - } - return B_ERROR; -} - - -BMessage* -MouseDevice::_BuildMouseMessage(uint32 what, uint64 when, uint32 buttons, - int32 deltaX, int32 deltaY) const -{ - BMessage* message = new BMessage(what); - if (message == NULL) - return NULL; - - if (message->AddInt64("when", when) < B_OK - || message->AddInt32("buttons", buttons) < B_OK - || message->AddInt32("x", deltaX) < B_OK - || message->AddInt32("y", deltaY) < B_OK) { - delete message; - return NULL; - } - - return message; -} - - -void -MouseDevice::_ComputeAcceleration(const mouse_movement& movements, - int32& _deltaX, int32& _deltaY, float& historyDeltaX, - float& historyDeltaY) const -{ - // basic mouse speed - float deltaX = (float)movements.xdelta * fSettings.accel.speed / 65536.0 - + historyDeltaX; - float deltaY = (float)movements.ydelta * fSettings.accel.speed / 65536.0 - + historyDeltaY; - - // acceleration - double acceleration = 1; - if (fSettings.accel.accel_factor) { - acceleration = 1 + sqrt(deltaX * deltaX + deltaY * deltaY) - * fSettings.accel.accel_factor / 524288.0; - } - - deltaX *= acceleration; - deltaY *= acceleration; - - if (deltaX >= 0) - _deltaX = (int32)floorf(deltaX); - else - _deltaX = (int32)ceilf(deltaX); - - if (deltaY >= 0) - _deltaY = (int32)floorf(deltaY); - else - _deltaY = (int32)ceilf(deltaY); - - historyDeltaX = deltaX - _deltaX; - historyDeltaY = deltaY - _deltaY; -} - - -uint32 -MouseDevice::_RemapButtons(uint32 buttons) const -{ - if (fDeviceRemapsButtons) - return buttons; - - uint32 newButtons = 0; - for (int32 i = 0; buttons; i++) { - if (buttons & 0x1) { -#if defined(HAIKU_TARGET_PLATFORM_HAIKU) || defined(HAIKU_TARGET_PLATFORM_DANO) - newButtons |= fSettings.map.button[i]; -#else - if (i == 0) - newButtons |= fSettings.map.left; - if (i == 1) - newButtons |= fSettings.map.right; - if (i == 2) - newButtons |= fSettings.map.middle; -#endif - } - buttons >>= 1; - } - - return newButtons; -} - - -// #pragma mark - - - -MouseInputDevice::MouseInputDevice() - : - fDevices(2, true), - fDeviceListLock("MouseInputDevice list") -{ - MID_CALLED(); - - StartMonitoringDevice(kMouseDevicesDirectory); - StartMonitoringDevice(kTouchpadDevicesDirectory); - _RecursiveScan(kMouseDevicesDirectory); - _RecursiveScan(kTouchpadDevicesDirectory); -} - - -MouseInputDevice::~MouseInputDevice() -{ - MID_CALLED(); - - StopMonitoringDevice(kTouchpadDevicesDirectory); - StopMonitoringDevice(kMouseDevicesDirectory); - fDevices.MakeEmpty(); -} - - -status_t -MouseInputDevice::InitCheck() -{ - MID_CALLED(); - - return BInputServerDevice::InitCheck(); -} - - -status_t -MouseInputDevice::Start(const char* name, void* cookie) -{ - MID_CALLED(); - - MouseDevice* device = (MouseDevice*)cookie; - - return device->Start(); -} - - -status_t -MouseInputDevice::Stop(const char* name, void* cookie) -{ - TRACE("%s(%s)\n", __PRETTY_FUNCTION__, name); - - MouseDevice* device = (MouseDevice*)cookie; - device->Stop(); - - return B_OK; -} - - -status_t -MouseInputDevice::Control(const char* name, void* cookie, - uint32 command, BMessage* message) -{ - TRACE("%s(%s, code: %lu)\n", __PRETTY_FUNCTION__, name, command); - - MouseDevice* device = (MouseDevice*)cookie; - - if (command == B_NODE_MONITOR) - return _HandleMonitor(message); - - if (command == MS_SET_TOUCHPAD_SETTINGS) - return device->UpdateTouchpadSettings(message); - - if (command >= B_MOUSE_TYPE_CHANGED - && command <= B_MOUSE_ACCELERATION_CHANGED) - return device->UpdateSettings(); - - return B_BAD_VALUE; -} - - -status_t -MouseInputDevice::_HandleMonitor(BMessage* message) -{ - MID_CALLED(); - - const char* path; - int32 opcode; - if (message->FindInt32("opcode", &opcode) != B_OK - || (opcode != B_ENTRY_CREATED && opcode != B_ENTRY_REMOVED) - || message->FindString("path", &path) != B_OK) - return B_BAD_VALUE; - - if (opcode == B_ENTRY_CREATED) - return _AddDevice(path); - -#if 0 - return _RemoveDevice(path); -#else - // Don't handle B_ENTRY_REMOVED, let the control thread take care of it. - return B_OK; -#endif -} - - -void -MouseInputDevice::_RecursiveScan(const char* directory) -{ - MID_CALLED(); - - BEntry entry; - BDirectory dir(directory); - while (dir.GetNextEntry(&entry) == B_OK) { - BPath path; - entry.GetPath(&path); - - if (!strcmp(path.Leaf(), "serial")) { - // skip serial - continue; - } - - if (entry.IsDirectory()) - _RecursiveScan(path.Path()); - else - _AddDevice(path.Path()); - } -} - - -MouseDevice* -MouseInputDevice::_FindDevice(const char* path) const -{ - MID_CALLED(); - - for (int32 i = fDevices.CountItems() - 1; i >= 0; i--) { - MouseDevice* device = fDevices.ItemAt(i); - if (strcmp(device->Path(), path) == 0) - return device; - } - - return NULL; -} - - -status_t -MouseInputDevice::_AddDevice(const char* path) -{ - MID_CALLED(); - - BAutolock _(fDeviceListLock); - - _RemoveDevice(path); - - MouseDevice* device = new(std::nothrow) MouseDevice(*this, path); - if (device == NULL) { - TRACE("No memory\n"); - return B_NO_MEMORY; - } - - if (!fDevices.AddItem(device)) { - TRACE("No memory in list\n"); - delete device; - return B_NO_MEMORY; - } - - input_device_ref* devices[2]; - devices[0] = device->DeviceRef(); - devices[1] = NULL; - - TRACE("adding path: %s, name: %s\n", path, devices[0]->name); - - return RegisterDevices(devices); -} - - -status_t -MouseInputDevice::_RemoveDevice(const char* path) -{ - MID_CALLED(); - - BAutolock _(fDeviceListLock); - - MouseDevice* device = _FindDevice(path); - if (device == NULL) { - TRACE("%s not found\n", path); - return B_ENTRY_NOT_FOUND; - } - - input_device_ref* devices[2]; - devices[0] = device->DeviceRef(); - devices[1] = NULL; - - TRACE("removing path: %s, name: %s\n", path, devices[0]->name); - - UnregisterDevices(devices); - - fDevices.RemoveItem(device); - - return B_OK; -} diff --git a/src/add-ons/input_server/devices/synergy/MouseInputDevice.h b/src/add-ons/input_server/devices/synergy/MouseInputDevice.h deleted file mode 100644 index b701e41..0000000 --- a/src/add-ons/input_server/devices/synergy/MouseInputDevice.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright 2004-2008, Haiku. - * Distributed under the terms of the MIT License. - * - * Authors: - * Stefano Ceccherini - */ -#ifndef MOUSE_INPUT_DEVICE_H -#define MOUSE_INPUT_DEVICE_H - - -#include <InputServerDevice.h> -#include <InterfaceDefs.h> -#include <Locker.h> - -#include <ObjectList.h> - - -class MouseDevice; - -class MouseInputDevice : public BInputServerDevice { -public: - MouseInputDevice(); - virtual ~MouseInputDevice(); - - virtual status_t InitCheck(); - - virtual status_t Start(const char* name, void* cookie); - virtual status_t Stop(const char* name, void* cookie); - - virtual status_t Control(const char* name, void* cookie, - uint32 command, BMessage* message); - -private: - friend class MouseDevice; - // TODO: needed by the control thread to remove a dead device - // find a better way... - - status_t _HandleMonitor(BMessage* message); - void _RecursiveScan(const char* directory); - - MouseDevice* _FindDevice(const char* path) const; - status_t _AddDevice(const char* path); - status_t _RemoveDevice(const char* path); - -private: - BObjectList<MouseDevice> fDevices; - BLocker fDeviceListLock; -}; - -extern "C" BInputServerDevice* instantiate_input_device(); - -#endif // MOUSE_INPUT_DEVICE_H diff --git a/src/add-ons/input_server/devices/synergy/TeamListItem.cpp b/src/add-ons/input_server/devices/synergy/TeamListItem.cpp deleted file mode 100644 index 20f2264..0000000 --- a/src/add-ons/input_server/devices/synergy/TeamListItem.cpp +++ /dev/null @@ -1,200 +0,0 @@ -/* - * Copyright 2004-2008, Haiku. - * Distributed under the terms of the MIT License. - * - * Authors: - * Jérôme Duval - */ - -#include "TeamListItem.h" - -#include <string.h> - -#include <FindDirectory.h> -#include <LocaleRoster.h> -#include <NodeInfo.h> -#include <Path.h> -#include <View.h> - - -static const int32 kItemMargin = 2; - - -bool gLocalizedNamePreferred; - - -TeamListItem::TeamListItem(team_info &teamInfo) - : - fTeamInfo(teamInfo), - fAppInfo(), - fMiniIcon(BRect(0, 0, 15, 15), B_RGBA32), - fLargeIcon(BRect(0, 0, 31, 31), B_RGBA32), - fFound(false), - fRefusingToQuit(false) -{ - int32 cookie = 0; - image_info info; - if (get_next_image_info(teamInfo.team, &cookie, &info) == B_OK) { - fPath = BPath(info.name); - BNode node(info.name); - BNodeInfo nodeInfo(&node); - nodeInfo.GetTrackerIcon(&fMiniIcon, B_MINI_ICON); - nodeInfo.GetTrackerIcon(&fLargeIcon, B_LARGE_ICON); - } - - if (be_roster->GetRunningAppInfo(fTeamInfo.team, &fAppInfo) != B_OK) - fAppInfo.signature[0] = '\0'; - - CacheLocalizedName(); -} - - -TeamListItem::~TeamListItem() -{ -} - - -void -TeamListItem::CacheLocalizedName() -{ - if (BLocaleRoster::Default()->GetLocalizedFileName(fLocalizedName, - fAppInfo.ref, true) != B_OK) - fLocalizedName = fPath.Leaf(); -} - - -void -TeamListItem::DrawItem(BView* owner, BRect frame, bool complete) -{ - rgb_color kHighlight = { 140, 140, 140, 0 }; - rgb_color kBlack = { 0, 0, 0, 0 }; - rgb_color kBlue = { 0, 0, 255, 0 }; - rgb_color kRed = { 255, 0, 0, 0 }; - - BRect r(frame); - - if (IsSelected() || complete) { - rgb_color color; - if (IsSelected()) - color = kHighlight; - else - color = owner->ViewColor(); - - owner->SetHighColor(color); - owner->SetLowColor(color); - owner->FillRect(r); - owner->SetHighColor(kBlack); - } else { - owner->SetLowColor(owner->ViewColor()); - } - - frame.left += 4; - BRect iconFrame(frame); - iconFrame.Set(iconFrame.left, iconFrame.top + 1, iconFrame.left + 15, - iconFrame.top + 16); - owner->SetDrawingMode(B_OP_ALPHA); - owner->SetBlendingMode(B_PIXEL_ALPHA, B_ALPHA_OVERLAY); - owner->DrawBitmap(&fMiniIcon, iconFrame); - owner->SetDrawingMode(B_OP_COPY); - - frame.left += 16; - if (fRefusingToQuit) - owner->SetHighColor(kRed); - else - owner->SetHighColor(IsSystemServer() ? kBlue : kBlack); - - BFont font = be_plain_font; - font_height finfo; - font.GetHeight(&finfo); - owner->SetFont(&font); - owner->MovePenTo(frame.left + 8, frame.top + ((frame.Height() - - (finfo.ascent + finfo.descent + finfo.leading)) / 2) - + finfo.ascent); - - if (gLocalizedNamePreferred) - owner->DrawString(fLocalizedName.String()); - else - owner->DrawString(fPath.Leaf()); -} - - -/*static*/ int32 -TeamListItem::MinimalHeight() -{ - return 16 + kItemMargin; -} - - -void -TeamListItem::Update(BView* owner, const BFont* font) -{ - // we need to override the update method so we can make sure - // the list item size doesn't change - BListItem::Update(owner, font); - if (Height() < MinimalHeight()) - SetHeight(MinimalHeight()); -} - - -const team_info* -TeamListItem::GetInfo() -{ - return &fTeamInfo; -} - - -bool -TeamListItem::IsSystemServer() -{ - static bool firstCall = true; - static BPath systemServersPath; - static BPath trackerPath; - static BPath deskbarPath; - - if (firstCall) { - find_directory(B_SYSTEM_SERVERS_DIRECTORY, &systemServersPath); - - find_directory(B_SYSTEM_DIRECTORY, &trackerPath); - trackerPath.Append("Tracker"); - - find_directory(B_SYSTEM_DIRECTORY, &deskbarPath); - deskbarPath.Append("Deskbar"); - - firstCall = false; - } - - if (strncmp(systemServersPath.Path(), fTeamInfo.args, - strlen(systemServersPath.Path())) == 0) - return true; - - if (strncmp(trackerPath.Path(), fTeamInfo.args, - strlen(trackerPath.Path())) == 0) - return true; - - if (strncmp(deskbarPath.Path(), fTeamInfo.args, - strlen(deskbarPath.Path())) == 0) - return true; - - return false; -} - - -bool -TeamListItem::IsApplication() const -{ - return fAppInfo.signature[0] != '\0'; -} - - -void -TeamListItem::SetRefusingToQuit(bool refusing) -{ - fRefusingToQuit = refusing; -} - - -bool -TeamListItem::IsRefusingToQuit() -{ - return fRefusingToQuit; -} diff --git a/src/add-ons/input_server/devices/synergy/TeamListItem.h b/src/add-ons/input_server/devices/synergy/TeamListItem.h deleted file mode 100644 index 79046c2..0000000 --- a/src/add-ons/input_server/devices/synergy/TeamListItem.h +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright 2004-2008, Haiku. - * Distributed under the terms of the MIT License. - * - * Authors: - * Jérôme Duval - */ -#ifndef TEAM_LIST_ITEM_H -#define TEAM_LIST_ITEM_H - - -#include <Bitmap.h> -#include <ListItem.h> -#include <Path.h> -#include <Roster.h> -#include <String.h> - - -extern bool gLocalizedNamePreferred; - - -class TeamListItem : public BListItem { -public: - TeamListItem(team_info& info); - virtual ~TeamListItem(); - - virtual void DrawItem(BView* owner, BRect frame, - bool complete = false); - virtual void Update(BView* owner, const BFont* font); - - void CacheLocalizedName(); - - const team_info* GetInfo(); - const BBitmap* LargeIcon() { return &fLargeIcon; }; - const BPath* Path() { return &fPath; }; - const char* AppSignature() { return fAppInfo.signature; }; - - bool IsSystemServer(); - bool IsApplication() const; - - bool Found() const { return fFound; } - void SetFound(bool found) { fFound = found; } - - void SetRefusingToQuit(bool refusing); - bool IsRefusingToQuit(); - - static int32 MinimalHeight(); - -private: - team_info fTeamInfo; - app_info fAppInfo; - BBitmap fMiniIcon; - BBitmap fLargeIcon; - BPath fPath; - BString fLocalizedName; - bool fFound; - bool fRefusingToQuit; -}; - - -#endif // TEAM_LIST_ITEM_H diff --git a/src/add-ons/input_server/devices/synergy/TeamMonitorWindow.cpp b/src/add-ons/input_server/devices/synergy/TeamMonitorWindow.cpp deleted file mode 100644 index 3c9e5fb..0000000 --- a/src/add-ons/input_server/devices/synergy/TeamMonitorWindow.cpp +++ /dev/null @@ -1,747 +0,0 @@ -/* - * Copyright 2004-2008, Haiku. - * Distributed under the terms of the MIT License. - * - * Authors: - * Jérôme Duval - * Axel Doerfler, axeld@xxxxxxxxxxxxxxxx - */ - -//! Keyboard input server addon - -#include "TeamMonitorWindow.h" - -#include <stdio.h> - -#include <Application.h> -#include <CardLayout.h> -#include <Catalog.h> -#include <GroupLayoutBuilder.h> -#include <IconView.h> -#include <LocaleRoster.h> -#include <Message.h> -#include <MessageRunner.h> -#include <Roster.h> -#include <ScrollView.h> -#include <Screen.h> -#include <SpaceLayoutItem.h> -#include <String.h> -#include <TextView.h> - -#include <syscalls.h> -#include <tracker_private.h> - -#include "KeyboardInputDevice.h" -#include "TeamListItem.h" - - -#undef B_TRANSLATION_CONTEXT -#define B_TRANSLATION_CONTEXT "Team monitor" - - -TeamMonitorWindow* gTeamMonitorWindow = NULL; - - -struct TeamQuitter { - team_id team; - thread_id thread; - BLooper* window; -}; - - -status_t -QuitTeamThreadFunction(void* data) -{ - TeamQuitter* teamQuitter = reinterpret_cast<TeamQuitter*>(data); - if (teamQuitter == NULL) - return B_ERROR; - - status_t status; - BMessenger messenger(NULL, teamQuitter->team, &status); - if (status != B_OK) - return status; - - BMessage message(B_QUIT_REQUESTED); - BMessage reply; - - messenger.SendMessage(&message, &reply, 3000000, 3000000); - - bool result; - if (reply.what != B_REPLY - || reply.FindBool("result", &result) != B_OK - || result == false) { - message.what = kMsgQuitFailed; - message.AddPointer("TeamQuitter", teamQuitter); - message.AddInt32("error", reply.what); - if (teamQuitter->window != NULL) - teamQuitter->window->PostMessage(&message); - return reply.what; - } - - return B_OK; -} - - -filter_result -FilterLocaleChanged(BMessage* message, BHandler** target, - BMessageFilter *filter) -{ - if (message->what == B_LOCALE_CHANGED && gTeamMonitorWindow != NULL) - gTeamMonitorWindow->LocaleChanged(); - - return B_DISPATCH_MESSAGE; -} - - -filter_result -FilterKeyDown(BMessage* message, BHandler** target, - BMessageFilter *filter) -{ - if (message->what == B_KEY_DOWN && gTeamMonitorWindow != NULL) { - if (gTeamMonitorWindow->HandleKeyDown(message)) - return B_SKIP_MESSAGE; - } - - return B_DISPATCH_MESSAGE; -} - - -class AllShowingTextView : public BTextView { -public: - AllShowingTextView(const char* name); - virtual void FrameResized(float width, float height); -}; - - -class TeamDescriptionView : public BView { -public: - TeamDescriptionView(); - virtual ~TeamDescriptionView(); - - virtual void MessageReceived(BMessage* message); - - void CtrlAltDelPressed(bool keyDown); - - void SetItem(TeamListItem* item); - TeamListItem* Item() { return fItem; } - -private: - TeamListItem* fItem; - int32 fSeconds; - BMessageRunner* fRebootRunner; - IconView* fIconView; - const char* fInfoString; - const char* fSysComponentString; - const char* fQuitOverdueString; - BCardLayout* fLayout; - AllShowingTextView* fIconTextView; - AllShowingTextView* fInfoTextView; -}; - - -static const uint32 kMsgUpdate = 'TMup'; -static const uint32 kMsgLaunchTerminal = 'TMlt'; -const uint32 TM_CANCEL = 'TMca'; -const uint32 TM_FORCE_REBOOT = 'TMfr'; -const uint32 TM_KILL_APPLICATION = 'TMka'; -const uint32 TM_QUIT_APPLICATION = 'TMqa'; -const uint32 TM_RESTART_DESKTOP = 'TMrd'; -const uint32 TM_SELECTED_TEAM = 'TMst'; - -static const uint32 kMsgRebootTick = 'TMrt'; - - -TeamMonitorWindow::TeamMonitorWindow() - : - BWindow(BRect(0, 0, 350, 400), B_TRANSLATE("Team monitor"), - B_TITLED_WINDOW_LOOK, B_MODAL_ALL_WINDOW_FEEL, - B_NOT_MINIMIZABLE | B_NOT_ZOOMABLE | B_ASYNCHRONOUS_CONTROLS - | B_CLOSE_ON_ESCAPE | B_AUTO_UPDATE_SIZE_LIMITS, - B_ALL_WORKSPACES), - fQuitting(false), - fUpdateRunner(NULL) -{ - BGroupLayout* layout = new BGroupLayout(B_VERTICAL); - float inset = 10; - layout->SetInsets(inset, inset, inset, inset); - layout->SetSpacing(inset); - SetLayout(layout); - - layout->View()->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); - - fListView = new BListView("teams"); - fListView->SetSelectionMessage(new BMessage(TM_SELECTED_TEAM)); - - BScrollView* scrollView = new BScrollView("scroll_teams", fListView, - 0, B_SUPPORTS_LAYOUT, false, true, B_FANCY_BORDER); - layout->AddView(scrollView); - - BGroupView* groupView = new BGroupView(B_HORIZONTAL); - layout->AddView(groupView); - - fKillButton = new BButton("kill", B_TRANSLATE("Kill application"), - new BMessage(TM_KILL_APPLICATION)); - groupView->AddChild(fKillButton); - fKillButton->SetEnabled(false); - - fQuitButton = new BButton("quit", B_TRANSLATE("Quit application"), - new BMessage(TM_QUIT_APPLICATION)); - groupView->AddChild(fQuitButton); - fQuitButton->SetEnabled(false); - [ *** diff truncated: 620 lines dropped *** ]