From f8136c627d4a3572ffc85ed8706c3ef40e7557ea Mon Sep 17 00:00:00 2001 From: Roman Chistokhodov Date: Sun, 1 Oct 2017 05:23:45 +0300 Subject: [PATCH 1/2] Add support for borderless (undecorated) window on sdl2 and x11 platforms --- src/dlangui/platforms/common/platform.d | 2 ++ src/dlangui/platforms/sdl/sdlapp.d | 2 ++ src/dlangui/platforms/x11/x11app.d | 32 +++++++++++++++++++++++++ 3 files changed, 36 insertions(+) diff --git a/src/dlangui/platforms/common/platform.d b/src/dlangui/platforms/common/platform.d index f58767d4..0e66885d 100644 --- a/src/dlangui/platforms/common/platform.d +++ b/src/dlangui/platforms/common/platform.d @@ -54,6 +54,8 @@ enum WindowFlag : uint { Modal = 4, /// measure window size on window.show() - helps if you want scrollWindow but on show() you want to set window to mainWidget measured size MeasureSize = 8, + /// window without decorations + Borderless = 16, } /// Window states diff --git a/src/dlangui/platforms/sdl/sdlapp.d b/src/dlangui/platforms/sdl/sdlapp.d index 8d3d0aaa..265aecd6 100644 --- a/src/dlangui/platforms/sdl/sdlapp.d +++ b/src/dlangui/platforms/sdl/sdlapp.d @@ -249,6 +249,8 @@ class SDLWindow : Window { windowFlags |= SDL_WINDOW_RESIZABLE; if (flags & WindowFlag.Fullscreen) windowFlags |= SDL_WINDOW_FULLSCREEN; + if (flags & WindowFlag.Borderless) + windowFlags = SDL_WINDOW_BORDERLESS; windowFlags |= SDL_WINDOW_ALLOW_HIGHDPI; static if (ENABLE_OPENGL) { if (_enableOpengl) diff --git a/src/dlangui/platforms/x11/x11app.d b/src/dlangui/platforms/x11/x11app.d index 28c584dc..54e66d01 100644 --- a/src/dlangui/platforms/x11/x11app.d +++ b/src/dlangui/platforms/x11/x11app.d @@ -44,6 +44,28 @@ static if (ENABLE_OPENGL) { alias XWindow = x11.Xlib.Window; alias DWindow = dlangui.platforms.common.platform.Window; +private struct MwmHints +{ + int flags; + int functions; + int decorations; + int input_mode; + int status; +} + +private enum +{ + MWM_HINTS_FUNCTIONS = (1L << 0), + MWM_HINTS_DECORATIONS = (1L << 1), + + MWM_FUNC_ALL = (1L << 0), + MWM_FUNC_RESIZE = (1L << 1), + MWM_FUNC_MOVE = (1L << 2), + MWM_FUNC_MINIMIZE = (1L << 3), + MWM_FUNC_MAXIMIZE = (1L << 4), + MWM_FUNC_CLOSE = (1L << 5) +} + private __gshared { Display * x11display; @@ -74,6 +96,8 @@ private __gshared Atom atom_NET_WM_STATE_HIDDEN; Atom atom_NET_WM_STATE_FULLSCREEN; + Atom atom_MOTIF_WM_HINTS; + Atom atom_DLANGUI_TIMER_EVENT; Atom atom_DLANGUI_TASK_EVENT; Atom atom_DLANGUI_CLOSE_WINDOW_EVENT; @@ -98,6 +122,7 @@ static void setupX11Atoms() atom_NET_WM_STATE_MAXIMIZED_HORZ = XInternAtom(x11display, "_NET_WM_STATE_MAXIMIZED_HORZ", True); atom_NET_WM_STATE_HIDDEN = XInternAtom(x11display, "_NET_WM_STATE_HIDDEN", True); atom_NET_WM_STATE_FULLSCREEN = XInternAtom(x11display, "_NET_WM_STATE_FULLSCREEN", True); + atom_MOTIF_WM_HINTS = XInternAtom(x11display, "_MOTIF_WM_HINTS", True); atom_DLANGUI_TIMER_EVENT = XInternAtom(x11display, "DLANGUI_TIMER_EVENT", False); atom_DLANGUI_TASK_EVENT = XInternAtom(x11display, "DLANGUI_TASK_EVENT", False); @@ -335,6 +360,13 @@ class X11Window : DWindow { else Log.w("Missing _NET_WM_STATE_FULLSCREEN atom"); } + if (flags & WindowFlag.Borderless) { + if (atom_MOTIF_WM_HINTS != None) { + MwmHints hints; + hints.flags = MWM_HINTS_DECORATIONS; + XChangeProperty(x11display, _win, atom_MOTIF_WM_HINTS, atom_MOTIF_WM_HINTS, 32, PropModeReplace, cast(ubyte*)&hints, hints.sizeof / 4); + } + } if (flags & WindowFlag.Modal) { if (_parent) { XSetTransientForHint(x11display, _win, _parent._win); From 0289d1762505a254f5abac331e6cb521ac2ea95b Mon Sep 17 00:00:00 2001 From: Roman Chistokhodov Date: Sun, 1 Oct 2017 16:07:35 +0300 Subject: [PATCH 2/2] Implement WindowFlag.Borderless for Windows --- src/dlangui/platforms/windows/winapp.d | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/dlangui/platforms/windows/winapp.d b/src/dlangui/platforms/windows/winapp.d index 4f1c2f4b..4d2781bd 100644 --- a/src/dlangui/platforms/windows/winapp.d +++ b/src/dlangui/platforms/windows/winapp.d @@ -282,6 +282,9 @@ class Win32Window : Window { _dy = screenRc.height; ws = WS_POPUP; } + if (flags & WindowFlag.Borderless) { + ws = WS_POPUP | WS_SYSMENU; + } _hwnd = CreateWindowW(toUTF16z(WIN_CLASS_NAME), // window class name