Use existing Qt functionality to get cursor position

Might resolve issues with cursor position detection on non-X windows on
Linux
This commit is contained in:
WarmUpTill 2022-11-27 12:43:49 +01:00 committed by WarmUpTill
parent cc3ce3f0e0
commit 05fce566f4
6 changed files with 8 additions and 46 deletions

View File

@ -251,29 +251,6 @@ void GetCurrentWindowTitle(std::string &title)
title = name;
}
std::pair<int, int> getCursorPos()
{
std::pair<int, int> pos(0, 0);
Display *dpy;
Window root;
Window ret_root;
Window ret_child;
int root_x;
int root_y;
int win_x;
int win_y;
unsigned int mask;
dpy = disp();
root = XDefaultRootWindow(dpy);
if (XQueryPointer(dpy, root, &ret_root, &ret_child, &root_x, &root_y,
&win_x, &win_y, &mask)) {
pos = std::pair<int, int>(root_x, root_y);
}
return pos;
}
bool isMaximized(const std::string &title)
{
if (!ewmhIsSupported()) {

View File

@ -99,17 +99,6 @@ void GetCurrentWindowTitle(std::string &title)
}
}
std::pair<int, int> getCursorPos()
{
std::pair<int, int> pos(0, 0);
CGEventRef event = CGEventCreate(NULL);
CGPoint cursorPos = CGEventGetLocation(event);
CFRelease(event);
pos.first = cursorPos.x;
pos.second = cursorPos.y;
return pos;
}
bool isWindowOriginOnScreen(NSDictionary *app, NSScreen *screen,
bool fullscreen = false)
{

View File

@ -10,7 +10,6 @@ void GetWindowList(QStringList &windows);
void GetCurrentWindowTitle(std::string &title);
bool isFullscreen(const std::string &title);
bool isMaximized(const std::string &title);
std::pair<int, int> getCursorPos();
int secondsSinceLastInput();
void GetProcessList(QStringList &processes);
void GetForegroundProcessName(std::string &name);

View File

@ -15,6 +15,7 @@
#include <QJsonDocument>
#include <QSystemTrayIcon>
#include <QGuiApplication>
#include <QCursor>
#include <unordered_map>
#include <regex>
#include <set>
@ -980,3 +981,9 @@ int findIdxInRagne(QComboBox *list, int start, int stop,
}
return foundIdx;
}
std::pair<int, int> getCursorPos()
{
auto cursorPos = QCursor::pos();
return {cursorPos.x(), cursorPos.y()};
}

View File

@ -88,3 +88,4 @@ void addSelectionGroup(QComboBox *selection, const QStringList &group,
bool addSeparator = true);
int findIdxInRagne(QComboBox *list, int start, int stop,
const std::string &value);
std::pair<int, int> getCursorPos();

View File

@ -124,17 +124,6 @@ void GetCurrentWindowTitle(std::string &title)
GetWindowTitle(window, title);
}
std::pair<int, int> getCursorPos()
{
std::pair<int, int> pos(0, 0);
POINT cursorPos;
if (GetPhysicalCursorPos(&cursorPos)) {
pos.first = cursorPos.x;
pos.second = cursorPos.y;
}
return pos;
}
HWND getHWNDfromTitle(std::string title)
{
HWND hwnd = NULL;