[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    branches/work/kwin_composite
From:       Luboš Luňák <l.lunak () kde ! org>
Date:       2007-04-15 14:39:11
Message-ID: 1176647951.029838.20952.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 654227 by lunakl:

Utility function for XGrabKeyboard().



 M  +1 -0      client.cpp  
 M  +1 -0      client.h  
 M  +1 -1      events.cpp  
 M  +5 -3      geometry.cpp  
 M  +2 -4      killwindow.cpp  
 M  +3 -4      tabbox.cpp  
 M  +26 -0     utils.cpp  
 M  +2 -0      utils.h  
 M  +3 -7      workspace.cpp  


--- branches/work/kwin_composite/client.cpp #654226:654227
@@ -73,6 +73,7 @@
         bridge( new Bridge( this )),
         move_faked_activity( false ),
         move_resize_grab_window( None ),
+        move_resize_has_keyboard_grab( false ),
         transient_for( NULL ),
         transient_for_id( None ),
         original_transient_for_id( None ),
--- branches/work/kwin_composite/client.h #654226:654227
@@ -377,6 +377,7 @@
         bool moveResizeMode;
         bool move_faked_activity;
         Window move_resize_grab_window;
+        bool move_resize_has_keyboard_grab;
         bool unrestrictedMoveResize;
 
         Position mode;
--- branches/work/kwin_composite/events.cpp #654226:654227
@@ -203,7 +203,7 @@
     if ( mouse_emulation && (e->type == ButtonPress || e->type == ButtonRelease ) ) 
         {
         mouse_emulation = false;
-        XUngrabKeyboard( display(), xTime() );
+        ungrabXKeyboard();
         }
 
     if ( e->type == PropertyNotify || e->type == ClientMessage ) 
--- branches/work/kwin_composite/geometry.cpp #654226:654227
@@ -2266,8 +2266,8 @@
         ButtonPressMask | ButtonReleaseMask | PointerMotionMask | EnterWindowMask | LeaveWindowMask,
         GrabModeAsync, GrabModeAsync, None, cursor.handle(), xTime() ) == Success )
         has_grab = true;
-    if( XGrabKeyboard( display(), frameId(), False, GrabModeAsync, GrabModeAsync, xTime() ) == Success )
-        has_grab = true;
+    if( grabXKeyboard( frameId()))
+        has_grab = move_resize_has_keyboard_grab = true;
     if( !has_grab ) // at least one grab is necessary in order to be able to finish move/resize
         {
         XDestroyWindow( display(), move_resize_grab_window );
@@ -2327,7 +2327,9 @@
     if ( ( isMove() && rules()->checkMoveResizeMode( options->moveMode ) != Options::Opaque )
       || ( isResize() && rules()->checkMoveResizeMode( options->resizeMode ) != Options::Opaque ) )
         ungrabXServer();
-    XUngrabKeyboard( display(), xTime() );
+    if( move_resize_has_keyboard_grab )
+        ungrabXKeyboard();
+    move_resize_has_keyboard_grab = false;
     XUngrabPointer( display(), xTime() );
     XDestroyWindow( display(), move_resize_grab_window );
     move_resize_grab_window = None;
--- branches/work/kwin_composite/killwindow.cpp #654226:654227
@@ -45,8 +45,7 @@
                      GrabModeAsync, GrabModeAsync, None,
                      kill_cursor, CurrentTime) == GrabSuccess) 
         {
-        XGrabKeyboard(display(), rootWindow(), False,
-                      GrabModeAsync, GrabModeAsync, CurrentTime);
+        grabXKeyboard();
 
         XEvent ev;
         int return_pressed  = 0;
@@ -103,8 +102,7 @@
             }
 
         ungrabXServer();
-
-        XUngrabKeyboard(display(), CurrentTime);
+        ungrabXKeyboard();
         XUngrabPointer(display(), CurrentTime);
         }
     }
--- branches/work/kwin_composite/tabbox.cpp #654226:654227
@@ -870,7 +870,7 @@
         return;
     if ( options->altTabStyle == Options::CDE || !options->focusPolicyIsReasonable())
         {
-        //XUngrabKeyboard(display(), xTime()); // need that because of accelerator raw mode
+        //ungrabXKeyboard(); // need that because of accelerator raw mode
         // CDE style raise / lower
         CDEWalkThroughWindows( true );
         }
@@ -1398,8 +1398,7 @@
 
 bool Workspace::establishTabBoxGrab()
     {
-    if( XGrabKeyboard( display(), root, false,
-        GrabModeAsync, GrabModeAsync, xTime()) != GrabSuccess )
+    if( !grabXKeyboard())
         return false;
     // Don't try to establish a global mouse grab using XGrabPointer, as that would prevent
     // using Alt+Tab while DND (#44972). However force passive grabs on all windows
@@ -1415,7 +1414,7 @@
 
 void Workspace::removeTabBoxGrab()
     {
-    XUngrabKeyboard(display(), xTime());
+    ungrabXKeyboard();
     assert( forced_global_mouse_grab );
     forced_global_mouse_grab = false;
     if( active_client != NULL )
--- branches/work/kwin_composite/utils.cpp #654226:654227
@@ -354,6 +354,32 @@
     return server_grab_count > 0;
     }
 
+static bool keyboard_grabbed = false;
+
+bool grabXKeyboard( Window w )
+    {
+    if( QWidget::keyboardGrabber() != NULL )
+        return false;
+    if( keyboard_grabbed )
+        return false;
+    if( qApp->activePopupWidget() != NULL )
+        return false;
+    if( w == None )
+        w = rootWindow();
+    if( XGrabKeyboard( display(), w, False,
+        GrabModeAsync, GrabModeAsync, xTime()) != GrabSuccess )
+        return false;
+    keyboard_grabbed = true;
+    return true;
+    }
+
+void ungrabXKeyboard()
+    {
+    assert( keyboard_grabbed );
+    keyboard_grabbed = false;
+    XUngrabKeyboard( display(), xTime());
+    }
+
 QPoint cursorPos()
     {
     return Workspace::self()->cursorPos();
--- branches/work/kwin_composite/utils.h #654226:654227
@@ -238,6 +238,8 @@
 void grabXServer();
 void ungrabXServer();
 bool grabbedXServer();
+bool grabXKeyboard( Window w = rootWindow());
+void ungrabXKeyboard();
 
 class Scene;
 extern Scene* scene;
--- branches/work/kwin_composite/workspace.cpp #654226:654227
@@ -1778,18 +1778,14 @@
  */
 void Workspace::slotMouseEmulation()
     {
-
     if ( mouse_emulation )
         {
-        XUngrabKeyboard(display(), xTime());
+        ungrabXKeyboard();
         mouse_emulation = false;
         return;
         }
 
-    if ( XGrabKeyboard(display(),
-                       root, false,
-                       GrabModeAsync, GrabModeAsync,
-                       xTime()) == GrabSuccess )
+    if( grabXKeyboard())
         {
         mouse_emulation = true;
         mouse_emulation_state = 0;
@@ -1987,7 +1983,7 @@
             }
     // fall through
         case XK_Escape:
-            XUngrabKeyboard(display(), xTime());
+            ungrabXKeyboard();
             mouse_emulation = false;
             return true;
         default:
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic