From de1d6abaf019252ed6d8369314f18b55b1b1bf9d Mon Sep 17 00:00:00 2001 From: Altair Wei Date: Sat, 2 Oct 2021 15:50:22 +0800 Subject: [PATCH] add showMacWindowButton --- examples/minimal/flwindow.cpp | 10 +++++++++- utilities.h | 1 + utilities_macos.mm | 28 ++++++++++++++++++++++++---- 3 files changed, 34 insertions(+), 5 deletions(-) diff --git a/examples/minimal/flwindow.cpp b/examples/minimal/flwindow.cpp index 0a998d4..44e9346 100644 --- a/examples/minimal/flwindow.cpp +++ b/examples/minimal/flwindow.cpp @@ -1,5 +1,6 @@ #include "flwindow.h" #include "../../framelesshelper.h" +#include "../../utilities.h" #include #include @@ -30,6 +31,13 @@ void FLWindow::initFramelessWindow() helper->setHitTestVisible(m_maximizeButton); helper->setHitTestVisible(m_closeButton); helper->install(); + +#ifdef Q_OS_MAC + m_minimizeButton->hide(); + m_maximizeButton->hide(); + m_closeButton->hide(); + Utilities::showMacWindowButton(windowHandle()); +#endif } void FLWindow::showEvent(QShowEvent *event) @@ -89,4 +97,4 @@ void FLWindow::setupUi() mainLayout->addWidget(m_titleBarWidget); mainLayout->addStretch(); setLayout(mainLayout); -} \ No newline at end of file +} diff --git a/utilities.h b/utilities.h index e2b50ea..9e2b154 100644 --- a/utilities.h +++ b/utilities.h @@ -74,6 +74,7 @@ FRAMELESSHELPER_API bool unsetMacWindowHook(QWindow* w); FRAMELESSHELPER_API bool setMacWindowFrameless(QWindow* w); FRAMELESSHELPER_API bool startMacDrag(QWindow* w, const QPoint& pos); FRAMELESSHELPER_API Qt::MouseButtons getMacMouseButtons(); +FRAMELESSHELPER_API bool showMacWindowButton(QWindow *w); #endif // Q_OS_MAC } diff --git a/utilities_macos.mm b/utilities_macos.mm index 638cc11..816f07a 100644 --- a/utilities_macos.mm +++ b/utilities_macos.mm @@ -223,16 +223,36 @@ bool setMacWindowFrameless(QWindow* w) nswindow.titlebarAppearsTransparent = true; nswindow.titleVisibility = NSWindowTitleHidden; nswindow.hasShadow = true; - nswindow.showsToolbarButton = false; + nswindow.movableByWindowBackground = false; nswindow.movable = false; - [nswindow standardWindowButton:NSWindowCloseButton].hidden = true; - [nswindow standardWindowButton:NSWindowMiniaturizeButton].hidden = true; - [nswindow standardWindowButton:NSWindowZoomButton].hidden = true; + + nswindow.showsToolbarButton = false; + [nswindow standardWindowButton:NSWindowCloseButton].hidden = true; + [nswindow standardWindowButton:NSWindowMiniaturizeButton].hidden = true; + [nswindow standardWindowButton:NSWindowZoomButton].hidden = true; + [nswindow makeKeyWindow]; return true; } +bool showMacWindowButton(QWindow *w) +{ + NSView* view = reinterpret_cast(w->winId()); + if (view == nullptr) + return false; + NSWindow* nswindow = [view window]; + if (nswindow == nullptr) + return false; + + nswindow.showsToolbarButton = true; + [nswindow standardWindowButton:NSWindowCloseButton].hidden = false; + [nswindow standardWindowButton:NSWindowMiniaturizeButton].hidden = false; + [nswindow standardWindowButton:NSWindowZoomButton].hidden = false; + + return true; +} + bool startMacDrag(QWindow* w, const QPoint& pos) { NSView* view = reinterpret_cast(w->winId());