fix strut error

Change-Id: Id983c0aaf6c8e07329c9dd9b2d66eb46520facff
This commit is contained in:
石博文 2017-11-14 14:20:04 +08:00
parent cbaaf52e82
commit 84b880384b
Notes: Deepin Code Review 2017-11-14 15:23:39 +08:00
Verified+1: Anonymous Coward #1000004
Code-Review+2: 石博文 <sbw@sbw.so>
Submitted-by: 石博文 <sbw@sbw.so>
Submitted-at: Tue, 14 Nov 2017 15:23:38 +0800
Reviewed-on: https://cr.deepin.io/28427
Project: dde/dde-dock
Branch: refs/heads/master
3 changed files with 58 additions and 30 deletions

View File

@ -124,11 +124,15 @@ public:
Q_PROPERTY(ushort ScreenHeight READ screenHeight NOTIFY ScreenHeightChanged) Q_PROPERTY(ushort ScreenHeight READ screenHeight NOTIFY ScreenHeightChanged)
inline ushort screenHeight() const inline ushort screenHeight() const
{ return qreal(qvariant_cast< ushort >(property("ScreenHeight"))) / qApp->devicePixelRatio(); } { return screenRawHeight() / qApp->devicePixelRatio(); }
inline ushort screenRawHeight() const
{ return qreal(qvariant_cast< ushort >(property("ScreenHeight"))); }
Q_PROPERTY(ushort ScreenWidth READ screenWidth NOTIFY ScreenWidthChanged) Q_PROPERTY(ushort ScreenWidth READ screenWidth NOTIFY ScreenWidthChanged)
inline ushort screenWidth() const inline ushort screenWidth() const
{ return qreal(qvariant_cast< ushort >(property("ScreenWidth"))) / qApp->devicePixelRatio(); } { return screenRawWidth() / qApp->devicePixelRatio(); }
inline ushort screenRawWidth() const
{ return qreal(qvariant_cast< ushort >(property("ScreenWidth"))); }
public Q_SLOTS: // METHODS public Q_SLOTS: // METHODS
inline QDBusPendingReply<> Apply() inline QDBusPendingReply<> Apply()

View File

@ -65,6 +65,8 @@ public:
Position position() const; Position position() const;
int screenHeight() const; int screenHeight() const;
int screenWidth() const; int screenWidth() const;
const int screenRawHeight() const { return m_displayInter->screenRawHeight(); }
const int screenRawWidth() const { return m_displayInter->screenRawWidth(); }
int expandTimeout() const; int expandTimeout() const;
int narrowTimeout() const; int narrowTimeout() const;

View File

