implement the wxGTK selective yield with a different approach: rather than getting the events ourselves and fetching them to gtk_main_do_event(), install our own wxgtk_main_do_event() to filter them (closes #10320 -- see bug reported in comment 19)

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@59541 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Francesco Montorsi
2009-03-14 23:59:21 +00:00
parent 48ae48a93b
commit 387e72bad6
2 changed files with 90 additions and 84 deletions

View File

@@ -15,6 +15,8 @@
// wxGUIEventLoop for wxGTK // wxGUIEventLoop for wxGTK
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
typedef union _GdkEvent GdkEvent;
class WXDLLIMPEXP_CORE wxGUIEventLoop : public wxEventLoopBase class WXDLLIMPEXP_CORE wxGUIEventLoop : public wxEventLoopBase
{ {
public: public:
@@ -28,6 +30,9 @@ public:
virtual void WakeUp(); virtual void WakeUp();
virtual bool YieldFor(long eventsToProcess); virtual bool YieldFor(long eventsToProcess);
void StoreGdkEventForLaterProcessing(GdkEvent* ev)
{ m_arrGdkEvents.Add(ev); }
protected: protected:
// the exit code of this event loop // the exit code of this event loop

View File

@@ -133,37 +133,8 @@ int wxGUIEventLoop::DispatchTimeout(unsigned long timeout)
// YieldFor // YieldFor
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
bool wxGUIEventLoop::YieldFor(long eventsToProcess) static void wxgtk_main_do_event(GdkEvent *event, wxGUIEventLoop* evtloop)
{ {
#if wxUSE_THREADS
if ( !wxThread::IsMain() )
{
// can't call gtk_main_iteration() from other threads like this
return true;
}
#endif // wxUSE_THREADS
m_isInsideYield = true;
m_eventsToProcessInsideYield = eventsToProcess;
#if wxUSE_LOG
// disable log flushing from here because a call to wxYield() shouldn't
// normally result in message boxes popping up &c
wxLog::Suspend();
#endif
// NOTE: gtk_main_iteration() doesn't allow us to filter events, so we
// rather use gtk_main_do_event() after filtering the events at
// GDK level
GdkDisplay* disp = gtk_widget_get_display(wxGetRootWindow());
// gdk_display_get_event() will transform X11 events into GDK events
// and will queue all of them in the display (private) structure;
// finally it will "unqueue" the last one and return it to us
GdkEvent* event = gdk_display_get_event(disp);
while (event)
{
// categorize the GDK event according to wxEventCategory. // categorize the GDK event according to wxEventCategory.
// See http://library.gnome.org/devel/gdk/unstable/gdk-Events.html#GdkEventType // See http://library.gnome.org/devel/gdk/unstable/gdk-Events.html#GdkEventType
// for more info. // for more info.
@@ -190,7 +161,6 @@ bool wxGUIEventLoop::YieldFor(long eventsToProcess)
cat = wxEVT_CATEGORY_USER_INPUT; cat = wxEVT_CATEGORY_USER_INPUT;
break; break;
case GDK_PROXIMITY_IN: case GDK_PROXIMITY_IN:
case GDK_PROXIMITY_OUT: case GDK_PROXIMITY_OUT:
@@ -211,7 +181,6 @@ bool wxGUIEventLoop::YieldFor(long eventsToProcess)
case GDK_NO_EXPOSE: case GDK_NO_EXPOSE:
case GDK_MAP: case GDK_MAP:
case GDK_UNMAP: case GDK_UNMAP:
//case GDK_DAMAGE:
case GDK_DRAG_ENTER: case GDK_DRAG_ENTER:
case GDK_DRAG_LEAVE: case GDK_DRAG_LEAVE:
@@ -228,14 +197,45 @@ bool wxGUIEventLoop::YieldFor(long eventsToProcess)
break; break;
} }
if (eventsToProcess & cat) // is this event allowed now?
if (evtloop->IsEventAllowedInsideYield(cat))
gtk_main_do_event(event); // process it now gtk_main_do_event(event); // process it now
else else if (event->type != GDK_NOTHING)
m_arrGdkEvents.Add(event); // process it later evtloop->StoreGdkEventForLaterProcessing(gdk_event_copy(event));
// process it later (but make a copy; the caller will free the event pointer)
}
// get next event bool wxGUIEventLoop::YieldFor(long eventsToProcess)
event = gdk_display_get_event(disp); {
#if wxUSE_THREADS
if ( !wxThread::IsMain() )
{
// can't call gtk_main_iteration() from other threads like this
return true;
} }
#endif // wxUSE_THREADS
m_isInsideYield = true;
m_eventsToProcessInsideYield = eventsToProcess;
#if wxUSE_LOG
// disable log flushing from here because a call to wxYield() shouldn't
// normally result in message boxes popping up &c
wxLog::Suspend();
#endif
// temporarily replace the global GDK event handler with our function, which
// categorizes the events and using m_eventsToProcessInsideYield decides
// if an event should be processed immediately or not
// NOTE: this approach is better than using gdk_display_get_event() because
// gtk_main_iteration() does more than just calling gdk_display_get_event()
// and then call gtk_main_do_event()!
// In particular in this way we also process input from sources like
// GIOChannels (this is needed for e.g. wxGUIAppTraits::WaitForChild).
gdk_event_handler_set ((GdkEventFunc)wxgtk_main_do_event, this, NULL);
while (Pending()) // avoid false positives from our idle source
gtk_main_iteration();
gdk_event_handler_set ((GdkEventFunc)gtk_main_do_event, NULL, NULL);
if (eventsToProcess != wxEVT_CATEGORY_CLIPBOARD) if (eventsToProcess != wxEVT_CATEGORY_CLIPBOARD)
{ {
@@ -252,6 +252,7 @@ bool wxGUIEventLoop::YieldFor(long eventsToProcess)
// then we fall into a never-ending loop... // then we fall into a never-ending loop...
// put all unprocessed GDK events back in the queue // put all unprocessed GDK events back in the queue
GdkDisplay* disp = gtk_widget_get_display(wxGetRootWindow());
for (size_t i=0; i<m_arrGdkEvents.GetCount(); i++) for (size_t i=0; i<m_arrGdkEvents.GetCount(); i++)
{ {
GdkEvent* ev = (GdkEvent*)m_arrGdkEvents[i]; GdkEvent* ev = (GdkEvent*)m_arrGdkEvents[i];