From 400ce8b5828802e466c29b864512b476c2bce7f4 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 25 Dec 2023 21:17:17 +0100 Subject: [PATCH] Return null from wxGetX11Display() when using Wayland Returning Wayland display pointer as XDisplay was really confusing and resulted in more weird crashes than just using null pointer directly. --- include/wx/utils.h | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/include/wx/utils.h b/include/wx/utils.h index f63215f5b3..47c5e356e6 100644 --- a/include/wx/utils.h +++ b/include/wx/utils.h @@ -763,19 +763,24 @@ void WXDLLIMPEXP_CORE wxGetMousePosition( int* x, int* y ); wxDisplayType type; }; WXDLLIMPEXP_CORE wxDisplayInfo wxGetDisplayInfo(); + + inline struct _XDisplay *wxGetX11Display() + { + const auto& info = wxGetDisplayInfo(); + return info.type == wxDisplayX11 ? (_XDisplay*)info.dpy : nullptr; + } #endif #ifdef __X__ WXDLLIMPEXP_CORE WXDisplay *wxGetDisplay(); WXDLLIMPEXP_CORE bool wxSetDisplay(const wxString& display_name); WXDLLIMPEXP_CORE wxString wxGetDisplayName(); -#endif // X or GTK+ -// use this function instead of the functions above in implementation code -inline struct _XDisplay *wxGetX11Display() -{ - return (_XDisplay *)wxGetDisplay(); -} + inline struct _XDisplay *wxGetX11Display() + { + return (_XDisplay *)wxGetDisplay(); + } +#endif // X #endif // X11 || wxGTK