From b78ddba11e9c830ce793fb76326cf497b6cbfd71 Mon Sep 17 00:00:00 2001 From: Henrik Hautakoski Date: Sun, 2 Oct 2022 17:01:40 +0200 Subject: [PATCH] Platform/Unix/X11Display: implement setDecoration() --- source/Platform/Unix/X11Display.cpp | 39 +++++++++++++++++++++++++++++ source/Platform/Unix/X11Display.h | 2 ++ 2 files changed, 41 insertions(+) diff --git a/source/Platform/Unix/X11Display.cpp b/source/Platform/Unix/X11Display.cpp index 9e087f6..dea7205 100644 --- a/source/Platform/Unix/X11Display.cpp +++ b/source/Platform/Unix/X11Display.cpp @@ -1,8 +1,10 @@ +#include #include #include #include "X11WindowEventHandler.h" #include "Xlib.h" +#include "wm_hints.h" #include "GLXContext.h" #include "X11Display.h" @@ -157,6 +159,43 @@ void X11Display::setVisible(bool visible) } } +void X11Display::setDecoration(unsigned decoration) +{ + Atom WMHintsAtom = Xlib::getAtom("_MOTIF_WM_HINTS", false); + + Log::info("X11: Decoration"); + + if (WMHintsAtom) { + WMHints hints; + std::memset(&hints, 0, sizeof(hints)); + hints.flags = MWM_HINTS_FUNCTIONS | MWM_HINTS_DECORATIONS; + hints.decorations = 0; + hints.functions = 0; + + if (decoration & DisplayDecorate::Menu) { + Log::info("X11: Decoration Menu"); + hints.decorations |= MWM_DECOR_BORDER | MWM_DECOR_TITLE | MWM_DECOR_MINIMIZE | MWM_DECOR_MENU; + hints.functions |= MWM_FUNC_MOVE | MWM_FUNC_MINIMIZE; + } + + if (decoration & DisplayDecorate::Resize) { + Log::info("X11: Decoration Resize"); + hints.decorations |= MWM_DECOR_MAXIMIZE | MWM_DECOR_RESIZEH; + hints.functions |= MWM_FUNC_MAXIMIZE | MWM_FUNC_RESIZE; + } + + if (decoration & DisplayDecorate::Close) { + Log::info("X11: Decoration Close"); + hints.decorations |= 0; + hints.functions |= MWM_FUNC_CLOSE; + } + + + ::XChangeProperty(Xlib::getDisplay(), m_win, WMHintsAtom, WMHintsAtom, + 32, PropModeReplace, (const unsigned char*)&hints, WMHINTS_NUM_ELEMENTS); + } +} + void X11Display::minimize() { ::XIconifyWindow(Xlib::getDisplay(), m_win, m_screen); diff --git a/source/Platform/Unix/X11Display.h b/source/Platform/Unix/X11Display.h index 403aaaf..04ee0e9 100644 --- a/source/Platform/Unix/X11Display.h +++ b/source/Platform/Unix/X11Display.h @@ -38,6 +38,8 @@ public : virtual void setVisible(bool visible); + virtual void setDecoration(unsigned decoration); + virtual void minimize(); virtual void maximize();