Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: some windows have dual title bars #622

Merged
merged 1 commit into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/widgets/dtitlebar.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ private Q_SLOTS:
D_PRIVATE_SLOT(void _q_toggleWindowState())
D_PRIVATE_SLOT(void _q_showMinimized())
D_PRIVATE_SLOT(void _q_onTopWindowMotifHintsChanged(quint32))
D_PRIVATE_SLOT(void _q_closeWindow())

#ifndef QT_NO_MENU
D_PRIVATE_SLOT(void _q_addDefaultMenuItems())
Expand Down
7 changes: 1 addition & 6 deletions src/widgets/dabstractdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,6 @@ void DAbstractDialogPrivate::init(bool blurIfPossible)
// TODO: 这里对dialog特殊处理,dialog不需要设置固定的位置,否则里面的坐标会发生偏移导致点击偏移
// 但是这不是问题的根本原因,还需要进一步分析。该属性在插件中做了特殊处理
q->QDialog::setProperty("DAbstractDialog", true);
auto noTitlebarEnabled = []{
QFunctionPointer enableNoTitlebar = qApp->platformFunction("_d_isEnableNoTitlebar");
bool enabled = qApp->platformName() == "dwayland" || qApp->property("_d_isDwayland").toBool();
return enabled && enableNoTitlebar != nullptr;
};

if (qApp->isDXcbPlatform()) {
handle = new DPlatformWindowHandle(q, q);
Expand All @@ -66,7 +61,7 @@ void DAbstractDialogPrivate::init(bool blurIfPossible)

bgBlurWidget->setBlurEnabled(blurIfPossible);
q->setAttribute(Qt::WA_TranslucentBackground, blurIfPossible);
} else if (noTitlebarEnabled()) {
} else if (DWindowManagerHelper::instance()->hasNoTitlebar()) {
handle = new DPlatformWindowHandle(q, q);

if (!handle->enableBlurWindow()) {
Expand Down
16 changes: 9 additions & 7 deletions src/widgets/dfloatingmessage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <QLabel>
#include <QDebug>
#include <QGraphicsDropShadowEffect>
#include <QWindow>

class MessageLabel : public QLabel
{
Expand Down Expand Up @@ -79,15 +80,16 @@ void DFloatingMessagePrivate::init()
closeButton->setIconSize(DSizeModeHelper::element(QSize(20, 20), QSize(32, 32)));

hBoxLayout->addWidget(closeButton);
q->connect(closeButton, &DIconButton::clicked, q, &DFloatingMessage::closeButtonClicked);

if(ENABLE_ANIMATIONS && ENABLE_ANIMATION_MESSAGE)
q->connect(closeButton, &DIconButton::clicked, q, [q]() {
q->close();
q->connect(closeButton, &DIconButton::clicked, q, [q]() {
if (q->windowHandle()) {
q->windowHandle()->close();
}
if(ENABLE_ANIMATIONS && ENABLE_ANIMATION_MESSAGE) {
Q_EMIT q->messageClosed();
});
else
q->connect(closeButton, &DIconButton::clicked, q, &DFloatingMessage::close);
}
Q_EMIT q->closeButtonClicked();
});
}

if (!ENABLE_ANIMATIONS || !ENABLE_ANIMATION_MESSAGE)
Expand Down
12 changes: 3 additions & 9 deletions src/widgets/dmainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <qwidgetaction.h>
#include <QScreen>

#include <DWindowManagerHelper>
#include <DAnchors>
#include <DConfig>

Expand All @@ -42,15 +43,8 @@ DMainWindowPrivate::DMainWindowPrivate(DMainWindow *qq)
{
titlebar = new DTitlebar(qq);
titlebar->setAccessibleName("DMainWindowTitlebar");
auto noTitlebarEnabled = []{
if (DGuiApplicationHelper::testAttribute(DGuiApplicationHelper::IsWaylandPlatform)) {
return true;
}
QFunctionPointer enableNoTitlebar = qApp->platformFunction("_d_isEnableNoTitlebar");
bool enabled = qApp->platformName() == "dwayland" || qApp->property("_d_isDwayland").toBool();
return enabled && enableNoTitlebar != nullptr;
};
if (DApplication::isDXcbPlatform() || noTitlebarEnabled()) {

if (DApplication::isDXcbPlatform() || DWindowManagerHelper::instance()->hasNoTitlebar()) {
handle = new DPlatformWindowHandle(qq, qq);
qq->setMenuWidget(titlebar);
} else {
Expand Down
10 changes: 9 additions & 1 deletion src/widgets/dtitlebar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ class DTitlebarPrivate : public DTK_CORE_NAMESPACE::DObjectPrivate
void _q_toggleWindowState();
void _q_showMinimized();
void _q_onTopWindowMotifHintsChanged(quint32 winId);
void _q_closeWindow();

#ifndef QT_NO_MENU
void _q_addDefaultMenuItems();
Expand Down Expand Up @@ -572,6 +573,13 @@ void DTitlebarPrivate::_q_toggleWindowState()
}
}

void DTitlebarPrivate::_q_closeWindow()
{
if (targetWindow()->windowHandle()) {
targetWindow()->windowHandle()->close();
}
}

void DTitlebarPrivate::_q_showMinimized()
{
targetWindow()->showMinimized();
Expand Down Expand Up @@ -1533,7 +1541,7 @@ void DTitlebar::setVisible(bool visible)
connect(d->maxButton, SIGNAL(clicked()), this, SLOT(_q_toggleWindowState()), Qt::UniqueConnection);
connect(this, SIGNAL(doubleClicked()), this, SLOT(_q_toggleWindowState()), Qt::UniqueConnection);
connect(d->minButton, SIGNAL(clicked()), this, SLOT(_q_showMinimized()), Qt::UniqueConnection);
connect(d->closeButton, &DWindowCloseButton::clicked, d->targetWindow(), &QWidget::close, Qt::UniqueConnection);
connect(d->closeButton, SIGNAL(clicked()), this, SLOT(_q_closeWindow()), Qt::UniqueConnection);

d->updateButtonsState(d->targetWindow()->windowFlags());
} else {
Expand Down