From 810b34241110367a5737e0ff6bd1fffa5d7286a0 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 28 Feb 2021 23:53:25 +0100 Subject: [PATCH 1/5] Avoid useless check for GTK_CHECK_VERSION Just use it inside the existing check for GTK itself. No real changes. --- src/unix/utilsx11.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/unix/utilsx11.cpp b/src/unix/utilsx11.cpp index aabd8912ca..58a5a0f74f 100644 --- a/src/unix/utilsx11.cpp +++ b/src/unix/utilsx11.cpp @@ -48,13 +48,11 @@ #endif GdkWindow* wxGetTopLevelGDK(); GtkWidget* wxGetTopLevelGTK(); -#endif -#ifdef GTK_CHECK_VERSION #if GTK_CHECK_VERSION(3,4,0) #define wxHAS_GETKEYSTATE_GTK #endif //GTK+ 3.4 -#endif +#endif // GTK // Only X11 backend is supported for wxGTK here (GTK < 2 has no others) #if !defined(__WXGTK__) || \ From f11db09e9b24052c9abe0892e4e485ab463a0b66 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 28 Feb 2021 23:55:43 +0100 Subject: [PATCH 2/5] Ad wxHAS_X11_SUPPORT helper to simplify the code This is much more readable than the existing (and now duplicated) __WXGTK__ || !__WXGTK20__ || GDK_WINDOWING_X11 check. No real changes. --- src/unix/utilsx11.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/unix/utilsx11.cpp b/src/unix/utilsx11.cpp index 58a5a0f74f..97efa620ee 100644 --- a/src/unix/utilsx11.cpp +++ b/src/unix/utilsx11.cpp @@ -45,6 +45,7 @@ #endif #ifdef GDK_WINDOWING_X11 #include +#define wxHAS_X11_SUPPORT #endif GdkWindow* wxGetTopLevelGDK(); GtkWidget* wxGetTopLevelGTK(); @@ -52,11 +53,12 @@ GtkWidget* wxGetTopLevelGTK(); #if GTK_CHECK_VERSION(3,4,0) #define wxHAS_GETKEYSTATE_GTK #endif //GTK+ 3.4 +#else +// When not using GTK we always use X11, as we don't support anything else. +#define wxHAS_X11_SUPPORT #endif // GTK -// Only X11 backend is supported for wxGTK here (GTK < 2 has no others) -#if !defined(__WXGTK__) || \ - (!defined(__WXGTK20__) || defined(GDK_WINDOWING_X11)) +#ifdef wxHAS_X11_SUPPORT // Various X11 Atoms used in this file: static Atom _NET_WM_STATE = 0; @@ -2593,7 +2595,7 @@ static bool wxGetKeyStateX11(wxKeyCode key) return (key_vector[keyCode >> 3] & (1 << (keyCode & 7))) != 0; } -#endif // !defined(__WXGTK__) || defined(GDK_WINDOWING_X11) +#endif // wxHAS_X11_SUPPORT // We need to use GDK functions when using wxGTK with a non-X11 backend, the // X11 code above can't work in this case. @@ -2647,8 +2649,7 @@ bool wxGetKeyState(wxKeyCode key) } #endif // GTK+ 3.4+ -#if !defined(__WXGTK__) || \ - (!defined(__WXGTK20__) || defined(GDK_WINDOWING_X11)) +#ifdef wxHAS_X11_SUPPORT return wxGetKeyStateX11(key); #endif From fa3cf062732e5a41f6f0c971d2b4d39159efb190 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 28 Feb 2021 23:59:51 +0100 Subject: [PATCH 3/5] Avoid possible "unreachable statement" warnings Don't return unconditionally before another return. Somehow gcc doesn't warn about it, but other compilers (and static analyzer tools) definitely do. No real changes. --- src/unix/utilsx11.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/unix/utilsx11.cpp b/src/unix/utilsx11.cpp index 97efa620ee..41ccf8dbaf 100644 --- a/src/unix/utilsx11.cpp +++ b/src/unix/utilsx11.cpp @@ -2650,7 +2650,8 @@ bool wxGetKeyState(wxKeyCode key) #endif // GTK+ 3.4+ #ifdef wxHAS_X11_SUPPORT - return wxGetKeyStateX11(key); + if ( wxGetKeyStateX11(key) ) + return true; #endif return false; From a8e918727a8a3796e359192b721f9aa262ae98a8 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 1 Mar 2021 13:06:17 +0100 Subject: [PATCH 4/5] Only include X11 headers when we actually need X11 support These headers may not be available at all when building wxGTK with Wayland-only GTK version. --- src/unix/utilsx11.cpp | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/src/unix/utilsx11.cpp b/src/unix/utilsx11.cpp index 41ccf8dbaf..2b5fa89732 100644 --- a/src/unix/utilsx11.cpp +++ b/src/unix/utilsx11.cpp @@ -13,8 +13,6 @@ // for compilers that support precompilation, includes "wx.h". #include "wx/wxprec.h" -#include "wx/unix/utilsx11.h" - #ifndef WX_PRECOMP #include "wx/log.h" #include "wx/app.h" @@ -26,16 +24,6 @@ #include "wx/apptrait.h" #include "wx/private/launchbrowser.h" -#ifdef __VMS -#pragma message disable nosimpint -#endif -#include -#include -#include -#ifdef __VMS -#pragma message enable nosimpint -#endif - #ifdef __WXGTK__ #ifdef __WXGTK20__ #include "wx/gtk/private/wrapgtk.h" @@ -60,6 +48,17 @@ GtkWidget* wxGetTopLevelGTK(); #ifdef wxHAS_X11_SUPPORT +#include "wx/unix/utilsx11.h" + +#ifdef __VMS +#pragma message disable nosimpint +#endif +#include +#include +#ifdef __VMS +#pragma message enable nosimpint +#endif + // Various X11 Atoms used in this file: static Atom _NET_WM_STATE = 0; static Atom _NET_WM_STATE_FULLSCREEN = 0; From 9a84e0b25e2602e55aa24833989cb1fbda5b3308 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 1 Mar 2021 13:09:06 +0100 Subject: [PATCH 5/5] Don't require X11 in CMake builds using Wayland-only GTK X11 headers and libraries are only required if we're actually using X11 which may not be the case. This allows to build wxGTK on the systems using Wayland-only GTK. --- build/cmake/modules/FindGTK3.cmake | 1 + build/cmake/toolkit.cmake | 15 +++++++++------ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/build/cmake/modules/FindGTK3.cmake b/build/cmake/modules/FindGTK3.cmake index 5c35029a81..8fee6f9f41 100644 --- a/build/cmake/modules/FindGTK3.cmake +++ b/build/cmake/modules/FindGTK3.cmake @@ -46,5 +46,6 @@ endif () include(CheckSymbolExists) set(CMAKE_REQUIRED_INCLUDES ${GTK3_INCLUDE_DIRS}) check_symbol_exists(GDK_WINDOWING_WAYLAND "gdk/gdk.h" wxHAVE_GDK_WAYLAND) +check_symbol_exists(GDK_WINDOWING_X11 "gdk/gdk.h" wxHAVE_GDK_X11) include(FindPackageHandleStandardArgs) FIND_PACKAGE_HANDLE_STANDARD_ARGS(GTK3 DEFAULT_MSG GTK3_INCLUDE_DIRS GTK3_LIBRARIES VERSION_OK) diff --git a/build/cmake/toolkit.cmake b/build/cmake/toolkit.cmake index 577d3c8661..bcbbd75491 100644 --- a/build/cmake/toolkit.cmake +++ b/build/cmake/toolkit.cmake @@ -69,12 +69,6 @@ set(wxTOOLKIT_INCLUDE_DIRS) set(wxTOOLKIT_LIBRARIES) set(wxTOOLKIT_VERSION) -if(UNIX AND NOT APPLE AND NOT WIN32) - find_package(X11 REQUIRED) - list(APPEND wxTOOLKIT_INCLUDE_DIRS ${X11_INCLUDE_DIR}) - list(APPEND wxTOOLKIT_LIBRARIES ${X11_LIBRARIES}) -endif() - if(WXGTK) if(WXGTK4) set(gtk_lib GTK4) @@ -121,6 +115,15 @@ if(WXGTK) endif() endif() +# We need X11 for non-GTK Unix ports (X11, Motif) and for GTK with X11 +# support, but not for Wayland-only GTK (which is why we have to do this after +# find_package(GTKx) above, as this is what sets wxHAVE_GDK_X11). +if(UNIX AND NOT APPLE AND NOT WIN32 AND (WXX11 OR WXMOTIF OR (WXGTK AND wxHAVE_GDK_X11))) + find_package(X11 REQUIRED) + list(APPEND wxTOOLKIT_INCLUDE_DIRS ${X11_INCLUDE_DIR}) + list(APPEND wxTOOLKIT_LIBRARIES ${X11_LIBRARIES}) +endif() + if(WXQT) set(QT_COMPONENTS Core Widgets Gui OpenGL Test) foreach(QT_COMPONENT ${QT_COMPONENTS})