Skip to content

Commit 4356c17

Browse files
fix X11 access on wayland (isl-org#7209)
* fix X11 access under Wayland * show glewInit error details * ignore GLEW_ERROR_NO_GLX_DISPLAY as not required on Wayland --------- Co-authored-by: Christian Rauch <Rauch.Christian@gmx.de>
1 parent 33e85b9 commit 4356c17

File tree

2 files changed

+27
-11
lines changed

2 files changed

+27
-11
lines changed

cpp/open3d/visualization/gui/NativeLinux.cpp

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "Application.h"
1111
#include "Native.h"
1212
#define GLFW_EXPOSE_NATIVE_X11 1
13+
#define GLFW_EXPOSE_NATIVE_WAYLAND 1
1314
#include <GLFW/glfw3native.h>
1415
#include <memory.h>
1516

@@ -18,20 +19,31 @@ namespace visualization {
1819
namespace gui {
1920

2021
void* GetNativeDrawable(GLFWwindow* glfw_window) {
21-
return (void*)glfwGetX11Window(glfw_window);
22+
const int platform = glfwGetPlatform();
23+
if (platform == GLFW_PLATFORM_X11) {
24+
return (void*)glfwGetX11Window(glfw_window);
25+
} else if (platform == GLFW_PLATFORM_WAYLAND) {
26+
return (void*)glfwGetWaylandWindow(glfw_window);
27+
} else {
28+
return nullptr;
29+
}
2230
}
2331

2432
void PostNativeExposeEvent(GLFWwindow* glfw_window) {
25-
Display* d = glfwGetX11Display();
26-
auto x11win = glfwGetX11Window(glfw_window);
33+
const int platform = glfwGetPlatform();
2734

28-
XEvent e;
29-
memset(&e, 0, sizeof(e));
30-
e.type = Expose;
31-
e.xexpose.window = x11win;
35+
if (platform == GLFW_PLATFORM_X11) {
36+
Display* d = glfwGetX11Display();
37+
auto x11win = glfwGetX11Window(glfw_window);
3238

33-
XSendEvent(d, x11win, False, ExposureMask, &e);
34-
XFlush(d);
39+
XEvent e;
40+
memset(&e, 0, sizeof(e));
41+
e.type = Expose;
42+
e.xexpose.window = x11win;
43+
44+
XSendEvent(d, x11win, False, ExposureMask, &e);
45+
XFlush(d);
46+
}
3547
}
3648

3749
void ShowNativeAlert(const char* message) {

cpp/open3d/visualization/visualizer/VisualizerRender.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,12 @@ bool Visualizer::InitOpenGL() {
3939
#endif
4040

4141
glewExperimental = true;
42-
if (glewInit() != GLEW_OK) {
43-
utility::LogWarning("Failed to initialize GLEW.");
42+
const GLenum init_ret = glewInit();
43+
if (init_ret != GLEW_OK && init_ret != GLEW_ERROR_NO_GLX_DISPLAY) {
44+
const std::string err_msg{
45+
reinterpret_cast<const char *>(glewGetErrorString(init_ret))};
46+
utility::LogWarning("Failed to initialize GLEW: {} ({})", err_msg,
47+
init_ret);
4448
return false;
4549
}
4650

0 commit comments

Comments
 (0)