diff options
author | Laszlo Agocs <laszlo.p.agocs@nokia.com> | 2011-06-03 11:30:23 +0200 |
---|---|---|
committer | Laszlo Agocs <laszlo.p.agocs@nokia.com> | 2011-06-03 11:59:15 +0200 |
commit | 1f456b4cbb93e3fea699878d117900b703146213 (patch) | |
tree | ce33b7dc746a1ef1b6a044fbcf742755c0c5744b /src/plugins/platforms | |
parent | 7d9fcaccb1e6e056336b9ad1f7f89afac4699aee (diff) |
Add support for mouse and keyboard grab.
Reviewed-by: Samuel Rødal
Diffstat (limited to 'src/plugins/platforms')
-rw-r--r-- | src/plugins/platforms/xcb/qxcbwindow.cpp | 37 | ||||
-rw-r--r-- | src/plugins/platforms/xcb/qxcbwindow.h | 3 |
2 files changed, 40 insertions, 0 deletions
diff --git a/src/plugins/platforms/xcb/qxcbwindow.cpp b/src/plugins/platforms/xcb/qxcbwindow.cpp index fc888b8289..81822474a4 100644 --- a/src/plugins/platforms/xcb/qxcbwindow.cpp +++ b/src/plugins/platforms/xcb/qxcbwindow.cpp @@ -1094,3 +1094,40 @@ void QXcbWindow::updateSyncRequestCounter() m_syncValue.hi = 0; } } + +bool QXcbWindow::setKeyboardGrabEnabled(bool grab) +{ + if (!grab) { + xcb_ungrab_keyboard(xcb_connection(), XCB_TIME_CURRENT_TIME); + return true; + } + xcb_grab_keyboard_cookie_t cookie = xcb_grab_keyboard(xcb_connection(), false, + m_window, XCB_TIME_CURRENT_TIME, + GrabModeAsync, GrabModeAsync); + xcb_generic_error_t *err; + xcb_grab_keyboard_reply_t *reply = xcb_grab_keyboard_reply(xcb_connection(), cookie, &err); + bool result = !(err || !reply || reply->status != XCB_GRAB_STATUS_SUCCESS); + free(reply); + free(err); + return result; +} + +bool QXcbWindow::setMouseGrabEnabled(bool grab) +{ + if (!grab) { + xcb_ungrab_pointer(xcb_connection(), XCB_TIME_CURRENT_TIME); + return true; + } + xcb_grab_pointer_cookie_t cookie = xcb_grab_pointer(xcb_connection(), false, m_window, + (ButtonPressMask | ButtonReleaseMask | ButtonMotionMask + | EnterWindowMask | LeaveWindowMask | PointerMotionMask), + GrabModeAsync, GrabModeAsync, + XCB_WINDOW_NONE, XCB_CURSOR_NONE, + XCB_TIME_CURRENT_TIME); + xcb_generic_error_t *err; + xcb_grab_pointer_reply_t *reply = xcb_grab_pointer_reply(xcb_connection(), cookie, &err); + bool result = !(err || !reply || reply->status != XCB_GRAB_STATUS_SUCCESS); + free(reply); + free(err); + return result; +} diff --git a/src/plugins/platforms/xcb/qxcbwindow.h b/src/plugins/platforms/xcb/qxcbwindow.h index 40d21f43da..57794fda07 100644 --- a/src/plugins/platforms/xcb/qxcbwindow.h +++ b/src/plugins/platforms/xcb/qxcbwindow.h @@ -76,6 +76,9 @@ public: QPlatformGLContext *glContext() const; + bool setKeyboardGrabEnabled(bool grab); + bool setMouseGrabEnabled(bool grab); + xcb_window_t xcb_window() const { return m_window; } uint depth() const { return m_depth; } QImage::Format format() const { return m_format; } |