Kaydet (Commit) 516a8ded authored tarafından Jan-Marek Glogowski's avatar Jan-Marek Glogowski

KDE4: change eventLoopType enum to glib bool

Just check for glib; it's the default in later Qt4 versions on unix.

Change-Id: Ia99466e9010eb835bea0c3c4420da3c8b3cd4671
üst daf01187
...@@ -45,21 +45,15 @@ ...@@ -45,21 +45,15 @@
#include <config_kde4.h> #include <config_kde4.h>
#if KDE_HAVE_GLIB
#define GLIB_EVENT_LOOP_SUPPORT 1
#else
#define GLIB_EVENT_LOOP_SUPPORT 0
#endif
#if GLIB_EVENT_LOOP_SUPPORT
#include <glib-2.0/glib.h>
#endif
KDEXLib::KDEXLib() : KDEXLib::KDEXLib() :
SalXLib(), m_bStartupDone(false), m_pApplication(0), SalXLib(), m_bStartupDone(false), m_pApplication(0),
m_pFreeCmdLineArgs(0), m_pAppCmdLineArgs(0), m_nFakeCmdLineArgs( 0 ), m_pFreeCmdLineArgs(0), m_pAppCmdLineArgs(0), m_nFakeCmdLineArgs( 0 ),
eventLoopType( LibreOfficeEventLoop ), m_frameWidth( -1 ) m_frameWidth( -1 ), m_isGlibEventLoopType(false)
{ {
#if KDE_HAVE_GLIB
m_isGlibEventLoopType = QAbstractEventDispatcher::instance()->inherits( "QEventDispatcherGlib" );
#endif
// the timers created here means they belong to the main thread. // the timers created here means they belong to the main thread.
// As the timeoutTimer runs the LO event queue, which may block on a dialog, // As the timeoutTimer runs the LO event queue, which may block on a dialog,
// the timer has to use a Qt::QueuedConnection, otherwise the nested event // the timer has to use a Qt::QueuedConnection, otherwise the nested event
...@@ -190,9 +184,17 @@ void KDEXLib::Init() ...@@ -190,9 +184,17 @@ void KDEXLib::Init()
// needs to be unlocked shortly before entering the main sleep (e.g. select()) and locked // needs to be unlocked shortly before entering the main sleep (e.g. select()) and locked
// immediatelly after. So we need to know which event loop implementation is used and // immediatelly after. So we need to know which event loop implementation is used and
// hook accordingly. // hook accordingly.
#if GLIB_EVENT_LOOP_SUPPORT #if KDE_HAVE_GLIB
#include <glib.h>
static GPollFunc old_gpoll = NULL; static GPollFunc old_gpoll = NULL;
static gint gpoll_wrapper( GPollFD*, guint, gint ); static gint gpoll_wrapper( GPollFD*, guint, gint );
gint gpoll_wrapper( GPollFD* ufds, guint nfds, gint timeout )
{
SalYieldMutexReleaser release; // release YieldMutex (and re-acquire at block end)
return old_gpoll( ufds, nfds, timeout );
}
#endif #endif
static bool ( *old_qt_event_filter )( void* ); static bool ( *old_qt_event_filter )( void* );
...@@ -208,35 +210,19 @@ static bool qt_event_filter( void* m ) ...@@ -208,35 +210,19 @@ static bool qt_event_filter( void* m )
void KDEXLib::setupEventLoop() void KDEXLib::setupEventLoop()
{ {
old_qt_event_filter = QAbstractEventDispatcher::instance()->setEventFilter( qt_event_filter ); old_qt_event_filter = QAbstractEventDispatcher::instance()->setEventFilter( qt_event_filter );
#if GLIB_EVENT_LOOP_SUPPORT #if KDE_HAVE_GLIB
// Glib is simple, it has g_main_context_set_poll_func() for wrapping the sleep call. if( m_isGlibEventLoopType )
// The catch is that Qt has a bug that allows triggering timers even when they should
// not be, leading to crashes caused by QClipboard re-entering the event loop.
// (http://bugreports.qt.nokia.com/browse/QTBUG-14461), so enable only with Qt>=4.8.0,
// where it is fixed.
#if QT_VERSION >= QT_VERSION_CHECK( 4, 8, 0 )
if( QAbstractEventDispatcher::instance()->inherits( "QEventDispatcherGlib" ))
{ {
eventLoopType = GlibEventLoop;
old_gpoll = g_main_context_get_poll_func( NULL ); old_gpoll = g_main_context_get_poll_func( NULL );
g_main_context_set_poll_func( NULL, gpoll_wrapper ); g_main_context_set_poll_func( NULL, gpoll_wrapper );
return; return;
} }
#endif #endif
#endif
}
#if GLIB_EVENT_LOOP_SUPPORT
gint gpoll_wrapper( GPollFD* ufds, guint nfds, gint timeout )
{
SalYieldMutexReleaser release; // release YieldMutex (and re-acquire at block end)
return old_gpoll( ufds, nfds, timeout );
} }
#endif
void KDEXLib::Insert( int fd, void* data, YieldFunc pending, YieldFunc queued, YieldFunc handle ) void KDEXLib::Insert( int fd, void* data, YieldFunc pending, YieldFunc queued, YieldFunc handle )
{ {
if( eventLoopType == LibreOfficeEventLoop ) if( !m_isGlibEventLoopType )
return SalXLib::Insert( fd, data, pending, queued, handle ); return SalXLib::Insert( fd, data, pending, queued, handle );
SocketData sdata; SocketData sdata;
sdata.data = data; sdata.data = data;
...@@ -251,7 +237,7 @@ void KDEXLib::Insert( int fd, void* data, YieldFunc pending, YieldFunc queued, Y ...@@ -251,7 +237,7 @@ void KDEXLib::Insert( int fd, void* data, YieldFunc pending, YieldFunc queued, Y
void KDEXLib::Remove( int fd ) void KDEXLib::Remove( int fd )
{ {
if( eventLoopType == LibreOfficeEventLoop ) if( !m_isGlibEventLoopType )
return SalXLib::Remove( fd ); return SalXLib::Remove( fd );
SocketData sdata = socketData.take( fd );// according to SalXLib::Remove() this should be safe SocketData sdata = socketData.take( fd );// according to SalXLib::Remove() this should be safe
delete sdata.notifier; delete sdata.notifier;
...@@ -265,7 +251,7 @@ void KDEXLib::socketNotifierActivated( int fd ) ...@@ -265,7 +251,7 @@ void KDEXLib::socketNotifierActivated( int fd )
void KDEXLib::Yield( bool bWait, bool bHandleAllCurrentEvents ) void KDEXLib::Yield( bool bWait, bool bHandleAllCurrentEvents )
{ {
if( eventLoopType == LibreOfficeEventLoop ) if( !m_isGlibEventLoopType )
{ {
if( qApp->thread() == QThread::currentThread()) if( qApp->thread() == QThread::currentThread())
{ {
...@@ -307,7 +293,7 @@ void KDEXLib::processYield( bool bWait, bool bHandleAllCurrentEvents ) ...@@ -307,7 +293,7 @@ void KDEXLib::processYield( bool bWait, bool bHandleAllCurrentEvents )
void KDEXLib::StartTimer( sal_uLong nMS ) void KDEXLib::StartTimer( sal_uLong nMS )
{ {
if( eventLoopType == LibreOfficeEventLoop ) if( !m_isGlibEventLoopType )
return SalXLib::StartTimer( nMS ); return SalXLib::StartTimer( nMS );
timeoutTimer.setInterval( nMS ); timeoutTimer.setInterval( nMS );
// QTimer's can be started only in their thread (main thread here) // QTimer's can be started only in their thread (main thread here)
...@@ -324,7 +310,7 @@ void KDEXLib::startTimeoutTimer() ...@@ -324,7 +310,7 @@ void KDEXLib::startTimeoutTimer()
void KDEXLib::StopTimer() void KDEXLib::StopTimer()
{ {
if( eventLoopType == LibreOfficeEventLoop ) if( !m_isGlibEventLoopType )
return SalXLib::StopTimer(); return SalXLib::StopTimer();
timeoutTimer.stop(); timeoutTimer.stop();
} }
...@@ -338,14 +324,14 @@ void KDEXLib::timeoutActivated() ...@@ -338,14 +324,14 @@ void KDEXLib::timeoutActivated()
void KDEXLib::Wakeup() void KDEXLib::Wakeup()
{ {
if( eventLoopType == LibreOfficeEventLoop ) if( !m_isGlibEventLoopType )
return SalXLib::Wakeup(); return SalXLib::Wakeup();
QAbstractEventDispatcher::instance( qApp->thread())->wakeUp(); // main thread event loop QAbstractEventDispatcher::instance( qApp->thread())->wakeUp(); // main thread event loop
} }
void KDEXLib::PostUserEvent() void KDEXLib::PostUserEvent()
{ {
if( eventLoopType == LibreOfficeEventLoop ) if( !m_isGlibEventLoopType )
return SalXLib::PostUserEvent(); return SalXLib::PostUserEvent();
if( qApp->thread() == QThread::currentThread()) if( qApp->thread() == QThread::currentThread())
startUserEventTimer(); startUserEventTimer();
......
...@@ -51,8 +51,8 @@ class KDEXLib : public QObject, public SalXLib ...@@ -51,8 +51,8 @@ class KDEXLib : public QObject, public SalXLib
QHash< int, SocketData > socketData; // key is fd QHash< int, SocketData > socketData; // key is fd
QTimer timeoutTimer; QTimer timeoutTimer;
QTimer userEventTimer; QTimer userEventTimer;
enum { LibreOfficeEventLoop, GlibEventLoop, QtUnixEventLoop } eventLoopType;
int m_frameWidth; int m_frameWidth;
bool m_isGlibEventLoopType;
private: private:
void setupEventLoop(); void setupEventLoop();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment