Add set_decorations method to Window (#365)

This has been stubbed on all platforms other than X11. The X11 implementation has also been
revised to toggle correctly, as it was previously only able to remove decorations.
This commit is contained in:
Francesca Sunshine 2017-12-22 07:50:46 -05:00 committed by Pierre Krieger
parent b36a8e010f
commit 463f316cb8
9 changed files with 79 additions and 37 deletions

View file

@ -3,6 +3,7 @@
- Add support for `Touch` for emscripten backend. - Add support for `Touch` for emscripten backend.
- Added support for `DroppedFile`, `HoveredFile`, and `HoveredFileCancelled` to X11 backend. - Added support for `DroppedFile`, `HoveredFile`, and `HoveredFileCancelled` to X11 backend.
- **Breaking:** `unix::WindowExt` no longer returns pointers for things that aren't actually pointers; `get_xlib_window` now returns `Option<std::os::raw::c_ulong>` and `get_xlib_screen_id` returns `Option<std::os::raw::c_int>`. Additionally, methods that previously returned `libc::c_void` have been changed to return `std::os::raw::c_void`, which are not interchangeable types, so users wanting the former will need to explicitly cast. - **Breaking:** `unix::WindowExt` no longer returns pointers for things that aren't actually pointers; `get_xlib_window` now returns `Option<std::os::raw::c_ulong>` and `get_xlib_screen_id` returns `Option<std::os::raw::c_int>`. Additionally, methods that previously returned `libc::c_void` have been changed to return `std::os::raw::c_void`, which are not interchangeable types, so users wanting the former will need to explicitly cast.
- Added `set_decorations` method to `Window` to allow decorations to be toggled after the window is built. Presently only implemented on X11.
# Version 0.9.0 (2017-12-01) # Version 0.9.0 (2017-12-01)

View file

@ -288,6 +288,11 @@ impl Window {
// Android has single screen maximized apps so nothing to do // Android has single screen maximized apps so nothing to do
} }
#[inline]
pub fn set_decorations(&self, _decorations: bool) {
// N/A
}
#[inline] #[inline]
pub fn get_current_monitor(&self) -> RootMonitorId { pub fn get_current_monitor(&self) -> RootMonitorId {
RootMonitorId{inner: MonitorId} RootMonitorId{inner: MonitorId}

View file

@ -517,6 +517,11 @@ impl Window {
// iOS has single screen maximized apps so nothing to do // iOS has single screen maximized apps so nothing to do
} }
#[inline]
pub fn set_decorations(&self, _decorations: bool) {
// N/A
}
#[inline] #[inline]
pub fn get_current_monitor(&self) -> ::MonitorId { pub fn get_current_monitor(&self) -> ::MonitorId {
::MonitorId{inner: MonitorId} ::MonitorId{inner: MonitorId}

View file

@ -354,6 +354,11 @@ impl Window {
// iOS has single screen maximized apps so nothing to do // iOS has single screen maximized apps so nothing to do
} }
#[inline]
pub fn set_decorations(&self, _decorations: bool) {
// N/A
}
#[inline] #[inline]
pub fn get_current_monitor(&self) -> RootMonitorId { pub fn get_current_monitor(&self) -> RootMonitorId {
RootMonitorId{inner: MonitorId} RootMonitorId{inner: MonitorId}

View file

@ -248,7 +248,9 @@ impl Window {
pub fn set_maximized(&self, maximized: bool) { pub fn set_maximized(&self, maximized: bool) {
match self { match self {
&Window::X(ref w) => w.set_maximized(maximized), &Window::X(ref w) => w.set_maximized(maximized),
&Window::Wayland(ref _w) => {}, &Window::Wayland(ref _w) => {
unimplemented!();
}
} }
} }
@ -256,7 +258,19 @@ impl Window {
pub fn set_fullscreen(&self, monitor: Option<RootMonitorId>) { pub fn set_fullscreen(&self, monitor: Option<RootMonitorId>) {
match self { match self {
&Window::X(ref w) => w.set_fullscreen(monitor), &Window::X(ref w) => w.set_fullscreen(monitor),
&Window::Wayland(ref _w) => {}, &Window::Wayland(ref _w) => {
unimplemented!();
}
}
}
#[inline]
pub fn set_decorations(&self, decorations: bool) {
match self {
&Window::X(ref w) => w.set_decorations(decorations),
&Window::Wayland(ref _w) => {
unimplemented!();
}
} }
} }

View file

@ -432,40 +432,36 @@ impl Window2 {
pub fn set_decorations(&self, decorations: bool) { pub fn set_decorations(&self, decorations: bool) {
#[repr(C)] #[repr(C)]
struct MotifWindowHints { struct MotifWindowHints {
flags: u32, flags: c_ulong,
functions: u32, functions: c_ulong,
decorations: u32, decorations: c_ulong,
input_mode: i32, input_mode: c_long,
status: u32, status: c_ulong,
} }
let wm_hints = unsafe { let wm_hints = unsafe { util::get_atom(&self.x.display, b"_MOTIF_WM_HINTS\0") }
(self.x.display.xlib.XInternAtom)(self.x.display.display, b"_MOTIF_WM_HINTS\0".as_ptr() as *const _, 0) .expect("Failed to call XInternAtom (_MOTIF_WM_HINTS)");
let hints = MotifWindowHints {
flags: 2, // MWM_HINTS_DECORATIONS
functions: 0,
decorations: decorations as _,
input_mode: 0,
status: 0,
}; };
self.x.display.check_errors().expect("Failed to call XInternAtom");
if !decorations { unsafe {
let hints = MotifWindowHints { (self.x.display.xlib.XChangeProperty)(
flags: 2, // MWM_HINTS_DECORATIONS self.x.display.display,
functions: 0, self.x.window,
decorations: 0, wm_hints,
input_mode: 0, wm_hints,
status: 0, 32, // struct members are longs
}; ffi::PropModeReplace,
&hints as *const _ as *const u8,
unsafe { 5 // struct has 5 members
(self.x.display.xlib.XChangeProperty)( );
self.x.display.display, self.x.window, (self.x.display.xlib.XFlush)(self.x.display.display);
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"); self.x.display.check_errors().expect("Failed to set decorations");

View file

@ -643,6 +643,11 @@ impl Window2 {
unimplemented!() unimplemented!()
} }
#[inline]
pub fn set_decorations(&self, _decorations: bool) {
unimplemented!()
}
#[inline] #[inline]
pub fn get_current_monitor(&self) -> RootMonitorId { pub fn get_current_monitor(&self) -> RootMonitorId {
unimplemented!() unimplemented!()

View file

@ -288,6 +288,11 @@ impl Window {
unimplemented!() unimplemented!()
} }
#[inline]
pub fn set_decorations(&self, _decorations: bool) {
unimplemented!()
}
#[inline] #[inline]
pub fn get_current_monitor(&self) -> RootMonitorId { pub fn get_current_monitor(&self) -> RootMonitorId {
unimplemented!() unimplemented!()

View file

@ -313,6 +313,12 @@ impl Window {
self.window.set_fullscreen(monitor) self.window.set_fullscreen(monitor)
} }
/// Turn window decorations on or off.
#[inline]
pub fn set_decorations(&self, decorations: bool) {
self.window.set_decorations(decorations)
}
/// Returns the current monitor the window is on or the primary monitor is nothing /// Returns the current monitor the window is on or the primary monitor is nothing
/// matches /// matches
pub fn get_current_monitor(&self) -> MonitorId { pub fn get_current_monitor(&self) -> MonitorId {