From 82edfe087c33185d91fc9d4de7b85238c653d465 Mon Sep 17 00:00:00 2001 From: Steve Williams Date: Tue, 20 Mar 2018 10:13:39 +0000 Subject: [PATCH 1/4] Ignore idea files --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 43a768cd..1c985260 100644 --- a/.gitignore +++ b/.gitignore @@ -19,3 +19,6 @@ src/gui/gui.pro.user* src/gui/.qmake.stash src/gui/.rnd src/setup/win32/synergy.suo +/.idea +/cmake-build-debug +/CMakeLists.txt.user From 35fb8c338948d4150c52fe35cae897c61c42a377 Mon Sep 17 00:00:00 2001 From: Andrew Nelless Date: Wed, 14 Mar 2018 13:35:42 +0000 Subject: [PATCH 2/4] Make macOS screen shape detection code more robust --- src/lib/platform/OSXScreen.h | 4 ++-- src/lib/platform/OSXScreen.mm | 29 +++++++++++++++++------------ 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/src/lib/platform/OSXScreen.h b/src/lib/platform/OSXScreen.h index 668e713b..25531e0e 100644 --- a/src/lib/platform/OSXScreen.h +++ b/src/lib/platform/OSXScreen.h @@ -109,8 +109,8 @@ protected: virtual IKeyState* getKeyState() const; private: - void updateScreenShape(); - void updateScreenShape(const CGDirectDisplayID, const CGDisplayChangeSummaryFlags); + bool updateScreenShape(); + bool updateScreenShape(const CGDirectDisplayID, const CGDisplayChangeSummaryFlags); void postMouseEvent(CGPoint&) const; // convenience function to send events diff --git a/src/lib/platform/OSXScreen.mm b/src/lib/platform/OSXScreen.mm index 0106ccf9..6c24a487 100644 --- a/src/lib/platform/OSXScreen.mm +++ b/src/lib/platform/OSXScreen.mm @@ -105,9 +105,12 @@ OSXScreen::OSXScreen(IEventQueue* events, bool isPrimary, bool autoShowHideCurso m_getDropTargetThread(NULL), m_impl(NULL) { + m_displayID = CGMainDisplayID(); + if (!updateScreenShape(m_displayID, 0)) { + throw std::runtime_error ("failed to initialize screen shape"); + } + try { - m_displayID = CGMainDisplayID(); - updateScreenShape(m_displayID, 0); m_screensaver = new OSXScreenSaver(m_events, getEventTarget()); m_keyState = new OSXKeyState(m_events); @@ -1212,9 +1215,10 @@ OSXScreen::displayReconfigurationCallback(CGDirectDisplayID displayID, CGDisplay LOG((CLOG_DEBUG1 "event: display was reconfigured: %x %x %x", flags, mask, flags & mask)); if (flags & mask) { /* Something actually did change */ - LOG((CLOG_DEBUG1 "event: screen changed shape; refreshing dimensions")); - screen->updateScreenShape(displayID, flags); + if (!screen->updateScreenShape(displayID, flags)) { + LOG((CLOG_ERR "failed to update screen shape during display reconfiguration")); + } } } @@ -1518,35 +1522,34 @@ OSXScreen::getKeyState() const return m_keyState; } -void -OSXScreen::updateScreenShape(const CGDirectDisplayID, const CGDisplayChangeSummaryFlags flags) +bool OSXScreen::updateScreenShape(const CGDirectDisplayID, const CGDisplayChangeSummaryFlags flags) { - updateScreenShape(); + return updateScreenShape(); } -void +bool OSXScreen::updateScreenShape() { // get info for each display CGDisplayCount displayCount = 0; if (CGGetActiveDisplayList(0, NULL, &displayCount) != CGDisplayNoErr) { - return; + return false; } if (displayCount == 0) { - return; + return false; } CGDirectDisplayID* displays = new CGDirectDisplayID[displayCount]; if (displays == NULL) { - return; + return false; } if (CGGetActiveDisplayList(displayCount, displays, &displayCount) != CGDisplayNoErr) { delete[] displays; - return; + return false; } // get smallest rect enclosing all display rects @@ -1575,6 +1578,8 @@ OSXScreen::updateScreenShape() LOG((CLOG_DEBUG "screen shape: center=%d,%d size=%dx%d on %u %s", m_x, m_y, m_w, m_h, displayCount, (displayCount == 1) ? "display" : "displays")); + + return true; } #pragma mark - From eb4047b9fb0f77e9d6991a4126218884455628ad Mon Sep 17 00:00:00 2001 From: Steve Williams Date: Thu, 29 Mar 2018 09:54:53 +0100 Subject: [PATCH 3/4] #5964 Can't click on client after sleep --- src/lib/platform/OSXScreen.mm | 3 +- src/lib/synergy/App.cpp | 11 +++++++ src/lib/synergy/DisplayInvalidException.h | 39 +++++++++++++++++++++++ 3 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 src/lib/synergy/DisplayInvalidException.h diff --git a/src/lib/platform/OSXScreen.mm b/src/lib/platform/OSXScreen.mm index 6c24a487..93bec0e9 100644 --- a/src/lib/platform/OSXScreen.mm +++ b/src/lib/platform/OSXScreen.mm @@ -39,6 +39,7 @@ #include "base/IEventQueue.h" #include "base/TMethodEventJob.h" #include "base/TMethodJob.h" +#include "synergy/DisplayInvalidException.h" #include #include @@ -107,7 +108,7 @@ OSXScreen::OSXScreen(IEventQueue* events, bool isPrimary, bool autoShowHideCurso { m_displayID = CGMainDisplayID(); if (!updateScreenShape(m_displayID, 0)) { - throw std::runtime_error ("failed to initialize screen shape"); + throw DisplayInvalidException ("failed to initialize screen shape"); } try { diff --git a/src/lib/synergy/App.cpp b/src/lib/synergy/App.cpp index 4c8c1808..8abf4dde 100644 --- a/src/lib/synergy/App.cpp +++ b/src/lib/synergy/App.cpp @@ -32,6 +32,7 @@ #include "ipc/IpcMessage.h" #include "ipc/Ipc.h" #include "base/EventQueue.h" +#include "DisplayInvalidException.h" #if SYSAPI_WIN32 #include "arch/win32/ArchMiscWindows.h" @@ -50,6 +51,7 @@ #include "platform/OSXDragSimulator.h" #endif + App* App::s_instance = nullptr; // @@ -125,6 +127,15 @@ App::run(int argc, char** argv) // using the exit(int) function! result = e.getCode(); } + catch (DisplayInvalidException& die) { + LOG((CLOG_CRIT "A display invalid exception error occurred: %s\n", die.what())); + // display invalid exceptions can occur when going to sleep. When this process exits, the + // UI will restart us instantly. We don't really want that behevior, so we quies for a bit + (void)sleep(10); + } + catch (std::runtime_error& re) { + LOG((CLOG_CRIT "A runtime error occurred: %s\n", re.what())); + } catch (std::exception& e) { LOG((CLOG_CRIT "An error occurred: %s\n", e.what())); } diff --git a/src/lib/synergy/DisplayInvalidException.h b/src/lib/synergy/DisplayInvalidException.h new file mode 100644 index 00000000..bdc32801 --- /dev/null +++ b/src/lib/synergy/DisplayInvalidException.h @@ -0,0 +1,39 @@ +/* + * synergy -- mouse and keyboard sharing utility + * Copyright (C) 2012-2018 Symless Ltd. + * Copyright (C) 2002 Chris Schoeneman + * + * This package is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * found in the file LICENSE that should have accompanied this file. + * + * This package is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#ifndef SYNERGY_DISPLAYINVALIDEXCEPTION_H +#define SYNERGY_DISPLAYINVALIDEXCEPTION_H + + +#include +#include + +class DisplayInvalidException : public std::runtime_error { + public: + DisplayInvalidException(const char* msg): + std::runtime_error(msg) + { + } + + DisplayInvalidException(std::string msg): + std::runtime_error(msg) + { + } +}; + + +#endif //SYNERGY_DISPLAYINVALIDEXCEPTION_H From 67c7d0993fdbd3605380cd2e5b52e9e375ca3f3a Mon Sep 17 00:00:00 2001 From: Steve Williams Date: Thu, 29 Mar 2018 10:08:48 +0100 Subject: [PATCH 4/4] #5964 Fix multiplatform sleep --- src/lib/synergy/App.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/synergy/App.cpp b/src/lib/synergy/App.cpp index 8abf4dde..78511608 100644 --- a/src/lib/synergy/App.cpp +++ b/src/lib/synergy/App.cpp @@ -131,7 +131,7 @@ App::run(int argc, char** argv) LOG((CLOG_CRIT "A display invalid exception error occurred: %s\n", die.what())); // display invalid exceptions can occur when going to sleep. When this process exits, the // UI will restart us instantly. We don't really want that behevior, so we quies for a bit - (void)sleep(10); + ARCH->sleep(10); } catch (std::runtime_error& re) { LOG((CLOG_CRIT "A runtime error occurred: %s\n", re.what()));