@ -33,6 +33,22 @@
#include <X11/X.h> #include <X11/X.h>
#include <X11/Xutil.h> #include <X11/Xutil.h>
const QPoint rawXPosition(const QPoint &scaledPos)
{
QRect g = qApp->primaryScreen()->geometry();
for (auto *screen : qApp->screens())
{
const QRect &sg = screen->geometry();
if (sg.contains(scaledPos))
{
g = sg;
break;
}
}
return g.topLeft() + (scaledPos - g.topLeft()) * qApp->devicePixelRatio();
}
MainWindow::MainWindow(QWidget *parent) MainWindow::MainWindow(QWidget *parent)
: QWidget(parent), : QWidget(parent),
@ -206,14 +222,20 @@ void MainWindow::compositeChanged()
void MainWindow::interalMove(const QPoint &p) void MainWindow::interalMove(const QPoint &p)
{ {
const auto ratio = devicePixelRatioF(); const auto ratio = devicePixelRatioF();
QPoint rp = p * ratio; QPoint rp = rawXPosition(p);
if (m_settings->hideMode() != HideMode::KeepShowing && if (m_settings->hideMode() != HideMode::KeepShowing &&
m_settings->hideState() == HideState::Hide && m_settings->hideState() == HideState::Hide &&
m_posChangeAni->state() == QVariantAnimation::Stopped) m_posChangeAni->state() == QVariantAnimation::Stopped)
{ {
const QRect &r = m_settings->primaryRawRect(); const QRect &r = m_settings->primaryRawRect();
rp.setY(r.bottom()); switch (m_settings->position())
{
case Left: rp.setX(r.x() - 1); break;
case Top: rp.setY(r.y() - 1); break;
case Right: rp.setX(r.right() - 2); break;
case Bottom: rp.setY(r.bottom() - 2); break;
}
} }
int h; int h;
@ -391,63 +413,63 @@ void MainWindow::setStrutPartial()
if (m_settings->hideMode() != Dock::KeepShowing) if (m_settings->hideMode() != Dock::KeepShowing)
return; return;
const auto ratio = devicePixelRatioF();
const int maxScreenHeight = m_settings->screenRawHeight();
const int maxScreenWidth = m_settings->screenRawWidth();
const Position side = m_settings->position(); const Position side = m_settings->position();
const int maxScreenHeight = m_settings->screenHeight(); const QPoint p = rawXPosition(m_posChangeAni->endValue().toPoint());
const int maxScreenWidth = m_settings->screenWidth(); const QSize s = m_settings->windowSize();
XcbMisc::Orientation orientation = XcbMisc::OrientationTop; XcbMisc::Orientation orientation = XcbMisc::OrientationTop;
uint strut = 0; uint strut = 0;
uint strutStart = 0; uint strutStart = 0;
uint strutEnd = 0; uint strutEnd = 0;
const QPoint p = m_posChangeAni->endValue().toPoint();
const QRect r = QRect(p, m_settings->windowSize());
QRect strutArea(0, 0, maxScreenWidth, maxScreenHeight); QRect strutArea(0, 0, maxScreenWidth, maxScreenHeight);
qDebug() << "screen info: " << r << p << strutArea;
switch (side) switch (side)
{ {
case Position::Top: case Position::Top:
orientation = XcbMisc::OrientationTop; orientation = XcbMisc::OrientationTop;
strut = r.bottom() + 1; strut = p.y() + s.height() * ratio;
strutStart = r.left(); strutStart = p.x();
strutEnd = r.right(); strutEnd = p.x() + s.width() * ratio;
strutArea.setLeft(strutStart); strutArea.setLeft(strutStart);
strutArea.setRight(strutEnd); strutArea.setRight(strutEnd);
strutArea.setBottom(r.bottom()); strutArea.setBottom(strut);
break; break;
case Position::Bottom: case Position::Bottom:
orientation = XcbMisc::OrientationBottom; orientation = XcbMisc::OrientationBottom;
strut = maxScreenHeight - p.y(); strut = maxScreenHeight - p.y();
strutStart = r.left(); strutStart = p.x();
strutEnd = r.right(); strutEnd = p.x() + s.width() * ratio;
strutArea.setLeft(strutStart); strutArea.setLeft(strutStart);
strutArea.setRight(strutEnd); strutArea.setRight(strutEnd);
strutArea.setTop(p.y()); strutArea.setTop(p.y());
break; break;
case Position::Left: case Position::Left:
orientation = XcbMisc::OrientationLeft; orientation = XcbMisc::OrientationLeft;
strut = r.right() + 1; strut = p.x() + s.width() * ratio;
strutStart = r.top(); strutStart = p.y();
strutEnd = r.bottom(); strutEnd = p.y() + s.height() * ratio;
strutArea.setTop(r.top()); strutArea.setTop(strutStart);
strutArea.setBottom(r.bottom()); strutArea.setBottom(strutEnd);
strutArea.setRight(r.right()); strutArea.setRight(strut);
break; break;
case Position::Right: case Position::Right:
orientation = XcbMisc::OrientationRight; orientation = XcbMisc::OrientationRight;
strut = maxScreenWidth - r.left(); strut = maxScreenWidth - p.x();
strutStart = r.top(); strutStart = p.y();
strutEnd = r.bottom(); strutEnd = p.y() + s.height() * ratio;
strutArea.setTop(r.top()); strutArea.setTop(strutStart);
strutArea.setBottom(r.bottom()); strutArea.setBottom(strutEnd);
strutArea.setLeft(r.left()); strutArea.setLeft(p.x());
break; break;
default: default:
Q_ASSERT(false); Q_ASSERT(false);
} }
qDebug() << "screen info: " << p << strutArea;
// pass if strut area is intersect with other screen // pass if strut area is intersect with other screen
int count = 0; int count = 0;
const QRect pr = m_settings->primaryRect(); const QRect pr = m_settings->primaryRect();
@ -463,7 +485,7 @@ void MainWindow::setStrutPartial()
if (count > 0) if (count > 0)
return; return;
m_xcbMisc->set_strut_partial(winId(), orientation, strut * qApp->devicePixelRatio(), strutStart, strutEnd); m_xcbMisc->set_strut_partial(winId(), orientation, strut, strutStart, strutEnd);
} }
void MainWindow::expand() void MainWindow::expand()