initial commit

Signed-off-by: Peter Siegmund <mars3142@noreply.mars3142.dev>
This commit is contained in:
2025-10-31 23:37:30 +01:00
commit bf6b52fd94
9654 changed files with 4035664 additions and 0 deletions

View File

@@ -0,0 +1,74 @@
/////////////////////////////////////////////////////////////////////////////
// Name: wx/unix/app.h
// Purpose: wxAppConsole implementation for Unix
// Author: Lukasz Michalski
// Created: 28/01/2005
// Copyright: (c) Lukasz Michalski
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
//Ensure that sigset_t is being defined
#include <signal.h>
#include <unordered_map>
class wxFDIODispatcher;
class wxFDIOHandler;
class wxWakeUpPipe;
// wxApp subclass implementing event processing for console applications
class WXDLLIMPEXP_BASE wxAppConsole : public wxAppConsoleBase
{
public:
wxAppConsole();
virtual ~wxAppConsole();
// override base class initialization
virtual bool Initialize(int& argc, wxChar** argv) override;
// Unix-specific: Unix signal handling
// -----------------------------------
// type of the function which can be registered as signal handler: notice
// that it isn't really a signal handler, i.e. it's not subject to the
// usual signal handlers constraints, because it is called later from
// CheckSignal() and not when the signal really occurs
typedef void (*SignalHandler)(int);
// Set signal handler for the given signal, SIG_DFL or SIG_IGN can be used
// instead of a function pointer
//
// Return true if handler was installed, false on error
bool SetSignalHandler(int signal, SignalHandler handler);
// Check if any Unix signals arrived since the last call and execute
// handlers for them
void CheckSignal();
// Register the signal wake up pipe with the given dispatcher.
//
// This is used by wxExecute(wxEXEC_NOEVENTS) implementation only.
//
// The pointer to the handler used for processing events on this descriptor
// is returned so that it can be deleted when we no longer needed it.
wxFDIOHandler* RegisterSignalWakeUpPipe(wxFDIODispatcher& dispatcher);
private:
// signal handler set up by SetSignalHandler() for all signals we handle,
// it just adds the signal to m_signalsCaught -- the real processing is
// done later, when CheckSignal() is called
static void HandleSignal(int signal);
// signals for which HandleSignal() had been called (reset from
// CheckSignal())
sigset_t m_signalsCaught;
// the signal handlers
std::unordered_map<int, SignalHandler> m_signalHandlerHash;
// pipe used for wake up signal handling: if a signal arrives while we're
// blocking for input, writing to this pipe triggers a call to our CheckSignal()
wxWakeUpPipe *m_signalWakeUpPipe;
};

View File

@@ -0,0 +1,66 @@
///////////////////////////////////////////////////////////////////////////////
// Name: wx/unix/apptbase.h
// Purpose: declaration of wxAppTraits for Unix systems
// Author: Vadim Zeitlin
// Created: 23.06.2003
// Copyright: (c) 2003 Vadim Zeitlin <vadim@wxwidgets.org>
// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
#ifndef _WX_UNIX_APPTBASE_H_
#define _WX_UNIX_APPTBASE_H_
#include "wx/evtloop.h"
#include "wx/evtloopsrc.h"
class wxExecuteData;
class wxFDIOManager;
class wxEventLoopSourcesManagerBase;
// ----------------------------------------------------------------------------
// wxAppTraits: the Unix version adds extra hooks needed by Unix code
// ----------------------------------------------------------------------------
class WXDLLIMPEXP_BASE wxAppTraits : public wxAppTraitsBase
{
public:
// wxExecute() support methods
// ---------------------------
// Wait for the process termination and return its exit code or -1 on error.
//
// Notice that this is only used when execData.flags contains wxEXEC_SYNC
// and does not contain wxEXEC_NOEVENTS, i.e. when we need to really wait
// until the child process exit and dispatch the events while doing it.
virtual int WaitForChild(wxExecuteData& execData);
#if wxUSE_SOCKETS
// return a pointer to the object which should be used to integrate
// monitoring of the file descriptors to the event loop (currently this is
// used for the sockets only but should be used for arbitrary event loop
// sources in the future)
//
// this object may be different for the console and GUI applications
//
// the pointer is not deleted by the caller as normally it points to a
// static variable
virtual wxFDIOManager *GetFDIOManager();
#endif // wxUSE_SOCKETS
#if wxUSE_CONSOLE_EVENTLOOP && wxUSE_EVENTLOOP_SOURCE
// Return a non-null pointer to the object responsible for managing the
// event loop sources in this kind of application.
virtual wxEventLoopSourcesManagerBase* GetEventLoopSourcesManager();
#endif // wxUSE_CONSOLE_EVENTLOOP && wxUSE_CONSOLE_EVENTLOOP
protected:
// Wait for the process termination by running the given event loop until
// this happens.
//
// This is used by the public WaitForChild() after creating the event loop
// of the appropriate kind.
int RunLoopUntilChildExit(wxExecuteData& execData, wxEventLoopBase& loop);
};
#endif // _WX_UNIX_APPTBASE_H_

View File

@@ -0,0 +1,94 @@
///////////////////////////////////////////////////////////////////////////////
// Name: wx/unix/apptrait.h
// Purpose: standard implementations of wxAppTraits for Unix
// Author: Vadim Zeitlin
// Created: 23.06.2003
// Copyright: (c) 2003 Vadim Zeitlin <vadim@wxwidgets.org>
// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
#ifndef _WX_UNIX_APPTRAIT_H_
#define _WX_UNIX_APPTRAIT_H_
// ----------------------------------------------------------------------------
// wxGUI/ConsoleAppTraits: must derive from wxAppTraits, not wxAppTraitsBase
// ----------------------------------------------------------------------------
class WXDLLIMPEXP_BASE wxConsoleAppTraits : public wxConsoleAppTraitsBase
{
public:
#if wxUSE_CONSOLE_EVENTLOOP
virtual wxEventLoopBase *CreateEventLoop() override;
#endif // wxUSE_CONSOLE_EVENTLOOP
#if wxUSE_TIMER
virtual wxTimerImpl *CreateTimerImpl(wxTimer *timer) override;
#endif
};
#if wxUSE_GUI
// GTK and Qt integrate sockets and child processes monitoring directly in
// their main loop, the other Unix ports do it at wxEventLoop level and so use
// the non-GUI traits and don't need anything here
//
// TODO: Should we use XtAddInput() for wxX11 too? Or, vice versa, if there is
// no advantage in doing this compared to the generic way currently used
// by wxX11, should we continue to use GTK-specific stuff?
#if defined(__WXGTK__) || defined(__WXQT__)
#define wxHAS_GUI_FDIOMANAGER
#define wxHAS_GUI_PROCESS_CALLBACKS
#endif // ports using wxFDIOManager
#if defined(__WXMAC__)
#define wxHAS_GUI_PROCESS_CALLBACKS
#define wxHAS_GUI_SOCKET_MANAGER
#endif
class WXDLLIMPEXP_CORE wxGUIAppTraits : public wxGUIAppTraitsBase
{
public:
virtual wxEventLoopBase *CreateEventLoop() override;
virtual int WaitForChild(wxExecuteData& execData) override;
#if wxUSE_TIMER
virtual wxTimerImpl *CreateTimerImpl(wxTimer *timer) override;
#endif
#if wxUSE_THREADS && defined(__WXGTK__)
virtual void MutexGuiEnter() override;
virtual void MutexGuiLeave() override;
#endif
wxPortId GetToolkitVersion(int *majVer = nullptr,
int *minVer = nullptr,
int *microVer = nullptr) const override;
virtual wxString GetDesktopEnvironment() const override;
#if defined(__WXGTK__) || defined(__WXQT__)
virtual wxString GetPlatformDescription() const override;
#endif
#if defined(__WXGTK__)
virtual bool ShowAssertDialog(const wxString& msg) override;
#endif
#if wxUSE_SOCKETS
#ifdef wxHAS_GUI_SOCKET_MANAGER
virtual wxSocketManager *GetSocketManager() override;
#endif
#ifdef wxHAS_GUI_FDIOMANAGER
virtual wxFDIOManager *GetFDIOManager() override;
#endif
#endif // wxUSE_SOCKETS
#if wxUSE_EVENTLOOP_SOURCE
virtual wxEventLoopSourcesManagerBase* GetEventLoopSourcesManager() override;
#endif
};
#endif // wxUSE_GUI
#endif // _WX_UNIX_APPTRAIT_H_

View File

@@ -0,0 +1,51 @@
/*
* Name: wx/unix/chkconf.h
* Purpose: Unix-specific config settings consistency checks
* Author: Vadim Zeitlin
* Created: 2007-07-14
* Copyright: (c) 2007 Vadim Zeitlin <vadim@wxwidgets.org>
* Licence: wxWindows licence
*/
/* THIS IS A C FILE, DON'T USE C++ FEATURES (IN PARTICULAR COMMENTS) IN IT */
#if wxUSE_CONSOLE_EVENTLOOP
# if !wxUSE_SELECT_DISPATCHER && !wxUSE_EPOLL_DISPATCHER
# ifdef wxABORT_ON_CONFIG_ERROR
# error "wxSelect/EpollDispatcher needed for console event loop"
# else
# undef wxUSE_SELECT_DISPATCHER
# define wxUSE_SELECT_DISPATCHER 1
# endif
# endif
#endif /* wxUSE_CONSOLE_EVENTLOOP */
#if wxUSE_FSWATCHER
# if !defined(wxHAS_INOTIFY) && !defined(wxHAS_KQUEUE)
# ifdef wxABORT_ON_CONFIG_ERROR
# error "wxFileSystemWatcher requires either inotify() or kqueue()"
# else
# undef wxUSE_FSWATCHER
# define wxUSE_FSWATCHER 0
# endif
# endif
#endif /* wxUSE_FSWATCHER */
#if wxUSE_GSTREAMER
# if !wxUSE_THREADS
# ifdef wxABORT_ON_CONFIG_ERROR
# error "GStreamer requires threads"
# else
# undef wxUSE_GSTREAMER
# define wxUSE_GSTREAMER 0
# endif
# endif
#endif /* wxUSE_GSTREAMER */
#ifndef wxUSE_XTEST
# ifdef wxABORT_ON_CONFIG_ERROR
# error "wxUSE_XTEST must be defined, please read comment near the top of this file."
# else
# define wxUSE_XTEST 0
# endif
#endif /* !defined(wxUSE_XTEST) */

View File

