Go to file
Joan Bruguera Micó 1fb96180f4 Handle map/unmap events on Wayland's wxGLCanvasEGL
Fixes hiding a wxGLCanvas on Wayland, either directly (`->Show(false)`)
or indirectly (e.g. when it is contained in a wxNotebook).

On Wayland, unlike on X11, to show the canvas on the screen, we need to
create a Wayland subsurface. This subsurface is detached from the GTK
widget associated to the canvas, thus it is not automatically mapped or
unmapped when the associated GTK widget is.
Rather, we need to manually keep it in sync with the widget's state.

Knowing what has to be done to map and unmap the canvas, while dealing
with edge cases properly, is not easy to someone not used to Wayland.
When the canvas is mapped, we have this graph of resources:

  EGL Surface (m_surface)
             |
             |
             v
  wl_egl window (m_wlEGLWindow)
             |
             |
             v
     Canvas wl_surface         GDK's toplevel window wl_surface
       (m_wlSurface)        (gdk_wayland_window_get_wl_surface(w))
              \                   which is shown to the user
               \                         ^
                \                       /
                 \                     /
                  v                   /
          Subsurface (m_wlSubsurface) to overlay
          the canvas onto the toplevel window

A simple way would be to destroy everything (m_surface, m_wlEGLWindow,
m_wlSurface, m_wlSubsurface) on unmap, and re-create it again on map.
Inefficiencies aside, this mostly works. However, it can mess with the
current OpenGL context. For example, suppose we have a (fragile)
program that places a canvas inside one of wxNotebook's tabs, and makes
the OpenGL context current only once at startup (e.g. on wxEVT_SHOW).
Switching between tabs will destroy and re-create the EGL Surface, so
the canvas will not be properly rendered when going back to its tab.

