feat: Add BrowserWindow option to hide window in Mission Control (macOS) (#36092)
* feat: Add BrowserWindow option to ignore Mission Control (macOS) * There are many circumstances when app developers may want to hide their windows from mission control. E.g., full screen overlays, small helper windows, dialogs, etc. * This PR adds the functionality, docs, and tests. * chore:Rename variables * Update shell/browser/native_window_mac.h Co-authored-by: Samuel Maddock <samuel.maddock@gmail.com> Co-authored-by: Samuel Maddock <samuel.maddock@gmail.com> Co-authored-by: John Kleinschmidt <jkleinsc@electronjs.org>
This commit is contained in:
parent
8b430c9d26
commit
15540975ff
9 changed files with 77 additions and 1 deletions
|
@ -881,6 +881,16 @@ gfx::Point BaseWindow::GetTrafficLightPosition() const {
|
|||
}
|
||||
#endif
|
||||
|
||||
#if BUILDFLAG(IS_MAC)
|
||||
bool BaseWindow::IsHiddenInMissionControl() {
|
||||
return window_->IsHiddenInMissionControl();
|
||||
}
|
||||
|
||||
void BaseWindow::SetHiddenInMissionControl(bool hidden) {
|
||||
window_->SetHiddenInMissionControl(hidden);
|
||||
}
|
||||
#endif
|
||||
|
||||
void BaseWindow::SetTouchBar(
|
||||
std::vector<gin_helper::PersistentDictionary> items) {
|
||||
window_->SetTouchBar(std::move(items));
|
||||
|
@ -1256,6 +1266,14 @@ void BaseWindow::BuildPrototype(v8::Isolate* isolate,
|
|||
.SetMethod("getTrafficLightPosition",
|
||||
&BaseWindow::GetTrafficLightPosition)
|
||||
#endif
|
||||
|
||||
#if BUILDFLAG(IS_MAC)
|
||||
.SetMethod("isHiddenInMissionControl",
|
||||
&BaseWindow::IsHiddenInMissionControl)
|
||||
.SetMethod("setHiddenInMissionControl",
|
||||
&BaseWindow::SetHiddenInMissionControl)
|
||||
#endif
|
||||
|
||||
.SetMethod("_setTouchBarItems", &BaseWindow::SetTouchBar)
|
||||
.SetMethod("_refreshTouchBarItem", &BaseWindow::RefreshTouchBarItem)
|
||||
.SetMethod("_setEscapeTouchBarItem", &BaseWindow::SetEscapeTouchBarItem)
|
||||
|
|
|
@ -198,6 +198,11 @@ class BaseWindow : public gin_helper::TrackableObject<BaseWindow>,
|
|||
gfx::Point GetTrafficLightPosition() const;
|
||||
#endif
|
||||
|
||||
#if BUILDFLAG(IS_MAC)
|
||||
bool IsHiddenInMissionControl();
|
||||
void SetHiddenInMissionControl(bool hidden);
|
||||
#endif
|
||||
|
||||
void SetTouchBar(std::vector<gin_helper::PersistentDictionary> items);
|
||||
void RefreshTouchBarItem(const std::string& item_id);
|
||||
void SetEscapeTouchBarItem(gin_helper::PersistentDictionary item);
|
||||
|
|
|
@ -227,6 +227,12 @@ class NativeWindow : public base::SupportsUserData,
|
|||
virtual void UpdateFrame() = 0;
|
||||
#endif
|
||||
|
||||
// whether windows should be ignored by mission control
|
||||
#if BUILDFLAG(IS_MAC)
|
||||
virtual bool IsHiddenInMissionControl() = 0;
|
||||
virtual void SetHiddenInMissionControl(bool hidden) = 0;
|
||||
#endif
|
||||
|
||||
// Touchbar API
|
||||
virtual void SetTouchBar(std::vector<gin_helper::PersistentDictionary> items);
|
||||
virtual void RefreshTouchBarItem(const std::string& item_id);
|
||||
|
|
|
@ -103,6 +103,8 @@ class NativeWindowMac : public NativeWindow,
|
|||
void SetDocumentEdited(bool edited) override;
|
||||
bool IsDocumentEdited() override;
|
||||
void SetIgnoreMouseEvents(bool ignore, bool forward) override;
|
||||
bool IsHiddenInMissionControl() override;
|
||||
void SetHiddenInMissionControl(bool hidden) override;
|
||||
void SetContentProtection(bool enable) override;
|
||||
void SetFocusable(bool focusable) override;
|
||||
bool IsFocusable() override;
|
||||
|
|
|
@ -209,6 +209,9 @@ NativeWindowMac::NativeWindowMac(const gin_helper::Dictionary& options,
|
|||
std::string windowType;
|
||||
options.Get(options::kType, &windowType);
|
||||
|
||||
bool hiddenInMissionControl = false;
|
||||
options.Get(options::kHiddenInMissionControl, &hiddenInMissionControl);
|
||||
|
||||
bool useStandardWindow = true;
|
||||
// eventually deprecate separate "standardWindow" option in favor of
|
||||
// standard / textured window types
|
||||
|
@ -347,6 +350,8 @@ NativeWindowMac::NativeWindowMac(const gin_helper::Dictionary& options,
|
|||
options.Get(options::kDisableAutoHideCursor, &disableAutoHideCursor);
|
||||
[window_ setDisableAutoHideCursor:disableAutoHideCursor];
|
||||
|
||||
SetHiddenInMissionControl(hiddenInMissionControl);
|
||||
|
||||
// Set maximizable state last to ensure zoom button does not get reset
|
||||
// by calls to other APIs.
|
||||
SetMaximizable(maximizable);
|
||||
|
@ -1085,9 +1090,17 @@ bool NativeWindowMac::IsDocumentEdited() {
|
|||
return [window_ isDocumentEdited];
|
||||
}
|
||||
|
||||
bool NativeWindowMac::IsHiddenInMissionControl() {
|
||||
NSUInteger collectionBehavior = [window_ collectionBehavior];
|
||||
return collectionBehavior & NSWindowCollectionBehaviorTransient;
|
||||
}
|
||||
|
||||
void NativeWindowMac::SetHiddenInMissionControl(bool hidden) {
|
||||
SetCollectionBehavior(hidden, NSWindowCollectionBehaviorTransient);
|
||||
}
|
||||
|
||||
void NativeWindowMac::SetIgnoreMouseEvents(bool ignore, bool forward) {
|
||||
[window_ setIgnoresMouseEvents:ignore];
|
||||
|
||||
if (!ignore) {
|
||||
SetForwardMouseMessages(NO);
|
||||
} else {
|
||||
|
|
|
@ -39,6 +39,8 @@ const char kOverlaySymbolColor[] = "symbolColor";
|
|||
// The custom height for Window Controls Overlay.
|
||||
const char kOverlayHeight[] = "height";
|
||||
|
||||
// whether to keep the window out of mission control
|
||||
const char kHiddenInMissionControl[] = "hiddenInMissionControl";
|
||||
// Whether the window should show in taskbar.
|
||||
const char kSkipTaskbar[] = "skipTaskbar";
|
||||
|
||||
|
|
|
@ -30,6 +30,7 @@ extern const char kMinimizable[];
|
|||
extern const char kMaximizable[];
|
||||
extern const char kFullScreenable[];
|
||||
extern const char kClosable[];
|
||||
extern const char kHiddenInMissionControl[];
|
||||
extern const char kFullscreen[];
|
||||
extern const char kSkipTaskbar[];
|
||||
extern const char kKiosk[];
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue