mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-04 17:33:05 +00:00
fix fake mouse motion position error
Change-Id: I3e02306c887292238559d1e49fff31643e36dd25
This commit is contained in:
parent
acd2180fa8
commit
cbaaf52e82
Notes:
Deepin Code Review
2017-11-14 11:49:57 +08:00
Verified+1: Anonymous Coward #1000004 Verified+1: <yefei@linuxdeepin.com> Code-Review+2: 石博文 <sbw@sbw.so> Submitted-by: 石博文 <sbw@sbw.so> Submitted-at: Tue, 14 Nov 2017 11:49:57 +0800 Reviewed-on: https://cr.deepin.io/28364 Project: dde/dde-dock Branch: refs/heads/master
@ -29,6 +29,7 @@
|
||||
#include <QProcess>
|
||||
#include <QThread>
|
||||
#include <QApplication>
|
||||
#include <QScreen>
|
||||
|
||||
#include <X11/extensions/shape.h>
|
||||
#include <X11/extensions/XTest.h>
|
||||
@ -41,6 +42,22 @@ static const qreal iconSize = 16;
|
||||
|
||||
#define DRAG_THRESHOLD 20
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
void sni_cleanup_xcb_image(void *data)
|
||||
{
|
||||
xcb_image_destroy(static_cast<xcb_image_t*>(data));
|
||||
@ -130,8 +147,7 @@ void TrayWidget::paintEvent(QPaintEvent *e)
|
||||
|
||||
// painter.drawImage(p.x(), p.y(), m_image.scaled(iconSize, iconSize));
|
||||
// }
|
||||
const auto ratio = devicePixelRatioF();
|
||||
const QPoint p = rect().center() - m_image.rect().center() / ratio;
|
||||
const QPoint p = rect().center() - m_image.rect().center() / m_image.devicePixelRatioF();
|
||||
painter.drawImage(p, m_image);
|
||||
|
||||
painter.end();
|
||||
@ -193,12 +209,11 @@ void TrayWidget::enterEvent(QEvent *e)
|
||||
// qDebug() << Q_FUNC_INFO;
|
||||
|
||||
// fake enter event
|
||||
const auto ratio = qApp->devicePixelRatio();
|
||||
const QPoint p(QCursor::pos());
|
||||
const QPoint p(rawXPosition(QCursor::pos()));
|
||||
configContainerPosition();
|
||||
setX11PassMouseEvent(false);
|
||||
setWindowOnTop(true);
|
||||
XTestFakeMotionEvent(QX11Info::display(), 0, p.x() * ratio, p.y() * ratio, CurrentTime);
|
||||
XTestFakeMotionEvent(QX11Info::display(), 0, p.x(), p.y(), CurrentTime);
|
||||
setX11PassMouseEvent(true);
|
||||
// setWindowOnTop(false);
|
||||
|
||||
@ -207,19 +222,11 @@ void TrayWidget::enterEvent(QEvent *e)
|
||||
|
||||
void TrayWidget::configContainerPosition()
|
||||
{
|
||||
const auto ratio = qApp->devicePixelRatio();
|
||||
auto c = QX11Info::connection();
|
||||
|
||||
QPoint p(QCursor::pos());
|
||||
// QPoint p(rect().center() - QPoint(8, 8));
|
||||
// QWidget *w = this;
|
||||
// while (w)
|
||||
// {
|
||||
// p += w->pos();
|
||||
// w = static_cast<QWidget *>(w->parent());
|
||||
// }
|
||||
const QPoint p(rawXPosition(QCursor::pos()));
|
||||
|
||||
const uint32_t containerVals[4] = {uint32_t(p.x() * ratio), uint32_t(p.y() * ratio), 1, 1};
|
||||
const uint32_t containerVals[4] = {uint32_t(p.x()), uint32_t(p.y()), 1, 1};
|
||||
xcb_configure_window(c, m_containerWid,
|
||||
XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y | XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT,
|
||||
containerVals);
|
||||
@ -371,11 +378,12 @@ void TrayWidget::sendClick(uint8_t mouseButton, int x, int y)
|
||||
// qDebug() << Q_FUNC_INFO;
|
||||
m_ignoreRepeat->start();
|
||||
|
||||
const auto ratio = qApp->devicePixelRatio();
|
||||
const QPoint p(rawXPosition(QPoint(x, y)));
|
||||
configContainerPosition();
|
||||
setX11PassMouseEvent(false);
|
||||
setWindowOnTop(true);
|
||||
XTestFakeMotionEvent(QX11Info::display(), 0, x * ratio, y * ratio, CurrentTime);
|
||||
XTestFakeMotionEvent(QX11Info::display(), 0, p.x(), p.y(), CurrentTime);
|
||||
XFlush(QX11Info::display());
|
||||
XTestFakeButtonEvent(QX11Info::display(), mouseButton, true, CurrentTime);
|
||||
XFlush(QX11Info::display());
|
||||
XTestFakeButtonEvent(QX11Info::display(), mouseButton, false, CurrentTime);
|
||||
|
Loading…
x
Reference in New Issue
Block a user