#include "x11backend.hpp" #include #include #include #include #include #include std::tuple PlatformBackend::getCursor() { xcb_connection_t *connection = QX11Info::connection(); xcb_xfixes_get_cursor_image_cookie_t cursorCookie = xcb_xfixes_get_cursor_image_unchecked(connection); QScopedPointer cursorReply(xcb_xfixes_get_cursor_image_reply(connection, cursorCookie, NULL)); if (cursorReply.isNull()) { return std::tuple(QPoint(0, 0), QPixmap()); } quint32 *pixels = xcb_xfixes_get_cursor_image_cursor_image(cursorReply.data()); if (!pixels) { return std::tuple(QPoint(0, 0), QPixmap()); } return std::tuple(QPoint(cursorReply->xhot, cursorReply->yhot), QPixmap::fromImage(QImage((quint8 *)pixels, cursorReply->width, cursorReply->height, QImage::Format_ARGB32_Premultiplied))); } pid_t PlatformBackend::pid() { return getpid(); } WId PlatformBackend::getActiveWID() { xcb_connection_t *connection = QX11Info::connection(); xcb_get_input_focus_reply_t *focusReply; xcb_query_tree_cookie_t treeCookie; xcb_query_tree_reply_t *treeReply; focusReply = xcb_get_input_focus_reply(connection, xcb_get_input_focus(connection), nullptr); xcb_window_t window = focusReply->focus; while (1) { treeCookie = xcb_query_tree(connection, window); treeReply = xcb_query_tree_reply(connection, treeCookie, nullptr); if (!treeReply) { window = 0; break; } if (window == treeReply->root || treeReply->parent == treeReply->root) { break; } else { window = treeReply->parent; } delete treeReply; } delete treeReply; return window; }