5#ifndef WINDOWS10BORDERHANDLER_P_H
6#define WINDOWS10BORDERHANDLER_P_H
17#include <QtGui/QWindow>
18#include <QtGui/QMouseEvent>
20#include <QWKCore/qwindowkit_windows.h>
21#include <QWKCore/private/qwkglobal_p.h>
22#include <QWKCore/private/abstractwindowcontext_p.h>
26 class Windows10BorderHandler :
public NativeEventFilter,
public SharedEventFilter {
28 inline Windows10BorderHandler(AbstractWindowContext *ctx) : ctx(ctx) {
29 ctx->installNativeEventFilter(
this);
30 ctx->installSharedEventFilter(
this);
33 inline void setupNecessaryAttributes() {
34 if (!isWin11OrGreater()) {
37 static QVariant defaultMargins = QVariant::fromValue(QMargins(0, 1, 0, 0));
38 ctx->setWindowAttribute(QStringLiteral(
"extra-margins"), defaultMargins);
42 ctx->setWindowAttribute(QStringLiteral(
"dark-mode"),
true);
45 inline bool isNormalWindow()
const {
46 return !(ctx->window()->windowStates() &
47 (Qt::WindowMinimized | Qt::WindowMaximized | Qt::WindowFullScreen));
50 inline void drawBorderEmulated(QPainter *painter,
const QRect &rect) {
54 const_cast<QRect *
>(&rect),
57 ctx->virtual_hook(AbstractWindowContext::DrawWindows10BorderHook_Emulated, args);
60 inline void drawBorderNative() {
61 ctx->virtual_hook(AbstractWindowContext::DrawWindows10BorderHook_Native,
nullptr);
64 inline int borderThickness()
const {
65 return ctx->windowAttribute(QStringLiteral(
"border-thickness")).toInt();
68 inline void updateExtraMargins(
bool windowActive) {
69 if (isWin11OrGreater()) {
76 static QVariant defaultMargins = QVariant::fromValue(QMargins(0, 1, 0, 0));
77 ctx->setWindowAttribute(QStringLiteral(
"extra-margins"), defaultMargins);
85 QRect frame = ctx->windowAttribute(QStringLiteral(
"window-rect")).toRect();
86 QMargins margins{0, -frame.top(), 0, 0};
87 ctx->setWindowAttribute(QStringLiteral(
"extra-margins"), QVariant::fromValue(margins));
90 virtual void updateGeometry() = 0;
92 virtual bool isWindowActive()
const {
93 return ctx->window()->isActive();
97 bool nativeEventFilter(
const QByteArray &eventType,
void *message,
98 QT_NATIVE_EVENT_RESULT_TYPE *result)
override {
101 const auto msg =
static_cast<const MSG *
>(message);
102 switch (msg->message) {
103 case WM_DPICHANGED: {
105 updateExtraMargins(isWindowActive());
110 updateExtraMargins(LOWORD(msg->wParam) != WA_INACTIVE);
114 case WM_THEMECHANGED:
115 case WM_SYSCOLORCHANGE:
116 case WM_DWMCOLORIZATIONCOLORCHANGED: {
122 if (ctx->windowAttribute(QStringLiteral(
"dark-mode")).toBool()) {
123 ctx->setWindowAttribute(QStringLiteral(
"dark-mode"),
true);
134 bool sharedEventFilter(QObject *obj, QEvent *event)
override {
137 if (event->type() == QEvent::WinIdChange) {
138 if (ctx->windowId()) {
139 setupNecessaryAttributes();
147 AbstractWindowContext *ctx;
QWindowKit namespace.
Definition abstractwindowcontext.cpp:13