Skip to content

Commit

Permalink
sync: from linuxdeepin/dtkwidget
Browse files Browse the repository at this point in the history
Synchronize source files from linuxdeepin/dtkwidget.

Source-pull-request: linuxdeepin/dtkwidget#564
  • Loading branch information
deepin-ci-robot committed Apr 11, 2024
1 parent c2c41d0 commit a94afdf
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions src/widgets/dtitlebar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -846,8 +846,8 @@ void DTitlebarPrivate::showSplitScreenWidget()
if (splitWidget->isVisible())
return;

auto centerPos = maxButton->mapToGlobal(maxButton->rect().center());
auto bottomPos = maxButton->mapToGlobal(maxButton->rect().bottomLeft());

QRect maxBtnRect = QRect(maxButton->mapToGlobal(maxButton->rect().topLeft()), maxButton->rect().size());

QRect rect;
if (QScreen *screen = QGuiApplication::screenAt(QCursor::pos())) {
Expand All @@ -856,11 +856,21 @@ void DTitlebarPrivate::showSplitScreenWidget()
rect = QGuiApplication::primaryScreen()->geometry();
}

if (bottomPos.y() + splitWidget->height() > rect.height()) {
splitWidget->show(QPoint(centerPos.x() - splitWidget->width() / 2, bottomPos.y() - maxButton->rect().height() - splitWidget->height()));
} else {
splitWidget->show(QPoint(centerPos.x() - splitWidget->width() / 2, bottomPos.y()));
int targetX = maxBtnRect.center().x() - splitWidget->width() / 2;
int targetY = maxBtnRect.bottom();


if (int outRightLen = maxBtnRect.center().x() - rect.x() + splitWidget->width() / 2 - rect.width(); outRightLen > 0) { // 超出右边缘
targetX -= outRightLen;
} else if (int outLeftLen = splitWidget->width() / 2 - maxBtnRect.center().x() + rect.x(); outLeftLen > 0) { // 超出左边缘
targetX += outLeftLen;
}

if (maxBtnRect.bottom() + splitWidget->height() - rect.y() > rect.height()) { // 超出下边缘
targetY -= maxButton->rect().height() + splitWidget->height();
}

splitWidget->show(QPoint(targetX, targetY));
}

void DTitlebarPrivate::hideSplitScreenWidget()
Expand Down

0 comments on commit a94afdf

Please sign in to comment.