Commit a13b176e authored by Oleg Solovyov's avatar Oleg Solovyov 🐴
Browse files

Calculate cursor position relative to top-left corner of current screen

QCursor::pos() returns an absolute position of cursor,
which is incorrect unless the screen's top-left corner is (0, 0).
This is used when calculating position of the icon created on
desktop.

BUG: 436216
parent 0e883d9b
......@@ -42,6 +42,7 @@
#include <QQuickItem>
#include <QQuickWindow>
#include <QTimer>
#include <QScreen>
#include <qplatformdefs.h>
#include <KAuthorized>
......@@ -239,6 +240,22 @@ QHash<int, QByteArray> FolderModel::staticRoleNames()
return roleNames;
}
void FolderModel::setMenuPos()
{
QPoint pos = QCursor::pos();
QScreen *screen = nullptr;
for (auto *s : qApp->screens()) {
if (s->geometry().contains(pos)) {
screen = s;
break;
}
}
if (screen) {
pos -= screen->geometry().topLeft();
}
m_menuPosition = pos;
}
void FolderModel::classBegin()
{
}
......@@ -1703,7 +1720,7 @@ void FolderModel::updateActions()
m_newMenu->checkUpToDate();
m_newMenu->setPopupFiles(QList<QUrl>() << m_dirModel->dirLister()->url());
// we need to set here as well, when the menu is shown via AppletInterface::eventFilter
m_menuPosition = QCursor::pos();
setMenuPos();
if (QAction *newMenuAction = m_actionCollection.action(QStringLiteral("newMenu"))) {
newMenuAction->setEnabled(itemProperties.supportsWriting());
......
......@@ -310,6 +310,7 @@ private:
bool blank;
};
void setMenuPos();
void createActions();
void addDragImage(QDrag *drag, int x, int y);
void setStatus(Status status);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment