WIP. Adapt to Windows Terminal style.

Don't remove the window frame totally, only remove the title bar instead
(including the top border).
We can resize outside our window just like any other normal window in
this way. And many strange problems caused by the removal of window
frame are gone such as background flicker.
However, we will need to paint the top frame border ourself. Otherwise
the window doesn't look very good.

Signed-off-by: Yuhang Zhao <2546789017@qq.com>
This commit is contained in:
Yuhang Zhao 2020-04-24 13:02:13 +08:00
parent f77e1adf61
commit 01707907cd
3 changed files with 787 additions and 752 deletions

View File

@ -1,7 +1,12 @@
#include "framelesshelper.h"
#include <QApplication>
#include <QWidget>
#include <QWindow>
#ifdef Q_OS_WINDOWS
#include "winnativeeventfilter.h"
#else
#include "framelesshelper.h"
#endif
int main(int argc, char *argv[]) {
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
@ -20,10 +25,19 @@ int main(int argc, char *argv[]) {
QApplication application(argc, argv);
#ifdef Q_OS_WINDOWS
// Do this AFTER the Q(Gui)Application is constructed!
WinNativeEventFilter::install();
#else
FramelessHelper helper;
#endif
QWindow window;
QWidget widget;
#ifndef Q_OS_WINDOWS
helper.setFramelessWindows({&widget});
#endif
window.show();
widget.show();
return QApplication::exec();

File diff suppressed because it is too large Load Diff

View File

@ -41,7 +41,6 @@ public:
BOOL fixedSize = FALSE, mouseTransparent = FALSE;
int borderWidth = -1, borderHeight = -1, titlebarHeight = -1;
QVector<QRect> ignoreAreas, draggableAreas;
QSize maximumSize = {-1, -1}, minimumSize = {-1, -1};
};
using WINDOW = struct _WINDOW {
@ -101,13 +100,4 @@ public:
bool nativeEventFilter(const QByteArray &eventType, void *message,
long *result) override;
#endif
private:
static void initWin32Api();
static void createUserData(HWND handle, const WINDOWDATA *data = nullptr);
static void updateGlass(HWND handle);
static qreal getPreferedNumber(qreal num);
static UINT getDotsPerInchForWindow(HWND handle);
static qreal getDevicePixelRatioForWindow(HWND handle);
static int getSystemMetricsForWindow(HWND handle, int index);
};