X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/f629f37a825f1f927c873a48317d967cb358fffd..8a31648287be0ef976f133de2786b137f1e98340:/src/gtk/evtloop.cpp?ds=sidebyside diff --git a/src/gtk/evtloop.cpp b/src/gtk/evtloop.cpp index 386e6e24f4..a35be35ab0 100644 --- a/src/gtk/evtloop.cpp +++ b/src/gtk/evtloop.cpp @@ -6,7 +6,7 @@ // Created: 10.07.01 // RCS-ID: $Id$ // Copyright: (c) 2001 Vadim Zeitlin -// License: wxWindows licence +// Licence: wxWindows licence /////////////////////////////////////////////////////////////////////////////// // ============================================================================ @@ -25,6 +25,7 @@ #endif #include "wx/evtloop.h" +#include "wx/evtloopsrc.h" #ifndef WX_PRECOMP #include "wx/app.h" @@ -32,6 +33,7 @@ #endif // WX_PRECOMP #include +#include // ============================================================================ // wxEventLoop implementation @@ -81,6 +83,86 @@ void wxGUIEventLoop::WakeUp() wxTheApp->WakeUpIdle(); } +// ---------------------------------------------------------------------------- +// wxEventLoop adding & removing sources +// ---------------------------------------------------------------------------- + +#if wxUSE_EVENTLOOP_SOURCE + +extern "C" +{ +static gboolean wx_on_channel_event(GIOChannel *channel, + GIOCondition condition, + gpointer data) +{ + wxUnusedVar(channel); // Unused if !wxUSE_LOG || !wxDEBUG_LEVEL + + wxLogTrace(wxTRACE_EVT_SOURCE, + "wx_on_channel_event, fd=%d, condition=%08x", + g_io_channel_unix_get_fd(channel), condition); + + wxEventLoopSourceHandler * const + handler = static_cast(data); + + if (condition & G_IO_IN || condition & G_IO_PRI) + handler->OnReadWaiting(); + if (condition & G_IO_OUT) + handler->OnWriteWaiting(); + else if (condition & G_IO_ERR || condition & G_IO_NVAL) + handler->OnExceptionWaiting(); + + // we never want to remove source here, so always return true + return TRUE; +} +} + +wxEventLoopSource * +wxGUIEventLoop::AddSourceForFD(int fd, + wxEventLoopSourceHandler *handler, + int flags) +{ + wxCHECK_MSG( fd != -1, NULL, "can't monitor invalid fd" ); + + int condition = 0; + if (flags & wxEVENT_SOURCE_INPUT) + condition |= G_IO_IN | G_IO_PRI; + if (flags & wxEVENT_SOURCE_OUTPUT) + condition |= G_IO_OUT; + if (flags & wxEVENT_SOURCE_EXCEPTION) + condition |= G_IO_ERR | G_IO_HUP | G_IO_NVAL; + + GIOChannel* channel = g_io_channel_unix_new(fd); + const unsigned sourceId = g_io_add_watch + ( + channel, + (GIOCondition)condition, + &wx_on_channel_event, + handler + ); + // it was ref'd by g_io_add_watch() so we can unref it here + g_io_channel_unref(channel); + + if ( !sourceId ) + return NULL; + + wxLogTrace(wxTRACE_EVT_SOURCE, + "Adding event loop source for fd=%d with GTK id=%u", + fd, sourceId); + + + return new wxGTKEventLoopSource(sourceId, handler, flags); +} + +wxGTKEventLoopSource::~wxGTKEventLoopSource() +{ + wxLogTrace(wxTRACE_EVT_SOURCE, + "Removing event loop source with GTK id=%u", m_sourceId); + + g_source_remove(m_sourceId); +} + +#endif // wxUSE_EVENTLOOP_SOURCE + // ---------------------------------------------------------------------------- // wxEventLoop message processing dispatching // ----------------------------------------------------------------------------