Skip to content

Commit b96ff08

Browse files
committed
fix(DTitlebar): check screen boundary before showing menu
When window is at screen edge, the menu popup position anchored at optionButton's bottom-left could overflow the screen boundary. Add screen boundary checks before QMenu::exec() to reposition the menu when it would exceed right, left, or bottom screen edges. Fixes: bug-312419
1 parent 8e8bcff commit b96ff08

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

‎src/widgets/dtitlebar.cpp‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1065,7 +1065,21 @@ void DTitlebar::showMenu()
10651065
bool isUpdated = config.value("featureUpdated", false).toBool();
10661066
DStyle::setRedPointVisible(d->aboutAction, isUpdated);
10671067

1068-
d->menu->exec(d->optionButton->mapToGlobal(d->optionButton->rect().bottomLeft()));
1068+
QPoint menuPos = d->optionButton->mapToGlobal(d->optionButton->rect().bottomLeft());
1069+
QSize menuSize = d->menu->sizeHint();
1070+
if (QScreen *screen = d->optionButton->screen()) {
1071+
QRect screenGeo = screen->availableGeometry();
1072+
if (menuPos.x() + menuSize.width() > screenGeo.right()) {
1073+
menuPos.setX(d->optionButton->mapToGlobal(d->optionButton->rect().bottomRight()).x() - menuSize.width());
1074+
}
1075+
if (menuPos.x() < screenGeo.left()) {
1076+
menuPos.setX(screenGeo.left());
1077+
}
1078+
if (menuPos.y() + menuSize.height() > screenGeo.bottom()) {
1079+
menuPos.setY(d->optionButton->mapToGlobal(d->optionButton->rect().topLeft()).y() - menuSize.height());
1080+
}
1081+
}
1082+
d->menu->exec(menuPos);
10691083
d->optionButton->update(); // FIX: bug-25253 sometimes optionButton not udpate after menu exec(but why?)
10701084
}
10711085
}

0 commit comments

Comments
 (0)