2021-10-24 02:07:56 +00:00
|
|
|
/*
|
2022-01-06 23:38:21 +00:00
|
|
|
Copyright 2021-2022 Peter Repukat - FlatspotSoftware
|
2021-10-24 02:07:56 +00:00
|
|
|
|
|
|
|
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>
|
|
|
|
|
2022-01-04 13:44:29 +00:00
|
|
|
#include <QtDebug>
|
|
|
|
#include <QFile>
|
|
|
|
#include <QTextStream>
|
|
|
|
|
2021-10-24 02:07:56 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
#include <Windows.h>
|
2022-01-04 16:48:25 +00:00
|
|
|
#include <VersionHelpers.h>
|
2021-10-24 02:07:56 +00:00
|
|
|
#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
|
|
|
|
|
2022-01-04 13:44:29 +00:00
|
|
|
//stolen from: https://stackoverflow.com/a/11202102/5106063
|
|
|
|
void myMessageHandler(QtMsgType type, const QMessageLogContext&, const QString& msg)
|
|
|
|
{
|
|
|
|
QString txt;
|
|
|
|
switch (type) {
|
|
|
|
case QtDebugMsg:
|
|
|
|
txt = QString("[%1] Debug: %2").arg(QDateTime::currentDateTime().toString(), msg);
|
|
|
|
break;
|
|
|
|
case QtInfoMsg:
|
|
|
|
txt = QString("[%1] Info: %2").arg(QDateTime::currentDateTime().toString(), msg);
|
|
|
|
break;
|
|
|
|
case QtWarningMsg:
|
|
|
|
txt = QString("[%1] Warning: %2").arg(QDateTime::currentDateTime().toString(), msg);
|
|
|
|
break;
|
|
|
|
case QtCriticalMsg:
|
|
|
|
txt = QString("[%1] Critical: %2").arg(QDateTime::currentDateTime().toString(), msg);
|
|
|
|
break;
|
|
|
|
case QtFatalMsg:
|
|
|
|
txt = QString("[%1] Fatal: %2").arg(QDateTime::currentDateTime().toString(), msg);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto path = std::filesystem::temp_directory_path()
|
|
|
|
.parent_path()
|
|
|
|
.parent_path()
|
|
|
|
.parent_path();
|
|
|
|
|
|
|
|
path /= "Roaming";
|
|
|
|
path /= "GlosSI";
|
|
|
|
if (!std::filesystem::exists(path))
|
|
|
|
std::filesystem::create_directories(path);
|
|
|
|
|
|
|
|
QFile outFile(QString::fromStdWString(path) + "/glossiconfig.log");
|
|
|
|
outFile.open(QIODevice::WriteOnly | QIODevice::Append);
|
|
|
|
QTextStream ts(&outFile);
|
|
|
|
ts << txt << '\n';
|
2022-01-04 14:59:12 +00:00
|
|
|
std::cout << txt.toStdString() << "\n";
|
2022-01-04 13:44:29 +00:00
|
|
|
}
|
|
|
|
|
2021-10-24 02:07:56 +00:00
|
|
|
int main(int argc, char* argv[])
|
|
|
|
{
|
2022-01-06 23:38:21 +00:00
|
|
|
|
2021-10-24 02:07:56 +00:00
|
|
|
#if defined(Q_OS_WIN)
|
|
|
|
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
|
2022-01-04 22:37:33 +00:00
|
|
|
HRESULT hr = ::CoInitializeEx(NULL, COINIT_MULTITHREADED);
|
2021-10-24 02:07:56 +00:00
|
|
|
#endif
|
|
|
|
|
2022-01-04 14:59:12 +00:00
|
|
|
if (argc < 3) {
|
|
|
|
auto path = std::filesystem::temp_directory_path()
|
|
|
|
.parent_path()
|
|
|
|
.parent_path()
|
|
|
|
.parent_path();
|
|
|
|
|
|
|
|
path /= "Roaming";
|
|
|
|
path /= "GlosSI";
|
|
|
|
if (!std::filesystem::exists(path))
|
|
|
|
std::filesystem::create_directories(path);
|
|
|
|
|
|
|
|
QFile outFile(QString::fromStdWString(path) + "/glossiconfig.log");
|
|
|
|
outFile.open(QIODevice::WriteOnly);
|
|
|
|
QTextStream ts(&outFile);
|
|
|
|
ts << '\n';
|
|
|
|
}
|
|
|
|
|
2021-10-24 02:07:56 +00:00
|
|
|
QGuiApplication app(argc, argv);
|
2022-01-04 13:44:29 +00:00
|
|
|
qInstallMessageHandler(myMessageHandler);
|
2021-10-24 02:07:56 +00:00
|
|
|
|
|
|
|
QQmlApplicationEngine engine;
|
|
|
|
UIModel uimodel;
|
2022-01-04 14:38:28 +00:00
|
|
|
if (argc >= 4) {
|
|
|
|
if (QString::fromStdString(argv[1]) == "remove") {
|
|
|
|
const auto write_res = uimodel.removeFromSteam(
|
2022-07-13 20:53:57 +00:00
|
|
|
QCoreApplication::arguments().at(2), QCoreApplication::arguments().at(3), true);
|
2022-01-04 14:38:28 +00:00
|
|
|
if (write_res) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
} else if (QString::fromStdString(argv[1]) == "add") {
|
|
|
|
const auto write_res = uimodel.addToSteam(
|
2022-07-13 20:53:57 +00:00
|
|
|
QCoreApplication::arguments().at(2), QCoreApplication::arguments().at(3), true);
|
2022-01-04 14:38:28 +00:00
|
|
|
if (write_res) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
2022-06-16 20:30:50 +00:00
|
|
|
|
|
|
|
QGuiApplication::setWindowIcon(QIcon(":/GloSC_Icon_small.png"));
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
2022-01-21 14:01:32 +00:00
|
|
|
HMODULE hUser = GetModuleHandle(L"user32.dll");
|
|
|
|
if (hUser) {
|
|
|
|
if (auto set_window_composition_attribute = reinterpret_cast<PSetWindowCompositionAttribute>(GetProcAddress(hUser, "SetWindowCompositionAttribute"))) {
|
|
|
|
AccentPolicy accent = {ACCENT_ENABLE_BLURBEHIND, 0, 0, 0};
|
|
|
|
WindowCompositionAttributeData data{};
|
|
|
|
data.Attribute = WCA_ACCENT_POLICY;
|
|
|
|
data.Data = &accent;
|
|
|
|
data.SizeOfData = sizeof(accent);
|
|
|
|
set_window_composition_attribute(hwnd, &data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-04 21:41:26 +00:00
|
|
|
//if (IsWindows10OrGreater()) {
|
|
|
|
// // undoc stuff for aero >= Win10
|
|
|
|
// int color = (0 << 24) + (0x21 << 16) + (0x11 << 8) + (0x11);
|
|
|
|
// AccentPolicy accPol{};
|
|
|
|
// accPol.AccentState = ACCENT_ENABLE_ACRYLICBLURBEHIND;
|
|
|
|
// accPol.AccentFlags = 2;
|
|
|
|
// accPol.GradientColor = color;
|
|
|
|
// accPol.AnimationId = 0;
|
|
|
|
// WindowCompositionAttributeData data{};
|
|
|
|
// data.Attribute = WindowCompositionAttribute::WCA_ACCENT_POLICY;
|
|
|
|
// data.Data = &accPol;
|
|
|
|
// data.SizeOfData = sizeof(accPol);
|
|
|
|
// auto user32dll = GetModuleHandle(L"user32.dll");
|
|
|
|
// if (user32dll) {
|
|
|
|
// PSetWindowCompositionAttribute SetWindowCompositionAttribute = (reinterpret_cast<PSetWindowCompositionAttribute>(GetProcAddress(user32dll, "SetWindowCompositionAttribute")));
|
|
|
|
// if (SetWindowCompositionAttribute) {
|
|
|
|
// auto res = SetWindowCompositionAttribute(hwnd, &data);
|
|
|
|
// if (SUCCEEDED(res)) {
|
|
|
|
// 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();
|
|
|
|
}
|