From 7a0a87a6f33d2227d6c396be057bb8a37d0c6e2b Mon Sep 17 00:00:00 2001 From: leethomas Date: Mon, 23 Jan 2017 20:36:09 -0800 Subject: [PATCH] implement relative window levels, closes #8153 --- atom/browser/api/atom_api_window.cc | 4 +++- atom/browser/native_window.h | 3 ++- atom/browser/native_window_mac.h | 3 ++- atom/browser/native_window_mac.mm | 11 +++++++++-- atom/browser/native_window_views.cc | 3 ++- atom/browser/native_window_views.h | 3 ++- 6 files changed, 20 insertions(+), 7 deletions(-) diff --git a/atom/browser/api/atom_api_window.cc b/atom/browser/api/atom_api_window.cc index efbd31b..44126cf 100644 --- a/atom/browser/api/atom_api_window.cc +++ b/atom/browser/api/atom_api_window.cc @@ -512,8 +512,10 @@ bool Window::IsClosable() { void Window::SetAlwaysOnTop(bool top, mate::Arguments* args) { std::string level = "floating"; + int relativeLevel = 0; args->GetNext(&level); - window_->SetAlwaysOnTop(top, level); + args->GetNext(&relativeLevel); + window_->SetAlwaysOnTop(top, level, relativeLevel); } bool Window::IsAlwaysOnTop() { diff --git a/atom/browser/native_window.h b/atom/browser/native_window.h index 3422db0..05c06df 100644 --- a/atom/browser/native_window.h +++ b/atom/browser/native_window.h @@ -119,7 +119,8 @@ class NativeWindow : public base::SupportsUserData, virtual void SetClosable(bool closable) = 0; virtual bool IsClosable() = 0; virtual void SetAlwaysOnTop(bool top, - const std::string& level = "floating") = 0; + const std::string& level = "floating", + int relativeLevel = 0) = 0; virtual bool IsAlwaysOnTop() = 0; virtual void Center() = 0; virtual void SetTitle(const std::string& title) = 0; diff --git a/atom/browser/native_window_mac.h b/atom/browser/native_window_mac.h index 759e51e..37786be 100644 --- a/atom/browser/native_window_mac.h +++ b/atom/browser/native_window_mac.h @@ -67,7 +67,8 @@ class NativeWindowMac : public NativeWindow, bool IsFullScreenable() override; void SetClosable(bool closable) override; bool IsClosable() override; - void SetAlwaysOnTop(bool top, const std::string& level) override; + void SetAlwaysOnTop(bool top, const std::string& level, + int relativeLevel) override; bool IsAlwaysOnTop() override; void Center() override; void SetTitle(const std::string& title) override; diff --git a/atom/browser/native_window_mac.mm b/atom/browser/native_window_mac.mm index 037d0be..6962611 100644 --- a/atom/browser/native_window_mac.mm +++ b/atom/browser/native_window_mac.mm @@ -1056,8 +1056,9 @@ bool NativeWindowMac::IsClosable() { return [window_ styleMask] & NSClosableWindowMask; } -void NativeWindowMac::SetAlwaysOnTop(bool top, const std::string& level) { +void NativeWindowMac::SetAlwaysOnTop(bool top, const std::string& level, int relativeLevel) { int windowLevel = NSNormalWindowLevel; + if (top) { if (level == "floating") { windowLevel = NSFloatingWindowLevel; @@ -1078,7 +1079,13 @@ void NativeWindowMac::SetAlwaysOnTop(bool top, const std::string& level) { windowLevel = NSDockWindowLevel; } } - [window_ setLevel:windowLevel]; + + NSInteger newLevel = windowLevel + relativeLevel; + if (newLevel >= 0 && newLevel < CGWindowLevelForKey(kCGMaximumWindowLevelKey)) { + [window_ setLevel:newLevel]; + } else { + [window_ setLevel:windowLevel]; + } } bool NativeWindowMac::IsAlwaysOnTop() { diff --git a/atom/browser/native_window_views.cc b/atom/browser/native_window_views.cc index d5dbbaa..e13608f 100644 --- a/atom/browser/native_window_views.cc +++ b/atom/browser/native_window_views.cc @@ -682,7 +682,8 @@ bool NativeWindowViews::IsClosable() { #endif } -void NativeWindowViews::SetAlwaysOnTop(bool top, const std::string& level) { +void NativeWindowViews::SetAlwaysOnTop(bool top, const std::string& level, + int relativeLevel) { window_->SetAlwaysOnTop(top); } diff --git a/atom/browser/native_window_views.h b/atom/browser/native_window_views.h index 110a4e9..f70904b 100644 --- a/atom/browser/native_window_views.h +++ b/atom/browser/native_window_views.h @@ -86,7 +86,8 @@ class NativeWindowViews : public NativeWindow, bool IsFullScreenable() override; void SetClosable(bool closable) override; bool IsClosable() override; - void SetAlwaysOnTop(bool top, const std::string& level) override; + void SetAlwaysOnTop(bool top, const std::string& level, + int relativeLevel) override; bool IsAlwaysOnTop() override; void Center() override; void SetTitle(const std::string& title) override; -- 2.7.4