fix: popupwindow is out of bounds at the edge of the screen

set the minimum value of x of popupwindow to the current screen
and the maximum value to the maximum x of the current screen

log:
This commit is contained in:
tsic404 2023-05-11 10:46:31 +08:00 committed by deepin-bot[bot]
parent 0a103e62bd
commit 15e5a0fadb

View File

@ -7,6 +7,8 @@
#include "imageutil.h"
#include "utils.h"
#include "dbusutil.h"
#include "dockscreen.h"
#include "displaymanager.h"
#include <QScreen>
#include <QApplication>
@ -18,6 +20,9 @@
DWIDGET_USE_NAMESPACE
#define DOCK_SCREEN DockScreen::instance()
#define DIS_INS DisplayManager::instance()
DockPopupWindow::DockPopupWindow(QWidget *parent)
: DBlurEffectWidget(parent)
, m_model(false)
@ -127,6 +132,14 @@ void DockPopupWindow::show(const int x, const int y)
break;
}
blockButtonRelease();
QScreen *screen = DIS_INS->screen(DOCK_SCREEN->current());
if (!screen)
return;
QRect screenRect = screen->geometry();
if (getContent()->width() > screenRect.width()) {
displayPoint.setX(qMax(screenRect.x(), displayPoint.x()));
displayPoint.setX(qMin(screenRect.x() + screenRect.width() - getContent()->width(), displayPoint.x()));
}
move(displayPoint);
resize(m_lastWidget->size());
DBlurEffectWidget::show();
@ -215,7 +228,10 @@ void DockPopupWindow::onButtonPress(int type, int x, int y, const QString &key)
{
if (!m_enableMouseRelease)
return;
QRect screenRect = this->screen()->geometry();
QScreen *screen = DIS_INS->screen(DOCK_SCREEN->current());
if (!screen)
return;
QRect screenRect = screen->geometry();
QRect popupRect(((pos() - screenRect.topLeft()) * qApp->devicePixelRatio() + screenRect.topLeft()), size() * qApp->devicePixelRatio());
if (popupRect.contains(QPoint(x, y)))
return;