Focus issues of a QXEmbed window

Koos Vriezen koos.vriezen at xs4all.nl
Tue Jul 16 15:10:01 BST 2002


Hi,

There is a problem with giving the focus to an embedded window with a
mouse click when a form element has the current focus.

I've attached a patch which fixes it. It does:
- do a XGrabButton on a embedded window when the mouse enters it and it
  doesn't have the focus
- do a XUngrabButton when the mouse leaves the embedded window or when
  it receives the focus
- put the focus to the embedded window when its clicked

This is similar behaviour as KWin does on its clients (damn, should have
looked at that earlier)

Regards,

Koos



-------------- next part --------------
Index: kdeui/qxembed.cpp
===================================================================
RCS file: /home/kde/kdelibs/kdeui/qxembed.cpp,v
retrieving revision 1.29
diff -u -3 -p -r1.29 qxembed.cpp
--- kdeui/qxembed.cpp	2002/07/15 22:04:18	1.29
+++ kdeui/qxembed.cpp	2002/07/16 13:26:22
@@ -20,6 +20,7 @@
 *****************************************************************************/
 
 #include <qapplication.h>
+#include <qmetaobject.h>
 #include <qptrlist.h>
 #include <qptrdict.h>
 #include <qguardedptr.h>
@@ -205,6 +206,20 @@ static int qxembed_x11_event_filter( XEv
     //kdDebug() << "qxembed_x11_event_filter " << KXEventUtil::getX11EventInfo(e) << endl;
 
     switch ( e->type ) {
+    case LeaveNotify: {
+        QWidget* w = QWidget::find( e->xkey.window );
+        if (w && w->metaObject()->inherits("QXEmbed"))
+            XUngrabButton( qt_xdisplay(), AnyButton, AnyModifier, e->xany.window );
+        break;
+    }
+    case EnterNotify: {
+        QWidget* w = QWidget::find( e->xkey.window );
+        if (w && w->metaObject()->inherits("QXEmbed") && !w->hasFocus())
+            XGrabButton(qt_xdisplay(), AnyButton, AnyModifier, e->xany.window,
+                    FALSE, ButtonPressMask, GrabModeSync, GrabModeAsync,
+                    None, None );
+        break;
+    }
     case XKeyPress: {
         int kc = XKeycodeToKeysym(qt_xdisplay(), e->xkey.keycode, 0);
         if ( kc == XK_Tab || kc == XK_ISO_Left_Tab ) {
@@ -572,6 +587,7 @@ void QXEmbed::keyReleaseEvent( QKeyEvent
 void QXEmbed::focusInEvent( QFocusEvent * e ){
     if (!window)
         return;
+    XUngrabButton( qt_xdisplay(), AnyButton, AnyModifier, window );
     int detail = XEMBED_FOCUS_CURRENT;
     if ( e->reason() == QFocusEvent::Tab )
         detail = tabForward?XEMBED_FOCUS_FIRST:XEMBED_FOCUS_LAST;
@@ -728,6 +744,15 @@ bool QXEmbed::x11Event( XEvent* e)
             window = e->xreparent.window;
             embed( window );
         }
+        break;
+    case ButtonPress:
+        QFocusEvent::setReason( QFocusEvent::Mouse );
+        setFocus();
+        QFocusEvent::resetReason();
+        XAllowEvents(qt_xdisplay(), ReplayPointer, CurrentTime);
+        return TRUE;
+    case ButtonRelease:
+        XAllowEvents(qt_xdisplay(), SyncPointer, CurrentTime);
         break;
     case MapRequest:
         if ( window && e->xmaprequest.window == window )


More information about the kfm-devel mailing list