Hotspot support
This commit is contained in:
parent
1961a67653
commit
927e7c4165
2
main.cpp
2
main.cpp
@ -3,7 +3,6 @@
|
|||||||
#include <QCommandLineParser>
|
#include <QCommandLineParser>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
#include <QtGlobal>
|
#include <QtGlobal>
|
||||||
#include <platformbackend.hpp>
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
bool verbose = false;
|
bool verbose = false;
|
||||||
@ -45,7 +44,6 @@ int main(int argc, char *argv[]) {
|
|||||||
parser.addOption(v);
|
parser.addOption(v);
|
||||||
parser.process(a);
|
parser.process(a);
|
||||||
verbose = parser.isSet(v);
|
verbose = parser.isSet(v);
|
||||||
PlatformBackend::inst().getCursor().save("test.png", "PNG");
|
|
||||||
|
|
||||||
MainWindow w;
|
MainWindow w;
|
||||||
w.show();
|
w.show();
|
||||||
|
@ -2,5 +2,5 @@
|
|||||||
|
|
||||||
QPixmap PlatformBackend::getCursor() {
|
QPixmap PlatformBackend::getCursor() {
|
||||||
#warning "TODO: Mac backend"
|
#warning "TODO: Mac backend"
|
||||||
return QPixmap();
|
return std::tuple<QPoint, QPixmap>(QPoint(0, 0), QPixmap());
|
||||||
}
|
}
|
||||||
|
@ -4,18 +4,18 @@
|
|||||||
#include <QtWin>
|
#include <QtWin>
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
|
|
||||||
QPixmap PlatformBackend::getCursor() {
|
std::tuple<QPoint, QPixmap> getCursor() {
|
||||||
CURSORINFO cursorInfo;
|
CURSORINFO cursorInfo;
|
||||||
cursorInfo.cbSize = sizeof(cursorInfo);
|
cursorInfo.cbSize = sizeof(cursorInfo);
|
||||||
if (GetCursorInfo(&cursorInfo)) {
|
if (GetCursorInfo(&cursorInfo)) {
|
||||||
if (cursorInfo.flags == CURSOR_SHOWING) {
|
if (cursorInfo.flags == CURSOR_SHOWING) {
|
||||||
ICONINFO info; // It took me 5 hours to get to here
|
ICONINFO info; // It took me 5 hours to get to here
|
||||||
if (GetIconInfo(cursorInfo.hCursor, &info)) {
|
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
|
} else
|
||||||
return QPixmap();
|
return std::tuple<QPoint, QPixmap>(QPoint(0, 0), QPixmap());
|
||||||
} else
|
} else
|
||||||
return QPixmap();
|
return std::tuple<QPoint, QPixmap>(QPoint(0, 0), QPixmap());
|
||||||
} else
|
} else
|
||||||
return QPixmap();
|
return std::tuple<QPoint, QPixmap>(QPoint(0, 0), QPixmap());
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
class PlatformBackend {
|
class PlatformBackend {
|
||||||
public:
|
public:
|
||||||
QPixmap getCursor();
|
std::tuple<QPoint, QPixmap> getCursor();
|
||||||
static PlatformBackend &inst() {
|
static PlatformBackend &inst() {
|
||||||
static PlatformBackend inst;
|
static PlatformBackend inst;
|
||||||
return inst;
|
return inst;
|
||||||
|
@ -6,17 +6,19 @@
|
|||||||
#include <xcb/xcb_util.h>
|
#include <xcb/xcb_util.h>
|
||||||
#include <xcb/xfixes.h>
|
#include <xcb/xfixes.h>
|
||||||
|
|
||||||
QPixmap PlatformBackend::getCursor() {
|
std::tuple<QPoint, QPixmap> PlatformBackend::getCursor() {
|
||||||
xcb_connection_t *connection = QX11Info::connection();
|
xcb_connection_t *connection = QX11Info::connection();
|
||||||
xcb_xfixes_get_cursor_image_cookie_t cursorCookie = xcb_xfixes_get_cursor_image_unchecked(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));
|
QScopedPointer<xcb_xfixes_get_cursor_image_reply_t> cursorReply(xcb_xfixes_get_cursor_image_reply(connection, cursorCookie, NULL));
|
||||||
if (cursorReply.isNull()) {
|
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());
|
quint32 *pixels = xcb_xfixes_get_cursor_image_cursor_image(cursorReply.data());
|
||||||
if (!pixels) {
|
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)));
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
class PlatformBackend {
|
class PlatformBackend {
|
||||||
public:
|
public:
|
||||||
QPixmap getCursor();
|
std::tuple<QPoint, QPixmap> getCursor();
|
||||||
static PlatformBackend &inst() {
|
static PlatformBackend &inst() {
|
||||||
static PlatformBackend inst;
|
static PlatformBackend inst;
|
||||||
return inst;
|
return inst;
|
||||||
|
@ -2,11 +2,19 @@
|
|||||||
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QClipboard>
|
#include <QClipboard>
|
||||||
|
#include <QPainter>
|
||||||
#include <QPixmap>
|
#include <QPixmap>
|
||||||
#include <QScreen>
|
#include <QScreen>
|
||||||
|
#include <platformbackend.hpp>
|
||||||
|
|
||||||
QPixmap *screenshotutil::fullscreen() {
|
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) {
|
QPixmap *screenshotutil::window(long wid) {
|
||||||
|
Loading…
Reference in New Issue
Block a user