added 1 changeset to branch 'refs/remotes/jessicah-github/synergy' old head: d8669c3d9d9b40a81c7e1cf14cf53ed872252389 new head: da8df3e20a3ffa7cb299848184a840fdfe1908db overview: https://github.com/jessicah/haiku/compare/d8669c3...da8df3e ---------------------------------------------------------------------------- da8df3e: synergy: use a settings file; improve shutdown * settings file is located in ~/config/settings/kernel/drivers/synergy * enable [false|true] * server <ip address> [ Jessica Hamilton <jessica.l.hamilton@xxxxxxxxx> ] ---------------------------------------------------------------------------- Commit: da8df3e20a3ffa7cb299848184a840fdfe1908db Author: Jessica Hamilton <jessica.l.hamilton@xxxxxxxxx> Date: Tue Sep 30 03:49:23 2014 UTC ---------------------------------------------------------------------------- 3 files changed, 102 insertions(+), 25 deletions(-) src/add-ons/input_server/devices/synergy/Jamfile | 2 +- .../devices/synergy/haiku-usynergy.cpp | 120 +++++++++++++++---- .../devices/synergy/haiku-usynergy.h | 5 + ---------------------------------------------------------------------------- diff --git a/src/add-ons/input_server/devices/synergy/Jamfile b/src/add-ons/input_server/devices/synergy/Jamfile index e11fd00..3241790 100644 --- a/src/add-ons/input_server/devices/synergy/Jamfile +++ b/src/add-ons/input_server/devices/synergy/Jamfile @@ -4,7 +4,7 @@ SetSubDirSupportedPlatformsBeOSCompatible ; SubDirHdrs $(HAIKU_TOP) src add-ons kernel bus_managers ps2 ; -UsePrivateHeaders input interface network shared ; +UsePrivateHeaders input interface network shared storage ; UsePrivateSystemHeaders ; Addon <input>synergy : 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 20094be..050ddb1 100644 --- a/src/add-ons/input_server/devices/synergy/haiku-usynergy.cpp +++ b/src/add-ons/input_server/devices/synergy/haiku-usynergy.cpp @@ -2,9 +2,15 @@ #include <Application.h> #include <Autolock.h> #include <Clipboard.h> +#include <FindDirectory.h> +#include <NodeMonitor.h> #include <Notification.h> #include <Screen.h> #include <OS.h> +#include <Path.h> +#include <PathFinder.h> +#include <PathMonitor.h> + #include <cstdlib> #include <strings.h> #include <errno.h> @@ -14,6 +20,7 @@ #include <netinet/in.h> #include <netdb.h> +#include <driver_settings.h> #include <keyboard_mouse_driver.h> #include "ATKeymap.h" @@ -21,6 +28,9 @@ #include "haiku-usynergy.h" +#define FILE_UPDATED 'fiUp' + + #define TRACE_SYNERGY_DEVICE #ifdef TRACE_SYNERGY_DEVICE @@ -46,6 +56,8 @@ uSynergyInputServerDevice::uSynergyInputServerDevice() threadActive(false), uSynergyHaikuContext(NULL), synergyServerSocket(-1), + fEnableSynergy(false), + fServerAddress(NULL), fUpdateSettings(false), fKeymapLock("synergy keymap lock") { @@ -75,6 +87,21 @@ uSynergyInputServerDevice::uSynergyInputServerDevice() be_app->AddHandler(this); be_app->Unlock(); } + + BPath path; + if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) == B_OK) + path.Append("kernel/drivers/synergy"); + + fFilename = new char[strlen(path.Path()) + 1]; + strcpy(fFilename, path.Path()); + + BEntry entry(fFilename); + + BPrivate::BPathMonitor::StartWatching(fFilename, B_WATCH_STAT | B_WATCH_FILES_ONLY, this); + + _UpdateSettings(); + + TRACE("synergy: monitoring settings file at '%s'\n", fFilename); } uSynergyInputServerDevice::~uSynergyInputServerDevice() @@ -104,32 +131,54 @@ void uSynergyInputServerDevice::MessageReceived(BMessage* message) { CALLED(); - - if (message->what != B_CLIPBOARD_CHANGED) { - BHandler::MessageReceived(message); - return; - } - - const char *text = NULL; - int32 len = 0; - BMessage *clip = NULL; - if (be_clipboard->Lock()) { - if ((clip = be_clipboard->Data()) == B_OK) { - clip->FindData("text/plain", B_MIME_TYPE, (const void **)&text, &len); + switch (message->what) { + case B_PATH_MONITOR: + { + const char* path = ""; + // only fall through for appropriate file + if (!(message->FindString("path", &path) == B_OK + && strcmp(path, fFilename) == 0)) { + break; // not the file we're looking for + } } - be_clipboard->Unlock(); + // fall-through + case FILE_UPDATED: + { + _UpdateSettings(); + if (threadActive) + Stop(NULL, NULL); + Start(NULL, NULL); + break; + } + case B_CLIPBOARD_CHANGED: + { + const char *text = NULL; + int32 len = 0; + BMessage *clip = NULL; + if (be_clipboard->Lock()) { + if ((clip = be_clipboard->Data()) == B_OK) { + clip->FindData("text/plain", B_MIME_TYPE, (const void **)&text, &len); + } + be_clipboard->Unlock(); + } + if (len > 0 && text != NULL) { + uSynergySendClipboard(this->uSynergyHaikuContext, text); + TRACE("synergy: data added to clipboard\n"); + } else + TRACE("synergy: couldn't add data to clipboard\n"); + } + default: + BHandler::MessageReceived(message); } - if (len > 0 && text != NULL) { - uSynergySendClipboard(this->uSynergyHaikuContext, text); - TRACE("synergy: data added to clipboard\n"); - } else - TRACE("synergy: couldn't add data to clipboard\n"); } status_t uSynergyInputServerDevice::Start(const char* name, void* cookie) { CALLED(); + if (fServerAddress == NULL || fEnableSynergy == false) + return B_NO_ERROR; + status_t status = B_OK; char threadName[B_OS_NAME_LENGTH]; snprintf(threadName, B_OS_NAME_LENGTH, "uSynergy haiku"); @@ -179,12 +228,22 @@ uSynergyInputServerDevice::Stop(const char* name, void* cookie) } status_t +uSynergyInputServerDevice::SystemShuttingDown() +{ + threadActive = false; + + return B_OK; +} + +status_t uSynergyInputServerDevice::Control(const char* name, void* cookie, uint32 command, BMessage* message) { - if (command == B_KEY_MAP_CHANGED) + if (command == B_KEY_MAP_CHANGED) { fUpdateSettings = true; + return B_OK; + } - return B_OK; + return B_BAD_VALUE; } BMessage* @@ -213,6 +272,15 @@ uSynergyInputServerDevice::_UpdateSettings() fModifiers = fKeymap.Map().lock_settings; fControlKey = fKeymap.KeyForModifier(B_LEFT_CONTROL_KEY); fCommandKey = fKeymap.KeyForModifier(B_LEFT_COMMAND_KEY); + + void* handle = load_driver_settings("synergy"); + if (handle == NULL) + return; + + fEnableSynergy = get_driver_boolean_parameter(handle, "enable", false, false); + fServerAddress = get_driver_parameter(handle, "server", NULL, NULL); + + unload_driver_settings(handle); } status_t @@ -245,6 +313,9 @@ uSynergyConnectHaiku(uSynergyCookie cookie) CALLED(); uSynergyInputServerDevice *inputDevice = (uSynergyInputServerDevice*)cookie; + if (inputDevice->fServerAddress == NULL || inputDevice->fEnableSynergy == false) + goto exit; + struct sockaddr_in server; server.sin_family = AF_INET; @@ -255,21 +326,22 @@ uSynergyConnectHaiku(uSynergyCookie cookie) if (inputDevice->synergyServerSocket < 0) { TRACE("synergy: socket couldn't be created\n"); - snooze(1000000); - return USYNERGY_FALSE; + goto exit; } 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); inputDevice->synergyServerSocket = -1; - snooze(1000000); // temporary workaround to avoid filling up log too quickly - return USYNERGY_FALSE; + goto exit; } else { TRACE("synergy: connected to remote host!!!\n"); return USYNERGY_TRUE; } +exit: + snooze(1000000); + return USYNERGY_FALSE; } uSynergyBool 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 d28e19d..1327351 100644 --- a/src/add-ons/input_server/devices/synergy/haiku-usynergy.h +++ b/src/add-ons/input_server/devices/synergy/haiku-usynergy.h @@ -40,6 +40,8 @@ class uSynergyInputServerDevice : public BHandler, public BInputServerDevice { virtual void MessageReceived(BMessage* message); virtual status_t Start(const char* name, void* cookie); virtual status_t Stop(const char* name, void* cookie); + virtual status_t SystemShuttingDown(); + virtual status_t Control(const char* name, void* cookie, uint32 command, BMessage* message); private: @@ -60,6 +62,9 @@ class uSynergyInputServerDevice : public BHandler, public BInputServerDevice { uint32 fModifiers; uint32 fCommandKey; uint32 fControlKey; + char* fFilename; + bool fEnableSynergy; + const char* fServerAddress; volatile bool fUpdateSettings;