@@ -0,0 +1,62 @@
///////////////////////////////////////////////////////////////////////////////
// Name: wx/unix/evtloop.h
// Purpose: declares wxEventLoop class
// Author: Lukasz Michalski (lm@zork.pl)
// Created: 2007-05-07
// Copyright: (c) 2007 Lukasz Michalski
// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
#ifndef _WX_UNIX_EVTLOOP_H_
#define _WX_UNIX_EVTLOOP_H_
#if wxUSE_CONSOLE_EVENTLOOP
// ----------------------------------------------------------------------------
// wxConsoleEventLoop
// ----------------------------------------------------------------------------
class wxEventLoopSource;
class wxFDIODispatcher;
class wxWakeUpPipeMT;
class WXDLLIMPEXP_BASE wxConsoleEventLoop
#ifdef __WXOSX__
: public wxCFEventLoop
#else
: public wxEventLoopManual
#endif
{
public:
// initialize the event loop, use IsOk() to check if we were successful
wxConsoleEventLoop();
virtual ~wxConsoleEventLoop();
// implement base class pure virtuals
virtual bool Pending() const override;
virtual bool Dispatch() override;
virtual int DispatchTimeout(unsigned long timeout) override;
virtual void WakeUp() override;
virtual bool IsOk() const override { return m_dispatcher != nullptr; }
protected:
virtual void OnNextIteration() override;
virtual void DoYieldFor(long eventsToProcess) override;
private:
// pipe used for wake up messages: when a child thread wants to wake up
// the event loop in the main thread it writes to this pipe
wxWakeUpPipeMT *m_wakeupPipe;
// the event loop source used to monitor this pipe
wxEventLoopSource* m_wakeupSource;
// either wxSelectDispatcher or wxEpollDispatcher
wxFDIODispatcher *m_dispatcher;
wxDECLARE_NO_COPY_CLASS(wxConsoleEventLoop);
};
#endif // wxUSE_CONSOLE_EVENTLOOP
#endif // _WX_UNIX_EVTLOOP_H_

View File

@@ -0,0 +1,48 @@
///////////////////////////////////////////////////////////////////////////////
// Name: wx/unix/evtloopsrc.h
// Purpose: wxUnixEventLoopSource class
// Author: Vadim Zeitlin
// Created: 2009-10-21
// Copyright: (c) 2009 Vadim Zeitlin <vadim@wxwidgets.org>
// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
#ifndef _WX_UNIX_EVTLOOPSRC_H_
#define _WX_UNIX_EVTLOOPSRC_H_
class wxFDIODispatcher;
class wxFDIOHandler;
// ----------------------------------------------------------------------------
// wxUnixEventLoopSource: wxEventLoopSource for Unix-like toolkits using fds
// ----------------------------------------------------------------------------
class wxUnixEventLoopSource : public wxEventLoopSource
{
public:
// dispatcher and fdioHandler are only used here to allow us to unregister
// from the event loop when we're destroyed
wxUnixEventLoopSource(wxFDIODispatcher *dispatcher,
wxFDIOHandler *fdioHandler,
int fd,
wxEventLoopSourceHandler *handler,
int flags)
: wxEventLoopSource(handler, flags),
m_dispatcher(dispatcher),
m_fdioHandler(fdioHandler),
m_fd(fd)
{
}
virtual ~wxUnixEventLoopSource();
private:
wxFDIODispatcher * const m_dispatcher;
wxFDIOHandler * const m_fdioHandler;
const int m_fd;
wxDECLARE_NO_COPY_CLASS(wxUnixEventLoopSource);
};
#endif // _WX_UNIX_EVTLOOPSRC_H_

View File

@@ -0,0 +1,35 @@
/////////////////////////////////////////////////////////////////////////////
// Name: wx/unix/fontutil.h
// Purpose: font-related helper functions for Unix/X11
// Author: Vadim Zeitlin
// Created: 05.11.99
// Copyright: (c) wxWidgets team
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef _WX_UNIX_FONTUTIL_H_
#define _WX_UNIX_FONTUTIL_H_
#ifdef __X__
typedef WXFontStructPtr wxNativeFont;
#elif defined(__WXGTK__)
typedef GdkFont *wxNativeFont;
#else
#error "Unsupported toolkit"
#endif
// returns the handle of the nearest available font or 0
extern wxNativeFont
wxLoadQueryNearestFont(double pointSize,
wxFontFamily family,
wxFontStyle style,
int weight,
bool underlined,
const wxString &facename,
wxFontEncoding encoding,
wxString* xFontName = nullptr);
// returns the font specified by the given XLFD
extern wxNativeFont wxLoadFont(const wxString& fontSpec);
#endif // _WX_UNIX_FONTUTIL_H_

View File

@@ -0,0 +1,36 @@
/////////////////////////////////////////////////////////////////////////////
// Name: wx/unix/fswatcher_inotify.h
// Purpose: wxInotifyFileSystemWatcher
// Author: Bartosz Bekier
// Created: 2009-05-26
// Copyright: (c) 2009 Bartosz Bekier <bartosz.bekier@gmail.com>
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef _WX_FSWATCHER_UNIX_H_
#define _WX_FSWATCHER_UNIX_H_
#include "wx/defs.h"
#if wxUSE_FSWATCHER
class WXDLLIMPEXP_BASE wxInotifyFileSystemWatcher :
public wxFileSystemWatcherBase
{
public:
wxInotifyFileSystemWatcher();
wxInotifyFileSystemWatcher(const wxFileName& path,
int events = wxFSW_EVENT_ALL);
virtual ~wxInotifyFileSystemWatcher();
void OnDirDeleted(const wxString& path);
protected:
bool Init();
};
#endif
#endif /* _WX_FSWATCHER_UNIX_H_ */

View File

@@ -0,0 +1,34 @@
/////////////////////////////////////////////////////////////////////////////
// Name: wx/unix/fswatcher_kqueue.h
// Purpose: wxKqueueFileSystemWatcher
// Author: Bartosz Bekier
// Created: 2009-05-26
// Copyright: (c) 2009 Bartosz Bekier <bartosz.bekier@gmail.com>
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef _WX_FSWATCHER_KQUEUE_H_
#define _WX_FSWATCHER_KQUEUE_H_
#include "wx/defs.h"
#if wxUSE_FSWATCHER
class WXDLLIMPEXP_BASE wxKqueueFileSystemWatcher :
public wxFileSystemWatcherBase
{
public:
wxKqueueFileSystemWatcher();
wxKqueueFileSystemWatcher(const wxFileName& path,
int events = wxFSW_EVENT_ALL);
virtual ~wxKqueueFileSystemWatcher();
protected:
bool Init();
};
#endif
#endif /* _WX_FSWATCHER_OSX_H_ */

View File

@@ -0,0 +1,192 @@
///////////////////////////////////////////////////////////////////////////////
// Name: wx/unix/glegl.h
// Purpose: class common for all EGL-based wxGLCanvas implementations
// Author: Scott Talbert
// Created: 2017-12-26
// Copyright: (c) 2017 Scott Talbert <swt@techie.net>
// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
#ifndef _WX_UNIX_GLEGL_H_
#define _WX_UNIX_GLEGL_H_
#include <GL/gl.h>
// This is to avoid including Wayland & EGL headers here to pollute namespace
struct wl_compositor;
struct wl_subcompositor;
struct wl_callback;
struct wl_egl_window;
struct wl_surface;
struct wl_region;
struct wl_subsurface;
typedef void *EGLDisplay;
typedef void *EGLConfig;
typedef void *EGLSurface;
typedef void *EGLContext;
class wxGLContextAttrs;
class wxGLAttributes;
// ----------------------------------------------------------------------------
// wxGLContext
// ----------------------------------------------------------------------------
class WXDLLIMPEXP_GL wxGLContext : public wxGLContextBase
{
public:
wxGLContext(wxGLCanvas *win,
const wxGLContext *other = nullptr,
const wxGLContextAttrs *ctxAttrs = nullptr);
virtual ~wxGLContext();
virtual bool SetCurrent(const wxGLCanvas& win) const override;
private:
EGLContext m_glContext;
wxDECLARE_CLASS(wxGLContext);
};
// ----------------------------------------------------------------------------
// wxGLCanvasEGL
// ----------------------------------------------------------------------------
class WXDLLIMPEXP_GL wxGLCanvasEGL : public wxGLCanvasBase
{
public:
// initialization and dtor
// -----------------------
// default ctor doesn't do anything, InitConfig() must be called
wxGLCanvasEGL() = default;
// initializes EGLConfig corresponding to the given attributes
bool InitVisual(const wxGLAttributes& dispAttrs);
// creates EGLSurface
bool CreateSurface();
virtual ~wxGLCanvasEGL();
// Wayland-specific callbacks
// --------------------------
void CreateWaylandSubsurface();
void DestroyWaylandSubsurface();
// implement wxGLCanvasBase methods
// --------------------------------
virtual bool SwapBuffers() override;
// X11-specific methods
// --------------------
// get the X11 handle of this window
virtual unsigned long GetXWindow() const = 0;
// override some wxWindow methods
// ------------------------------
// return true only if the window is realized: OpenGL context can't be
// created until we are
virtual bool IsShownOnScreen() const override;
// implementation only from now on
// -------------------------------
// get the EGLConfig we use
EGLConfig GetEGLConfig() const { return m_config; }
EGLDisplay GetEGLDisplay() const { return m_display; }
EGLSurface GetEGLSurface() const { return m_surface; }
static EGLDisplay GetDisplay();
// initialize the global default GL config, return false if matching config
// not found
static bool InitDefaultConfig(const int *attribList);
// get the default EGL Config (may be null, shouldn't be freed by caller)
static EGLConfig GetDefaultConfig() { return ms_glEGLConfig; }
// free the global GL visual, called by wxGLApp
static void FreeDefaultConfig();
// initializes EGLConfig
//
// returns nullptr if EGLConfig couldn't be initialized, otherwise caller
// is responsible for freeing the pointer
static EGLConfig InitConfig(const wxGLAttributes& dispAttrs);
// Only called when using Wayland to indicate that we should be redrawn.
void OnWLFrameCallback();
wl_compositor *m_wlCompositor = nullptr;
wl_subcompositor *m_wlSubcompositor = nullptr;
wl_callback *m_wlFrameCallbackHandler = nullptr;
wl_egl_window *m_wlEGLWindow = nullptr;
private:
EGLConfig m_config = nullptr;
EGLDisplay m_display = nullptr;
EGLSurface m_surface = nullptr;
unsigned long m_xwindow = 0;
wl_surface *m_wlSurface = nullptr;
wl_region *m_wlRegion = nullptr;
wl_subsurface *m_wlSubsurface = nullptr;
bool m_readyToDraw = false;
bool m_swapIntervalSet = false;
// the global/default versions of the above
static EGLConfig ms_glEGLConfig;
friend void wxEGLUpdatePosition(wxGLCanvasEGL* win);
friend void wxEGLSetScale(wxGLCanvasEGL* win, int scale);
};
// ----------------------------------------------------------------------------
// wxGLApp
// ----------------------------------------------------------------------------
// this is used in wx/glcanvas.h, prevent it from defining a generic wxGLApp
#define wxGL_APP_DEFINED
class WXDLLIMPEXP_GL wxGLApp : public wxGLAppBase
{
public:
wxGLApp() : wxGLAppBase() { }
// implement wxGLAppBase method
virtual bool InitGLVisual(const int *attribList) override
{
return wxGLCanvasEGL::InitDefaultConfig(attribList);
}
// This method is not currently used by the library itself, but remains for
// backwards compatibility and also because wxGTK has it we could start
// using it for the same purpose in wxX11 too some day.
virtual void* GetXVisualInfo() override
{
return wxGLCanvasEGL::GetDefaultConfig();
}
// and override this wxApp method to clean up
virtual int OnExit() override
{
wxGLCanvasEGL::FreeDefaultConfig();
return wxGLAppBase::OnExit();
}
private:
wxDECLARE_DYNAMIC_CLASS(wxGLApp);
};
#endif // _WX_UNIX_GLEGL_H_

