From 0b530b026da46d7a05788ae1a35ce5d24886f947 Mon Sep 17 00:00:00 2001 From: Gabriel Martinez Date: Sun, 5 Mar 2017 09:27:03 -0800 Subject: [PATCH 1/2] Support disabling window decorations in X11 This uses the incredibly old and ugly _MOTIF_WM_HINTS property: http://stackoverflow.com/questions/5134297/xlib-how-does-this-removing-window-decoration-work Using _NET_WM_WINDOW_TYPE from the Extended Window Manager Hints spec (https://specifications.freedesktop.org/wm-spec/wm-spec-latest.html) would be preferred, but it requires knowing up front what the user intends their window to be. _MOTIF_WM_HINTS should work for now. --- src/platform/linux/x11/window.rs | 43 ++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/src/platform/linux/x11/window.rs b/src/platform/linux/x11/window.rs index 7bf0a9fc..59732f58 100644 --- a/src/platform/linux/x11/window.rs +++ b/src/platform/linux/x11/window.rs @@ -596,6 +596,7 @@ impl Window { }; window.set_title(&window_attrs.title); + window.set_decorations(window_attrs.decorations); if window_attrs.visible { unsafe { @@ -653,6 +654,48 @@ impl Window { } + pub fn set_decorations(&self, decorations: bool) { + #[repr(C)] + struct MotifWindowHints { + flags: u32, + functions: u32, + decorations: u32, + input_mode: i32, + status: u32, + } + + let wm_hints = unsafe { + (self.x.display.xlib.XInternAtom)(self.x.display.display, b"_MOTIF_WM_HINTS\0".as_ptr() as *const _, 0) + }; + self.x.display.check_errors().expect("Failed to call XInternAtom"); + + if !decorations { + let hints = MotifWindowHints { + flags: 2, // MWM_HINTS_DECORATIONS + functions: 0, + decorations: 0, + input_mode: 0, + status: 0, + }; + + unsafe { + (self.x.display.xlib.XChangeProperty)( + self.x.display.display, self.x.window, + wm_hints, wm_hints, 32 /* Size of elements in struct */, + ffi::PropModeReplace, &hints as *const MotifWindowHints as *const u8, + 5 /* Number of elements in struct */); + (self.x.display.xlib.XFlush)(self.x.display.display); + } + } else { + unsafe { + (self.x.display.xlib.XDeleteProperty)(self.x.display.display, self.x.window, wm_hints); + (self.x.display.xlib.XFlush)(self.x.display.display); + } + } + + self.x.display.check_errors().expect("Failed to set decorations"); + } + pub fn show(&self) { unsafe { (self.x.display.xlib.XMapRaised)(self.x.display.display, self.x.window); From deeda596896573a9ad9a5f24e0a7b2f8e6e46d39 Mon Sep 17 00:00:00 2001 From: Gabriel Martinez Date: Sun, 5 Mar 2017 14:50:39 -0800 Subject: [PATCH 2/2] Clean up macOS window style logic * Remove NSTitledWindowMask for windows with no decorations. This makes sure that they do not have a title bar. * Transparency is not be taken into account as we could have a window with a titlebar or without that is transparent. --- src/platform/macos/window.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/platform/macos/window.rs b/src/platform/macos/window.rs index 51c66018..09ec570d 100644 --- a/src/platform/macos/window.rs +++ b/src/platform/macos/window.rs @@ -311,23 +311,22 @@ impl Window { } }; - let masks = if screen.is_some() || attrs.transparent { - // Fullscreen or transparent window + let masks = if screen.is_some() { + // Fullscreen window appkit::NSBorderlessWindowMask as NSUInteger | appkit::NSResizableWindowMask as NSUInteger | appkit::NSTitledWindowMask as NSUInteger } else if attrs.decorations { - // Classic opaque window with titlebar + // Window with a titlebar appkit::NSClosableWindowMask as NSUInteger | appkit::NSMiniaturizableWindowMask as NSUInteger | appkit::NSResizableWindowMask as NSUInteger | appkit::NSTitledWindowMask as NSUInteger } else { - // Opaque window without a titlebar + // Window without a titlebar appkit::NSClosableWindowMask as NSUInteger | appkit::NSMiniaturizableWindowMask as NSUInteger | appkit::NSResizableWindowMask as NSUInteger | - appkit::NSTitledWindowMask as NSUInteger | appkit::NSFullSizeContentViewWindowMask as NSUInteger };