ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
NativeLinux.cpp
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - CloudViewer: www.cloudViewer.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2024 www.cloudViewer.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
8 #include <GLFW/glfw3.h>
9 
10 #include "Application.h"
11 #include "Native.h"
12 #define GLFW_EXPOSE_NATIVE_X11 1
13 #ifdef CLOUDVIEWER_GLFW_HAS_WAYLAND
14 #define GLFW_EXPOSE_NATIVE_WAYLAND 1
15 #endif
16 #include <GLFW/glfw3native.h>
17 #include <memory.h>
18 
19 namespace cloudViewer {
20 namespace visualization {
21 namespace gui {
22 
23 void* GetNativeDrawable(GLFWwindow* glfw_window) {
24  const int platform = glfwGetPlatform();
25  if (platform == GLFW_PLATFORM_X11) {
26  return (void*)glfwGetX11Window(glfw_window);
27  }
28 #ifdef CLOUDVIEWER_GLFW_HAS_WAYLAND
29  else if (platform == GLFW_PLATFORM_WAYLAND) {
30  return (void*)glfwGetWaylandWindow(glfw_window);
31  }
32 #endif
33  else {
34  return nullptr;
35  }
36 }
37 
38 void PostNativeExposeEvent(GLFWwindow* glfw_window) {
39  const int platform = glfwGetPlatform();
40 
41  if (platform == GLFW_PLATFORM_X11) {
42  Display* d = glfwGetX11Display();
43  auto x11win = glfwGetX11Window(glfw_window);
44 
45  XEvent e;
46  memset(&e, 0, sizeof(e));
47  e.type = Expose;
48  e.xexpose.window = x11win;
49 
50  XSendEvent(d, x11win, False, ExposureMask, &e);
51  XFlush(d);
52  }
53 }
54 
55 void ShowNativeAlert(const char* message) {
56  // Linux doesn't have a native alert
57  Application::GetInstance().ShowMessageBox("Alert", message);
58 }
59 
60 } // namespace gui
61 } // namespace visualization
62 } // namespace cloudViewer
void ShowMessageBox(const char *title, const char *message)
void ShowNativeAlert(const char *message)
Definition: NativeLinux.cpp:55
void PostNativeExposeEvent(GLFWwindow *glfw_window)
Definition: NativeLinux.cpp:38
void * GetNativeDrawable(GLFWwindow *glfw_window)
Definition: NativeLinux.cpp:23
Generic file read and write utility for python interface.