Skip to content

Commit

Permalink
feat: add bordless window on mac
Browse files Browse the repository at this point in the history
Change-Id: Iafc1439bc51297a420d5cb0b7c064b86661d2847
  • Loading branch information
Iceyer committed Nov 28, 2017
1 parent 20782b5 commit 5f47b89
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 9 deletions.
20 changes: 20 additions & 0 deletions src/platforms/mac/osxwindow.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Copyright (C) 2015 ~ 2017 Deepin Technology Co., Ltd.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

namespace OSX {
void HideWindowTitlebar(long winid);
}
41 changes: 41 additions & 0 deletions src/platforms/mac/osxwindow.mm
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright (C) 2015 ~ 2017 Deepin Technology Co., Ltd.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include "osxwindow.h"

#include <Cocoa/Cocoa.h>

namespace OSX {

void HideWindowTitlebar(long winId)
{
NSView *view = reinterpret_cast<NSView *>(winId);
NSWindow* window = [view window];

[window setStyleMask: [window styleMask] | NSFullSizeContentViewWindowMask | NSWindowTitleHidden];

[window setTitlebarAppearsTransparent:YES];
[window setMovableByWindowBackground:YES];

[[window standardWindowButton:NSWindowCloseButton] setHidden:YES];
[[window standardWindowButton:NSWindowMiniaturizeButton] setHidden:YES];
[[window standardWindowButton:NSWindowZoomButton] setHidden:YES];

window.titleVisibility = NSWindowTitleHidden;
}

}
20 changes: 19 additions & 1 deletion src/widgets/dmainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
#include <QWindow>
#include <QMouseEvent>

#ifdef Q_OS_MAC
#include "osxwindow.h"
#endif

/// shadow
#define SHADOW_COLOR_NORMAL QColor(0, 0, 0, 255 * 35/100)
#define SHADOW_COLOR_ACTIVE QColor(0, 0, 0, 255 * 60/100)
Expand All @@ -42,8 +46,12 @@ DMainWindowPrivate::DMainWindowPrivate(DMainWindow *qq)
handle = new DPlatformWindowHandle(qq, qq);
qq->setMenuWidget(titlebar);
} else {
qq->setMenuWidget(titlebar);
#ifdef Q_OS_MAC
OSX::HideWindowTitlebar(qq->winId());
#else
titlebar->setEmbedMode(true);
qq->setContentsMargins(0, titlebar->height(), 0, 0);
#endif
}
}

Expand Down Expand Up @@ -96,6 +104,8 @@ void DMainWindowPrivate::init()
}
});
}


}

/*!
Expand Down Expand Up @@ -517,6 +527,14 @@ void DMainWindow::setAutoInputMaskByClipPath(bool autoInputMaskByClipPath)
d->handle->setAutoInputMaskByClipPath(autoInputMaskByClipPath);
}

#ifdef Q_OS_MAC
void DMainWindow::setWindowFlags(Qt::WindowFlags type)
{
QMainWindow::setWindowFlags(type);
OSX::HideWindowTitlebar(winId());
}
#endif

DMainWindow::DMainWindow(DMainWindowPrivate &dd, QWidget *parent)
: QMainWindow(parent)
, DObject(dd)
Expand Down
5 changes: 5 additions & 0 deletions src/widgets/dmainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ public Q_SLOTS:
void setEnableBlurWindow(bool enableBlurWindow);
void setAutoInputMaskByClipPath(bool autoInputMaskByClipPath);

// TODO: remove it if there is an batter sulotion
#ifdef Q_OS_MAC
void setWindowFlags(Qt::WindowFlags type);
#endif

Q_SIGNALS:
void windowRadiusChanged();
void borderWidthChanged();
Expand Down
8 changes: 0 additions & 8 deletions src/widgets/dtitlebar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -543,14 +543,6 @@ bool DTitlebar::eventFilter(QObject *obj, QEvent *event)
d->maxButton->setMaximized(d->parentWindow->windowState() == Qt::WindowMaximized);
// }
break;
case QEvent::Resize:
case QEvent::Show:
if (d->embedMode) {
const auto margins = d->parentWindow->contentsMargins();
auto horizontalOffset = margins.left() + margins.right();
setFixedWidth(d->parentWindow->width() - horizontalOffset);
}
break;
case QEvent::ShowToParent:
d->updateButtonsFunc();
break;
Expand Down
12 changes: 12 additions & 0 deletions src/widgets/widgets.pri
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,18 @@ linux{

}

mac{
HEADERS +=\
$$PWD/../platforms/mac/osxwindow.h

OBJECTIVE_SOURCES += \
$$PWD/../platforms/mac/osxwindow.mm

INCLUDEPATH += $$PWD/../platforms/mac

LIBS += -framework Foundation -framework Cocoa
}

HEADERS += $$PWD/dslider.h\
$$PWD/dthememanager.h \
$$PWD/dapplication.h \
Expand Down

0 comments on commit 5f47b89

Please sign in to comment.