Skip to content

Commit 1d08c8b

Browse files
Fix top border & misc tweaks (#167)
* Update * update --------- Co-authored-by: SineStriker <55847490+SineStriker@users.noreply.github.com>
1 parent 0aada6f commit 1d08c8b

File tree

5 files changed

+31
-25
lines changed

5 files changed

+31
-25
lines changed

src/core/contexts/win32windowcontext.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -920,13 +920,8 @@ namespace QWK {
920920

921921
const DynamicApis &apis = DynamicApis::instance();
922922
const auto &extendMargins = [this, &apis, hwnd]() {
923-
// For some unknown reason, the window background is totally black when the host object
924-
// is a QWidget. And extending the window frame into the client area seems to fix it
925-
// magically.
926-
// We don't need the following *HACK* for QtQuick windows.
927-
if (!m_host->isWidgetType()) {
928-
return;
929-
}
923+
// For some unknown reason, the window background is totally black and extending
924+
// the window frame into the client area seems to fix it magically.
930925
// After many times of trying, we found that the Acrylic/Mica/Mica Alt background
931926
// only appears on the native Win32 window's background, so naturally we want to
932927
// extend the window frame into the whole client area to be able to let the special
@@ -955,6 +950,7 @@ namespace QWK {
955950

956951
const auto &effectBugWorkaround = [this, hwnd]() {
957952
// We don't need the following *HACK* for QWidget windows.
953+
// Completely based on actual experiments, root reason is totally unknown.
958954
if (m_host->isWidgetType()) {
959955
return;
960956
}

src/core/shared/windows10borderhandler_p.h

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,12 @@ namespace QWK {
3131
}
3232

3333
inline void setupNecessaryAttributes() {
34-
// https://github.com/microsoft/terminal/blob/71a6f26e6ece656084e87de1a528c4a8072eeabd/src/cascadia/WindowsTerminal/NonClientIslandWindow.cpp#L940
35-
// Must extend top frame to client area
36-
static QVariant defaultMargins = QVariant::fromValue(QMargins(0, 1, 0, 0));
37-
ctx->setWindowAttribute(QStringLiteral("extra-margins"), defaultMargins);
34+
if (!isWin11OrGreater()) {
35+
// https://github.com/microsoft/terminal/blob/71a6f26e6ece656084e87de1a528c4a8072eeabd/src/cascadia/WindowsTerminal/NonClientIslandWindow.cpp#L940
36+
// Must extend top frame to client area
37+
static QVariant defaultMargins = QVariant::fromValue(QMargins(0, 1, 0, 0));
38+
ctx->setWindowAttribute(QStringLiteral("extra-margins"), defaultMargins);
39+
}
3840

3941
// Enable dark mode by default, otherwise the system borders are white
4042
ctx->setWindowAttribute(QStringLiteral("dark-mode"), true);
@@ -45,7 +47,17 @@ namespace QWK {
4547
(Qt::WindowMinimized | Qt::WindowMaximized | Qt::WindowFullScreen));
4648
}
4749

48-
inline void drawBorder() {
50+
inline void drawBorderEmulated(QPainter *painter, const QRect &rect) {
51+
QRegion region(rect);
52+
void *args[] = {
53+
painter,
54+
const_cast<QRect *>(&rect),
55+
&region,
56+
};
57+
ctx->virtual_hook(AbstractWindowContext::DrawWindows10BorderHook_Emulated, args);
58+
}
59+
60+
inline void drawBorderNative() {
4961
ctx->virtual_hook(AbstractWindowContext::DrawWindows10BorderHook_Native, nullptr);
5062
}
5163

@@ -54,6 +66,11 @@ namespace QWK {
5466
}
5567

5668
inline void updateExtraMargins(bool windowActive) {
69+
if (isWin11OrGreater()) {
70+
return;
71+
}
72+
73+
// ### FIXME: transparent seam
5774
if (windowActive) {
5875
// Restore margins when the window is active
5976
static QVariant defaultMargins = QVariant::fromValue(QMargins(0, 1, 0, 0));

src/quick/quickwindowagent_win.cpp

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -97,21 +97,14 @@ namespace QWK {
9797
BorderItem::~BorderItem() = default;
9898

9999
void BorderItem::updateGeometry() {
100-
setHeight(borderThickness());
100+
setHeight(borderThickness() / window()->devicePixelRatio());
101101
setVisible(isNormalWindow());
102102
}
103103

104104
void BorderItem::paint(QPainter *painter) {
105105
Q_UNUSED(painter)
106106
if (shouldEnableEmulatedPainter()) {
107-
QRect rect(QPoint(0, 0), size().toSize());
108-
QRegion region(rect);
109-
void *args[] = {
110-
painter,
111-
&rect,
112-
&region,
113-
};
114-
ctx->virtual_hook(AbstractWindowContext::DrawWindows10BorderHook_Emulated, args);
107+
drawBorderEmulated(painter, QRect({0, 0}, size().toSize()));
115108
} else {
116109
needPaint = true;
117110
}
@@ -170,7 +163,7 @@ namespace QWK {
170163
void BorderItem::_q_afterSynchronizing() {
171164
if (needPaint) {
172165
needPaint = false;
173-
drawBorder();
166+
drawBorderNative();
174167
}
175168
}
176169

src/widgets/widgetwindowagent.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ namespace QWK {
6161
w->setAttribute(Qt::WA_DontCreateNativeAncestors);
6262
// Make sure the native window handle is actually created before we apply
6363
// various hooks.
64-
w->setAttribute(Qt::WA_NativeWindow); // ### FIXME: Remove
64+
//w->setAttribute(Qt::WA_NativeWindow); // ### FIXME: Check
6565

6666
d->setup(w, new WidgetItemDelegate());
6767
d->hostWidget = w;

src/widgets/widgetwindowagent_win.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ namespace QWK {
8383
// Due to the timer or user action, Qt will repaint some regions spontaneously,
8484
// even if there is no WM_PAINT message, we must wait for it to finish painting
8585
// and then update the top border area.
86-
drawBorder();
86+
drawBorderNative();
8787
}
8888

8989
inline void forwardEventToWindowAndDraw(QWindow *window, QEvent *event) {
@@ -97,7 +97,7 @@ namespace QWK {
9797

9898
// Upon receiving the WM_PAINT message, Qt will repaint the entire view, and we
9999
// must wait for it to finish painting before drawing this top border area.
100-
drawBorder();
100+
drawBorderNative();
101101
}
102102

103103
protected:

0 commit comments

Comments
 (0)