@ -39,7 +39,6 @@
* *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
# include "qeventloop_glib_p.h" // includes qplatformdefs.h
# include "qeventloop_glib_p.h" // includes qplatformdefs.h
# include "ntqeventloop.h"
# include "ntqeventloop.h"
# include "ntqapplication.h"
# include "ntqapplication.h"
@ -49,32 +48,33 @@
# if defined(QT_THREAD_SUPPORT)
# if defined(QT_THREAD_SUPPORT)
# include "ntqmutex.h"
# include "ntqmutex.h"
# include "ntqthread.h"
# endif // QT_THREAD_SUPPORT
# endif // QT_THREAD_SUPPORT
# include <errno.h>
# include <errno.h>
# include <glib.h>
# include <glib.h>
// #define DEBUG_QT_GLIBMAINLOOP 1
// TQt-GSource Structure and Callbacks
// TQt-GSource Structure and Callbacks
typedef struct {
typedef struct {
GSource source ;
GSource source ;
TQEventLoop * qeventLoop ;
TQEventLoop * qeventLoop ;
} TQtGSource ;
} TQtGSource ;
static gboolean qt_gsource_prepare ( GSource * source ,
static gboolean qt_gsource_prepare ( GSource * source , gint * timeout ) ;
gint * timeout ) ;
static gboolean qt_gsource_check ( GSource * source ) ;
static gboolean qt_gsource_check ( GSource * source ) ;
static gboolean qt_gsource_dispatch ( GSource * source ,
static gboolean qt_gsource_dispatch ( GSource * source , GSourceFunc callback , gpointer user_data ) ;
GSourceFunc callback , gpointer user_data ) ;
static GSourceFuncs qt_gsource_funcs = {
static GSourceFuncs qt_gsource_funcs = {
qt_gsource_prepare ,
qt_gsource_prepare ,
qt_gsource_check ,
qt_gsource_check ,
qt_gsource_dispatch ,
qt_gsource_dispatch ,
NULL ,
NULL ,
NULL ,
NULL ,
NULL
NULL
} ;
} ;
// forward main loop callbacks to TQEventLoop methods!
// forward main loop callbacks to TQEventLoop methods!
@ -82,25 +82,51 @@ static GSourceFuncs qt_gsource_funcs = {
static gboolean qt_gsource_prepare ( GSource * source ,
static gboolean qt_gsource_prepare ( GSource * source ,
gint * timeout )
gint * timeout )
{
{
TQtGSource * qtGSource ;
TQtGSource * qtGSource = ( TQtGSource * ) source ;
qtGSource = ( TQtGSource * ) source ;
TQEventLoop * candidateEventLoop = qtGSource - > qeventLoop ;
return qtGSource - > qeventLoop - > gsourcePrepare ( source , timeout ) ;
TQEventLoop * activeThreadEventLoop = TQApplication : : eventLoop ( ) ;
if ( candidateEventLoop = = activeThreadEventLoop ) {
return candidateEventLoop - > gsourcePrepare ( source , timeout ) ;
}
else {
// Prepare failed
return FALSE ;
}
}
}
static gboolean qt_gsource_check ( GSource * source )
static gboolean qt_gsource_check ( GSource * source )
{
{
TQtGSource * qtGSource = ( TQtGSource * ) source ;
TQtGSource * qtGSource = ( TQtGSource * ) source ;
return qtGSource - > qeventLoop - > gsourceCheck ( source ) ;
TQEventLoop * candidateEventLoop = qtGSource - > qeventLoop ;
TQEventLoop * activeThreadEventLoop = TQApplication : : eventLoop ( ) ;
if ( candidateEventLoop = = activeThreadEventLoop ) {
return candidateEventLoop - > gsourceCheck ( source ) ;
}
else {
// Check failed
return FALSE ;
}
}
}
static gboolean qt_gsource_dispatch ( GSource * source ,
static gboolean qt_gsource_dispatch ( GSource * source ,
GSourceFunc callback , gpointer user_data )
GSourceFunc callback , gpointer user_data )
{
{
Q_UNUSED ( callback ) ;
Q_UNUSED ( callback ) ;
Q_UNUSED ( user_data ) ;
Q_UNUSED ( user_data ) ;
TQtGSource * qtGSource = ( TQtGSource * ) source ;
TQtGSource * qtGSource = ( TQtGSource * ) source ;
return qtGSource - > qeventLoop - > gsourceDispatch ( source ) ;
TQEventLoop * candidateEventLoop = qtGSource - > qeventLoop ;
TQEventLoop * activeThreadEventLoop = TQApplication : : eventLoop ( ) ;
if ( candidateEventLoop = = activeThreadEventLoop ) {
return candidateEventLoop - > gsourceDispatch ( source ) ;
}
else {
// Dispatch failed
return FALSE ;
}
}
}
@ -134,105 +160,107 @@ static TQVFuncList *qt_postselect_handler = 0;
void qt_install_preselect_handler ( VFPTR handler )
void qt_install_preselect_handler ( VFPTR handler )
{
{
if ( ! qt_preselect_handler )
if ( ! qt_preselect_handler ) {
qt_preselect_handler = new TQVFuncList ;
qt_preselect_handler = new TQVFuncList ;
qt_preselect_handler - > append ( handler ) ;
}
qt_preselect_handler - > append ( handler ) ;
}
}
void qt_remove_preselect_handler ( VFPTR handler )
void qt_remove_preselect_handler ( VFPTR handler )
{
{
if ( qt_preselect_handler ) {
if ( qt_preselect_handler ) {
TQVFuncList : : Iterator it = qt_preselect_handler - > find ( handler ) ;
TQVFuncList : : Iterator it = qt_preselect_handler - > find ( handler ) ;
if ( it ! = qt_preselect_handler - > end ( ) )
if ( it ! = qt_preselect_handler - > end ( ) ) {
qt_preselect_handler - > remove ( it ) ;
qt_preselect_handler - > remove ( it ) ;
}
}
}
}
}
void qt_install_postselect_handler ( VFPTR handler )
void qt_install_postselect_handler ( VFPTR handler )
{
{
if ( ! qt_postselect_handler )
if ( ! qt_postselect_handler ) {
qt_postselect_handler = new TQVFuncList ;
qt_postselect_handler = new TQVFuncList ;
qt_postselect_handler - > prepend ( handler ) ;
}
qt_postselect_handler - > prepend ( handler ) ;
}
}
void qt_remove_postselect_handler ( VFPTR handler )
void qt_remove_postselect_handler ( VFPTR handler )
{
{
if ( qt_postselect_handler ) {
if ( qt_postselect_handler ) {
TQVFuncList : : Iterator it = qt_postselect_handler - > find ( handler ) ;
TQVFuncList : : Iterator it = qt_postselect_handler - > find ( handler ) ;
if ( it ! = qt_postselect_handler - > end ( ) )
if ( it ! = qt_postselect_handler - > end ( ) ) {
qt_postselect_handler - > remove ( it ) ;
qt_postselect_handler - > remove ( it ) ;
}
}
}
}
}
void TQEventLoop : : init ( )
void TQEventLoop : : init ( )
{
{
// initialize ProcessEventFlags (all events & wait for more)
// initialize ProcessEventFlags (all events & wait for more)
d - > pev_flags = AllEvents | WaitForMore ;
d - > pev_flags = AllEvents | WaitForMore ;
// initialize the common parts of the event loop
// initialize the common parts of the event loop
if ( pipe ( d - > thread_pipe ) < 0 ) {
if ( pipe ( d - > thread_pipe ) < 0 ) {
// Error!
// Error!
}
}
fcntl ( d - > thread_pipe [ 0 ] , F_SETFD , FD_CLOEXEC ) ;
fcntl ( d - > thread_pipe [ 0 ] , F_SETFD , FD_CLOEXEC ) ;
fcntl ( d - > thread_pipe [ 1 ] , F_SETFD , FD_CLOEXEC ) ;
fcntl ( d - > thread_pipe [ 1 ] , F_SETFD , FD_CLOEXEC ) ;
// intitialize the X11 parts of the event loop
d - > xfd = - 1 ;
if ( tqt_is_gui_used )
d - > xfd = XConnectionNumber ( TQPaintDevice : : x11AppDisplay ( ) ) ;
// new GSource
TQtGSource * qtGSource = ( TQtGSource * ) g_source_new ( & qt_gsource_funcs ,
sizeof ( TQtGSource ) ) ;
g_source_set_can_recurse ( ( GSource * ) qtGSource , TRUE ) ;
qtGSource - > qeventLoop = this ;
// init main loop and attach gsource
// intitialize the X11 parts of the event loop
d - > xfd = - 1 ;
if ( tqt_is_gui_used & & TQApplication : : isGuiThread ( ) ) {
d - > xfd = XConnectionNumber ( TQPaintDevice : : x11AppDisplay ( ) ) ;
}
# ifdef DEBUG_QT_GLIBMAINLOOP
// new main context for thread
printf ( " inside init(1) \n " ) ;
d - > ctx = g_main_context_new ( ) ;
# endif
g_main_context_push_thread_default ( d - > ctx ) ;
g_main_loop_new ( NULL , 1 ) ;
// new GSource
TQtGSource * qtGSource = ( TQtGSource * ) g_source_new ( & qt_gsource_funcs , sizeof ( TQtGSource ) ) ;
g_source_set_can_recurse ( ( GSource * ) qtGSource , TRUE ) ;
qtGSource - > qeventLoop = this ;
g_source_attach ( ( GSource * ) qtGSource , NULL ) ;
// init main loop and attach gsource
# ifdef DEBUG_QT_GLIBMAINLOOP
printf ( " inside init(1) \n " ) ;
# endif
d - > gSource = ( GSource * ) qtGSource ;
g_main_loop_new ( d - > ctx , 1 ) ;
g_source_attach ( ( GSource * ) qtGSource , d - > ctx ) ;
d - > gSource = ( GSource * ) qtGSource ;
// poll for X11 events
// poll for X11 events
if ( tqt_is_gui_used & & TQApplication : : isGuiThread ( ) ) {
if ( tqt_is_gui_used ) {
d - > x_gPollFD . fd = d - > xfd ;
d - > x_gPollFD . fd = d - > xfd ;
d - > x_gPollFD . events = G_IO_IN | G_IO_HUP ;
d - > x_gPollFD . events = G_IO_IN | G_IO_HUP | G_IO_ERR ;
g_source_add_poll ( d - > gSource , & d - > x_gPollFD ) ;
g_source_add_poll ( d - > gSource , & d - > x_gPollFD ) ;
}
}
// poll thread-pipe
// poll thread-pipe
d - > threadPipe_gPollFD . fd = d - > thread_pipe [ 0 ] ;
d - > threadPipe_gPollFD . fd = d - > thread_pipe [ 0 ] ;
d - > threadPipe_gPollFD . events = G_IO_IN | G_IO_HUP ;
d - > threadPipe_gPollFD . events = G_IO_IN | G_IO_HUP | G_IO_ERR ;
g_source_add_poll ( d - > gSource , & d - > threadPipe_gPollFD ) ;
g_source_add_poll ( d - > gSource , & d - > threadPipe_gPollFD ) ;
# ifdef DEBUG_QT_GLIBMAINLOOP
# ifdef DEBUG_QT_GLIBMAINLOOP
printf ( " inside init(2) \n " ) ;
printf ( " inside init(2) \n " ) ;
# endif
# endif
}
}
void TQEventLoop : : cleanup ( )
void TQEventLoop : : cleanup ( )
{
{
// cleanup the common parts of the event loop
// cleanup the common parts of the event loop
close ( d - > thread_pipe [ 0 ] ) ;
close ( d - > thread_pipe [ 0 ] ) ;
close ( d - > thread_pipe [ 1 ] ) ;
close ( d - > thread_pipe [ 1 ] ) ;
cleanupTimers ( ) ;
cleanupTimers ( ) ;
// cleanup the X11 parts of the event loop
d - > xfd = - 1 ;
// cleanup the X11 parts of the event loop
// unref the main context
d - > xfd = - 1 ;
g_main_context_unref ( d - > ctx ) ;
// todo: destroy gsource
// todo: destroy gsource
}
}
@ -240,107 +268,110 @@ void TQEventLoop::cleanup()
bool TQEventLoop : : processEvents ( ProcessEventsFlags flags )
bool TQEventLoop : : processEvents ( ProcessEventsFlags flags )
{
{
# ifdef DEBUG_QT_GLIBMAINLOOP
# ifdef DEBUG_QT_GLIBMAINLOOP
printf ( " inside processEvents(1) looplevel=%d \n " , d - > looplevel ) ;
printf ( " inside processEvents(1) looplevel=%d \n " , d - > looplevel ) ;
# endif
# endif
ProcessEventsFlags save_flags ;
int rval ;
ProcessEventsFlags save_flags ;
save_flags = d - > pev_flags ;
int rval ;
save_flags = d - > pev_flags ;
d - > pev_flags = flags ;
d - > pev_flags = flags ;
rval = g_main_context_iteration ( NULL , flags & WaitForMore ? TRUE : FALSE ) ;
rval = g_main_context_iteration ( d - > ctx , flags & WaitForMore ? TRUE : FALSE ) ;
d - > pev_flags = save_flags ;
d - > pev_flags = save_flags ;
# ifdef DEBUG_QT_GLIBMAINLOOP
# ifdef DEBUG_QT_GLIBMAINLOOP
printf ( " inside processEvents(2) looplevel=%d rval=%d \n " , d - > looplevel , rval ) ;
printf ( " inside processEvents(2) looplevel=%d rval=%d \n " , d - > looplevel , rval ) ;
# endif
# endif
return rval ; // were events processed?
return rval ; // were events processed?
}
}
bool TQEventLoop : : processX11Events ( )
bool TQEventLoop : : processX11Events ( )
{
{
ProcessEventsFlags flags = d - > pev_flags ;
ProcessEventsFlags flags = d - > pev_flags ;
// process events from the X server
// process events from the X server
XEvent event ;
XEvent event ;
int nevents = 0 ;
int nevents = 0 ;
# if defined(QT_THREAD_SUPPORT)
# if defined(QT_THREAD_SUPPORT)
TQMutexLocker locker ( TQApplication : : tqt_mutex ) ;
TQMutexLocker locker ( TQApplication : : tqt_mutex ) ;
# endif
# endif
// handle gui and posted events
// handle gui and posted events
if ( tqt_is_gui_used ) {
if ( tqt_is_gui_used ) {
TQApplication : : sendPostedEvents ( ) ;
TQApplication : : sendPostedEvents ( ) ;
// Two loops so that posted events accumulate
if ( TQApplication : : isGuiThread ( ) ) {
while ( XPending ( TQPaintDevice : : x11AppDisplay ( ) ) ) {
// Two loops so that posted events accumulate
// also flushes output buffer
while ( XPending ( TQPaintDevice : : x11AppDisplay ( ) ) ) {
while ( XPending ( TQPaintDevice : : x11AppDisplay ( ) ) ) {
// also flushes output buffer
if ( d - > shortcut ) {
while ( XPending ( TQPaintDevice : : x11AppDisplay ( ) ) ) {
return FALSE ;
if ( d - > shortcut ) {
}
return FALSE ;
}
XNextEvent ( TQPaintDevice : : x11AppDisplay ( ) , & event ) ;
XNextEvent ( TQPaintDevice : : x11AppDisplay ( ) , & event ) ;
if ( flags & ExcludeUserInput ) {
switch ( event . type ) {
if ( flags & ExcludeUserInput ) {
case ButtonPress :
switch ( event . type ) {
case ButtonRelease :
case ButtonPress :
case MotionNotify :
case ButtonRelease :
case XKeyPress :
case MotionNotify :
case XKeyRelease :
case XKeyPress :
case EnterNotify :
case XKeyRelease :
case LeaveNotify :
case EnterNotify :
continue ;
case LeaveNotify :
continue ;
case ClientMessage :
{
case ClientMessage :
// from qapplication_x11.cpp
{
extern Atom tqt_wm_protocols ;
// from qapplication_x11.cpp
extern Atom tqt_wm_take_focus ;
extern Atom tqt_wm_protocols ;
extern Atom qt_qt_scrolldone ;
extern Atom tqt_wm_take_focus ;
extern Atom qt_qt_scrolldone ;
// only keep the wm_take_focus and
// qt_qt_scrolldone protocols, discard all
// only keep the wm_take_focus and
// other client messages
// qt_qt_scrolldone protocols, discard all
if ( event . xclient . format ! = 32 )
// other client messages
continue ;
if ( event . xclient . format ! = 32 )
continue ;
if ( event . xclient . message_type = = tqt_wm_protocols | |
( Atom ) event . xclient . data . l [ 0 ] = = tqt_wm_take_focus )
if ( event . xclient . message_type = = tqt_wm_protocols | |
break ;
( Atom ) event . xclient . data . l [ 0 ] = = tqt_wm_take_focus )
if ( event . xclient . message_type = = qt_qt_scrolldone )
break ;
break ;
if ( event . xclient . message_type = = qt_qt_scrolldone )
break ;
}
default : break ;
}
}
nevents + + ;
if ( tqApp - > x11ProcessEvent ( & event ) = = 1 ) {
return TRUE ;
}
}
}
}
default : break ;
}
}
}
nevents + + ;
if ( tqApp - > x11ProcessEvent ( & event ) = = 1 )
return TRUE ;
}
}
}
}
if ( d - > shortcut ) {
if ( d - > shortcut ) {
return FALSE ;
return FALSE ;
}
}
TQApplication : : sendPostedEvents ( ) ;
TQApplication : : sendPostedEvents ( ) ;
const uint exclude_all = ExcludeSocketNotifiers | 0x08 ;
const uint exclude_all = ExcludeSocketNotifiers | 0x08 ;
// 0x08 == ExcludeTimers for X11 only
// 0x08 == ExcludeTimers for X11 only
if ( nevents > 0 & & ( flags & exclude_all ) = = exclude_all & &
if ( nevents > 0 & & ( flags & exclude_all ) = = exclude_all & & ( flags & WaitForMore ) ) {
( flags & WaitForMore ) ) {
return TRUE ;
return TRUE ;
}
}
return FALSE ;
return FALSE ;
}
}
@ -348,125 +379,110 @@ bool TQEventLoop::gsourcePrepare(GSource *gs, int * timeout)
{
{
Q_UNUSED ( gs ) ;
Q_UNUSED ( gs ) ;
# ifdef DEBUG_QT_GLIBMAINLOOP
# ifdef DEBUG_QT_GLIBMAINLOOP
printf ( " inside gsourcePrepare(1) \n " ) ;
printf ( " inside gsourcePrepare(1) \n " ) ;
# endif
# endif
ProcessEventsFlags flags = d - > pev_flags ;
ProcessEventsFlags flags = d - > pev_flags ;
# if defined(QT_THREAD_SUPPORT)
# if defined(QT_THREAD_SUPPORT)
TQMutexLocker locker ( TQApplication : : tqt_mutex ) ;
TQMutexLocker locker ( TQApplication : : tqt_mutex ) ;
# endif
# endif
// don't block if exitLoop() or exit()/quit() has been called.
// don't block if exitLoop() or exit()/quit() has been called.
bool canWait = d - > exitloop | | d - > quitnow ? FALSE : ( flags & WaitForMore ) ;
bool canWait = d - > exitloop | | d - > quitnow ? FALSE : ( flags & WaitForMore ) ;
// Process timers and socket notifiers - the common UNIX stuff
// Process timers and socket notifiers - the common UNIX stuff
// return the maximum time we can wait for an event.
// return the maximum time we can wait for an event.
static timeval zerotm ;
static timeval zerotm ;
timeval * tm = 0 ;
timeval * tm = 0 ;
if ( ! ( flags & 0x08 ) ) { // 0x08 == ExcludeTimers for X11 only
if ( ! ( flags & 0x08 ) ) { // 0x08 == ExcludeTimers for X11 only
tm = qt_wait_timer ( ) ; // wait for timer or X event
tm = qt_wait_timer ( ) ; // wait for timer or X event
if ( ! canWait ) {
if ( ! canWait ) {
if ( ! tm )
if ( ! tm ) {
tm = & zerotm ;
tm = & zerotm ;
tm - > tv_sec = 0 ; // no time to wait
}
tm - > tv_usec = 0 ;
tm - > tv_sec = 0 ; // no time to wait
}
tm - > tv_usec = 0 ;
}
}
}
// include or exclude SocketNotifiers (by setting or cleaning poll events)
// include or exclude SocketNotifiers (by setting or cleaning poll events)
if ( ! ( flags & ExcludeSocketNotifiers ) ) {
if ( ! ( flags & ExcludeSocketNotifiers ) ) {
TQPtrListIterator < TQSockNotGPollFD > it ( d - > sn_list ) ;
TQPtrListIterator < TQSockNotGPollFD > it ( d - > sn_list ) ;
TQSockNotGPollFD * sn ;
TQSockNotGPollFD * sn ;
while ( ( sn = it . current ( ) ) ) {
while ( ( sn = it . current ( ) ) ) {
+ + it ;
+ + it ;
sn - > gPollFD . events = sn - > events ; // restore poll events
sn - > gPollFD . events = sn - > events ; // restore poll events
}
}
} else {
}
TQPtrListIterator < TQSockNotGPollFD > it ( d - > sn_list ) ;
else {
TQSockNotGPollFD * sn ;
TQPtrListIterator < TQSockNotGPollFD > it ( d - > sn_list ) ;
while ( ( sn = it . current ( ) ) ) {
TQSockNotGPollFD * sn ;
+ + it ;
while ( ( sn = it . current ( ) ) ) {
sn - > gPollFD . events = 0 ; // delete poll events
+ + it ;
sn - > gPollFD . events = 0 ; // delete poll events
}
}
}
}
# ifdef DEBUG_QT_GLIBMAINLOOP
# ifdef DEBUG_QT_GLIBMAINLOOP
printf ( " inside gsourcePrepare(2) canwait=%d \n " , canWait ) ;
printf ( " inside gsourcePrepare(2) canwait=%d \n " , canWait ) ;
# endif
# endif
if ( canWait )
emit aboutToBlock ( ) ;
if ( canWait ) {
emit aboutToBlock ( ) ;
}
if ( qt_preselect_handler ) {
if ( qt_preselect_handler ) {
TQVFuncList : : Iterator it , end = qt_preselect_handler - > end ( ) ;
TQVFuncList : : Iterator it , end = qt_preselect_handler - > end ( ) ;
for ( it = qt_preselect_handler - > begin ( ) ; it ! = end ; + + it )
for ( it = qt_preselect_handler - > begin ( ) ; it ! = end ; + + it )
( * * it ) ( ) ;
( * * it ) ( ) ;
}
}
// unlock the GUI mutex and select. when we return from this function, there is
# ifdef DEBUG_QT_GLIBMAINLOOP
// something for us to do
printf ( " inside gsourcePrepare(2.1) canwait=%d \n " , canWait ) ;
# if defined(QT_THREAD_SUPPORT)
locker . mutex ( ) - > unlock ( ) ;
# endif
# endif
# ifdef DEBUG_QT_GLIBMAINLOOP
printf ( " inside gsourcePrepare(2.1) canwait=%d \n " , canWait ) ;
# endif
// do we have to dispatch events?
// do we have to dispatch events?
if ( hasPendingEvents ( ) ) {
if ( hasPendingEvents ( ) ) {
* timeout = 0 ; // no time to stay in poll
* timeout = 0 ; // no time to stay in poll
# ifdef DEBUG_QT_GLIBMAINLOOP
# ifdef DEBUG_QT_GLIBMAINLOOP
printf ( " inside gsourcePrepare(3a) \n " ) ;
printf ( " inside gsourcePrepare(3a) \n " ) ;
# endif
# endif
return FALSE ;
return FALSE ;
}
}
// stay in poll until something happens?
// stay in poll until something happens?
if ( ! tm ) { // fixme
if ( ! tm ) { // fixme
* timeout = - 1 ; // wait forever
* timeout = - 1 ; // wait forever
# ifdef DEBUG_QT_GLIBMAINLOOP
# ifdef DEBUG_QT_GLIBMAINLOOP
printf ( " inside gsourcePrepare(3b) timeout=%d \n " , * timeout ) ;
printf ( " inside gsourcePrepare(3b) timeout=%d \n " , * timeout ) ;
# endif
# endif
return FALSE ;
return FALSE ;
}
}
// else timeout >=0
// else timeout >=0
* timeout = tm - > tv_sec * 1000 + tm - > tv_usec / 1000 ;
* timeout = tm - > tv_sec * 1000 + tm - > tv_usec / 1000 ;
# ifdef DEBUG_QT_GLIBMAINLOOP
# ifdef DEBUG_QT_GLIBMAINLOOP
printf ( " inside gsourcePrepare(3c) timeout=%d \n " , * timeout ) ;
printf ( " inside gsourcePrepare(3c) timeout=%d \n " , * timeout ) ;
# endif
# endif
return FALSE ;
return FALSE ;
}
}
bool TQEventLoop : : gsourceCheck ( GSource * gs ) {
bool TQEventLoop : : gsourceCheck ( GSource * gs ) {
Q_UNUSED ( gs ) ;
Q_UNUSED ( gs ) ;
# ifdef DEBUG_QT_GLIBMAINLOOP
# ifdef DEBUG_QT_GLIBMAINLOOP
printf ( " inside gsourceCheck(1) \n " ) ;
printf ( " inside gsourceCheck(1) \n " ) ;
# endif
# endif
// Socketnotifier events?
// Socketnotifier events?
TQPtrList < TQSockNotGPollFD > * list = & d - > sn_list ;
TQPtrList < TQSockNotGPollFD > * list = & d - > sn_list ;
//if ( list ) {
//if ( list ) {
TQSockNotGPollFD * sn = list - > first ( ) ;
TQSockNotGPollFD * sn = list - > first ( ) ;
while ( sn ) {
while ( sn ) {
if ( sn - > gPollFD . revents )
if ( sn - > gPollFD . revents )
@ -476,45 +492,43 @@ bool TQEventLoop::gsourceCheck(GSource *gs) {
//}
//}
if ( d - > x_gPollFD . revents ) {
if ( d - > x_gPollFD . revents ) {
# ifdef DEBUG_QT_GLIBMAINLOOP
# ifdef DEBUG_QT_GLIBMAINLOOP
printf ( " inside gsourceCheck(2) xfd! \n " ) ;
printf ( " inside gsourceCheck(2) xfd! \n " ) ;
# endif
# endif
return TRUE ; // we got events!
return TRUE ; // we got events!
}
}
if ( d - > threadPipe_gPollFD . revents ) {
if ( d - > threadPipe_gPollFD . revents ) {
# ifdef DEBUG_QT_GLIBMAINLOOP
# ifdef DEBUG_QT_GLIBMAINLOOP
printf ( " inside gsourceCheck(2) threadpipe!! \n " ) ;
printf ( " inside gsourceCheck(2) threadpipe!! \n " ) ;
# endif
# endif
return TRUE ; // we got events!
return TRUE ; // we got events!
}
}
if ( hasPendingEvents ( ) ) {
if ( hasPendingEvents ( ) ) {
# ifdef DEBUG_QT_GLIBMAINLOOP
# ifdef DEBUG_QT_GLIBMAINLOOP
printf ( " inside gsourceCheck(2) pendingEvents! \n " ) ;
printf ( " inside gsourceCheck(2) pendingEvents! \n " ) ;
# endif
# endif
return TRUE ; // we got more X11 events!
return TRUE ; // we got more X11 events!
}
}
// check if we have timers to activate?
// check if we have timers to activate?
timeval * tm = qt_wait_timer ( ) ;
timeval * tm = qt_wait_timer ( ) ;
if ( tm & & ( tm - > tv_sec = = 0 & & tm - > tv_usec = = 0 ) ) {
# ifdef DEBUG_QT_GLIBMAINLOOP
printf ( " inside gsourceCheck(2) qtwaittimer! \n " ) ;
# endif
if ( tm & & ( tm - > tv_sec = = 0 & & tm - > tv_usec = = 0 ) ) {
return TRUE ;
# ifdef DEBUG_QT_GLIBMAINLOOP
}
printf ( " inside gsourceCheck(2) qtwaittimer! \n " ) ;
# endif
return TRUE ;
}
// nothing to dispatch
# ifdef DEBUG_QT_GLIBMAINLOOP
// nothing to dispatch
printf ( " inside gsourceCheck(2) nothing to dispatch! \n " ) ;
# ifdef DEBUG_QT_GLIBMAINLOOP
# endif
printf ( " inside gsourceCheck(2) nothing to dispatch! \n " ) ;
# endif
return FALSE ;
return FALSE ;
}
}
@ -526,44 +540,41 @@ bool TQEventLoop::gsourceDispatch(GSource *gs) {
TQMutexLocker locker ( TQApplication : : tqt_mutex ) ;
TQMutexLocker locker ( TQApplication : : tqt_mutex ) ;
# endif
# endif
# if defined(QT_THREAD_SUPPORT)
# if defined(QT_THREAD_SUPPORT)
locker . mutex ( ) - > lock ( ) ;
if ( locker . mutex ( ) ) locker . mutex ( ) - > lock ( ) ;
# endif
# endif
int nevents = 0 ;
int nevents = 0 ;
ProcessEventsFlags flags = d - > pev_flags ;
ProcessEventsFlags flags = d - > pev_flags ;
# ifdef DEBUG_QT_GLIBMAINLOOP
# ifdef DEBUG_QT_GLIBMAINLOOP
printf ( " inside gsourceDispatch(1) \n " ) ;
printf ( " inside gsourceDispatch(1) \n " ) ;
# endif
# endif
// we are awake, broadcast it
// we are awake, broadcast it
emit awake ( ) ;
emit awake ( ) ;
emit tqApp - > guiThreadAwake ( ) ;
emit tqApp - > guiThreadAwake ( ) ;
// some other thread woke us up... consume the data on the thread pipe so that
// some other thread woke us up... consume the data on the thread pipe so that
// select doesn't immediately return next time
// select doesn't immediately return next time
if ( d - > threadPipe_gPollFD . revents ) {
if ( d - > threadPipe_gPollFD . revents ) {
char c ;
char c ;
if ( : : read ( d - > thread_pipe [ 0 ] , & c , 1 ) < 0 ) {
if ( : : read ( d - > thread_pipe [ 0 ] , & c , 1 ) < 0 ) {
// Error!
// Error!
}
}
}
}
if ( qt_postselect_handler ) {
if ( qt_postselect_handler ) {
TQVFuncList : : Iterator it , end = qt_postselect_handler - > end ( ) ;
TQVFuncList : : Iterator it , end = qt_postselect_handler - > end ( ) ;
for ( it = qt_postselect_handler - > begin ( ) ; it ! = end ; + + it )
for ( it = qt_postselect_handler - > begin ( ) ; it ! = end ; + + it )
( * * it ) ( ) ;
( * * it ) ( ) ;
}
}
// activate socket notifiers
// activate socket notifiers
if ( ! ( flags & ExcludeSocketNotifiers ) ) {
if ( ! ( flags & ExcludeSocketNotifiers ) ) {
// if select says data is ready on any socket, then set the socket notifier
// if select says data is ready on any socket, then set the socket notifier
// to pending
// to pending
// if ( &d->sn_list ) {
// if ( &d->sn_list ) {
TQPtrList < TQSockNotGPollFD > * list = & d - > sn_list ;
TQPtrList < TQSockNotGPollFD > * list = & d - > sn_list ;
TQSockNotGPollFD * sn = list - > first ( ) ;
TQSockNotGPollFD * sn = list - > first ( ) ;
while ( sn ) {
while ( sn ) {
@ -574,38 +585,36 @@ bool TQEventLoop::gsourceDispatch(GSource *gs) {
// }
// }
nevents + = activateSocketNotifiers ( ) ;
nevents + = activateSocketNotifiers ( ) ;
}
}
// activate timers
// activate timers
if ( ! ( flags & 0x08 ) ) {
if ( ! ( flags & 0x08 ) ) {
// 0x08 == ExcludeTimers for X11 only
// 0x08 == ExcludeTimers for X11 only
nevents + = activateTimers ( ) ;
nevents + = activateTimers ( ) ;
}
}
// return true if we handled events, false otherwise
// return true if we handled events, false otherwise
//return (nevents > 0);
//return (nevents > 0);
// now process x11 events!
// now process x11 events!
# ifdef DEBUG_QT_GLIBMAINLOOP
# ifdef DEBUG_QT_GLIBMAINLOOP
printf ( " inside gsourceDispatch(2) hasPendingEvents=%d \n " , hasPendingEvents ( ) ) ;
printf ( " inside gsourceDispatch(2) hasPendingEvents=%d \n " , hasPendingEvents ( ) ) ;
# endif
# endif
if ( hasPendingEvents ( ) ) {
if ( hasPendingEvents ( ) ) {
// color approx. optimization - only on X11
// color approx. optimization - only on X11
qt_reset_color_avail ( ) ;
qt_reset_color_avail ( ) ;
# if defined(QT_THREAD_SUPPORT)
if ( locker . mutex ( ) ) locker . mutex ( ) - > unlock ( ) ;
# endif
processX11Events ( ) ;
processX11Events ( ) ;
}
}
else {
# if defined(QT_THREAD_SUPPORT)
# if defined(QT_THREAD_SUPPORT)
locker . mutex ( ) - > unlock ( ) ;
if ( locker . mutex ( ) ) locker . mutex ( ) - > unlock ( ) ;
# endif
# endif
}
if ( d - > singletoolkit ) {
if ( d - > singletoolkit ) {
return TRUE ; // Eat the event
return TRUE ; // Eat the event
@ -617,21 +626,27 @@ bool TQEventLoop::gsourceDispatch(GSource *gs) {
bool TQEventLoop : : hasPendingEvents ( ) const
bool TQEventLoop : : hasPendingEvents ( ) const
{
{
extern uint qGlobalPostedEventsCount ( ) ; // from qapplication.cpp
extern uint qGlobalPostedEventsCount ( ) ; // from qapplication.cpp
return ( qGlobalPostedEventsCount ( ) | | ( tqt_is_gui_used ? XPending ( TQPaintDevice : : x11AppDisplay ( ) ) : 0 ) ) ;
return ( qGlobalPostedEventsCount ( ) | | ( ( tqt_is_gui_used & & TQApplication : : isGuiThread ( ) ) ? XPending ( TQPaintDevice : : x11AppDisplay ( ) ) : 0 ) ) ;
}
}
void TQEventLoop : : appStartingUp ( )
void TQEventLoop : : appStartingUp ( )
{
{
if ( tqt_is_gui_used )
if ( tqt_is_gui_used ) {
d - > xfd = XConnectionNumber ( TQPaintDevice : : x11AppDisplay ( ) ) ;
d - > xfd = XConnectionNumber ( TQPaintDevice : : x11AppDisplay ( ) ) ;
if ( ( d - > x_gPollFD . fd = = - 1 ) & & TQApplication : : isGuiThread ( ) ) {
d - > x_gPollFD . fd = d - > xfd ;
d - > x_gPollFD . events = G_IO_IN | G_IO_HUP | G_IO_ERR ;
g_source_add_poll ( d - > gSource , & d - > x_gPollFD ) ;
}
}
}
}
void TQEventLoop : : appClosingDown ( )
void TQEventLoop : : appClosingDown ( )
{
{
d - > xfd = - 1 ;
d - > xfd = - 1 ;
}
}
void TQEventLoop : : setSingleToolkitEventHandling ( bool enabled ) {
void TQEventLoop : : setSingleToolkitEventHandling ( bool enabled ) {
d - > singletoolkit = enabled ;
d - > singletoolkit = enabled ;
}
}