Skip to content

Commit

Permalink
Add set_decorations method to Window (#365)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
francesca64 authored and tomaka committed Dec 22, 2017
1 parent b36a8e0 commit 463f316
Show file tree
Hide file tree
Showing 9 changed files with 79 additions and 37 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
- Add support for `Touch` for emscripten 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.
- 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)

Expand Down
9 changes: 7 additions & 2 deletions src/platform/android/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ impl EventsLoop {
MonitorId
}


pub fn poll_events<F>(&mut self, mut callback: F)
where F: FnMut(::Event)
{
Expand Down Expand Up @@ -101,7 +101,7 @@ impl EventsLoop {
None
}
};

if let Some(event) = e {
callback(event);
}
Expand Down Expand Up @@ -288,6 +288,11 @@ impl Window {
// Android has single screen maximized apps so nothing to do
}

#[inline]
pub fn set_decorations(&self, _decorations: bool) {
// N/A
}

#[inline]
pub fn get_current_monitor(&self) -> RootMonitorId {
RootMonitorId{inner: MonitorId}
Expand Down
7 changes: 6 additions & 1 deletion src/platform/emscripten/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,11 @@ impl Window {
// iOS has single screen maximized apps so nothing to do
}

#[inline]
pub fn set_decorations(&self, _decorations: bool) {
// N/A
}

#[inline]
pub fn get_current_monitor(&self) -> ::MonitorId {
::MonitorId{inner: MonitorId}
Expand Down Expand Up @@ -693,7 +698,7 @@ fn key_translate_virt(input: [ffi::EM_UTF8; ffi::EM_HTML5_SHORT_STRING_LEN_BYTES
"PreviousCandidate" => None,
"Process" => None,
"SingleCandidate" => None,

"HangulMode" => None,
"HanjaMode" => None,
"JunjaMode" => None,
Expand Down
5 changes: 5 additions & 0 deletions src/platform/ios/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,11 @@ impl Window {
// iOS has single screen maximized apps so nothing to do
}

#[inline]
pub fn set_decorations(&self, _decorations: bool) {
// N/A
}

#[inline]
pub fn get_current_monitor(&self) -> RootMonitorId {
RootMonitorId{inner: MonitorId}
Expand Down
18 changes: 16 additions & 2 deletions src/platform/linux/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,15 +248,29 @@ impl Window {
pub fn set_maximized(&self, maximized: bool) {
match self {
&Window::X(ref w) => w.set_maximized(maximized),
&Window::Wayland(ref _w) => {},
&Window::Wayland(ref _w) => {
unimplemented!();
}
}
}

#[inline]
pub fn set_fullscreen(&self, monitor: Option<RootMonitorId>) {
match self {
&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!();
}
}
}

Expand Down
56 changes: 26 additions & 30 deletions src/platform/linux/x11/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -432,40 +432,36 @@ impl Window2 {
pub fn set_decorations(&self, decorations: bool) {
#[repr(C)]
struct MotifWindowHints {
flags: u32,
functions: u32,
decorations: u32,
input_mode: i32,
status: u32,
flags: c_ulong,
functions: c_ulong,
decorations: c_ulong,
input_mode: c_long,
status: c_ulong,
}

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");
let wm_hints = unsafe { util::get_atom(&self.x.display, b"_MOTIF_WM_HINTS\0") }
.expect("Failed to call XInternAtom (_MOTIF_WM_HINTS)");

if !decorations {
let hints = MotifWindowHints {
flags: 2, // MWM_HINTS_DECORATIONS
functions: 0,
decorations: 0,
input_mode: 0,
status: 0,
};
let hints = MotifWindowHints {
flags: 2, // MWM_HINTS_DECORATIONS
functions: 0,
decorations: decorations as _,
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);
}
unsafe {
(self.x.display.xlib.XChangeProperty)(
self.x.display.display,
self.x.window,
wm_hints,
wm_hints,
32, // struct members are longs
ffi::PropModeReplace,
&hints as *const _ as *const u8,
5 // struct has 5 members
);
(self.x.display.xlib.XFlush)(self.x.display.display);
}

self.x.display.check_errors().expect("Failed to set decorations");
Expand Down
5 changes: 5 additions & 0 deletions src/platform/macos/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,11 @@ impl Window2 {
unimplemented!()
}

#[inline]
pub fn set_decorations(&self, _decorations: bool) {
unimplemented!()
}

#[inline]
pub fn get_current_monitor(&self) -> RootMonitorId {
unimplemented!()
Expand Down
9 changes: 7 additions & 2 deletions src/platform/windows/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl Window {
{
let mut w_attr = Some(w_attr.clone());
let mut pl_attr = Some(pl_attr.clone());

let (tx, rx) = channel();

events_loop.execute_in_thread(move |inserter| {
Expand Down Expand Up @@ -288,6 +288,11 @@ impl Window {
unimplemented!()
}

#[inline]
pub fn set_decorations(&self, _decorations: bool) {
unimplemented!()
}

#[inline]
pub fn get_current_monitor(&self) -> RootMonitorId {
unimplemented!()
Expand All @@ -298,7 +303,7 @@ impl Drop for Window {
#[inline]
fn drop(&mut self) {
unsafe {
// We are sending WM_CLOSE, and our callback will process this by calling DefWindowProcW,
// We are sending WM_CLOSE, and our callback will process this by calling DefWindowProcW,
// which in turn will send a WM_DESTROY.
user32::PostMessageW(self.window.0, winapi::WM_CLOSE, 0, 0);
}
Expand Down
6 changes: 6 additions & 0 deletions src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,12 @@ impl Window {
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
/// matches
pub fn get_current_monitor(&self) -> MonitorId {
Expand Down

0 comments on commit 463f316

Please sign in to comment.