View File

@@ -0,0 +1,131 @@
///////////////////////////////////////////////////////////////////////////////
// Name: wx/unix/glx11.h
// Purpose: class common for all X11-based wxGLCanvas implementations
// Author: Vadim Zeitlin
// Created: 2007-04-15
// Copyright: (c) 2007 Vadim Zeitlin <vadim@wxwidgets.org>
// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
#ifndef _WX_UNIX_GLX11_H_
#define _WX_UNIX_GLX11_H_
#include <GL/gl.h>
typedef struct __GLXcontextRec* GLXContext;
typedef struct __GLXFBConfigRec* GLXFBConfig;
// ----------------------------------------------------------------------------
// wxGLContext
// ----------------------------------------------------------------------------
class WXDLLIMPEXP_GL wxGLContext : public wxGLContextBase
{
public:
wxGLContext(wxGLCanvas *win,
const wxGLContext *other = nullptr,
const wxGLContextAttrs *ctxAttrs = nullptr);
virtual ~wxGLContext();
virtual bool SetCurrent(const wxGLCanvas& win) const override;
private:
GLXContext m_glContext;
wxDECLARE_CLASS(wxGLContext);
};
// ----------------------------------------------------------------------------
// wxGLCanvasX11
// ----------------------------------------------------------------------------
class WXDLLIMPEXP_GL wxGLCanvasX11 : public wxGLCanvasBase
{
public:
// initialization and dtor
// -----------------------
// default ctor doesn't do anything, InitVisual() must be called
wxGLCanvasX11();
// initializes GLXFBConfig and XVisualInfo corresponding to the given attributes
bool InitVisual(const wxGLAttributes& dispAttrs);
// frees XVisualInfo info
virtual ~wxGLCanvasX11();
// implement wxGLCanvasBase methods
// --------------------------------
virtual bool SwapBuffers() override;
// X11-specific methods
// --------------------
// return GLX version: 13 means 1.3 &c
static int GetGLXVersion();
// return true if multisample extension is available
static bool IsGLXMultiSampleAvailable();
// get the X11 handle of this window
virtual unsigned long GetXWindow() const = 0;
// GLX-specific methods
// --------------------
// override some wxWindow methods
// ------------------------------
// return true only if the window is realized: OpenGL context can't be
// created until we are
virtual bool IsShownOnScreen() const override;
// implementation only from now on
// -------------------------------
// get the GLXFBConfig/XVisualInfo we use
GLXFBConfig *GetGLXFBConfig() const { return m_fbc; }
void* GetXVisualInfo() const { return m_vi; }
// initialize the global default GL visual, return false if matching visual
// not found
static bool InitDefaultVisualInfo(const int *attribList);
private:
GLXFBConfig *m_fbc;
void* m_vi;
bool m_swapIntervalSet = false;
};
// ----------------------------------------------------------------------------
// wxGLApp
// ----------------------------------------------------------------------------
// this is used in wx/glcanvas.h, prevent it from defining a generic wxGLApp
#define wxGL_APP_DEFINED
class WXDLLIMPEXP_GL wxGLApp : public wxGLAppBase
{
public:
virtual bool InitGLVisual(const int *attribList) override;
// This method is not currently used by the library itself, but remains for
// backwards compatibility and also because wxGTK has it we could start
// using it for the same purpose in wxX11 too some day.
virtual void* GetXVisualInfo() override;
// and override this wxApp method to clean up
virtual int OnExit() override;
private:
wxDECLARE_DYNAMIC_CLASS(wxGLApp);
};
#endif // _WX_UNIX_GLX11_H_

View File

@@ -0,0 +1,93 @@
/////////////////////////////////////////////////////////////////////////////
// Name: wx/unix/joystick.h
// Purpose: wxJoystick class
// Author: Guilhem Lavaux
// Created: 01/02/97
// Copyright: (c) Guilhem Lavaux
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef _WX_UNIX_JOYSTICK_H_
#define _WX_UNIX_JOYSTICK_H_
#include "wx/event.h"
class WXDLLIMPEXP_FWD_CORE wxJoystickThread;
class WXDLLIMPEXP_ADV wxJoystick: public wxObject
{
wxDECLARE_DYNAMIC_CLASS(wxJoystick);
public:
/*
* Public interface
*/
wxJoystick(int joystick = wxJOYSTICK1);
virtual ~wxJoystick();
// Attributes
////////////////////////////////////////////////////////////////////////////
wxPoint GetPosition() const;
int GetPosition(unsigned axis) const;
bool GetButtonState(unsigned button) const;
int GetZPosition() const;
int GetButtonState() const;
int GetPOVPosition() const;
int GetPOVCTSPosition() const;
int GetRudderPosition() const;
int GetUPosition() const;
int GetVPosition() const;
int GetMovementThreshold() const;
void SetMovementThreshold(int threshold) ;
// Capabilities
////////////////////////////////////////////////////////////////////////////
bool IsOk() const; // Checks that the joystick is functioning
static int GetNumberJoysticks() ;
int GetManufacturerId() const ;
int GetProductId() const ;
wxString GetProductName() const ;
int GetXMin() const;
int GetYMin() const;
int GetZMin() const;
int GetXMax() const;
int GetYMax() const;
int GetZMax() const;
int GetNumberButtons() const;
int GetNumberAxes() const;
int GetMaxButtons() const;
int GetMaxAxes() const;
int GetPollingMin() const;
int GetPollingMax() const;
int GetRudderMin() const;
int GetRudderMax() const;
int GetUMin() const;
int GetUMax() const;
int GetVMin() const;
int GetVMax() const;
bool HasRudder() const;
bool HasZ() const;
bool HasU() const;
bool HasV() const;
bool HasPOV() const;
bool HasPOV4Dir() const;
bool HasPOVCTS() const;
// Operations
////////////////////////////////////////////////////////////////////////////
// pollingFreq = 0 means that movement events are sent when above the threshold.
// If pollingFreq > 0, events are received every this many milliseconds.
bool SetCapture(wxWindow* win, int pollingFreq = 0);
bool ReleaseCapture();
protected:
int m_device;
int m_joystick;
wxJoystickThread* m_thread;
};
#endif // _WX_UNIX_JOYSTICK_H_

View File

@@ -0,0 +1,173 @@
/////////////////////////////////////////////////////////////////////////////
// Name: wx/unix/mimetype.h
// Purpose: classes and functions to manage MIME types
// Author: Vadim Zeitlin
// Created: 23.09.98
// Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
// Licence: wxWindows licence (part of wxExtra library)
/////////////////////////////////////////////////////////////////////////////
#ifndef _MIMETYPE_IMPL_H
#define _MIMETYPE_IMPL_H
#include "wx/mimetype.h"
#if wxUSE_MIMETYPE
class wxMimeTypeCommands;
WX_DEFINE_ARRAY_PTR(wxMimeTypeCommands *, wxMimeCommandsArray);
// this is the real wxMimeTypesManager for Unix
class WXDLLIMPEXP_BASE wxMimeTypesManagerImpl
{
public:
// ctor and dtor
wxMimeTypesManagerImpl();
virtual ~wxMimeTypesManagerImpl();
// load all data into memory - done when it is needed for the first time
void Initialize(int mailcapStyles = wxMAILCAP_ALL,
const wxString& extraDir = wxEmptyString);
// and delete the data here
void ClearData();
// implement containing class functions
wxFileType *GetFileTypeFromExtension(const wxString& ext);
wxFileType *GetFileTypeFromMimeType(const wxString& mimeType);
size_t EnumAllFileTypes(wxArrayString& mimetypes);
void AddFallback(const wxFileTypeInfo& filetype);
// add information about the given mimetype
void AddMimeTypeInfo(const wxString& mimetype,
const wxString& extensions,
const wxString& description);
void AddMailcapInfo(const wxString& strType,
const wxString& strOpenCmd,
const wxString& strPrintCmd,
const wxString& strTest,
const wxString& strDesc);
// add a new record to the user .mailcap/.mime.types files
wxFileType *Associate(const wxFileTypeInfo& ftInfo);
// remove association
bool Unassociate(wxFileType *ft);
// accessors
// get the string containing space separated extensions for the given
// file type
wxString GetExtension(size_t index) { return m_aExtensions[index]; }
protected:
void InitIfNeeded();
wxArrayString m_aTypes, // MIME types
m_aDescriptions, // descriptions (just some text)
m_aExtensions, // space separated list of extensions
m_aIcons; // Icon filenames
// verb=command pairs for this file type
wxMimeCommandsArray m_aEntries;
// are we initialized?
bool m_initialized;
wxString GetCommand(const wxString &verb, size_t nIndex) const;
// Read XDG *.desktop file
void LoadXDGApp(const wxString& filename);
// Scan XDG directory
void LoadXDGAppsFilesFromDir(const wxString& dirname);
// Load XDG globs files
void LoadXDGGlobs(const wxString& filename);
// functions used to do associations
virtual int AddToMimeData(const wxString& strType,
const wxString& strIcon,
wxMimeTypeCommands *entry,
const wxArrayString& strExtensions,
const wxString& strDesc,
bool replaceExisting = true);
virtual bool DoAssociation(const wxString& strType,
const wxString& strIcon,
wxMimeTypeCommands *entry,
const wxArrayString& strExtensions,
const wxString& strDesc);
virtual wxString GetIconFromMimeType(const wxString& mime);
// give it access to m_aXXX variables
friend class WXDLLIMPEXP_FWD_BASE wxFileTypeImpl;
};
class WXDLLIMPEXP_BASE wxFileTypeImpl
{
public:
// initialization functions
// this is used to construct a list of mimetypes which match;
// if built with GetFileTypeFromMimetype index 0 has the exact match and
// index 1 the type / * match
// if built with GetFileTypeFromExtension, index 0 has the mimetype for
// the first extension found, index 1 for the second and so on
void Init(wxMimeTypesManagerImpl *manager, size_t index)
{ m_manager = manager; m_index.Add(index); }
// accessors
bool GetExtensions(wxArrayString& extensions);
bool GetMimeType(wxString *mimeType) const
{ *mimeType = m_manager->m_aTypes[m_index[0]]; return true; }
bool GetMimeTypes(wxArrayString& mimeTypes) const;
bool GetIcon(wxIconLocation *iconLoc) const;
bool GetDescription(wxString *desc) const
{ *desc = m_manager->m_aDescriptions[m_index[0]]; return true; }
bool GetOpenCommand(wxString *openCmd,
const wxFileType::MessageParameters& params) const
{
*openCmd = GetExpandedCommand(wxT("open"), params);
return (! openCmd -> IsEmpty() );
}
bool GetPrintCommand(wxString *printCmd,
const wxFileType::MessageParameters& params) const
{
*printCmd = GetExpandedCommand(wxT("print"), params);
return (! printCmd -> IsEmpty() );
}
// return the number of commands defined for this file type, 0 if none
size_t GetAllCommands(wxArrayString *verbs, wxArrayString *commands,
const wxFileType::MessageParameters& params) const;
// remove the record for this file type
// probably a mistake to come here, use wxMimeTypesManager.Unassociate (ft) instead
bool Unassociate(wxFileType *ft)
{
return m_manager->Unassociate(ft);
}
// set an arbitrary command, ask confirmation if it already exists and
// overwriteprompt is TRUE
bool SetCommand(const wxString& cmd, const wxString& verb, bool overwriteprompt = true);
bool SetDefaultIcon(const wxString& strIcon = wxEmptyString, int index = 0);
wxString
GetExpandedCommand(const wxString & verb,
const wxFileType::MessageParameters& params) const;
private:
wxMimeTypesManagerImpl *m_manager;
wxArrayInt m_index; // in the wxMimeTypesManagerImpl arrays
};
#endif // wxUSE_MIMETYPE
#endif // _MIMETYPE_IMPL_H

