Skip to content
25 changes: 22 additions & 3 deletions src/core/contexts/cocoawindowcontext.mm
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <Cocoa/Cocoa.h>

#include <QtGui/QGuiApplication>
#include <QDebug>

#include "qwkglobal_p.h"
#include "systemwindow_p.h"
Expand Down Expand Up @@ -185,6 +186,10 @@ void windowEvent(NSEventType eventType) override {
}

default:
if (!screenRectCallback || !systemButtonVisible) {
return;
}
updateSystemButtonRect();
break;
}
}
Expand Down Expand Up @@ -218,6 +223,8 @@ void updateSystemButtonRect() {
const auto &midButton = buttons[1];
const auto &rightButton = buttons[2];

[rightButton.superview setFrameSize:NSMakeSize(84, 48)];

auto titlebar = rightButton.superview;
int titlebarHeight = titlebar.frame.size.height;

Expand All @@ -233,6 +240,18 @@ void updateSystemButtonRect() {
// do the necessary transformations
center.ry() = titlebarHeight - center.y();

QString log = QString("[DBG] Updating system button rect: TBH: %1 ViewSize: (%2, %3) Center: (%4, %5) ButtonFrame: (%6, %7) Spacing %8")
.arg(titlebarHeight)
.arg(viewSize.width)
.arg(viewSize.height)
.arg(center.x())
.arg(center.y())
.arg(width)
.arg(height)
.arg(spacing);

qInfo() << log;

// Mid button
NSPoint centerOrigin = {
center.x() - width / 2,
Expand Down Expand Up @@ -709,22 +728,22 @@ static inline void releaseWindowProxy(const WId windowId) {
Q_UNUSED(oldAttribute)

if (key == QStringLiteral("no-system-buttons")) {
if (attribute.type() != QVariant::Bool)
if (attribute.typeId() != QMetaType::Bool)
return false;
ensureWindowProxy(m_windowId)->setSystemButtonVisible(!attribute.toBool());
return true;
}

if (key == QStringLiteral("blur-effect")) {
auto mode = NSWindowProxy::BlurMode::None;
if (attribute.type() == QVariant::Bool) {
if (attribute.typeId() == QMetaType::Bool) {
if (attribute.toBool()) {
NSString *osxMode =
[[NSUserDefaults standardUserDefaults] stringForKey:@"AppleInterfaceStyle"];
mode = [osxMode isEqualToString:@"Dark"] ? NSWindowProxy::BlurMode::Dark
: NSWindowProxy::BlurMode::Light;
}
} else if (attribute.type() == QVariant::String) {
} else if (attribute.typeId() == QMetaType::QString) {
auto value = attribute.toString();
if (value == QStringLiteral("dark")) {
mode = NSWindowProxy::BlurMode::Dark;
Expand Down