[Libreoffice-commits] .: 2 commits - vcl/unx
Lubos Lunak
llunak at kemper.freedesktop.org
Tue Apr 5 09:31:15 PDT 2011
vcl/unx/source/dtrans/X11_selection.cxx | 55 ++++++++++++--------------------
1 file changed, 22 insertions(+), 33 deletions(-)
New commits:
commit 0b2b6df0867a09ca562a342c2e10c1a314d6f48e
Author: LuboÅ¡ LuÅák <l.lunak at suse.cz>
Date: Tue Apr 5 18:25:22 2011 +0200
rework confused and racy clipboard event polling (bnc#683941)
It does not work reliably to just poll on the X connection fd,
as there may be already incoming events in the Xlib queue (removed
from the fd connection). So XPending() call is necessary; which
additionally ensures the output queue is flushed before polling.
The second poll() seems to have been just introduced as a result
of failing to understand this, and the strange XPending() nesting
later is no longer needed either.
diff --git a/vcl/unx/source/dtrans/X11_selection.cxx b/vcl/unx/source/dtrans/X11_selection.cxx
index 4358c35..4a4e9a4 100644
--- a/vcl/unx/source/dtrans/X11_selection.cxx
+++ b/vcl/unx/source/dtrans/X11_selection.cxx
@@ -3730,41 +3730,29 @@ bool SelectionManager::handleXEvent( XEvent& rEvent )
void SelectionManager::dispatchEvent( int millisec )
{
- pollfd aPollFD;
- XEvent event;
-
- // query socket handle to poll on
- aPollFD.fd = ConnectionNumber( m_pDisplay );
- aPollFD.events = POLLIN;
- aPollFD.revents = 0;
+ // acquire the mutex to prevent other threads
+ // from using the same X connection
+ osl::ResettableMutexGuard aGuard(m_aMutex);
- // wait for activity (outside the xlib)
- if( poll( &aPollFD, 1, millisec ) > 0 )
+ if( !XPending( m_pDisplay ))
+ { // wait for any events if none are already queued
+ pollfd aPollFD;
+ aPollFD.fd = XConnectionNumber( m_pDisplay );
+ aPollFD.events = POLLIN;
+ aPollFD.revents = 0;
+ // release mutex for the time of waiting for possible data
+ aGuard.clear();
+ if( poll( &aPollFD, 1, millisec ) <= 0 )
+ return;
+ aGuard.reset();
+ }
+ while( XPending( m_pDisplay ))
{
- // now acquire the mutex to prevent other threads
- // from using the same X connection
- osl::ResettableMutexGuard aGuard(m_aMutex);
-
- // prevent that another thread already ate the input
- // this can happen if e.g. another thread does
- // an X request getting a response. the response
- // would be removed from the queue and we would end up
- // with an empty socket here
- if( poll( &aPollFD, 1, 0 ) > 0 )
- {
- int nPending = 1;
- while( nPending )
- {
- nPending = XPending( m_pDisplay );
- if( nPending )
- {
- XNextEvent( m_pDisplay, &event );
- aGuard.clear();
- handleXEvent( event );
- aGuard.reset();
- }
- }
- }
+ XEvent event;
+ XNextEvent( m_pDisplay, &event );
+ aGuard.clear();
+ handleXEvent( event );
+ aGuard.reset();
}
}
commit f799bf7120e0415cfe1d8b20747d08e39953ae60
Author: LuboÅ¡ LuÅák <l.lunak at suse.cz>
Date: Tue Apr 5 13:58:37 2011 +0200
add trailing newline to debug output
diff --git a/vcl/unx/source/dtrans/X11_selection.cxx b/vcl/unx/source/dtrans/X11_selection.cxx
index 5a27af6..4358c35 100644
--- a/vcl/unx/source/dtrans/X11_selection.cxx
+++ b/vcl/unx/source/dtrans/X11_selection.cxx
@@ -1799,6 +1799,7 @@ bool SelectionManager::handleSelectionRequest( XSelectionRequestEvent& rRequest
fprintf( stderr, " \"%s\"", OUStringToOString( getString( pProps[i]), RTL_TEXTENCODING_ISO_8859_1 ).getStr() );
XFree( pProps );
}
+ fprintf( stderr, "\n" );
}
#endif
}
More information about the Libreoffice-commits
mailing list