View File

@@ -0,0 +1,101 @@
///////////////////////////////////////////////////////////////////////////////
// Name: wx/unix/pipe.h
// Purpose: wxPipe class
// Author: Vadim Zeitlin
// Created: 24.06.2003 (extracted from src/unix/utilsunx.cpp)
// Copyright: (c) 2003 Vadim Zeitlin <vadim@wxwidgets.org>
// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
#ifndef _WX_UNIX_PIPE_H_
#define _WX_UNIX_PIPE_H_
#include <unistd.h>
#include <fcntl.h>
#include "wx/log.h"
#include "wx/intl.h"
// ----------------------------------------------------------------------------
// wxPipe: this class encapsulates pipe() system call
// ----------------------------------------------------------------------------
class wxPipe
{
public:
// the symbolic names for the pipe ends
enum Direction
{
Read,
Write
};
enum
{
INVALID_FD = -1
};
// default ctor doesn't do anything
wxPipe() { m_fds[Read] = m_fds[Write] = INVALID_FD; }
// create the pipe, return TRUE if ok, FALSE on error
bool Create()
{
if ( pipe(m_fds) == -1 )
{
wxLogSysError(wxGetTranslation("Pipe creation failed"));
return false;
}
return true;
}
// switch the given end of the pipe to non-blocking IO
bool MakeNonBlocking(Direction which)
{
const int flags = fcntl(m_fds[which], F_GETFL, 0);
if ( flags == -1 )
return false;
return fcntl(m_fds[which], F_SETFL, flags | O_NONBLOCK) == 0;
}
// return TRUE if we were created successfully
bool IsOk() const { return m_fds[Read] != INVALID_FD; }
// return the descriptor for one of the pipe ends
int operator[](Direction which) const { return m_fds[which]; }
// detach a descriptor, meaning that the pipe dtor won't close it, and
// return it
int Detach(Direction which)
{
int fd = m_fds[which];
m_fds[which] = INVALID_FD;
return fd;
}
// close the pipe descriptors
void Close()
{
for ( size_t n = 0; n < WXSIZEOF(m_fds); n++ )
{
if ( m_fds[n] != INVALID_FD )
{
close(m_fds[n]);
m_fds[n] = INVALID_FD;
}
}
}
// dtor closes the pipe descriptors
~wxPipe() { Close(); }
private:
int m_fds[2];
};
#endif // _WX_UNIX_PIPE_H_

View File

@@ -0,0 +1,19 @@
///////////////////////////////////////////////////////////////////////////////
// Name: wx/unix/private.h
// Purpose: miscellaneous private things for Unix wx ports
// Author: Vadim Zeitlin
// Created: 2005-09-25
// Copyright: (c) 2005 Vadim Zeitlin <vadim@wxwidgets.org>
// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
#ifndef _WX_UNIX_PRIVATE_H_
#define _WX_UNIX_PRIVATE_H_
// this file is currently empty as its original contents was moved to
// include/wx/private/fd.h but let's keep it for now in case we need it for
// something again in the future
#include "wx/private/fd.h"
#endif // _WX_UNIX_PRIVATE_H_

View File

@@ -0,0 +1,175 @@
///////////////////////////////////////////////////////////////////////////////
// Name: wx/unix/private/displayx11.h
// Purpose: Helper functions used by wxX11 and wxGTK ports
// Author: Vadim Zeitlin
// Created: 2018-10-04 (extracted from src/unix/displayx11.cpp)
// Copyright: (c) 2002-2018 wxWindows team
// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
#ifndef _WX_UNIX_PRIVATE_DISPLAYX11_H_
#define _WX_UNIX_PRIVATE_DISPLAYX11_H_
#include "wx/defs.h"
#include <X11/Xlib.h>
#include <X11/Xatom.h>
#include "wx/unix/private/x11ptr.h"
#if wxUSE_DISPLAY
#include "wx/log.h"
#include "wx/translation.h"
#ifdef HAVE_X11_EXTENSIONS_XF86VMODE_H
#include <X11/extensions/xf86vmode.h>
//
// See (http://www.xfree86.org/4.2.0/XF86VidModeDeleteModeLine.3.html) for more
// info about xf86 video mode extensions
//
//free private data common to x (usually s3) servers
#define wxClearXVM(vm) if(vm.privsize) XFree(vm.c_private)
// Correct res rate from GLFW
#define wxCRR2(v,dc) (int) (((1000.0f * (float) dc) /*PIXELS PER SECOND */) / ((float) v.htotal * v.vtotal /*PIXELS PER FRAME*/) + 0.5f)
#define wxCRR(v) wxCRR2(v,v.dotclock)
#define wxCVM2(v, dc, display, nScreen) wxVideoMode(v.hdisplay, v.vdisplay, DefaultDepth(display, nScreen), wxCRR2(v,dc))
#define wxCVM(v, display, nScreen) wxCVM2(v, v.dotclock, display, nScreen)
wxArrayVideoModes wxXF86VidMode_GetModes(const wxVideoMode& mode, Display* display, int nScreen)
{
wxX11Ptr<XF86VidModeModeInfo*> ppXModes; //Enumerated Modes
int nNumModes; //Number of modes enumerated....
wxArrayVideoModes Modes; //modes to return...
if (XF86VidModeGetAllModeLines(display, nScreen, &nNumModes, ppXModes.Out()))
{
for (int i = 0; i < nNumModes; ++i)
{
XF86VidModeModeInfo& info = *ppXModes[i];
const wxVideoMode vm = wxCVM(info, display, nScreen);
if (vm.Matches(mode))
{
Modes.Add(vm);
}
wxClearXVM(info);
}
}
else //OOPS!
{
wxLogSysError(_("Failed to enumerate video modes"));
}
return Modes;
}
wxVideoMode wxXF86VidMode_GetCurrentMode(Display* display, int nScreen)
{
XF86VidModeModeLine VM;
int nDotClock;
if ( !XF86VidModeGetModeLine(display, nScreen, &nDotClock, &VM) )
return wxVideoMode();
wxClearXVM(VM);
return wxCVM2(VM, nDotClock, display, nScreen);
}
bool wxXF86VidMode_ChangeMode(const wxVideoMode& mode, Display* display, int nScreen)
{
wxX11Ptr<XF86VidModeModeInfo*> ppXModes; //Enumerated Modes
int nNumModes; //Number of modes enumerated....
if(!XF86VidModeGetAllModeLines(display, nScreen, &nNumModes, ppXModes.Out()))
{
wxLogSysError(_("Failed to change video mode"));
return false;
}
bool bRet = false;
if (mode == wxDefaultVideoMode)
{
bRet = XF86VidModeSwitchToMode(display, nScreen, ppXModes[0]) != 0;
for (int i = 0; i < nNumModes; ++i)
{
wxClearXVM((*ppXModes[i]));
}
}
else
{
for (int i = 0; i < nNumModes; ++i)
{
if (!bRet &&
ppXModes[i]->hdisplay == mode.GetWidth() &&
ppXModes[i]->vdisplay == mode.GetHeight() &&
wxCRR((*ppXModes[i])) == mode.GetRefresh())
{
//switch!
bRet = XF86VidModeSwitchToMode(display, nScreen, ppXModes[i]) != 0;
}
wxClearXVM((*ppXModes[i]));
}
}
return bRet;
}
#else // !HAVE_X11_EXTENSIONS_XF86VMODE_H
wxArrayVideoModes wxX11_GetModes(const wxDisplayImpl* impl, const wxVideoMode& modeMatch, Display* display)
{
int count_return;
wxX11Ptr<int> depths(XListDepths(display, 0, &count_return));
wxArrayVideoModes modes;
if ( depths )
{
const wxRect rect = impl->GetGeometry();
for ( int x = 0; x < count_return; ++x )
{
wxVideoMode mode(rect.width, rect.height, depths[x]);
if ( mode.Matches(modeMatch) )
{
modes.Add(mode);
}
}
}
return modes;
}
#endif // !HAVE_X11_EXTENSIONS_XF86VMODE_H
#endif // wxUSE_DISPLAY
void wxGetWorkAreaX11(Screen* screen, int& x, int& y, int& width, int& height)
{
Display* display = DisplayOfScreen(screen);
Atom property = XInternAtom(display, "_NET_WORKAREA", true);
if (property)
{
Atom actual_type;
int actual_format;
unsigned long nitems;
unsigned long bytes_after;
wxX11Ptr<unsigned char> data;
Status status = XGetWindowProperty(
display, RootWindowOfScreen(screen), property,
0, 4, false, XA_CARDINAL,
&actual_type, &actual_format, &nitems, &bytes_after, data.Out());
if (status == Success && actual_type == XA_CARDINAL &&
actual_format == 32 && nitems == 4)
{
const long* p = (const long*)data.get();
x = p[0];
y = p[1];
width = p[2];
height = p[3];
}
}
}
#endif // _WX_UNIX_PRIVATE_DISPLAYX11_H_

View File

