From 6a9a180688348154fdfec562dbd026e9e47256c6 Mon Sep 17 00:00:00 2001 From: crs Date: Mon, 29 Apr 2002 14:08:48 +0000 Subject: [PATCH] Made event selection a little more robust. Also fixed failure to marshall clipboard data when updating primary clipboards. --- client/CXWindowsSecondaryScreen.cpp | 10 +++++++++- client/CXWindowsSecondaryScreen.h | 1 + server/CServer.cpp | 2 ++ server/CXWindowsPrimaryScreen.cpp | 14 ++++++++++++-- server/CXWindowsPrimaryScreen.h | 1 + synergy/CXWindowsScreen.cpp | 19 +++++++++++++++---- synergy/CXWindowsScreen.h | 3 +++ 7 files changed, 43 insertions(+), 7 deletions(-) diff --git a/client/CXWindowsSecondaryScreen.cpp b/client/CXWindowsSecondaryScreen.cpp index 84995990..d4d1c912 100644 --- a/client/CXWindowsSecondaryScreen.cpp +++ b/client/CXWindowsSecondaryScreen.cpp @@ -319,7 +319,7 @@ void CXWindowsSecondaryScreen::onOpenDisplay() // as the cursor enters the screen or the display's real cursor is // moved. XSetWindowAttributes attr; - attr.event_mask = LeaveWindowMask | PropertyChangeMask; + attr.event_mask = LeaveWindowMask; attr.do_not_propagate_mask = 0; attr.override_redirect = True; attr.cursor = createBlankCursor(); @@ -349,6 +349,14 @@ void CXWindowsSecondaryScreen::onCloseDisplay() m_window = None; } +long CXWindowsSecondaryScreen::getEventMask(Window w) const +{ + if (w == m_window) + return LeaveWindowMask; + else + return NoEventMask; +} + void CXWindowsSecondaryScreen::leaveNoLock(Display* display) { assert(display != NULL); diff --git a/client/CXWindowsSecondaryScreen.h b/client/CXWindowsSecondaryScreen.h index 5f4eda9f..29809de6 100644 --- a/client/CXWindowsSecondaryScreen.h +++ b/client/CXWindowsSecondaryScreen.h @@ -34,6 +34,7 @@ class CXWindowsSecondaryScreen : public CXWindowsScreen, public ISecondaryScreen // CXWindowsScreen overrides virtual void onOpenDisplay(); virtual void onCloseDisplay(); + virtual long getEventMask(Window) const; private: struct KeyCodeMask { diff --git a/server/CServer.cpp b/server/CServer.cpp index bd24f766..a2e593fa 100644 --- a/server/CServer.cpp +++ b/server/CServer.cpp @@ -950,6 +950,8 @@ void CServer::updatePrimaryClipboard(ClipboardID id) // if clipboard changed then other screens have an // out-of-date clipboard. if (time != clipboard.m_clipboard.getTime()) { + log((CLOG_DEBUG "clipboard %d changed", id)); + clipboard.m_clipboardData = clipboard.m_clipboard.marshall(); clearGotClipboard(id); m_primaryInfo->m_gotClipboard[id] = true; } diff --git a/server/CXWindowsPrimaryScreen.cpp b/server/CXWindowsPrimaryScreen.cpp index 73a1de48..0ce318cc 100644 --- a/server/CXWindowsPrimaryScreen.cpp +++ b/server/CXWindowsPrimaryScreen.cpp @@ -406,6 +406,17 @@ void CXWindowsPrimaryScreen::onCloseDisplay() m_window = None; } +long CXWindowsPrimaryScreen::getEventMask(Window w) const +{ + if (w == m_window) + return PointerMotionMask |// PointerMotionHintMask | + ButtonPressMask | ButtonReleaseMask | + KeyPressMask | KeyReleaseMask | + KeymapStateMask; + else + return PointerMotionMask | SubstructureNotifyMask; +} + void CXWindowsPrimaryScreen::selectEvents( Display* display, Window w) const { @@ -419,8 +430,7 @@ void CXWindowsPrimaryScreen::selectEvents( return; // select events of interest - XSelectInput(display, w, PointerMotionMask | SubstructureNotifyMask | - PropertyChangeMask); + XSelectInput(display, w, PointerMotionMask | SubstructureNotifyMask); // recurse on child windows Window rw, pw, *cw; diff --git a/server/CXWindowsPrimaryScreen.h b/server/CXWindowsPrimaryScreen.h index 1cdc1563..f6ab7a63 100644 --- a/server/CXWindowsPrimaryScreen.h +++ b/server/CXWindowsPrimaryScreen.h @@ -29,6 +29,7 @@ class CXWindowsPrimaryScreen : public CXWindowsScreen, public IPrimaryScreen { // CXWindowsScreen overrides virtual void onOpenDisplay(); virtual void onCloseDisplay(); + virtual long getEventMask(Window) const; private: void selectEvents(Display*, Window) const; diff --git a/synergy/CXWindowsScreen.cpp b/synergy/CXWindowsScreen.cpp index 51109584..4c55a5fd 100644 --- a/synergy/CXWindowsScreen.cpp +++ b/synergy/CXWindowsScreen.cpp @@ -672,7 +672,7 @@ void CXWindowsScreen::processClipboardRequest( clipboard.m_requests.erase(index); delete list; } - XSelectInput(m_display, requestor, NoEventMask); + XSelectInput(m_display, requestor, getEventMask(requestor)); } // request has been serviced @@ -765,9 +765,12 @@ bool CXWindowsScreen::sendClipboardData( list->push_back(request); // start watching requestor for property changes and - // destruction - XSelectInput(m_display, requestor, StructureNotifyMask | - PropertyChangeMask); + // destruction, in addition to other events required by + // the subclass. + XSelectInput(m_display, requestor, + getEventMask(requestor) | + StructureNotifyMask | + PropertyChangeMask); // FIXME -- handle Alloc errors (by returning false) // set property to INCR @@ -968,6 +971,11 @@ Time CXWindowsScreen::getCurrentTime(Window window) const Time CXWindowsScreen::getCurrentTimeNoLock( Window window) const { + // select property events on window + // note -- this will break clipboard transfer if used on a requestor + // window, so don't do that. + XSelectInput(m_display, window, getEventMask(window) | PropertyChangeMask); + // do a zero-length append to get the current time unsigned char dummy; XChangeProperty(m_display, window, m_atomSynergyTime, @@ -992,6 +1000,9 @@ Time CXWindowsScreen::getCurrentTimeNoLock( assert(xevent.xproperty.window == window); assert(xevent.xproperty.atom == m_atomSynergyTime); + // restore event mask + XSelectInput(m_display, window, getEventMask(window)); + return xevent.xproperty.time; } diff --git a/synergy/CXWindowsScreen.h b/synergy/CXWindowsScreen.h index ec8cfb7e..21e8d639 100644 --- a/synergy/CXWindowsScreen.h +++ b/synergy/CXWindowsScreen.h @@ -101,6 +101,9 @@ class CXWindowsScreen { // called by closeDisplay() to virtual void onCloseDisplay() = 0; + // get the X event mask required by the subclass for the given window + virtual long getEventMask(Window) const = 0; + private: struct CPropertyNotifyInfo { public: