[macOS] Move the window if there is no title bar (#382)

* macOS: Move the window if there is no title bar

On macOS by default windows can only be moved by clicking and
dragging on the titlebar, if we spawn a window without one we
need to set the `movableByWindowBackground` property.

Partial fix for #368

* macOS: Make moveByWindowBackground optional

Implements setting the property via WindowBuilderExt:

    WindowBuilder::new()
        .with_decorations(false)
        .with_movable_by_window_background(true)

* Update CHANGELOG
This commit is contained in:
Robert Günzler 2018-01-22 18:07:51 +00:00 committed by Pierre Krieger
parent 0e81251f3a
commit 7e1c70964d
3 changed files with 19 additions and 2 deletions

View file

@ -1,5 +1,6 @@
# Unreleased
- Added method `os::macos::WindowBuilderExt::with_movable_by_window_background(bool)` that allows to move a window without a titlebar - `with_decorations(false)`
- Implement `Window::set_fullscreen`, `Window::set_maximized` and `Window::set_decorations` for Wayland.
# Version 0.10.0 (2017-12-27)

View file

@ -63,6 +63,7 @@ impl From<ActivationPolicy> for NSApplicationActivationPolicy {
/// Additional methods on `WindowBuilder` that are specific to MacOS.
pub trait WindowBuilderExt {
fn with_activation_policy(self, activation_policy: ActivationPolicy) -> WindowBuilder;
fn with_movable_by_window_background(self, movable_by_window_background: bool) -> WindowBuilder;
}
impl WindowBuilderExt for WindowBuilder {
@ -72,6 +73,13 @@ impl WindowBuilderExt for WindowBuilder {
self.platform_specific.activation_policy = activation_policy;
self
}
/// Enables click-and-drag behavior for the entire window, not just the titlebar
#[inline]
fn with_movable_by_window_background(mut self, movable_by_window_background: bool) -> WindowBuilder {
self.platform_specific.movable_by_window_background = movable_by_window_background;
self
}
}
/// Additional methods on `MonitorId` that are specific to MacOS.

View file

@ -254,6 +254,7 @@ impl Drop for WindowDelegate {
#[derive(Clone, Default)]
pub struct PlatformSpecificWindowBuilderAttributes {
pub activation_policy: ActivationPolicy,
pub movable_by_window_background: bool,
}
pub struct Window2 {
@ -312,7 +313,7 @@ impl Window2 {
None => { return Err(OsError(format!("Couldn't create NSApplication"))); },
};
let window = match Window2::create_window(win_attribs)
let window = match Window2::create_window(win_attribs, pl_attribs)
{
Some(window) => window,
None => { return Err(OsError(format!("Couldn't create NSWindow"))); },
@ -381,7 +382,10 @@ impl Window2 {
}
}
fn create_window(attrs: &WindowAttributes) -> Option<IdRef> {
fn create_window(
attrs: &WindowAttributes,
pl_attrs: &PlatformSpecificWindowBuilderAttributes)
-> Option<IdRef> {
unsafe {
let screen = match attrs.fullscreen {
Some(ref monitor_id) => {
@ -449,6 +453,10 @@ impl Window2 {
window.setTitlebarAppearsTransparent_(YES);
}
if pl_attrs.movable_by_window_background {
window.setMovableByWindowBackground_(YES);
}
if screen.is_some() {
window.setLevel_(appkit::NSMainMenuWindowLevel as i64 + 1);
}