@@ -0,0 +1,53 @@
/////////////////////////////////////////////////////////////////////////////
// Name: wx/unix/private/epolldispatcher.h
// Purpose: wxEpollDispatcher class
// Authors: Lukasz Michalski
// Created: April 2007
// Copyright: (c) Lukasz Michalski
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef _WX_PRIVATE_EPOLLDISPATCHER_H_
#define _WX_PRIVATE_EPOLLDISPATCHER_H_
#include "wx/defs.h"
#ifdef wxUSE_EPOLL_DISPATCHER
#include "wx/private/fdiodispatcher.h"
struct epoll_event;
class WXDLLIMPEXP_BASE wxEpollDispatcher : public wxFDIODispatcher
{
public:
// create a new instance of this class, can return nullptr if
// epoll() is not supported on this system
//
// the caller should delete the returned pointer
static wxEpollDispatcher *Create();
virtual ~wxEpollDispatcher();
// implement base class pure virtual methods
virtual bool RegisterFD(int fd, wxFDIOHandler* handler, int flags = wxFDIO_ALL) override;
virtual bool ModifyFD(int fd, wxFDIOHandler* handler, int flags = wxFDIO_ALL) override;
virtual bool UnregisterFD(int fd) override;
virtual bool HasPending() const override;
virtual int Dispatch(int timeout = TIMEOUT_INFINITE) override;
private:
// ctor is private, use Create()
wxEpollDispatcher(int epollDescriptor);
// common part of HasPending() and Dispatch(): calls epoll_wait() with the
// given timeout
int DoPoll(epoll_event *events, int numEvents, int timeout) const;
int m_epollDescriptor;
};
#endif // wxUSE_EPOLL_DISPATCHER
#endif // _WX_PRIVATE_SOCKETEVTDISPATCH_H_

View File

@@ -0,0 +1,102 @@
/////////////////////////////////////////////////////////////////////////////
// Name: wx/unix/private/execute.h
// Purpose: private details of wxExecute() implementation
// Author: Vadim Zeitlin
// Copyright: (c) 1998 Robert Roebling, Julian Smart, Vadim Zeitlin
// (c) 2013 Vadim Zeitlin
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef _WX_UNIX_EXECUTE_H
#define _WX_UNIX_EXECUTE_H
#include "wx/app.h"
#include "wx/process.h"
#if wxUSE_STREAMS
#include "wx/unix/pipe.h"
#include "wx/private/streamtempinput.h"
#endif
#include <unordered_map>
class wxEventLoopBase;
// Information associated with a running child process.
class wxExecuteData
{
public:
wxExecuteData()
{
m_flags =
m_pid = 0;
m_exitcode = -1;
m_process = nullptr;
m_syncEventLoop = nullptr;
#if wxUSE_STREAMS
m_fdOut =
m_fdErr = wxPipe::INVALID_FD;
#endif // wxUSE_STREAMS
}
// This must be called in the parent process as soon as fork() returns to
// update us with the effective child PID. It also ensures that we handle
// SIGCHLD to be able to detect when this PID exits, so wxTheApp must be
// available.
void OnStart(int pid);
// Called when the child process exits.
void OnExit(int exitcode);
// Return true if we should (or already did) redirect the child IO.
bool IsRedirected() const { return m_process && m_process->IsRedirected(); }
// wxExecute() flags
int m_flags;
// the pid of the child process
int m_pid;
// The exit code of the process, set once the child terminates.
int m_exitcode;
// the associated process object or nullptr
wxProcess *m_process;
// Local event loop used to wait for the child process termination in
// synchronous execution case. We can't create it ourselves as its exact
// type depends on the application kind (console/GUI), so we rely on
// wxAppTraits setting up this pointer to point to the appropriate object.
wxEventLoopBase *m_syncEventLoop;
#if wxUSE_STREAMS
// the input buffer bufOut is connected to stdout, this is why it is
// called bufOut and not bufIn
wxStreamTempInputBuffer m_bufOut,
m_bufErr;
// the corresponding FDs, -1 if not redirected
int m_fdOut,
m_fdErr;
#endif // wxUSE_STREAMS
private:
// SIGCHLD signal handler that checks whether any of the currently running
// children have exited.
static void OnSomeChildExited(int sig);
// All currently running child processes indexed by their PID.
//
// Notice that the container doesn't own its elements.
using ChildProcessesData = std::unordered_map<int, wxExecuteData*>;
static ChildProcessesData ms_childProcesses;
wxDECLARE_NO_COPY_CLASS(wxExecuteData);
};
#endif // _WX_UNIX_EXECUTE_H

View File

@@ -0,0 +1,136 @@
///////////////////////////////////////////////////////////////////////////////
// Name: wx/unix/private/executeiohandler.h
// Purpose: IO handler class for the FD used by wxExecute() under Unix
// Author: Rob Bresalier, Vadim Zeitlin
// Created: 2013-01-06
// Copyright: (c) 2013 Rob Bresalier, Vadim Zeitlin
// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
#ifndef _WX_UNIX_PRIVATE_EXECUTEIOHANDLER_H_
#define _WX_UNIX_PRIVATE_EXECUTEIOHANDLER_H_
#include "wx/private/streamtempinput.h"
// This class handles IO events on the pipe FD connected to the child process
// stdout/stderr and is used by wxExecute().
//
// Currently it can derive from either wxEventLoopSourceHandler or
// wxFDIOHandler depending on the kind of dispatcher/event loop it is used
// with. In the future, when we get rid of wxFDIOHandler entirely, it will
// derive from wxEventLoopSourceHandler only.
template <class T>
class wxExecuteIOHandlerBase : public T
{
public:
wxExecuteIOHandlerBase(int fd, wxStreamTempInputBuffer& buf)
: m_fd(fd),
m_buf(buf)
{
m_callbackDisabled = false;
}
// Called when the associated descriptor is available for reading.
virtual void OnReadWaiting() override
{
// Sync process, process all data coming at us from the pipe so that
// the pipe does not get full and cause a deadlock situation.
m_buf.Update();
if ( m_buf.Eof() )
DisableCallback();
}
// These methods are never called as we only monitor the associated FD for
// reading, but we still must implement them as they're pure virtual in the
// base class.
virtual void OnWriteWaiting() override { }
virtual void OnExceptionWaiting() override { }
// Disable any future calls to our OnReadWaiting(), can be called when
// we're sure that no more input is forthcoming.
void DisableCallback()
{
if ( !m_callbackDisabled )
{
m_callbackDisabled = true;
DoDisable();
}
}
protected:
const int m_fd;
private:
virtual void DoDisable() = 0;
wxStreamTempInputBuffer& m_buf;
// If true, DisableCallback() had been already called.
bool m_callbackDisabled;
wxDECLARE_NO_COPY_CLASS(wxExecuteIOHandlerBase);
};
// This is the version used with wxFDIODispatcher, which must be passed to the
// ctor in order to register this handler with it.
class wxExecuteFDIOHandler : public wxExecuteIOHandlerBase<wxFDIOHandler>
{
public:
wxExecuteFDIOHandler(wxFDIODispatcher& dispatcher,
int fd,
wxStreamTempInputBuffer& buf)
: wxExecuteIOHandlerBase<wxFDIOHandler>(fd, buf),
m_dispatcher(dispatcher)
{
dispatcher.RegisterFD(fd, this, wxFDIO_INPUT);
}
virtual ~wxExecuteFDIOHandler()
{
DisableCallback();
}
private:
virtual void DoDisable() override
{
m_dispatcher.UnregisterFD(m_fd);
}
wxFDIODispatcher& m_dispatcher;
wxDECLARE_NO_COPY_CLASS(wxExecuteFDIOHandler);
};
// And this is the version used with an event loop. As AddSourceForFD() is
// static, we don't require passing the event loop to the ctor but an event
// loop must be running to handle our events.
class wxExecuteEventLoopSourceHandler
: public wxExecuteIOHandlerBase<wxEventLoopSourceHandler>
{
public:
wxExecuteEventLoopSourceHandler(int fd, wxStreamTempInputBuffer& buf)
: wxExecuteIOHandlerBase<wxEventLoopSourceHandler>(fd, buf)
{
m_source = wxEventLoop::AddSourceForFD(fd, this, wxEVENT_SOURCE_INPUT);
}
virtual ~wxExecuteEventLoopSourceHandler()
{
DisableCallback();
}
private:
virtual void DoDisable() override
{
delete m_source;
m_source = nullptr;
}
wxEventLoopSource* m_source;
wxDECLARE_NO_COPY_CLASS(wxExecuteEventLoopSourceHandler);
};
#endif // _WX_UNIX_PRIVATE_EXECUTEIOHANDLER_H_

View File

@@ -0,0 +1,27 @@
///////////////////////////////////////////////////////////////////////////////
// Name: wx/unix/private/fdiounix.h
// Purpose: wxFDIOManagerUnix class used by console Unix applications
// Author: Vadim Zeitlin
// Created: 2009-08-17
// Copyright: (c) 2009 Vadim Zeitlin <vadim@wxwidgets.org>
// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
#ifndef _UNIX_PRIVATE_FDIOUNIX_H_
#define _UNIX_PRIVATE_FDIOUNIX_H_
#include "wx/private/fdiomanager.h"
// ----------------------------------------------------------------------------
// wxFDIOManagerUnix: implement wxFDIOManager interface using wxFDIODispatcher
// ----------------------------------------------------------------------------
class wxFDIOManagerUnix : public wxFDIOManager
{
public:
virtual int AddInput(wxFDIOHandler *handler, int fd, Direction d) override;
virtual void RemoveInput(wxFDIOHandler *handler, int fd, Direction d) override;
};
#endif // _UNIX_PRIVATE_FDIOUNIX_H_

View File

@@ -0,0 +1,71 @@
/////////////////////////////////////////////////////////////////////////////
// Name: wx/unix/private/fswatcher_inotify.h
// Purpose: File system watcher impl classes
// Author: Bartosz Bekier
// Created: 2009-05-26
// Copyright: (c) 2009 Bartosz Bekier <bartosz.bekier@gmail.com>
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef WX_UNIX_PRIVATE_FSWATCHER_INOTIFY_H_
#define WX_UNIX_PRIVATE_FSWATCHER_INOTIFY_H_
#include "wx/filename.h"
#include "wx/evtloopsrc.h"
// ============================================================================
// wxFSWatcherEntry implementation & helper declarations
// ============================================================================
class wxFSWatcherImplUNIX;
class wxFSWatchEntry : public wxFSWatchInfo
{
public:
wxFSWatchEntry(const wxFSWatchInfo& winfo) :
wxFSWatchInfo(winfo)
{
}
int GetWatchDescriptor() const
{
return m_wd;
}
void SetWatchDescriptor(int wd)
{
m_wd = wd;
}
private:
int m_wd;
wxDECLARE_NO_COPY_CLASS(wxFSWatchEntry);
};
// ============================================================================
// wxFSWSourceHandler helper class
// ============================================================================
class wxFSWatcherImplUnix;
/**
* Handler for handling i/o from inotify descriptor
*/
class wxFSWSourceHandler : public wxEventLoopSourceHandler
{
public:
wxFSWSourceHandler(wxFSWatcherImplUnix* service) :
m_service(service)
{ }
virtual void OnReadWaiting() override;
virtual void OnWriteWaiting() override;
virtual void OnExceptionWaiting() override;
protected:
wxFSWatcherImplUnix* m_service;
};
#endif /* WX_UNIX_PRIVATE_FSWATCHER_INOTIFY_H_ */

View File

