X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/bd00fe32fb099384c5fdd337e3749ae461ae497f..c7db82dced50cce6ac8440a442a8fd3f6e25c2ab:/src/x11/utils.cpp diff --git a/src/x11/utils.cpp b/src/x11/utils.cpp index 4640a12221..2f06547b2d 100644 --- a/src/x11/utils.cpp +++ b/src/x11/utils.cpp @@ -34,6 +34,8 @@ #endif #include "wx/apptrait.h" +#include "wx/generic/private/timer.h" +#include "wx/evtloop.h" #include #include @@ -110,6 +112,7 @@ void wxCheckForFinishedChildren() // Map empty, delete it. delete gs_procmap; gs_procmap = NULL; + return; } for (it = gs_procmap->begin();it != gs_procmap->end(); ++it) { @@ -153,15 +156,24 @@ void wxBell() } #endif -wxToolkitInfo& wxGUIAppTraits::GetToolkitInfo() +wxPortId wxGUIAppTraits::GetToolkitVersion(int *verMaj, int *verMin) const { - static wxToolkitInfo info; - info.shortName = _T("x11univ"); - info.name = _T("wxX11"); - info.versionMajor = 0; - info.versionMinor = 0; - info.os = wxX11; - return info; + // get X protocol version + Display *display = wxGlobalDisplay(); + if (display) + { + if ( verMaj ) + *verMaj = ProtocolVersion (display); + if ( verMin ) + *verMin = ProtocolRevision (display); + } + + return wxPORT_X11; +} + +wxEventLoopBase* wxGUIAppTraits::CreateEventLoop() +{ + return new wxEventLoop; } // ---------------------------------------------------------------------------- @@ -234,40 +246,57 @@ void wxClientDisplayRect(int *x, int *y, int *width, int *height) wxDisplaySize(width, height); } +wxWindow* wxFindWindowAtPoint(const wxPoint& pt) +{ + return wxGenericFindWindowAtPoint(pt); +} + // Configurable display in wxX11 and wxMotif -static WXDisplay *gs_currentDisplay = NULL; +static Display *gs_currentDisplay = NULL; static wxString gs_displayName; WXDisplay *wxGetDisplay() { - if (gs_currentDisplay) - return gs_currentDisplay; - return wxApp::GetDisplay(); + return (WXDisplay *)gs_currentDisplay; } -bool wxSetDisplay(const wxString& display_name) +// close the current display +void wxCloseDisplay() { - gs_displayName = display_name; - - if ( display_name.empty() ) + if ( gs_currentDisplay ) { - gs_currentDisplay = NULL; + if ( XCloseDisplay(gs_currentDisplay) != 0 ) + { + wxLogWarning(_("Failed to close the display \"%s\""), + gs_displayName.c_str()); + } - return true; + gs_currentDisplay = NULL; + gs_displayName.clear(); } - else - { - Display* display = XOpenDisplay((char*) display_name.c_str()); +} - if (display) - { - gs_currentDisplay = (WXDisplay*) display; - return true; - } - else - return false; +bool wxSetDisplay(const wxString& displayName) +{ + Display *dpy = XOpenDisplay + ( + displayName.empty() ? NULL + : (const char *)displayName.mb_str() + ); + + if ( !dpy ) + { + wxLogError(_("Failed to open display \"%s\"."), displayName.c_str()); + return false; } + + wxCloseDisplay(); + + gs_currentDisplay = dpy; + gs_displayName = displayName; + + return true; } wxString wxGetDisplayName() @@ -275,10 +304,20 @@ wxString wxGetDisplayName() return gs_displayName; } -wxWindow* wxFindWindowAtPoint(const wxPoint& pt) +#include "wx/module.h" + +// the module responsible for closing the X11 display at the program end +class wxX11DisplayModule : public wxModule { - return wxGenericFindWindowAtPoint(pt); -} +public: + virtual bool OnInit() { return true; } + virtual void OnExit() { wxCloseDisplay(); } + +private: + DECLARE_DYNAMIC_CLASS(wxX11DisplayModule) +}; + +IMPLEMENT_DYNAMIC_CLASS(wxX11DisplayModule, wxModule) // ---------------------------------------------------------------------------- // Some colour manipulation routines