From 4f1a6ac732f7f879b082b6d413ca4918c6b06dc3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20R=C3=B8dal?= Date: Mon, 6 Jun 2011 09:07:46 +0200 Subject: Implemented QXcbScreen::topLevelAt(const QPoint &p). This makes the tst_QWidget::widgetAt() auto-test pass. --- src/plugins/platforms/xcb/qxcbconnection.h | 4 +-- src/plugins/platforms/xcb/qxcbintegration.cpp | 3 +- src/plugins/platforms/xcb/qxcbscreen.cpp | 46 +++++++++++++++++++++++++++ src/plugins/platforms/xcb/qxcbscreen.h | 2 ++ 4 files changed, 52 insertions(+), 3 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/platforms/xcb/qxcbconnection.h b/src/plugins/platforms/xcb/qxcbconnection.h index 01014775b9..e0cb1d954e 100644 --- a/src/plugins/platforms/xcb/qxcbconnection.h +++ b/src/plugins/platforms/xcb/qxcbconnection.h @@ -282,6 +282,8 @@ public: template inline xcb_generic_event_t *checkEvent(const T &checker); + QXcbWindow *platformWindowFromId(xcb_window_t id); + private slots: void processXcbEvents(); @@ -291,8 +293,6 @@ private: #ifdef XCB_USE_DRI2 void initializeDri2(); #endif - QXcbWindow *platformWindowFromId(xcb_window_t id); - xcb_connection_t *m_connection; const xcb_setup_t *m_setup; diff --git a/src/plugins/platforms/xcb/qxcbintegration.cpp b/src/plugins/platforms/xcb/qxcbintegration.cpp index 0f0b25f5b2..c63a29b675 100644 --- a/src/plugins/platforms/xcb/qxcbintegration.cpp +++ b/src/plugins/platforms/xcb/qxcbintegration.cpp @@ -215,6 +215,8 @@ QPixmap QXcbIntegration::grabWindow(WId window, int x, int y, int width, int hei y = translate_reply->dst_y; window = root; + + free(translate_reply); free(reply); reply = root_reply; } else { @@ -338,7 +340,6 @@ QPixmap QXcbIntegration::grabWindow(WId window, int x, int y, int width, int hei return result; } - bool QXcbIntegration::hasOpenGL() const { #if defined(XCB_USE_GLX) diff --git a/src/plugins/platforms/xcb/qxcbscreen.cpp b/src/plugins/platforms/xcb/qxcbscreen.cpp index 1b6bf30294..0d0c4a5138 100644 --- a/src/plugins/platforms/xcb/qxcbscreen.cpp +++ b/src/plugins/platforms/xcb/qxcbscreen.cpp @@ -40,6 +40,7 @@ ****************************************************************************/ #include "qxcbscreen.h" +#include "qxcbwindow.h" #include @@ -145,6 +146,51 @@ QXcbScreen::~QXcbScreen() { } +QWindow *QXcbScreen::topLevelAt(const QPoint &p) const +{ + xcb_window_t root = m_screen->root; + + int x = p.x(); + int y = p.y(); + + xcb_generic_error_t *error; + + xcb_window_t parent = root; + xcb_window_t child = root; + + do { + xcb_translate_coordinates_cookie_t translate_cookie = + xcb_translate_coordinates(xcb_connection(), parent, child, x, y); + + xcb_translate_coordinates_reply_t *translate_reply = + xcb_translate_coordinates_reply(xcb_connection(), translate_cookie, &error); + + if (!translate_reply) { + if (error) { + connection()->handleXcbError(error); + free(error); + } + return 0; + } + + parent = child; + child = translate_reply->child; + x = translate_reply->dst_x; + y = translate_reply->dst_y; + + free(translate_reply); + + if (!child || child == root) + return 0; + + QPlatformWindow *platformWindow = connection()->platformWindowFromId(child); + if (platformWindow) + return platformWindow->window(); + } while (parent != child); + + return 0; +} + const xcb_visualtype_t *QXcbScreen::visualForId(xcb_visualid_t visualid) const { QMap::const_iterator it = m_visuals.find(visualid); diff --git a/src/plugins/platforms/xcb/qxcbscreen.h b/src/plugins/platforms/xcb/qxcbscreen.h index d2a38b0791..cb84e55ccc 100644 --- a/src/plugins/platforms/xcb/qxcbscreen.h +++ b/src/plugins/platforms/xcb/qxcbscreen.h @@ -57,6 +57,8 @@ public: QXcbScreen(QXcbConnection *connection, xcb_screen_t *screen, int number); ~QXcbScreen(); + QWindow *topLevelAt(const QPoint &point) const; + QRect geometry() const; int depth() const; QImage::Format format() const; -- cgit v1.2.3