@ -54,6 +54,7 @@
# include <errno.h>
# include <errno.h>
# include <glib.h>
# include <glib.h>
# include <sys/syscall.h>
// #define DEBUG_QT_GLIBMAINLOOP 1
// #define DEBUG_QT_GLIBMAINLOOP 1
@ -109,7 +110,7 @@ static gboolean qt_gsource_check ( GSource *source )
}
}
}
}
static gboolean qt_gsource_dispatch ( GSource * source , GSourceFunc callback , gpointer user_data )
static gboolean qt_gsource_dispatch ( GSource * source , GSourceFunc callback , gpointer user_data )
{
{
Q_UNUSED ( callback ) ;
Q_UNUSED ( callback ) ;
Q_UNUSED ( user_data ) ;
Q_UNUSED ( user_data ) ;
@ -195,7 +196,7 @@ void qt_remove_postselect_handler( VFPTR handler )
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 ) {
@ -239,13 +240,12 @@ void TQEventLoop::init()
// 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 | G_IO_ERR ;
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 ( )
@ -266,25 +266,24 @@ 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 eventloop=%p d->ctx=%p this=%p \n " , d - > looplevel , TQApplication : : eventLoop ( ) , d - > ctx , this ) ; fflush ( stdout ) ;
# endif
# endif
ProcessEventsFlags save_flags ;
ProcessEventsFlags save_flags ;
int rval ;
int rval ;
save_flags = d - > pev_flags ;
save_flags = d - > pev_flags ;
d - > pev_flags = flags ;
d - > pev_flags = flags ;
rval = g_main_context_iteration ( d - > ctx , 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 eventloop=%p d->ctx=%p this=%p rval=%d\n " , d - > looplevel , TQApplication: : eventLoop ( ) , d - > ctx , this , rval ) ; fflush ( stdout ) ;
# endif
# endif
return rval ; // were events processed?
return rval ; // were events processed?
}
}
@ -312,9 +311,9 @@ bool TQEventLoop::processX11Events()
if ( d - > shortcut ) {
if ( d - > shortcut ) {
return FALSE ;
return FALSE ;
}
}
XNextEvent ( TQPaintDevice : : x11AppDisplay ( ) , & event ) ;
XNextEvent ( TQPaintDevice : : x11AppDisplay ( ) , & event ) ;
if ( flags & ExcludeUserInput ) {
if ( flags & ExcludeUserInput ) {
switch ( event . type ) {
switch ( event . type ) {
case ButtonPress :
case ButtonPress :
@ -325,31 +324,31 @@ bool TQEventLoop::processX11Events()
case EnterNotify :
case EnterNotify :
case LeaveNotify :
case LeaveNotify :
continue ;
continue ;
case ClientMessage :
case ClientMessage :
{
{
// from qapplication_x11.cpp
// from qapplication_x11.cpp
extern Atom tqt_wm_protocols ;
extern Atom tqt_wm_protocols ;
extern Atom tqt_wm_take_focus ;
extern Atom tqt_wm_take_focus ;
extern Atom qt_qt_scrolldone ;
extern Atom qt_qt_scrolldone ;
// only keep the wm_take_focus and
// only keep the wm_take_focus and
// qt_qt_scrolldone protocols, discard all
// qt_qt_scrolldone protocols, discard all
// other client messages
// other client messages
if ( event . xclient . format ! = 32 )
if ( event . xclient . format ! = 32 )
continue ;
continue ;
if ( event . xclient . message_type = = tqt_wm_protocols | |
if ( event . xclient . message_type = = tqt_wm_protocols | |
( Atom ) event . xclient . data . l [ 0 ] = = tqt_wm_take_focus )
( Atom ) event . xclient . data . l [ 0 ] = = tqt_wm_take_focus )
break ;
break ;
if ( event . xclient . message_type = = qt_qt_scrolldone )
if ( event . xclient . message_type = = qt_qt_scrolldone )
break ;
break ;
}
}
default : break ;
default : break ;
}
}
}
}
nevents + + ;
nevents + + ;
if ( tqApp - > x11ProcessEvent ( & event ) = = 1 ) {
if ( tqApp - > x11ProcessEvent ( & event ) = = 1 ) {
return TRUE ;
return TRUE ;
@ -358,13 +357,13 @@ bool TQEventLoop::processX11Events()
}
}
}
}
}
}
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 & & ( flags & WaitForMore ) ) {
if ( nevents > 0 & & ( flags & exclude_all ) = = exclude_all & & ( flags & WaitForMore ) ) {
@ -372,27 +371,27 @@ bool TQEventLoop::processX11Events()
}
}
return FALSE ;
return FALSE ;
}
}
bool TQEventLoop : : gsourcePrepare ( GSource * gs , int * timeout )
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 ;
@ -406,13 +405,13 @@ bool TQEventLoop::gsourcePrepare(GSource *gs, int * timeout)
tm - > tv_usec = 0 ;
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
}
}
}
}
@ -420,7 +419,7 @@ bool TQEventLoop::gsourcePrepare(GSource *gs, int * timeout)
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 = 0 ; // delete poll events
sn - > gPollFD . events = 0 ; // delete poll events
}
}
}
}
@ -428,7 +427,7 @@ bool TQEventLoop::gsourcePrepare(GSource *gs, int * timeout)
# 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 ) {
if ( canWait ) {
emit aboutToBlock ( ) ;
emit aboutToBlock ( ) ;
}
}
@ -442,7 +441,7 @@ bool TQEventLoop::gsourcePrepare(GSource *gs, int * timeout)
# ifdef DEBUG_QT_GLIBMAINLOOP
# ifdef DEBUG_QT_GLIBMAINLOOP
printf ( " inside gsourcePrepare(2.1) canwait=%d \n " , canWait ) ;
printf ( " inside gsourcePrepare(2.1) canwait=%d \n " , canWait ) ;
# endif
# 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
@ -451,7 +450,7 @@ bool TQEventLoop::gsourcePrepare(GSource *gs, int * timeout)
# 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
@ -460,10 +459,10 @@ bool TQEventLoop::gsourcePrepare(GSource *gs, int * 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
@ -519,7 +518,7 @@ bool TQEventLoop::gsourceCheck(GSource *gs) {
# ifdef DEBUG_QT_GLIBMAINLOOP
# ifdef DEBUG_QT_GLIBMAINLOOP
printf ( " inside gsourceCheck(2) qtwaittimer! \n " ) ;
printf ( " inside gsourceCheck(2) qtwaittimer! \n " ) ;
# endif
# endif
return TRUE ;
return TRUE ;
}
}
@ -553,10 +552,10 @@ bool TQEventLoop::gsourceDispatch(GSource *gs) {
// 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 ) {
@ -666,4 +665,4 @@ void TQEventLoop::setSingleToolkitEventHandling(bool enabled) {
d - > ctx_is_default = true ;
d - > ctx_is_default = true ;
}
}
}
}
}
}