mirror of
https://github.com/italicsjenga/winit-sonoma-fix.git
synced 2025-01-12 05:31:31 +11:00
Merge pull request #152 from mystal/fix_decorations
Support removing window decorations in x11 and macOS
This commit is contained in:
commit
aa9678454d
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue