add showMacWindowButton

This commit is contained in:
Altair Wei 2021-10-02 15:50:22 +08:00
parent ce69d1a4c5
commit de1d6abaf0
3 changed files with 34 additions and 5 deletions

View File

@ -1,5 +1,6 @@
#include "flwindow.h"
#include "../../framelesshelper.h"
#include "../../utilities.h"
#include <QScreen>
#include <QVBoxLayout>
@ -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);
}
}

View File

@ -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
}

View File

@ -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<NSView *>(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<NSView *>(w->winId());