Hotspot support

This commit is contained in:
ArsenArsen 2017-05-13 23:33:36 +02:00
parent 1961a67653
commit 927e7c4165
7 changed files with 23 additions and 15 deletions

View File

@ -3,7 +3,6 @@
#include <QCommandLineParser>
#include <QTimer>
#include <QtGlobal>
#include <platformbackend.hpp>
#include <stdio.h>
bool verbose = false;
@ -45,7 +44,6 @@ int main(int argc, char *argv[]) {
parser.addOption(v);
parser.process(a);
verbose = parser.isSet(v);
PlatformBackend::inst().getCursor().save("test.png", "PNG");
MainWindow w;
w.show();

View File

@ -2,5 +2,5 @@
QPixmap PlatformBackend::getCursor() {
#warning "TODO: Mac backend"
return QPixmap();
return std::tuple<QPoint, QPixmap>(QPoint(0, 0), QPixmap());
}

View File

@ -4,18 +4,18 @@
#include <QtWin>
#include <windows.h>
QPixmap PlatformBackend::getCursor() {
std::tuple<QPoint, QPixmap> getCursor() {
CURSORINFO cursorInfo;
cursorInfo.cbSize = sizeof(cursorInfo);
if (GetCursorInfo(&cursorInfo)) {
if (cursorInfo.flags == CURSOR_SHOWING) {
ICONINFO info; // It took me 5 hours to get to here
if (GetIconInfo(cursorInfo.hCursor, &info)) {
return QtWin::fromHBITMAP(info.hbmColor);
return std::tuple<QPoint, QPixmap>(QPoint(info.xHotspot, info.yHotspot), QtWin::fromHBITMAP(info.hbmColor));
} else
return QPixmap();
return std::tuple<QPoint, QPixmap>(QPoint(0, 0), QPixmap());
} else
return QPixmap();
return std::tuple<QPoint, QPixmap>(QPoint(0, 0), QPixmap());
} else
return QPixmap();
return std::tuple<QPoint, QPixmap>(QPoint(0, 0), QPixmap());
}

View File

@ -5,7 +5,7 @@
class PlatformBackend {
public:
QPixmap getCursor();
std::tuple<QPoint, QPixmap> getCursor();
static PlatformBackend &inst() {
static PlatformBackend inst;
return inst;

View File

@ -6,17 +6,19 @@
#include <xcb/xcb_util.h>
#include <xcb/xfixes.h>
QPixmap PlatformBackend::getCursor() {
std::tuple<QPoint, QPixmap> PlatformBackend::getCursor() {
xcb_connection_t *connection = QX11Info::connection();
xcb_xfixes_get_cursor_image_cookie_t cursorCookie = xcb_xfixes_get_cursor_image_unchecked(connection);
QScopedPointer<xcb_xfixes_get_cursor_image_reply_t> cursorReply(xcb_xfixes_get_cursor_image_reply(connection, cursorCookie, NULL));
if (cursorReply.isNull()) {
return QPixmap();
return std::tuple<QPoint, QPixmap>(QPoint(0, 0), QPixmap());
}
quint32 *pixels = xcb_xfixes_get_cursor_image_cursor_image(cursorReply.data());
if (!pixels) {
return QPixmap();
return std::tuple<QPoint, QPixmap>(QPoint(0, 0), QPixmap());
}
return QPixmap::fromImage(QImage((quint8 *)pixels, cursorReply->width, cursorReply->height, QImage::Format_ARGB32_Premultiplied));
return std::tuple<QPoint, QPixmap>(QPoint(cursorReply->xhot, cursorReply->yhot),
QPixmap::fromImage(QImage((quint8 *)pixels, cursorReply->width, cursorReply->height,
QImage::Format_ARGB32_Premultiplied)));
}

View File

@ -5,7 +5,7 @@
class PlatformBackend {
public:
QPixmap getCursor();
std::tuple<QPoint, QPixmap> getCursor();
static PlatformBackend &inst() {
static PlatformBackend inst;
return inst;

View File

@ -2,11 +2,19 @@
#include <QApplication>
#include <QClipboard>
#include <QPainter>
#include <QPixmap>
#include <QScreen>
#include <platformbackend.hpp>
QPixmap *screenshotutil::fullscreen() {
return window(0);
QPixmap *noCursor = window(0);
QScopedPointer<QPixmap> p(noCursor);
QPixmap *withCursor = new QPixmap(noCursor->size());
QPainter painter(withCursor);
auto cursorData = PlatformBackend::inst().getCursor();
painter.drawPixmap(std::get<0>(cursorData), std::get<1>(cursorData));
return withCursor;
}
QPixmap *screenshotutil::window(long wid) {