Skip to content

Commit

Permalink
fix: always show button on none linux
Browse files Browse the repository at this point in the history
Change-Id: I0f4dc2081f747d695014e137795da18071eca22d
  • Loading branch information
iceyer committed Apr 22, 2019
1 parent c90c910 commit 633617d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
5 changes: 2 additions & 3 deletions src/widgets/dborderlesswidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,6 @@ DBorderlessWidget::DBorderlessWidget(DBorderlessWidgetPrivate &dd, QWidget *pare
QWidget::setMouseTracking(true);

QWidget::setAttribute(Qt::WA_TranslucentBackground, true);
QWidget::setWindowFlags(Qt::Window | Qt::FramelessWindowHint);

setWindowFlags(windowFlags());
setDecorationFlags(decorationFlags());

Expand Down Expand Up @@ -488,8 +486,9 @@ Qt::WindowFlags DBorderlessWidget::windowFlags()
void DBorderlessWidget::setWindowFlags(Qt::WindowFlags type)
{
D_D(DBorderlessWidget);
QWidget::setWindowFlags(type | Qt::FramelessWindowHint);
d->dwindowFlags = type;
d->titlebar->setWindowFlags(type);
d->titlebar->setWindowFlags(type &~ Qt::Window);
}

/*!
Expand Down
27 changes: 20 additions & 7 deletions src/widgets/dtitlebar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,12 @@ void DTitlebarPrivate::updateButtonsState(Qt::WindowFlags type)
bool useDXcb = DPlatformWindowHandle::isEnabledDXcb(targetWindow());
bool isFullscreen = targetWindow()->windowState().testFlag(Qt::WindowFullScreen);

bool showTitle = (type.testFlag(Qt::WindowTitleHint) || !useDXcb) && !embedMode;
bool forceShow = !useDXcb;
#ifndef Q_OS_LINUX
forceShow = false;
#endif

bool showTitle = (type.testFlag(Qt::WindowTitleHint) || forceShow) && !embedMode;
if (titleLabel) {
titleLabel->setVisible(showTitle);
}
Expand All @@ -295,22 +300,29 @@ void DTitlebarPrivate::updateButtonsState(Qt::WindowFlags type)
// Never show in embed/fullscreen
bool forceHide = embedMode || isFullscreen;

bool showMin = (type.testFlag(Qt::WindowMinimizeButtonHint) || !useDXcb) && !forceHide;
bool showMin = (type.testFlag(Qt::WindowMinimizeButtonHint) || forceShow) && !forceHide;
minButton->setVisible(showMin);


bool allowResize = true;

if (q->window() && q->window()->windowHandle()) {
auto functions_hints = DWindowManagerHelper::getMotifFunctions(q->window()->windowHandle());
allowResize = functions_hints.testFlag(DWindowManagerHelper::FUNC_RESIZE);
}

bool showMax = (type.testFlag(Qt::WindowMaximizeButtonHint) || !useDXcb) && !forceHide && allowResize;
bool showMax = (type.testFlag(Qt::WindowMaximizeButtonHint) || forceShow) && !forceHide && allowResize;
// qDebug() << "max:"
// << "allowResize" << allowResize
// << "useDXcb" << useDXcb
// << "forceHide" << forceHide
// << "type.testFlag(Qt::WindowMaximizeButtonHint)" << type.testFlag(Qt::WindowMaximizeButtonHint);
maxButton->setVisible(showMax);

bool showClose = (type.testFlag(Qt::WindowCloseButtonHint) || !useDXcb) && !forceHide;
bool showClose = (type.testFlag(Qt::WindowCloseButtonHint) || forceShow) && !forceHide;
closeButton->setVisible(showClose);

bool showOption = (type.testFlag(Qt::WindowSystemMenuHint) || !useDXcb) && !isFullscreen;
bool showOption = (type.testFlag(Qt::WindowSystemMenuHint) || forceShow) && !isFullscreen;
optionButton->setVisible(showOption);

buttonArea->adjustSize();
Expand All @@ -325,8 +337,9 @@ void DTitlebarPrivate::updateButtonsFunc()
{
optionButton->setDisabled(disableFlags.testFlag(Qt::WindowSystemMenuHint));

if (!targetWindowHandle)
if (!targetWindowHandle) {
return;
}

// 根据 disableFlags 更新窗口标志,而标题栏上具体按钮的开启/禁用状态只根据
// 窗口标志改变后做更新,且窗口标志改变后也会同步更新 disableFlags 的值,
Expand Down Expand Up @@ -429,7 +442,7 @@ void DTitlebarPrivate::_q_onTopWindowMotifHintsChanged(quint32 winId)

minButton->setEnabled(functions_hints.testFlag(DWindowManagerHelper::FUNC_MINIMIZE));
maxButton->setEnabled(functions_hints.testFlag(DWindowManagerHelper::FUNC_MAXIMIZE)
&& functions_hints.testFlag(DWindowManagerHelper::FUNC_RESIZE));
&& functions_hints.testFlag(DWindowManagerHelper::FUNC_RESIZE));
closeButton->setEnabled(functions_hints.testFlag(DWindowManagerHelper::FUNC_CLOSE));
// sync button state
#if QT_VERSION >= QT_VERSION_CHECK(5, 7, 0)
Expand Down

0 comments on commit 633617d

Please sign in to comment.