So we need to be smarter, and find some way to hide the subsurface
instead. The obvious way would be to unmap the canvas wl_surface
(m_wlSurface), as according to the Wayland spec., "a sub-surface is
hidden [...] if a NULL wl_buffer is applied [to the canvas surface]."
(https://wayland.freedesktop.org/docs/html/apa.html#protocol-spec-wl_subsurface)
However, as far as I can tell, this can't be done. There's no API to
hide an wl_egl window, and directly applying a NULL wl_buffer to the
canvas surface initially hides it, but seems to breaks the associated
window so that it crashes when one attempts to show it again.

So what remains, is destroying the overlay subsurface (m_wlSubsurface).
When doing it, to the spec, "the wl_surface is unmapped immediately.".

And not only does this work, but it also deals with the annoying fact
that on current GTK3 versions, when the GDK's toplevel window is
unmapped, its wl_surface is not just unmapped, but entirely destroyed.
(Side note: This may not have been intended, and has been changed for
GTK4, see: https://gitlab.gnome.org/GNOME/gtk/-/commit/5d3cec5441ca)
So we'd have to re-create the subsurface because of this anyway.

So, this works nicely, and as far as I can tell (documentation is a bit
scarce), there's no problem to leaving m_wlSurface (and its associated
m_wlEGLWindow and m_surface) unmapped in this way.

See #22580, #23835.

(cherry picked from commit 952de605f622cc7a3c30257365046ecd1a307808)
2023-09-22 16:37:04 +02:00
.circleci Add a Fedora CI build using Circle CI 2022-08-14 17:17:50 +02:00
.github Exclude some bakefiles from Whitespace code check too 2023-07-25 16:10:39 -04:00
3rdparty Fix building tests with MSVS 2022 in C++20 mode with /permissive- 2022-01-04 23:13:39 +01:00
art Add wxART_QUIT icon to Tango art provider 2022-03-20 21:52:25 +01:00
build Pin httpbin to the previously working 0.7.0 version 2023-08-24 03:40:12 +02:00
demos Update version to 3.2.3 2023-02-10 15:09:17 +01:00
distrib Remove setup0.h files 2021-01-31 19:02:56 +01:00
docs Handle map/unmap events on Wayland's wxGLCanvasEGL 2023-09-22 16:37:04 +02:00
include Handle map/unmap events on Wayland's wxGLCanvasEGL 2023-09-22 16:37:04 +02:00
interface Document more macOS-only wxTextCtrl methods 2023-09-21 22:59:49 +02:00
lib Add support for PCRE2 for OpenVMS 2021-08-20 10:00:17 +02:00
locale Update Brazilian Portuguese translations for 3.2.2 2023-03-29 12:32:23 +02:00
misc Use grep instead of fgrep and egrep 2023-05-10 23:48:09 +02:00
samples Fix crash due to logging bug in the event sample 2023-09-21 22:57:29 +02:00
src Handle map/unmap events on Wayland's wxGLCanvasEGL 2023-09-22 16:37:04 +02:00
tests Fix DynamicLibrary::Load() test for less common platforms 2023-08-24 03:40:12 +02:00
utils Add support for multi-resolution bitmaps to wxrc 2023-08-24 03:40:12 +02:00
.cirrus.yml CI: ignore CircleCI config files from all other CIs 2023-04-04 17:18:02 +02:00
.editorconfig
.git-blame-ignore-revs Don't account for another commit with whitespace-only changes 2022-07-02 22:17:42 +02:00
.gitattributes Mark MSVS *.vcxproj.filters files as using CR LF as well 2021-11-24 12:13:12 +01:00
.gitignore updating gitignore, adding workspace to wxcocoa_in 2021-11-22 18:03:06 +01:00
.gitmodules Add simple wxBitmapBundle::FromSVG() implementation using NanoSVG 2021-10-05 16:06:43 +01:00
.mailmap Update mailmap 2022-05-30 19:07:53 +02:00
acinclude.m4
aclocal.m4
appveyor.yml CI: ignore CircleCI config files from all other CIs 2023-04-04 17:18:02 +02:00
autoconf_inc.m4 Update to bakefile 0.2.13 to fix DLL directory creation 2022-04-23 23:11:31 +02:00
autogen.sh
CMakeLists.txt Update copyright years to 2023 in 3.2 branch too 2023-01-03 04:21:29 +01:00
config.guess Update config.{guess,sub} scripts to latest versions 2021-03-17 09:53:58 -07:00
config.sub Update config.{guess,sub} scripts to latest versions 2021-03-17 09:53:58 -07:00
configure Add support for building WebView with libwebkit2gtk-4.1 2023-07-22 23:46:32 +02:00
configure.in Add support for building WebView with libwebkit2gtk-4.1 2023-07-22 23:46:32 +02:00
descrip.mms
install-sh
Makefile.in Use grep instead of fgrep and egrep 2023-05-10 23:48:09 +02:00
mkinstalldirs
README-GIT.md Remove setup0.h files 2021-01-31 19:02:56 +01:00
README.md Increase the last tested clang version to 14 2022-04-27 23:44:16 +02:00
regen
setup.h_vms Remove checks for [v]snprintf() and vsscanf() declarations 2022-04-14 00:33:51 +02:00
setup.h.in Fix wxKeyEvent::GetKeyCode() for non-US keyboard layouts 2023-04-30 15:21:43 +02:00
version-script.in Handle map/unmap events on Wayland's wxGLCanvasEGL 2023-09-22 16:37:04 +02:00
wx-config-inplace.in
wx-config.in Fix using generated wx-config in CMake builds 2023-06-12 20:49:10 +02:00
wxwidgets.props Provide more details in the error message from wxwidgets.props 2022-03-28 00:03:46 +01:00
wxwin.m4 Add serial number to wxwin.m4 2022-10-07 02:06:10 +02:00

About

wxWidgets is a free and open source cross-platform C++ framework for writing advanced GUI applications using native controls.

wxWidgets Logo

wxWidgets allows you to write native-looking GUI applications for all the major desktop platforms and also helps with abstracting the differences in the non-GUI aspects between them. It is free for the use in both open source and commercial applications, comes with the full, easy to read and modify, source and extensive documentation and a collection of more than a hundred examples. You can learn more about wxWidgets at https://www.wxwidgets.org/ and read its documentation online at https://docs.wxwidgets.org/

Platforms

AppVeyor Unix (make) Unix (CMake) MSW (MSVC) MSW (gcc) Mac OSS-Fuzz

This version of wxWidgets supports the following primary platforms:

  • Windows XP, Vista, 7, 8, 10 and 11 (32/64 bits).
  • Most Unix variants using the GTK+ toolkit (version 2.6 or newer or 3.x).
  • macOS (10.10 or newer) using Cocoa under both amd64 and ARM platforms.

Most popular C++ compilers are supported including but not limited to:

  • Microsoft Visual C++ 2005 or later (up to 2022).
  • g++ 4 or later (up to 12), including MinGW/MinGW-64/TDM under Windows.
  • Clang (up to 14).
  • Intel icc compiler.
  • Oracle (ex-Sun) CC.

Licence

wxWidgets licence is a modified version of LGPL explicitly allowing not distributing the sources of an application using the library even in the case of static linking.

Building

For building the library, please see platform-specific documentation under docs/<port> directory, e.g. here are the instructions for wxGTK, wxMSW and wxOSX.

If you're building the sources checked out from Git, and not from a released version, please see these additional Git-specific notes.

Further information

If you are looking for community support, you can get it from

Commercial support is also available.

Finally, keep in mind that wxWidgets is an open source project collaboratively developed by its users and your contributions to it are always welcome. Please check our guidelines if you'd like to do it.

Have fun!

The wxWidgets Team.