From 34c587e86477b0848498b2e2e2c0eeb31b1e21e2 Mon Sep 17 00:00:00 2001 From: crs Date: Fri, 24 May 2002 14:37:12 +0000 Subject: [PATCH] added support for locking to a screen when the sroll lock is toggled on or when any key or button is pressed. fully implemented on X but stubbed out for now on win32. --- server/CMSWindowsPrimaryScreen.cpp | 6 +++++ server/CMSWindowsPrimaryScreen.h | 1 + server/CServer.cpp | 12 +++++++++- server/CXWindowsPrimaryScreen.cpp | 35 +++++++++++++++++++++++++++++- server/CXWindowsPrimaryScreen.h | 1 + synergy/IPrimaryScreen.h | 5 +++++ 6 files changed, 58 insertions(+), 2 deletions(-) diff --git a/server/CMSWindowsPrimaryScreen.cpp b/server/CMSWindowsPrimaryScreen.cpp index 43136b07..546536d0 100644 --- a/server/CMSWindowsPrimaryScreen.cpp +++ b/server/CMSWindowsPrimaryScreen.cpp @@ -255,6 +255,12 @@ KeyModifierMask CMSWindowsPrimaryScreen::getToggleMask() const return mask; } +bool CMSWindowsPrimaryScreen::isLockedToScreen() const +{ + // FIXME + return false; +} + void CMSWindowsPrimaryScreen::onOpenDisplay() { assert(m_window == NULL); diff --git a/server/CMSWindowsPrimaryScreen.h b/server/CMSWindowsPrimaryScreen.h index 35bb7167..9d44c912 100644 --- a/server/CMSWindowsPrimaryScreen.h +++ b/server/CMSWindowsPrimaryScreen.h @@ -27,6 +27,7 @@ public: virtual SInt32 getJumpZoneSize() const; virtual void getClipboard(ClipboardID, IClipboard*) const; virtual KeyModifierMask getToggleMask() const; + virtual bool isLockedToScreen() const; protected: // CMSWindowsScreen overrides diff --git a/server/CServer.cpp b/server/CServer.cpp index 16cb7576..09739198 100644 --- a/server/CServer.cpp +++ b/server/CServer.cpp @@ -489,7 +489,17 @@ void CServer::onMouseWheel(SInt32 delta) bool CServer::isLockedToScreen() const { - // FIXME + // locked if primary says we're locked + if (m_primary->isLockedToScreen()) { + return true; + } + + // locked if scroll-lock is toggled on + if ((m_primary->getToggleMask() & KeyModifierScrollLock) != 0) { + return true; + } + + // not locked return false; } diff --git a/server/CXWindowsPrimaryScreen.cpp b/server/CXWindowsPrimaryScreen.cpp index ebaabeba..26e374c0 100644 --- a/server/CXWindowsPrimaryScreen.cpp +++ b/server/CXWindowsPrimaryScreen.cpp @@ -424,8 +424,9 @@ KeyModifierMask CXWindowsPrimaryScreen::getToggleMask() const int xRoot, yRoot, xWindow, yWindow; unsigned int state; if (!XQueryPointer(display, m_window, &root, &window, - &xRoot, &yRoot, &xWindow, &yWindow, &state)) + &xRoot, &yRoot, &xWindow, &yWindow, &state)) { return 0; + } // convert to KeyModifierMask KeyModifierMask mask = 0; @@ -439,6 +440,38 @@ KeyModifierMask CXWindowsPrimaryScreen::getToggleMask() const return mask; } +bool CXWindowsPrimaryScreen::isLockedToScreen() const +{ + CDisplayLock display(this); + + // query the pointer to get the button state + Window root, window; + int xRoot, yRoot, xWindow, yWindow; + unsigned int state; + if (XQueryPointer(display, m_window, &root, &window, + &xRoot, &yRoot, &xWindow, &yWindow, &state)) { + if ((state & (Button1Mask | Button2Mask | Button3Mask | + Button4Mask | Button5Mask)) != 0) { + return true; + } + } + + // get logical keyboard state + char keyMap[32]; + memset(keyMap, 0, sizeof(keyMap)); + XQueryKeymap(display, keyMap); + + // locked if any key is down + for (unsigned int i = 0; i < sizeof(keyMap); ++i) { + if (keyMap[i] != 0) { + return true; + } + } + + // not locked + return false; +} + void CXWindowsPrimaryScreen::onOpenDisplay() { assert(m_window == None); diff --git a/server/CXWindowsPrimaryScreen.h b/server/CXWindowsPrimaryScreen.h index 381b013a..03e5bc98 100644 --- a/server/CXWindowsPrimaryScreen.h +++ b/server/CXWindowsPrimaryScreen.h @@ -25,6 +25,7 @@ public: virtual SInt32 getJumpZoneSize() const; virtual void getClipboard(ClipboardID, IClipboard*) const; virtual KeyModifierMask getToggleMask() const; + virtual bool isLockedToScreen() const; protected: // CXWindowsScreen overrides diff --git a/synergy/IPrimaryScreen.h b/synergy/IPrimaryScreen.h index 64c44bec..02535ac9 100644 --- a/synergy/IPrimaryScreen.h +++ b/synergy/IPrimaryScreen.h @@ -84,6 +84,11 @@ public: // the returned mask should have the corresponding bit set for // each toggle key that is active. virtual KeyModifierMask getToggleMask() const = 0; + + // return true if any key or button is being pressed or if there's + // any other reason that the user should not be allowed to switch + // screens. + virtual bool isLockedToScreen() const = 0; }; #endif