@@ -0,0 +1,108 @@
/////////////////////////////////////////////////////////////////////////////
// Name: wx/unix/private/fswatcher_kqueue.h
// Purpose: File system watcher impl classes
// Author: Bartosz Bekier
// Created: 2009-05-26
// Copyright: (c) 2009 Bartosz Bekier <bartosz.bekier@gmail.com>
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef WX_UNIX_PRIVATE_FSWATCHER_KQUEUE_H_
#define WX_UNIX_PRIVATE_FSWATCHER_KQUEUE_H_
#include <fcntl.h>
#include <unistd.h>
#include "wx/dir.h"
#include "wx/debug.h"
#include "wx/arrstr.h"
// ============================================================================
// wxFSWatcherEntry implementation & helper declarations
// ============================================================================
class wxFSWatcherImplKqueue;
class wxFSWatchEntryKq : public wxFSWatchInfo
{
public:
struct wxDirState
{
wxDirState(const wxFSWatchInfo& winfo)
{
if (!wxDir::Exists(winfo.GetPath()))
return;
wxDir dir(winfo.GetPath());
wxCHECK_RET( dir.IsOpened(),
wxString::Format(wxASCII_STR("Unable to open dir '%s'"), winfo.GetPath()));
wxString filename;
bool ret = dir.GetFirst(&filename);
while (ret)
{
files.push_back(filename);
ret = dir.GetNext(&filename);
}
}
wxSortedArrayString files;
};
wxFSWatchEntryKq(const wxFSWatchInfo& winfo) :
wxFSWatchInfo(winfo), m_lastState(winfo)
{
m_fd = wxOpen(m_path, O_RDONLY, 0);
if (m_fd == -1)
{
wxLogSysError(_("Unable to open path '%s'"), m_path);
}
}
virtual ~wxFSWatchEntryKq()
{
(void) Close();
}
bool Close()
{
if (!IsOk())
return false;
int ret = close(m_fd);
if (ret == -1)
{
wxLogSysError(_("Unable to close path '%s'"), m_path);
}
m_fd = -1;
return ret != -1;
}
bool IsOk() const
{
return m_fd != -1;
}
int GetFileDescriptor() const
{
return m_fd;
}
void RefreshState()
{
m_lastState = wxDirState(*this);
}
const wxDirState& GetLastState() const
{
return m_lastState;
}
private:
int m_fd;
wxDirState m_lastState;
wxDECLARE_NO_COPY_CLASS(wxFSWatchEntryKq);
};
#endif /* WX_UNIX_PRIVATE_FSWATCHER_KQUEUE_H_ */

View File

@@ -0,0 +1,37 @@
///////////////////////////////////////////////////////////////////////////////
// Name: wx/unix/private/pipestream.h
// Purpose: Unix wxPipeInputStream and wxPipeOutputStream declarations
// Author: Vadim Zeitlin
// Created: 2013-06-08 (extracted from wx/unix/pipe.h)
// Copyright: (c) 2013 Vadim Zeitlin <vadim@wxwidgets.org>
// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
#ifndef _WX_UNIX_PRIVATE_PIPESTREAM_H_
#define _WX_UNIX_PRIVATE_PIPESTREAM_H_
#include "wx/wfstream.h"
class wxPipeInputStream : public wxFileInputStream
{
public:
explicit wxPipeInputStream(int fd) : wxFileInputStream(fd) { }
// return true if the pipe is still opened
bool IsOpened() const { return !Eof(); }
// return true if we have anything to read, don't block
virtual bool CanRead() const override;
};
class wxPipeOutputStream : public wxFileOutputStream
{
public:
wxPipeOutputStream(int fd) : wxFileOutputStream(fd) { }
// Override the base class version to ignore "pipe full" errors: this is
// not an error for this class.
size_t OnSysWrite(const void *buffer, size_t size) override;
};
#endif // _WX_UNIX_PRIVATE_PIPESTREAM_H_

View File

@@ -0,0 +1,151 @@
/////////////////////////////////////////////////////////////////////////////
// Name: wx/unix/private/sockunix.h
// Purpose: wxSocketImpl implementation for Unix systems
// Authors: Guilhem Lavaux, Vadim Zeitlin
// Created: April 1997
// Copyright: (c) 1997 Guilhem Lavaux
// (c) 2008 Vadim Zeitlin
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef _WX_UNIX_GSOCKUNX_H_
#define _WX_UNIX_GSOCKUNX_H_
#include <unistd.h>
#include <sys/ioctl.h>
// Under older (Open)Solaris versions FIONBIO is declared in this header only.
// In the newer versions it's included by sys/ioctl.h but it's simpler to just
// include it always instead of testing for whether it is or not.
#ifdef __SOLARIS__
#include <sys/filio.h>
#endif
#include "wx/private/fdiomanager.h"
#define wxCloseSocket close
class wxSocketImplUnix : public wxSocketImpl,
public wxFDIOHandler
{
public:
wxSocketImplUnix(wxSocketBase& wxsocket)
: wxSocketImpl(wxsocket)
{
m_fds[0] =
m_fds[1] = -1;
}
virtual void ReenableEvents(wxSocketEventFlags flags) override
{
// Events are only ever used for non-blocking sockets.
if ( GetSocketFlags() & wxSOCKET_BLOCK )
return;
// enable the notifications about input/output being available again in
// case they were disabled by OnRead/WriteWaiting()
//
// notice that we'd like to enable the events here only if there is
// nothing more left on the socket right now as otherwise we're going
// to get a "ready for whatever" notification immediately (well, during
// the next event loop iteration) and disable the event back again
// which is rather inefficient but unfortunately doing it like this
// doesn't work because the existing code (e.g. src/common/sckipc.cpp)
// expects to keep getting notifications about the data available from
// the socket even if it didn't read all the data the last time, so we
// absolutely have to continue generating them
EnableEvents(flags);
}
virtual void UpdateBlockingState() override
{
// Make this int and not bool to allow passing it to ioctl().
int isNonBlocking = (GetSocketFlags() & wxSOCKET_BLOCK) == 0;
ioctl(m_fd, FIONBIO, &isNonBlocking);
DoEnableEvents(wxSOCKET_INPUT_FLAG | wxSOCKET_OUTPUT_FLAG, isNonBlocking);
}
// wxFDIOHandler methods
virtual void OnReadWaiting() override;
virtual void OnWriteWaiting() override;
virtual void OnExceptionWaiting() override;
virtual bool IsOk() const override { return m_fd != INVALID_SOCKET; }
private:
virtual wxSocketError GetLastError() const override;
virtual void DoClose() override
{
DisableEvents();
wxCloseSocket(m_fd);
}
// enable or disable notifications for socket input/output events
void EnableEvents(int flags = wxSOCKET_INPUT_FLAG | wxSOCKET_OUTPUT_FLAG)
{ DoEnableEvents(flags, true); }
void DisableEvents(int flags = wxSOCKET_INPUT_FLAG | wxSOCKET_OUTPUT_FLAG)
{ DoEnableEvents(flags, false); }
// really enable or disable socket input/output events
void DoEnableEvents(int flags, bool enable);
protected:
// descriptors for input and output event notification channels associated
// with the socket
int m_fds[2];
private:
// notify the associated wxSocket about a change in socket state and shut
// down the socket if the event is wxSOCKET_LOST
void OnStateChange(wxSocketNotify event);
// check if there is any input available, return 1 if yes, 0 if no or -1 on
// error
int CheckForInput();
// give it access to our m_fds
friend class wxSocketFDBasedManager;
};
// A version of wxSocketManager which uses FDs for socket IO: it is used by
// Unix console applications and some X11-like ports (wxGTK and wxQt but not
// wxX11 currently) which implement their own port-specific wxFDIOManagers
class wxSocketFDBasedManager : public wxSocketManager
{
public:
wxSocketFDBasedManager()
{
m_fdioManager = nullptr;
}
virtual bool OnInit() override;
virtual void OnExit() override { }
virtual wxSocketImpl *CreateSocket(wxSocketBase& wxsocket) override
{
return new wxSocketImplUnix(wxsocket);
}
virtual void Install_Callback(wxSocketImpl *socket_, wxSocketNotify event) override;
virtual void Uninstall_Callback(wxSocketImpl *socket_, wxSocketNotify event) override;
protected:
// get the FD index corresponding to the given wxSocketNotify
wxFDIOManager::Direction
GetDirForEvent(wxSocketImpl *socket, wxSocketNotify event);
// access the FDs we store
int& FD(wxSocketImplUnix *socket, wxFDIOManager::Direction d)
{
return socket->m_fds[d];
}
wxFDIOManager *m_fdioManager;
wxDECLARE_NO_COPY_CLASS(wxSocketFDBasedManager);
};
#endif /* _WX_UNIX_GSOCKUNX_H_ */

View File

@@ -0,0 +1,138 @@
/////////////////////////////////////////////////////////////////////////////
// Name: wx/unix/private/timer.h
// Purpose: wxTimer for wxBase (unix)
// Author: Lukasz Michalski
// Created: 15/01/2005
// Copyright: (c) Lukasz Michalski
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef _WX_UNIX_PRIVATE_TIMER_H_
#define _WX_UNIX_PRIVATE_TIMER_H_
#if wxUSE_TIMER
#include "wx/private/timer.h"
#include <list>
// the type used for milliseconds is large enough for microseconds too but
// introduce a synonym for it to avoid confusion
typedef wxMilliClock_t wxUsecClock_t;
// ----------------------------------------------------------------------------
// wxTimer implementation class for Unix platforms
// ----------------------------------------------------------------------------
// NB: we have to export at least this symbol from the shared library, because
// it's used by wxDFB's wxCore
class WXDLLIMPEXP_BASE wxUnixTimerImpl : public wxTimerImpl
{
public:
wxUnixTimerImpl(wxTimer *timer);
virtual ~wxUnixTimerImpl();
virtual bool IsRunning() const override;
virtual bool Start(int milliseconds = -1, bool oneShot = false) override;
virtual void Stop() override;
// for wxTimerScheduler only: resets the internal flag indicating that the
// timer is running
void MarkStopped()
{
wxASSERT_MSG( m_isRunning, wxT("stopping non-running timer?") );
m_isRunning = false;
}
private:
bool m_isRunning;
};
// ----------------------------------------------------------------------------
// wxTimerSchedule: information about a single timer, used by wxTimerScheduler
// ----------------------------------------------------------------------------
struct wxTimerSchedule
{
wxTimerSchedule(wxUnixTimerImpl *timer, wxUsecClock_t expiration)
: m_timer(timer),
m_expiration(expiration)
{
}
// the timer itself (we don't own this pointer)
wxUnixTimerImpl *m_timer;
// the time of its next expiration, in usec
wxUsecClock_t m_expiration;
};
// the linked list of all active timers, we keep it sorted by expiration time
using wxTimerList = std::list<wxTimerSchedule>;
// ----------------------------------------------------------------------------
// wxTimerScheduler: class responsible for updating all timers
// ----------------------------------------------------------------------------
class wxTimerScheduler
{
public:
// get the unique timer scheduler instance
static wxTimerScheduler& Get()
{
if ( !ms_instance )
ms_instance = new wxTimerScheduler;
return *ms_instance;
}
// must be called on shutdown to delete the global timer scheduler
static void Shutdown()
{
if ( ms_instance )
{
delete ms_instance;
ms_instance = nullptr;
}
}
// adds timer which should expire at the given absolute time to the list
void AddTimer(wxUnixTimerImpl *timer, wxUsecClock_t expiration);
// remove timer from the list, called automatically from timer dtor
void RemoveTimer(wxUnixTimerImpl *timer);
// the functions below are used by the event loop implementation to monitor
// and notify timers:
// if this function returns true, the time remaining until the next time
// expiration is returned in the provided parameter (always positive or 0)
//
// it returns false if there are no timers
bool GetNext(wxUsecClock_t *remaining) const;
// trigger the timer event for all timers which have expired, return true
// if any did
bool NotifyExpired();
private:
// ctor and dtor are private, this is a singleton class only created by
// Get() and destroyed by Shutdown()
wxTimerScheduler() = default;
~wxTimerScheduler() = default;
// add the given timer schedule to the list in the right place
void DoAddTimer(const wxTimerSchedule& s);
// the list of all currently active timers sorted by expiration
wxTimerList m_timers;
static wxTimerScheduler *ms_instance;
};
#endif // wxUSE_TIMER
#endif // _WX_UNIX_PRIVATE_TIMER_H_

