@ -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"
@ -62,11 +61,9 @@ typedef struct {
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 ,
@ -134,38 +131,43 @@ 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
@ -177,13 +179,12 @@ void TQEventLoop::init()
// intitialize the X11 parts of the event loop
// intitialize the X11 parts of the event loop
d - > xfd = - 1 ;
d - > xfd = - 1 ;
if ( tqt_is_gui_used )
if ( tqt_is_gui_used & & TQApplication : : isGuiThread ( ) ) {
d - > xfd = XConnectionNumber ( TQPaintDevice : : x11AppDisplay ( ) ) ;
d - > xfd = XConnectionNumber ( TQPaintDevice : : x11AppDisplay ( ) ) ;
}
// new GSource
// new GSource
TQtGSource * qtGSource = ( TQtGSource * ) g_source_new ( & qt_gsource_funcs , sizeof ( TQtGSource ) ) ;
TQtGSource * qtGSource = ( TQtGSource * ) g_source_new ( & qt_gsource_funcs ,
sizeof ( TQtGSource ) ) ;
g_source_set_can_recurse ( ( GSource * ) qtGSource , TRUE ) ;
g_source_set_can_recurse ( ( GSource * ) qtGSource , TRUE ) ;
@ -191,9 +192,9 @@ void TQEventLoop::init()
// init main loop and attach gsource
// init main loop and attach gsource
# ifdef DEBUG_QT_GLIBMAINLOOP
# ifdef DEBUG_QT_GLIBMAINLOOP
printf ( " inside init(1) \n " ) ;
printf ( " inside init(1) \n " ) ;
# endif
# endif
g_main_loop_new ( NULL , 1 ) ;
g_main_loop_new ( NULL , 1 ) ;
@ -203,9 +204,7 @@ void TQEventLoop::init()
// poll for X11 events
// poll for X11 events
if ( tqt_is_gui_used ) {
if ( tqt_is_gui_used & & TQApplication : : isGuiThread ( ) ) {
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_source_add_poll ( d - > gSource , & d - > x_gPollFD ) ;
g_source_add_poll ( d - > gSource , & d - > x_gPollFD ) ;
@ -218,9 +217,9 @@ void TQEventLoop::init()
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
}
}
@ -240,9 +239,10 @@ 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 ;
ProcessEventsFlags save_flags ;
int rval ;
int rval ;
save_flags = d - > pev_flags ;
save_flags = d - > pev_flags ;
@ -253,9 +253,9 @@ bool TQEventLoop::processEvents( ProcessEventsFlags flags )
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?
}
}
@ -276,6 +276,7 @@ bool TQEventLoop::processX11Events()
if ( tqt_is_gui_used ) {
if ( tqt_is_gui_used ) {
TQApplication : : sendPostedEvents ( ) ;
TQApplication : : sendPostedEvents ( ) ;
if ( TQApplication : : isGuiThread ( ) ) {
// Two loops so that posted events accumulate
// Two loops so that posted events accumulate
while ( XPending ( TQPaintDevice : : x11AppDisplay ( ) ) ) {
while ( XPending ( TQPaintDevice : : x11AppDisplay ( ) ) ) {
// also flushes output buffer
// also flushes output buffer
@ -327,6 +328,7 @@ bool TQEventLoop::processX11Events()
}
}
}
}
}
}
}
if ( d - > shortcut ) {
if ( d - > shortcut ) {
return FALSE ;
return FALSE ;
@ -336,8 +338,7 @@ bool TQEventLoop::processX11Events()
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,9 +349,9 @@ 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 ;
@ -369,15 +370,15 @@ bool TQEventLoop::gsourcePrepare(GSource *gs, int * timeout)
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_sec = 0 ; // no time to wait
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 ;
@ -385,7 +386,8 @@ bool TQEventLoop::gsourcePrepare(GSource *gs, int * timeout)
+ + it ;
+ + it ;
sn - > gPollFD . events = sn - > events ; // restore poll events
sn - > gPollFD . events = sn - > events ; // restore poll events
}
}
} else {
}
else {
TQPtrListIterator < TQSockNotGPollFD > it ( d - > sn_list ) ;
TQPtrListIterator < TQSockNotGPollFD > it ( d - > sn_list ) ;
TQSockNotGPollFD * sn ;
TQSockNotGPollFD * sn ;
while ( ( sn = it . current ( ) ) ) {
while ( ( sn = it . current ( ) ) ) {
@ -394,13 +396,13 @@ 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 ( ) ;
}
if ( qt_preselect_handler ) {
if ( qt_preselect_handler ) {
TQVFuncList : : Iterator it , end = qt_preselect_handler - > end ( ) ;
TQVFuncList : : Iterator it , end = qt_preselect_handler - > end ( ) ;
@ -414,9 +416,9 @@ bool TQEventLoop::gsourcePrepare(GSource *gs, int * timeout)
locker . mutex ( ) - > unlock ( ) ;
locker . mutex ( ) - > unlock ( ) ;
# endif
# endif
# 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 ( ) ) {
@ -443,10 +445,9 @@ bool TQEventLoop::gsourcePrepare(GSource *gs, int * timeout)
// 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 ;
}
}
@ -455,9 +456,9 @@ bool TQEventLoop::gsourcePrepare(GSource *gs, int * timeout)
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?
@ -476,23 +477,23 @@ 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!
}
}
@ -501,18 +502,18 @@ bool TQEventLoop::gsourceCheck(GSource *gs) {
timeval * tm = qt_wait_timer ( ) ;
timeval * tm = qt_wait_timer ( ) ;
if ( tm & & ( tm - > tv_sec = = 0 & & tm - > tv_usec = = 0 ) ) {
if ( tm & & ( tm - > tv_sec = = 0 & & tm - > tv_usec = = 0 ) ) {
# 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 ;
}
}
// nothing to dispatch
// nothing to dispatch
# ifdef DEBUG_QT_GLIBMAINLOOP
# ifdef DEBUG_QT_GLIBMAINLOOP
printf ( " inside gsourceCheck(2) nothing to dispatch! \n " ) ;
printf ( " inside gsourceCheck(2) nothing to dispatch! \n " ) ;
# endif
# endif
return FALSE ;
return FALSE ;
}
}
@ -533,9 +534,9 @@ bool TQEventLoop::gsourceDispatch(GSource *gs) {
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 ( ) ;
@ -562,8 +563,6 @@ bool TQEventLoop::gsourceDispatch(GSource *gs) {
// 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 ) {
@ -582,25 +581,21 @@ bool TQEventLoop::gsourceDispatch(GSource *gs) {
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 ( ) ;
processX11Events ( ) ;
processX11Events ( ) ;
}
}
# if defined(QT_THREAD_SUPPORT)
# if defined(QT_THREAD_SUPPORT)
@ -618,13 +613,14 @@ 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 ( ) ) ;
}
}
}
void TQEventLoop : : appClosingDown ( )
void TQEventLoop : : appClosingDown ( )