2021-10-24 02:07:56 +00:00
|
|
|
/*
|
|
|
|
Copyright 2021 Peter Repukat - FlatspotSoftware
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
#include <QGuiApplication>
|
|
|
|
#include <QQmlApplicationEngine>
|
|
|
|
#include <QQmlContext>
|
|
|
|
#include <QWindow>
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
2021-10-28 09:41:27 +00:00
|
|
|
#include <VersionHelpers.h>
|
2021-10-24 02:07:56 +00:00
|
|
|
#include <Windows.h>
|
|
|
|
#include <dwmapi.h>
|
|
|
|
#pragma comment(lib, "Dwmapi.lib")
|
2021-10-28 17:33:56 +00:00
|
|
|
#include "ExeImageProvider.h"
|
2021-10-24 02:07:56 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "UIModel.h"
|
2021-10-25 16:00:34 +00:00
|
|
|
#include "WinEventFilter.h"
|
2021-10-24 02:07:56 +00:00
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
// Some undocument stuff to enable aero on win10 or higher...
|
2021-10-28 09:41:27 +00:00
|
|
|
enum AccentState {
|
2021-10-24 02:07:56 +00:00
|
|
|
ACCENT_DISABLED = 0,
|
|
|
|
ACCENT_ENABLE_GRADIENT = 1,
|
|
|
|
ACCENT_ENABLE_TRANSPARENTGRADIENT = 2,
|
|
|
|
ACCENT_ENABLE_BLURBEHIND = 3,
|
2021-10-24 10:17:38 +00:00
|
|
|
ACCENT_ENABLE_ACRYLICBLURBEHIND = 4,
|
|
|
|
ACCENT_ENABLE_HOSTBACKDROP = 5, // RS5 1809
|
|
|
|
ACCENT_INVALID_STATE = 6
|
2021-10-24 02:07:56 +00:00
|
|
|
};
|
2021-10-28 09:41:27 +00:00
|
|
|
struct AccentPolicy {
|
2021-10-24 02:07:56 +00:00
|
|
|
|
|
|
|
AccentState AccentState;
|
|
|
|
int AccentFlags;
|
|
|
|
int GradientColor;
|
|
|
|
int AnimationId;
|
|
|
|
};
|
|
|
|
|
2021-10-28 09:41:27 +00:00
|
|
|
enum WindowCompositionAttribute {
|
2021-10-24 02:07:56 +00:00
|
|
|
// ...
|
|
|
|
WCA_ACCENT_POLICY = 19
|
|
|
|
// ...
|
|
|
|
};
|
2021-10-28 09:41:27 +00:00
|
|
|
struct WindowCompositionAttributeData {
|
2021-10-24 02:07:56 +00:00
|
|
|
WindowCompositionAttribute Attribute;
|
|
|
|
void* Data;
|
|
|
|
int SizeOfData;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef HRESULT(__stdcall* PSetWindowCompositionAttribute)(HWND hwnd, WindowCompositionAttributeData* pattrs);
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
int main(int argc, char* argv[])
|
|
|
|
{
|
|
|
|
#if defined(Q_OS_WIN)
|
|
|
|
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
QGuiApplication app(argc, argv);
|
|
|
|
|
|
|
|
QQmlApplicationEngine engine;
|
|
|
|
UIModel uimodel;
|
2021-10-28 17:33:56 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
engine.addImageProvider(QLatin1String("exe"), new ExeImageProvider());
|
|
|
|
#endif
|
2021-10-24 02:07:56 +00:00
|
|
|
engine.rootContext()->setContextProperty("uiModel", QVariant::fromValue(&uimodel));
|
|
|
|
engine.load(QUrl(QStringLiteral("qrc:/qml/main.qml")));
|
|
|
|
if (engine.rootObjects().isEmpty())
|
|
|
|
return -1;
|
|
|
|
#ifdef _WIN32
|
|
|
|
|
|
|
|
// As a Qt.Frameless window sucks ass, and doesn't support Aerosnap and resizing and all that stuff is cumbersome on windows...
|
|
|
|
// Use good old dwm...
|
|
|
|
|
|
|
|
// First get window from QML.
|
|
|
|
auto window = qobject_cast<QWindow*>(engine.rootObjects()[0]);
|
|
|
|
const HWND hwnd = reinterpret_cast<HWND>(window->winId());
|
|
|
|
// Clear it's title bar
|
|
|
|
// NO!(!!) We wan't to keep WS_THICKFRAME, as that's what gives us a shadow, aerosnap, proper resizing, win11 round corners
|
|
|
|
// ...and all that good stuff!
|
|
|
|
auto style = GetWindowLong(hwnd, GWL_STYLE);
|
|
|
|
style &= ~(WS_CAPTION | WS_MINIMIZE | WS_MAXIMIZE | WS_SYSMENU);
|
|
|
|
SetWindowLong(hwnd, GWL_STYLE, style);
|
|
|
|
|
|
|
|
// Enable blurbehind (not needed?) anyway gives nice background on win7 and 8
|
2021-10-29 17:51:59 +00:00
|
|
|
// LOL.. just realizing < Win 10 is not supported by HidHide driver...
|
|
|
|
// let's see what users think...
|
2021-10-24 23:14:34 +00:00
|
|
|
DWM_BLURBEHIND bb{};
|
2021-10-28 09:41:27 +00:00
|
|
|
bb.dwFlags = DWM_BB_ENABLE;
|
|
|
|
bb.fEnable = true;
|
|
|
|
bb.hRgnBlur = nullptr;
|
2021-10-24 02:07:56 +00:00
|
|
|
DwmEnableBlurBehindWindow(hwnd, &bb);
|
|
|
|
|
2021-10-28 09:41:27 +00:00
|
|
|
if (IsWindows10OrGreater()) {
|
2021-10-24 10:17:38 +00:00
|
|
|
// undoc stuff for aero >= Win10
|
|
|
|
int color = (0 << 24) + (0x21 << 16) + (0x11 << 8) + (0x11);
|
2021-10-24 23:14:34 +00:00
|
|
|
AccentPolicy accPol{};
|
|
|
|
accPol.AccentState = ACCENT_ENABLE_ACRYLICBLURBEHIND;
|
2021-10-28 09:41:27 +00:00
|
|
|
accPol.AccentFlags = 2;
|
|
|
|
accPol.GradientColor = color;
|
2021-10-24 23:14:34 +00:00
|
|
|
accPol.AnimationId = 0;
|
|
|
|
WindowCompositionAttributeData data{};
|
|
|
|
data.Attribute = WindowCompositionAttribute::WCA_ACCENT_POLICY;
|
2021-10-28 09:41:27 +00:00
|
|
|
data.Data = &accPol;
|
|
|
|
data.SizeOfData = sizeof(accPol);
|
2021-10-24 10:17:38 +00:00
|
|
|
auto user32dll = GetModuleHandle(L"user32.dll");
|
|
|
|
if (user32dll) {
|
2021-10-28 09:41:27 +00:00
|
|
|
PSetWindowCompositionAttribute SetWindowCompositionAttribute = (reinterpret_cast<PSetWindowCompositionAttribute>(GetProcAddress(user32dll, "SetWindowCompositionAttribute")));
|
|
|
|
if (SetWindowCompositionAttribute) {
|
2021-10-24 10:17:38 +00:00
|
|
|
auto res = SetWindowCompositionAttribute(hwnd, &data);
|
2021-10-28 09:41:27 +00:00
|
|
|
if (SUCCEEDED(res)) {
|
2021-10-24 10:17:38 +00:00
|
|
|
uimodel.setAcrylicEffect(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-10-24 02:07:56 +00:00
|
|
|
|
|
|
|
// extend the frame fully into the client area => draw all outside the window frame.
|
2021-10-28 09:41:27 +00:00
|
|
|
MARGINS margins = {-1};
|
2021-10-24 02:07:56 +00:00
|
|
|
DwmExtendFrameIntoClientArea(hwnd, &margins);
|
|
|
|
|
|
|
|
// To Fix top window frame, install native event filter
|
|
|
|
// basically the Qt. equivalent of having a own WndProc
|
|
|
|
// for more info see WinEventFilter.h
|
|
|
|
auto filter = std::make_shared<WinEventFilter>();
|
|
|
|
app.installNativeEventFilter(filter.get());
|
|
|
|
|
|
|
|
RECT rcClient;
|
|
|
|
GetWindowRect(hwnd, &rcClient);
|
|
|
|
|
|
|
|
// Inform the application of the frame change.
|
|
|
|
SetWindowPos(hwnd,
|
2021-10-28 09:41:27 +00:00
|
|
|
NULL,
|
|
|
|
rcClient.left, rcClient.top,
|
|
|
|
rcClient.right - rcClient.left, rcClient.bottom - rcClient.top,
|
|
|
|
SWP_FRAMECHANGED);
|
2021-10-24 02:07:56 +00:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return app.exec();
|
|
|
|
}
|