diff --git a/cpp/open3d/visualization/gui/BitmapWindowSystem.h b/cpp/open3d/visualization/gui/BitmapWindowSystem.h index 8b7268630a7..9efa41b42ec 100644 --- a/cpp/open3d/visualization/gui/BitmapWindowSystem.h +++ b/cpp/open3d/visualization/gui/BitmapWindowSystem.h @@ -92,6 +92,9 @@ class BitmapWindowSystem : public WindowSystem { MenuBase* CreateOSMenu() override; + /// SetFullScreen is a no-op + void SetFullScreen(OSWindow, bool) override{}; + private: struct Impl; std::unique_ptr impl_; diff --git a/cpp/open3d/visualization/gui/GLFWWindowSystem.cpp b/cpp/open3d/visualization/gui/GLFWWindowSystem.cpp index 37f17121007..0bd38d9fb0a 100644 --- a/cpp/open3d/visualization/gui/GLFWWindowSystem.cpp +++ b/cpp/open3d/visualization/gui/GLFWWindowSystem.cpp @@ -546,6 +546,20 @@ MenuBase* GLFWWindowSystem::CreateOSMenu() { #endif } +void GLFWWindowSystem::SetFullScreen(OSWindow w, bool bFullScreen) { + if (!bFullScreen) { + glfwSetWindowMonitor((GLFWwindow*)w, NULL, win_x_, win_y_, win_width_, + win_height_, GLFW_DONT_CARE); + } else { + glfwGetWindowSize((GLFWwindow*)w, &win_width_, &win_height_); + glfwGetWindowPos((GLFWwindow*)w, &win_x_, &win_y_); + GLFWmonitor* monitor = glfwGetPrimaryMonitor(); + const GLFWvidmode* mode = glfwGetVideoMode(monitor); + glfwSetWindowMonitor((GLFWwindow*)w, monitor, 0, 0, mode->width, + mode->height, mode->refreshRate); + } +} + } // namespace gui } // namespace visualization } // namespace open3d diff --git a/cpp/open3d/visualization/gui/GLFWWindowSystem.h b/cpp/open3d/visualization/gui/GLFWWindowSystem.h index a74a37af3e6..2e65184ec8a 100644 --- a/cpp/open3d/visualization/gui/GLFWWindowSystem.h +++ b/cpp/open3d/visualization/gui/GLFWWindowSystem.h @@ -70,6 +70,8 @@ class GLFWWindowSystem : public WindowSystem { MenuBase* CreateOSMenu() override; + void SetFullScreen(OSWindow w, bool bFullScreen) override; + private: static void DrawCallback(GLFWwindow* window); static void ResizeCallback(GLFWwindow* window, int os_width, int os_height); @@ -86,6 +88,11 @@ class GLFWWindowSystem : public WindowSystem { static void CharCallback(GLFWwindow* window, unsigned int utf32char); static void DragDropCallback(GLFWwindow*, int count, const char* paths[]); static void CloseCallback(GLFWwindow* window); + + int win_width_; + int win_height_; + int win_x_; + int win_y_; }; } // namespace gui diff --git a/cpp/open3d/visualization/gui/Window.cpp b/cpp/open3d/visualization/gui/Window.cpp index bb023903792..2952272e082 100644 --- a/cpp/open3d/visualization/gui/Window.cpp +++ b/cpp/open3d/visualization/gui/Window.cpp @@ -676,6 +676,11 @@ void Window::ShowMenu(bool show) { SetNeedsLayout(); } +void Window::SetFullScreen(bool bFullScreen) { + auto& ws = Application::GetInstance().GetWindowSystem(); + ws.SetFullScreen(GetOSWindow(), bFullScreen); +} + LayoutContext Window::GetLayoutContext() { return {GetTheme(), impl_->imgui_}; } void Window::Layout(const LayoutContext& context) { diff --git a/cpp/open3d/visualization/gui/Window.h b/cpp/open3d/visualization/gui/Window.h index b186d760699..656e2936aca 100644 --- a/cpp/open3d/visualization/gui/Window.h +++ b/cpp/open3d/visualization/gui/Window.h @@ -162,6 +162,8 @@ class Window { /// WebRTCWindowSystem. std::string GetWebRTCUID() const; + void SetFullScreen(bool bFullScreen); + protected: /// Returns the preferred size of the window. The window is not /// obligated to honor this size. If all children of the window diff --git a/cpp/open3d/visualization/gui/WindowSystem.h b/cpp/open3d/visualization/gui/WindowSystem.h index 682e732acb7..ab01b0b8108 100644 --- a/cpp/open3d/visualization/gui/WindowSystem.h +++ b/cpp/open3d/visualization/gui/WindowSystem.h @@ -85,6 +85,8 @@ class WindowSystem { rendering::FilamentRenderer* renderer) = 0; virtual MenuBase* CreateOSMenu() = 0; + + virtual void SetFullScreen(OSWindow w, bool bFullScreen) = 0; }; } // namespace gui diff --git a/cpp/pybind/visualization/gui/gui.cpp b/cpp/pybind/visualization/gui/gui.cpp index ed8484c6176..5b84e5dbc59 100644 --- a/cpp/pybind/visualization/gui/gui.cpp +++ b/cpp/pybind/visualization/gui/gui.cpp @@ -484,6 +484,9 @@ void pybind_gui_classes(py::module &m) { "show_menu(show): shows or hides the menu in the window, " "except on macOS since the menubar is not in the window " "and all applications must have a menubar.") + .def("set_full_screen", &PyWindow::SetFullScreen, + "Make the window fullscreen or reset to previous state.", + "fullscreen"_a = true) .def_property_readonly( "renderer", &PyWindow::GetRenderer, "Gets the rendering.Renderer object for the Window"); diff --git a/examples/python/visualization/vis_gui.py b/examples/python/visualization/vis_gui.py index 3cf28e29684..07a6110a443 100644 --- a/examples/python/visualization/vis_gui.py +++ b/examples/python/visualization/vis_gui.py @@ -279,6 +279,11 @@ def __init__(self, width, height): h.add_stretch() view_ctrls.add_child(h) + self._fullscreen = gui.Checkbox("Fullscreen") + self._fullscreen.set_on_checked(w.set_full_screen) + view_ctrls.add_fixed(separation_height) + view_ctrls.add_child(self._fullscreen) + self._show_skybox = gui.Checkbox("Show skymap") self._show_skybox.set_on_checked(self._on_show_skybox) view_ctrls.add_fixed(separation_height)