View File

@@ -0,0 +1,69 @@
///////////////////////////////////////////////////////////////////////////////
// Name: wx/unix/private/uilocale.h
// Purpose: Various locale-related helpers used under Unix systems only
// Author: Vadim Zeitlin
// Created: 2021-08-14 (extracted from src/common/intl.cpp)
// Copyright: (c) 2021 Vadim Zeitlin <vadim@wxwidgets.org>
// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
#ifndef _WX_UNIX_PRIVATE_UILOCALE_H_
#define _WX_UNIX_PRIVATE_UILOCALE_H_
#include "wx/string.h"
// get just the language part ("en" in "en_GB")
inline wxString ExtractLang(const wxString& langFull)
{
return langFull.BeforeFirst('_');
}
// get everything else (including the leading '_')
inline wxString ExtractNotLang(const wxString& langFull)
{
size_t pos = langFull.find('_');
if ( pos != wxString::npos )
return langFull.substr(pos);
else
return wxString();
}
const char *wxSetlocaleTryAll(int c, const wxLocaleIdent& lc);
// Extract date format from D_T_FMT value.
wxString wxGetDateFormatOnly(const wxString& fmt);
// Helper class changing the global locale to the one specified by the
// environment variables in its ctor and restoring it in its dtor.
namespace
{
class TempLocaleSetter
{
public:
wxCLANG_WARNING_SUPPRESS(unused-member-function)
explicit TempLocaleSetter(int localeCategory,
const wxString& localeId = wxString())
: m_localeCategory(localeCategory),
m_localeOrig(strdup(setlocale(localeCategory, nullptr)))
{
setlocale(localeCategory, localeId.mb_str());
}
~TempLocaleSetter()
{
setlocale(m_localeCategory, m_localeOrig);
free(m_localeOrig);
}
wxCLANG_WARNING_RESTORE(unused-member-function)
private:
const int m_localeCategory;
char* const m_localeOrig;
wxDECLARE_NO_COPY_CLASS(TempLocaleSetter);
};
} // anonymous namespace
#endif // _WX_UNIX_PRIVATE_UILOCALE_H_

View File

@@ -0,0 +1,97 @@
///////////////////////////////////////////////////////////////////////////////
// Name: wx/unix/private/wakeuppipe.h
// Purpose: Helper class allowing to wake up the main thread.
// Author: Vadim Zeitlin
// Created: 2013-06-09 (extracted from src/unix/evtloopunix.cpp)
// Copyright: (c) 2013 Vadim Zeitlin <vadim@wxwidgets.org>
// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
#ifndef _WX_UNIX_PRIVATE_WAKEUPPIPE_H_
#define _WX_UNIX_PRIVATE_WAKEUPPIPE_H_
#include "wx/unix/pipe.h"
#include "wx/evtloopsrc.h"
// ----------------------------------------------------------------------------
// wxWakeUpPipe: allows to wake up the event loop by writing to it
// ----------------------------------------------------------------------------
// This class is not MT-safe, see wxWakeUpPipeMT below for a wake up pipe
// usable from other threads.
class wxWakeUpPipe : public wxEventLoopSourceHandler
{
public:
// Create and initialize the pipe.
//
// It's the callers responsibility to add the read end of this pipe,
// returned by GetReadFd(), to the code blocking on input.
wxWakeUpPipe();
// Wake up the blocking operation involving this pipe.
//
// It simply writes to the write end of the pipe.
//
// As indicated by its name, this method does no locking and so can be
// called only from the main thread.
void WakeUpNoLock();
// Same as WakeUp() but without locking.
// Return the read end of the pipe.
int GetReadFd() { return m_pipe[wxPipe::Read]; }
// Implement wxEventLoopSourceHandler pure virtual methods
virtual void OnReadWaiting() override;
virtual void OnWriteWaiting() override { }
virtual void OnExceptionWaiting() override { }
private:
wxPipe m_pipe;
// This flag is set to true after writing to the pipe and reset to false
// after reading from it in the main thread. Having it allows us to avoid
// overflowing the pipe with too many writes if the main thread can't keep
// up with reading from it.
bool m_pipeIsEmpty;
};
// ----------------------------------------------------------------------------
// wxWakeUpPipeMT: thread-safe version of wxWakeUpPipe
// ----------------------------------------------------------------------------
// This class can be used from multiple threads, i.e. its WakeUp() can be
// called concurrently.
class wxWakeUpPipeMT : public wxWakeUpPipe
{
#if wxUSE_THREADS
public:
wxWakeUpPipeMT() = default;
// Thread-safe wrapper around WakeUpNoLock(): can be called from another
// thread to wake up the main one.
void WakeUp()
{
wxCriticalSectionLocker lock(m_pipeLock);
WakeUpNoLock();
}
virtual void OnReadWaiting() override
{
wxCriticalSectionLocker lock(m_pipeLock);
wxWakeUpPipe::OnReadWaiting();
}
private:
// Protects access to m_pipeIsEmpty.
wxCriticalSection m_pipeLock;
#endif // wxUSE_THREADS
};
#endif // _WX_UNIX_PRIVATE_WAKEUPPIPE_H_

View File

@@ -0,0 +1,67 @@
///////////////////////////////////////////////////////////////////////////////
// Name: wx/unix/private/x11ptr.h
// Purpose: Simple RAII helper for calling XFree() automatically
// Author: Vadim Zeitlin
// Created: 2025-04-28
// Copyright: (c) 2025 Vadim Zeitlin <vadim@wxwidgets.org>
// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
#ifndef _WX_UNIX_PRIVATE_X11PTR_H_
#define _WX_UNIX_PRIVATE_X11PTR_H_
#include <X11/Xlib.h>
// ----------------------------------------------------------------------------
// Convenience class for calling XFree() automatically
// ----------------------------------------------------------------------------
template <typename T>
class wxX11Ptr
{
public:
wxX11Ptr() = default;
explicit wxX11Ptr(const T *p) : m_ptr(const_cast<T*>(p)) { }
wxX11Ptr(wxX11Ptr&& other) : m_ptr(other.m_ptr) { other.m_ptr = nullptr; }
~wxX11Ptr() { reset(); }
wxX11Ptr& operator=(wxX11Ptr&& other)
{
if ( &other != this )
{
reset(other.m_ptr);
other.m_ptr = nullptr;
}
return *this;
}
const T* get() const { return m_ptr; }
operator const T*() const { return m_ptr; }
T* operator->() const { return m_ptr; }
void reset(T* p = nullptr)
{
if ( m_ptr )
XFree(m_ptr);
m_ptr = p;
}
T** Out()
{
wxASSERT_MSG( !m_ptr, wxS("Can't reuse the same object.") );
return &m_ptr;
}
private:
// We store the pointer as non-const because it avoids casts in the dtor
// and Out(), but it's actually always handled as a const one.
T* m_ptr = nullptr;
wxDECLARE_NO_COPY_CLASS(wxX11Ptr);
};
#endif // _WX_UNIX_PRIVATE_X11PTR_H_

View File

@@ -0,0 +1,159 @@
/////////////////////////////////////////////////////////////////////////////
// Name: wx/unix/sound.h
// Purpose: wxSound class
// Author: Julian Smart, Vaclav Slavik
// Created: 25/10/98
// Copyright: (c) Julian Smart, Vaclav Slavik
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef _WX_SOUND_H_
#define _WX_SOUND_H_
#include "wx/defs.h"
#if wxUSE_SOUND
#include "wx/object.h"
// ----------------------------------------------------------------------------
// wxSound: simple audio playback class
// ----------------------------------------------------------------------------
class WXDLLIMPEXP_FWD_CORE wxSoundBackend;
class WXDLLIMPEXP_FWD_CORE wxSound;
class WXDLLIMPEXP_FWD_BASE wxDynamicLibrary;
/// Sound data, as loaded from .wav file:
class WXDLLIMPEXP_CORE wxSoundData
{
public:
wxSoundData() : m_refCnt(1) {}
void IncRef();
void DecRef();
// .wav header information:
unsigned m_channels; // num of channels (mono:1, stereo:2)
unsigned m_samplingRate;
unsigned m_bitsPerSample; // if 8, then m_data contains unsigned 8bit
// samples (wxUint8), if 16 then signed 16bit
// (wxInt16)
unsigned m_samples; // length in samples:
// wave data:
size_t m_dataBytes;
wxUint8 *m_data; // m_dataBytes bytes of data
private:
~wxSoundData();
unsigned m_refCnt;
wxUint8 *m_dataWithHeader; // ditto, but prefixed with .wav header
friend class wxSound;
};
/// Simple sound class:
class WXDLLIMPEXP_CORE wxSound : public wxSoundBase
{
public:
wxSound();
wxSound(const wxString& fileName, bool isResource = false);
wxSound(size_t size, const void* data);
virtual ~wxSound();
// Create from resource or file
bool Create(const wxString& fileName, bool isResource = false);
// Create from data
bool Create(size_t size, const void* data);
bool IsOk() const { return m_data != nullptr; }
// Stop playing any sound
static void Stop();
// Returns true if a sound is being played
static bool IsPlaying();
// for internal use
static void UnloadBackend();
protected:
bool DoPlay(unsigned flags) const override;
static void EnsureBackend();
void Free();
bool LoadWAV(const void* data, size_t length, bool copyData);
static wxSoundBackend *ms_backend;
#if wxUSE_LIBSDL && wxUSE_PLUGINS
// FIXME - temporary, until we have plugins architecture
static wxDynamicLibrary *ms_backendSDL;
#endif
private:
wxSoundData *m_data;
};
// ----------------------------------------------------------------------------
// wxSoundBackend:
// ----------------------------------------------------------------------------
// This is interface to sound playing implementation. There are multiple
// sound architectures in use on Unix platforms and wxWidgets can use several
// of them for playback, depending on their availability at runtime; hence
// the need for backends. This class is for use by wxWidgets and people writing
// additional backends only, it is _not_ for use by applications!
// Structure that holds playback status information
struct wxSoundPlaybackStatus
{
// playback is in progress
bool m_playing;
// main thread called wxSound::Stop()
bool m_stopRequested;
};
// Audio backend interface
class WXDLLIMPEXP_CORE wxSoundBackend
{
public:
virtual ~wxSoundBackend() = default;
// Returns the name of the backend (e.g. "Open Sound System")
virtual wxString GetName() const = 0;
// Returns priority (higher priority backends are tried first)
virtual int GetPriority() const = 0;
// Checks if the backend's audio system is available and the backend can
// be used for playback
virtual bool IsAvailable() const = 0;
// Returns true if the backend is capable of playing sound asynchronously.
// If false, then wxWidgets creates a playback thread and handles async
// playback, otherwise it is left up to the backend (will usually be more
// effective).
virtual bool HasNativeAsyncPlayback() const = 0;
// Plays the sound. flags are same flags as those passed to wxSound::Play.
// The function should periodically check the value of
// status->m_stopRequested and terminate if it is set to true (it may
// be modified by another thread)
virtual bool Play(wxSoundData *data, unsigned flags,
volatile wxSoundPlaybackStatus *status) = 0;
// Stops playback (if something is played).
virtual void Stop() = 0;
// Returns true if the backend is playing anything at the moment.
// (This method is never called for backends that don't support async
// playback.)
virtual bool IsPlaying() const = 0;
};
#endif // wxUSE_SOUND
#endif // _WX_SOUND_H_

