throw an error for out of bounds window levels
This commit is contained in:
parent
fb741285c6
commit
1f5518b91e
6 changed files with 20 additions and 8 deletions
|
@ -513,9 +513,16 @@ bool Window::IsClosable() {
|
||||||
void Window::SetAlwaysOnTop(bool top, mate::Arguments* args) {
|
void Window::SetAlwaysOnTop(bool top, mate::Arguments* args) {
|
||||||
std::string level = "floating";
|
std::string level = "floating";
|
||||||
int relativeLevel = 0;
|
int relativeLevel = 0;
|
||||||
|
std::string error;
|
||||||
|
|
||||||
args->GetNext(&level);
|
args->GetNext(&level);
|
||||||
args->GetNext(&relativeLevel);
|
args->GetNext(&relativeLevel);
|
||||||
window_->SetAlwaysOnTop(top, level, relativeLevel);
|
|
||||||
|
window_->SetAlwaysOnTop(top, level, relativeLevel, &error);
|
||||||
|
|
||||||
|
if (!error.empty()) {
|
||||||
|
args->ThrowError(error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Window::IsAlwaysOnTop() {
|
bool Window::IsAlwaysOnTop() {
|
||||||
|
|
|
@ -120,7 +120,8 @@ class NativeWindow : public base::SupportsUserData,
|
||||||
virtual bool IsClosable() = 0;
|
virtual bool IsClosable() = 0;
|
||||||
virtual void SetAlwaysOnTop(bool top,
|
virtual void SetAlwaysOnTop(bool top,
|
||||||
const std::string& level = "floating",
|
const std::string& level = "floating",
|
||||||
int relativeLevel = 0) = 0;
|
int relativeLevel = 0,
|
||||||
|
std::string* error = nullptr) = 0;
|
||||||
virtual bool IsAlwaysOnTop() = 0;
|
virtual bool IsAlwaysOnTop() = 0;
|
||||||
virtual void Center() = 0;
|
virtual void Center() = 0;
|
||||||
virtual void SetTitle(const std::string& title) = 0;
|
virtual void SetTitle(const std::string& title) = 0;
|
||||||
|
|
|
@ -68,7 +68,7 @@ class NativeWindowMac : public NativeWindow,
|
||||||
void SetClosable(bool closable) override;
|
void SetClosable(bool closable) override;
|
||||||
bool IsClosable() override;
|
bool IsClosable() override;
|
||||||
void SetAlwaysOnTop(bool top, const std::string& level,
|
void SetAlwaysOnTop(bool top, const std::string& level,
|
||||||
int relativeLevel) override;
|
int relativeLevel, std::string* error) override;
|
||||||
bool IsAlwaysOnTop() override;
|
bool IsAlwaysOnTop() override;
|
||||||
void Center() override;
|
void Center() override;
|
||||||
void SetTitle(const std::string& title) override;
|
void SetTitle(const std::string& title) override;
|
||||||
|
|
|
@ -1056,8 +1056,10 @@ bool NativeWindowMac::IsClosable() {
|
||||||
return [window_ styleMask] & NSClosableWindowMask;
|
return [window_ styleMask] & NSClosableWindowMask;
|
||||||
}
|
}
|
||||||
|
|
||||||
void NativeWindowMac::SetAlwaysOnTop(bool top, const std::string& level, int relativeLevel) {
|
void NativeWindowMac::SetAlwaysOnTop(bool top, const std::string& level, int relativeLevel,
|
||||||
|
std::string* error) {
|
||||||
int windowLevel = NSNormalWindowLevel;
|
int windowLevel = NSNormalWindowLevel;
|
||||||
|
CGWindowLevel maxWindowLevel = CGWindowLevelForKey(kCGMaximumWindowLevelKey);
|
||||||
|
|
||||||
if (top) {
|
if (top) {
|
||||||
if (level == "floating") {
|
if (level == "floating") {
|
||||||
|
@ -1081,10 +1083,12 @@ void NativeWindowMac::SetAlwaysOnTop(bool top, const std::string& level, int rel
|
||||||
}
|
}
|
||||||
|
|
||||||
NSInteger newLevel = windowLevel + relativeLevel;
|
NSInteger newLevel = windowLevel + relativeLevel;
|
||||||
if (newLevel >= 0 && newLevel < CGWindowLevelForKey(kCGMaximumWindowLevelKey)) {
|
|
||||||
|
if (newLevel >= 0 && newLevel <= maxWindowLevel) {
|
||||||
[window_ setLevel:newLevel];
|
[window_ setLevel:newLevel];
|
||||||
} else {
|
} else {
|
||||||
[window_ setLevel:windowLevel];
|
*error = std::string([[NSString stringWithFormat:
|
||||||
|
@"relativeLevel must be between 0 and %d", maxWindowLevel] UTF8String]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -683,7 +683,7 @@ bool NativeWindowViews::IsClosable() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void NativeWindowViews::SetAlwaysOnTop(bool top, const std::string& level,
|
void NativeWindowViews::SetAlwaysOnTop(bool top, const std::string& level,
|
||||||
int relativeLevel) {
|
int relativeLevel, std::string* error) {
|
||||||
window_->SetAlwaysOnTop(top);
|
window_->SetAlwaysOnTop(top);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -87,7 +87,7 @@ class NativeWindowViews : public NativeWindow,
|
||||||
void SetClosable(bool closable) override;
|
void SetClosable(bool closable) override;
|
||||||
bool IsClosable() override;
|
bool IsClosable() override;
|
||||||
void SetAlwaysOnTop(bool top, const std::string& level,
|
void SetAlwaysOnTop(bool top, const std::string& level,
|
||||||
int relativeLevel) override;
|
int relativeLevel, std::string& error) override;
|
||||||
bool IsAlwaysOnTop() override;
|
bool IsAlwaysOnTop() override;
|
||||||
void Center() override;
|
void Center() override;
|
||||||
void SetTitle(const std::string& title) override;
|
void SetTitle(const std::string& title) override;
|
||||||
|
|
Loading…
Add table
Reference in a new issue