Skip to content

Commit 43fe159

Browse files
authored
Merge pull request #759 from nuttyartist/fix-frameless-window-init
Fix macOS frameless window initialization and titlebar toggle
2 parents 155819c + 6f4060b commit 43fe159

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

src/framelesswindow.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ class CFramelessWindow : public QMainWindow
143143
bool m_bCloseBtnQuit;
144144
bool m_bNativeSystemBtn;
145145
bool m_bIsCloseBtnEnabled, m_bIsMinBtnEnabled, m_bIsZoomBtnEnabled;
146+
bool m_bInitialized;
146147

147148
//===============================================
148149
// TODO

src/framelesswindow.mm

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
m_bIsCloseBtnEnabled(true),
1414
m_bIsMinBtnEnabled(true),
1515
m_bIsZoomBtnEnabled(true),
16-
m_bTitleBarVisible(false)
16+
m_bTitleBarVisible(false),
17+
m_bInitialized(false)
1718
{
18-
initUI();
1919
}
2020

2121
@interface AppObserver : NSObject
@@ -237,6 +237,12 @@ - (void)zoomButtonAction:(id)sender
237237

238238
void CFramelessWindow::showEvent(QShowEvent *event)
239239
{
240+
// Initialize the window styling on first show, when the native window is fully created
241+
if (!m_bInitialized) {
242+
m_bInitialized = true;
243+
initUI();
244+
}
245+
240246
// FIXME: Figure out why this fails to trigger our AppObserver listener sometimes. :/
241247
[NSApp unhide:nil];
242248
QMainWindow::showEvent(event);
@@ -308,7 +314,7 @@ - (void)zoomButtonAction:(id)sender
308314

309315
m_bTitleBarVisible = bTitlebarVisible;
310316
if (bTitlebarVisible) {
311-
window.styleMask ^= NSWindowStyleMaskFullSizeContentView; // MAC_10_10及以上版本支持
317+
window.styleMask &= ~NSWindowStyleMaskFullSizeContentView; // MAC_10_10及以上版本支持
312318
} else {
313319
window.styleMask |= NSWindowStyleMaskFullSizeContentView; // MAC_10_10及以上版本支持
314320
}

0 commit comments

Comments
 (0)