View File

@@ -0,0 +1,97 @@
///////////////////////////////////////////////////////////////////////////////
// Name: wx/unix/stackwalk.h
// Purpose: declaration of wxStackWalker for Unix
// Author: Vadim Zeitlin
// Created: 2005-01-19
// Copyright: (c) 2005 Vadim Zeitlin <vadim@wxwidgets.org>
// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
#ifndef _WX_UNIX_STACKWALK_H_
#define _WX_UNIX_STACKWALK_H_
// ----------------------------------------------------------------------------
// wxStackFrame
// ----------------------------------------------------------------------------
class WXDLLIMPEXP_BASE wxStackFrame : public wxStackFrameBase
{
friend class wxStackWalker;
public:
// arguments are the stack depth of this frame, its address and the return
// value of backtrace_symbols() for it
//
// NB: we don't copy syminfo pointer so it should have lifetime at least as
// long as ours
wxStackFrame(size_t level = 0, void *address = nullptr, const char *syminfo = nullptr)
: wxStackFrameBase(level, address)
{
m_syminfo = syminfo;
}
protected:
virtual void OnGetName() override;
// optimized for the 2 step initialization done by wxStackWalker
void Set(const wxString &name, const wxString &filename, const char* syminfo,
size_t level, size_t numLine, void *address)
{
m_level = level;
m_name = name;
m_filename = filename;
m_syminfo = syminfo;
m_line = numLine;
m_address = address;
}
private:
const char *m_syminfo;
};
// ----------------------------------------------------------------------------
// wxStackWalker
// ----------------------------------------------------------------------------
class WXDLLIMPEXP_BASE wxStackWalker : public wxStackWalkerBase
{
public:
// we need the full path to the program executable to be able to use
// addr2line, normally we can retrieve it from wxTheApp but if wxTheApp
// doesn't exist or doesn't have the correct value, the path may be given
// explicitly
wxStackWalker(const char *argv0 = nullptr)
{
ms_exepath = wxString::FromAscii(argv0);
}
~wxStackWalker()
{
FreeStack();
}
virtual void Walk(size_t skip = 1, size_t maxDepth = wxSTACKWALKER_MAX_DEPTH) override;
#if wxUSE_ON_FATAL_EXCEPTION
virtual void WalkFromException(size_t maxDepth = wxSTACKWALKER_MAX_DEPTH) override { Walk(2, maxDepth); }
#endif // wxUSE_ON_FATAL_EXCEPTION
static const wxString& GetExePath() { return ms_exepath; }
// these two may be used to save the stack at some point (fast operation)
// and then process it later (slow operation)
void SaveStack(size_t maxDepth);
void ProcessFrames(size_t skip);
void FreeStack();
private:
int InitFrames(wxStackFrame *arr, size_t n, void **addresses, char **syminfo);
static wxString ms_exepath;
static void *ms_addresses[];
static char **ms_symbols;
static int m_depth;
};
#endif // _WX_UNIX_STACKWALK_H_

View File

@@ -0,0 +1,66 @@
///////////////////////////////////////////////////////////////////////////////
// Name: wx/unix/stdpaths.h
// Purpose: wxStandardPaths for Unix systems
// Author: Vadim Zeitlin
// Created: 2004-10-19
// Copyright: (c) 2004 Vadim Zeitlin <vadim@wxwidgets.org>
// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
#ifndef _WX_UNIX_STDPATHS_H_
#define _WX_UNIX_STDPATHS_H_
// ----------------------------------------------------------------------------
// wxStandardPaths
// ----------------------------------------------------------------------------
class WXDLLIMPEXP_BASE wxStandardPaths : public wxStandardPathsBase
{
public:
// tries to determine the installation prefix automatically (Linux only right
// now) and returns /usr/local if it failed
void DetectPrefix();
// set the program installation directory which is /usr/local by default
//
// under some systems (currently only Linux) the program directory can be
// determined automatically but for portable programs you should always set
// it explicitly
void SetInstallPrefix(const wxString& prefix);
// get the program installation prefix
//
// if the prefix had been previously by SetInstallPrefix, returns that
// value, otherwise calls DetectPrefix()
wxString GetInstallPrefix() const;
// implement base class pure virtuals
virtual wxString GetExecutablePath() const override;
virtual wxString GetConfigDir() const override;
virtual wxString GetUserConfigDir() const override;
virtual wxString GetDataDir() const override;
virtual wxString GetLocalDataDir() const override;
virtual wxString GetUserDataDir() const override;
virtual wxString GetPluginsDir() const override;
virtual wxString GetLocalizedResourcesDir(const wxString& lang,
ResourceCat category) const override;
virtual wxString GetSharedLibrariesDir() const override;
#ifndef __VMS
virtual wxString GetUserDir(Dir userDir) const override;
#endif
virtual wxString MakeConfigFileName(const wxString& basename,
ConfigFileConv conv = ConfigFileConv_Ext
) const override;
protected:
// Ctor is protected, use wxStandardPaths::Get() instead of instantiating
// objects of this class directly.
wxStandardPaths() = default;
private:
wxString m_prefix;
};
#endif // _WX_UNIX_STDPATHS_H_

View File

@@ -0,0 +1,39 @@
/////////////////////////////////////////////////////////////////////////
// File: wx/unix/taskbarx11.h
// Purpose: Defines wxTaskBarIcon class for most common X11 desktops
// Author: Vaclav Slavik
// Created: 04/04/2003
// Copyright: (c) Vaclav Slavik, 2003
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////
#ifndef _WX_UNIX_TASKBAR_H_
#define _WX_UNIX_TASKBAR_H_
class WXDLLIMPEXP_FWD_CORE wxTaskBarIconArea;
class WXDLLIMPEXP_CORE wxTaskBarIcon: public wxTaskBarIconBase
{
public:
wxTaskBarIcon();
virtual ~wxTaskBarIcon();
// Accessors:
bool IsOk() const;
bool IsIconInstalled() const;
// Operations:
bool SetIcon(const wxBitmapBundle& icon, const wxString& tooltip = wxEmptyString) override;
bool RemoveIcon() override;
bool PopupMenu(wxMenu *menu) override;
protected:
wxTaskBarIconArea *m_iconWnd;
private:
void OnDestroy(wxWindowDestroyEvent&);
wxDECLARE_DYNAMIC_CLASS(wxTaskBarIcon);
};
#endif // _WX_UNIX_TASKBAR_H_

View File

@@ -0,0 +1,87 @@
/////////////////////////////////////////////////////////////////////////////
// Name: wx/unix/utilsx11.h
// Purpose: Miscellaneous X11 functions
// Author: Mattia Barbon, Vaclav Slavik, Vadim Zeitlin
// Created: 25.03.02
// Copyright: (c) wxWidgets team
// (c) 2010 Vadim Zeitlin
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifndef _WX_UNIX_UTILSX11_H_
#define _WX_UNIX_UTILSX11_H_
#include "wx/defs.h"
#include "wx/gdicmn.h"
#include <X11/Xlib.h>
// NB: Content of this header is for wxWidgets' private use! It is not
// part of public API and may be modified or even disappear in the future!
#if defined(__WXGTK__) || defined(__WXX11__) || defined(__WXQT__)
#if defined(__WXGTK__) || defined(__WXQT__)
typedef void WXDisplay;
typedef void* WXWindow;
#endif
typedef unsigned long WXKeySym;
int wxCharCodeXToWX(WXKeySym keySym);
WXKeySym wxCharCodeWXToX(int id);
#ifdef __WXX11__
int wxUnicodeCharXToWX(WXKeySym keySym);
#endif
class wxIconBundle;
void wxSetIconsX11( WXDisplay* display, WXWindow window,
const wxIconBundle& ib );
enum wxX11FullScreenMethod
{
wxX11_FS_AUTODETECT = 0,
wxX11_FS_WMSPEC,
wxX11_FS_KDE,
wxX11_FS_GENERIC
};
wxX11FullScreenMethod wxGetFullScreenMethodX11(WXDisplay* display,
WXWindow rootWindow);
void wxSetFullScreenStateX11(WXDisplay* display, WXWindow rootWindow,
WXWindow window, bool show, wxRect *origSize,
wxX11FullScreenMethod method);
// Class wrapping X11 Display: it opens it in ctor and closes it in dtor.
class wxX11Display
{
public:
wxX11Display() { m_dpy = XOpenDisplay(nullptr); }
~wxX11Display() { if ( m_dpy ) XCloseDisplay(m_dpy); }
// Pseudo move ctor: steals the open display from the other object.
explicit wxX11Display(wxX11Display& display)
{
m_dpy = display.m_dpy;
display.m_dpy = nullptr;
}
operator Display *() const { return m_dpy; }
// Using DefaultRootWindow() with an object of wxX11Display class doesn't
// compile because it is a macro which tries to cast wxX11Display so
// provide a convenient helper.
Window DefaultRoot() const { return DefaultRootWindow(m_dpy); }
private:
Display *m_dpy;
wxDECLARE_NO_COPY_CLASS(wxX11Display);
};
#endif // __WXGTK__, __WXX11__
#endif // _WX_UNIX_UTILSX11_H_