summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichele Calgaro <michele.calgaro@yahoo.it>2020-04-29 00:10:33 +0900
committerSlávek Banko <slavek.banko@axis.cz>2021-02-02 00:58:56 +0100
commit5a19653cb5ad16e1f941d2c49f447c952e7058fa (patch)
tree1d9048f62e77a44579a79646a790a4032b411780
parente9d6b1eb3d47e8258ac7e23c23f1977caed9e219 (diff)
downloadqt3-5a19653cb5ad16e1f941d2c49f447c952e7058fa.tar.gz
qt3-5a19653cb5ad16e1f941d2c49f447c952e7058fa.zip
Improved code for keyboard and mouse grabbing and releasing to avoid
unnecessary actions. This relates loosely to bug 2955. Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it> (cherry picked from commit bc1b1fed7dda5d3143e1fc9f6a38783ff8389f4d)
-rw-r--r--src/kernel/qwidget_x11.cpp51
1 files changed, 28 insertions, 23 deletions
diff --git a/src/kernel/qwidget_x11.cpp b/src/kernel/qwidget_x11.cpp
index 1eb4bcb..54c37e6 100644
--- a/src/kernel/qwidget_x11.cpp
+++ b/src/kernel/qwidget_x11.cpp
@@ -1487,28 +1487,31 @@ void QWidget::grabMouse()
void QWidget::grabMouse( const QCursor &cursor )
{
if ( !qt_nograb() ) {
- if ( mouseGrb )
- mouseGrb->releaseMouse();
+ if ( mouseGrb != this ) {
+ if ( mouseGrb ) {
+ mouseGrb->releaseMouse();
+ }
#if defined(QT_CHECK_STATE)
- int status =
+ int status =
#endif
- XGrabPointer( x11Display(), winId(), False,
- (uint)(ButtonPressMask | ButtonReleaseMask |
- PointerMotionMask | EnterWindowMask | LeaveWindowMask),
- GrabModeAsync, GrabModeAsync,
- None, cursor.handle(), qt_x_time );
+ XGrabPointer( x11Display(), winId(), False,
+ (uint)(ButtonPressMask | ButtonReleaseMask |
+ PointerMotionMask | EnterWindowMask | LeaveWindowMask),
+ GrabModeAsync, GrabModeAsync,
+ None, cursor.handle(), qt_x_time );
#if defined(QT_CHECK_STATE)
- if ( status ) {
- const char *s =
- status == GrabNotViewable ? "\"GrabNotViewable\"" :
- status == AlreadyGrabbed ? "\"AlreadyGrabbed\"" :
- status == GrabFrozen ? "\"GrabFrozen\"" :
- status == GrabInvalidTime ? "\"GrabInvalidTime\"" :
- "<?>";
- qWarning( "Grabbing the mouse failed with %s", s );
- }
+ if ( status ) {
+ const char *s =
+ status == GrabNotViewable ? "\"GrabNotViewable\"" :
+ status == AlreadyGrabbed ? "\"AlreadyGrabbed\"" :
+ status == GrabFrozen ? "\"GrabFrozen\"" :
+ status == GrabInvalidTime ? "\"GrabInvalidTime\"" :
+ "<?>";
+ qWarning( "Grabbing the mouse failed with %s", s );
+ }
#endif
- mouseGrb = this;
+ mouseGrb = this;
+ }
}
}
@@ -1548,11 +1551,13 @@ void QWidget::releaseMouse()
void QWidget::grabKeyboard()
{
if ( !qt_nograb() ) {
- if ( keyboardGrb )
- keyboardGrb->releaseKeyboard();
- XGrabKeyboard( x11Display(), winid, False, GrabModeAsync, GrabModeAsync,
- qt_x_time );
- keyboardGrb = this;
+ if ( keyboardGrb != this ) {
+ if ( keyboardGrb ) {
+ keyboardGrb->releaseKeyboard();
+ }
+ XGrabKeyboard( x11Display(), winid, False, GrabModeAsync, GrabModeAsync, qt_x_time );
+ keyboardGrb = this;
+ }
}
}