From a16bbf59b783b2657218a86e79852d44badee65d Mon Sep 17 00:00:00 2001 From: JP Cimalando Date: Tue, 5 Nov 2019 13:09:29 +0100 Subject: [PATCH] Support disabling window decorations in X11 and Win32 --- dgl/Window.hpp | 3 +++ dgl/src/Window.cpp | 61 +++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 63 insertions(+), 1 deletion(-) diff --git a/dgl/Window.hpp b/dgl/Window.hpp index 931177ead..bddd7281c 100644 --- a/dgl/Window.hpp +++ b/dgl/Window.hpp @@ -100,6 +100,9 @@ class Window bool isResizable() const noexcept; void setResizable(bool yesNo); + bool isDecorated() const noexcept; + void setDecorated(bool yesNo); + uint getWidth() const noexcept; uint getHeight() const noexcept; Size getSize() const noexcept; diff --git a/dgl/src/Window.cpp b/dgl/src/Window.cpp index 61218b08d..5880be529 100644 --- a/dgl/src/Window.cpp +++ b/dgl/src/Window.cpp @@ -94,6 +94,7 @@ struct Window::PrivateData { fFirstInit(true), fVisible(false), fResizable(true), + fDecorated(true), fUsingEmbed(false), fWidth(1), fHeight(1), @@ -134,6 +135,7 @@ struct Window::PrivateData { fFirstInit(true), fVisible(false), fResizable(true), + fDecorated(true), fUsingEmbed(false), fWidth(1), fHeight(1), @@ -188,6 +190,7 @@ struct Window::PrivateData { fFirstInit(true), fVisible(parentId != 0), fResizable(resizable), + fDecorated(true), fUsingEmbed(parentId != 0), fWidth(1), fHeight(1), @@ -659,6 +662,43 @@ struct Window::PrivateData { // ------------------------------------------------------------------- + void setDecorated(const bool yesNo) + { + if (fDecorated == yesNo) + { + DBG("Window setDecorated matches current state, ignoring request\n"); + return; + } + + fDecorated = yesNo; + +#if defined(DISTRHO_OS_HAIKU) + // TODO +#elif defined(DISTRHO_OS_MAC) + // TODO +#elif defined(DISTRHO_OS_WINDOWS) + const int winFlags = fDecorated ? GetWindowLong(hwnd, GWL_STYLE) | WS_CAPTION + : GetWindowLong(hwnd, GWL_STYLE) & ~WS_CAPTION; + + RECT rect = {0, 0, 0, 0}; + GetWindowRect(hwnd, &rect); + rect.right = rect.left + fWidth; + rect.bottom = rect.top + fHeight; + AdjustWindowRectEx(&rect, fUsingEmbed ? WS_CHILD : winFlags, FALSE, WS_EX_TOPMOST); + + SetWindowLong(hwnd, GWL_STYLE, winFlags); + MoveWindow(hwnd, rect.left, rect.top, rect.right-rect.left, rect.bottom-rect.top, TRUE); +#else + Atom motifWmHints = XInternAtom(xDisplay, "_MOTIF_WM_HINTS", True); + long hints[5] = {2, 0, fDecorated ? 1 : 0, 0, 0}; // see MotifWmHints in LessTif MwmUtil.h + XChangeProperty(xDisplay, xWindow, + motifWmHints, motifWmHints, 32, PropModeReplace, + (unsigned char*)&hints, 5); +#endif + } + + // ------------------------------------------------------------------- + void setGeometryConstraints(uint width, uint height, bool aspect) { // Did you forget to set DISTRHO_UI_USER_RESIZABLE ? @@ -726,7 +766,7 @@ struct Window::PrivateData { } } #elif defined(DISTRHO_OS_WINDOWS) - const int winFlags = WS_POPUPWINDOW | WS_CAPTION | (fResizable ? WS_SIZEBOX : 0x0); + const int winFlags = WS_POPUPWINDOW | (fDecorated ? WS_CAPTION : 0x00) | (fResizable ? WS_SIZEBOX : 0x0); RECT wr = { 0, 0, static_cast(width), static_cast(height) }; AdjustWindowRectEx(&wr, fUsingEmbed ? WS_CHILD : winFlags, FALSE, WS_EX_TOPMOST); @@ -753,6 +793,14 @@ struct Window::PrivateData { XSetWMNormalHints(xDisplay, xWindow, &sizeHints); } + { + Atom motifWmHints = XInternAtom(xDisplay, "_MOTIF_WM_HINTS", True); + long hints[5] = {2, 0, fDecorated ? 1 : 0, 0, 0}; + XChangeProperty(xDisplay, xWindow, + motifWmHints, motifWmHints, 32, PropModeReplace, + (unsigned char*)&hints, 5); + } + XResizeWindow(xDisplay, xWindow, width, height); if (! forced) @@ -1229,6 +1277,7 @@ struct Window::PrivateData { bool fFirstInit; bool fVisible; bool fResizable; + bool fDecorated; bool fUsingEmbed; uint fWidth; uint fHeight; @@ -1615,6 +1664,16 @@ void Window::setResizable(bool yesNo) pData->setResizable(yesNo); } +bool Window::isDecorated() const noexcept +{ + return pData->fDecorated; +} + +void Window::setDecorated(bool yesNo) +{ + pData->setDecorated(yesNo); +} + void Window::setGeometryConstraints(uint width, uint height, bool aspect) { pData->setGeometryConstraints(width, height, aspect);