bug-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

maintaining key window on unhide


From: Matt Rice
Subject: maintaining key window on unhide
Date: Wed, 18 Oct 2006 09:41:56 -0700 (PDT)

heres some horrible patches i wouldn't even consider
commiting

it attempts to work around the issue where
after hiding/unhiding the key window is not maintained

theres numerous issues, some of which i'm not quite
sure how the patch fixes...

these are mostly related to the fact that
some of the window methods e.g. orderFrontRegardless:
which are not supposed to make the window key, in fact
do 
because the window manager asks GNUstep to take focus,
and it will (if the window -canBecomeKeyWindow).

as described in this comment in
_handleTakeFocus:forContext:

/*
 * Here the app asked for this (if key_win==nil) or
there was a
 * click on the title bar or some other reason (window
mapped,
 * etc). We don't necessarily want to forward the
event for the
 * last reason but we just have to deal with that
since we can
 * never be sure if it's necessary.
 */

compounding on this is that the WM_TAKE_FOCUS event
isn't recieved until sometime after the runloop has
run, so a 
[win1 orderFrontRegardless];
immediately followed by
[win2 makeKeyAndOrderFront:nil];

win1 will be mapped, and win 2 will be ordered front,
then the window manager seems to request win1 as key

then there is also that
unhideWithoutActivation calls makeKeyAndOrderFront: 
which seems like an activation thing to me..

this patch causes issues where, an app is not hidden
but inactive, when selecting a window which was not
the previous key window, it will end up with 2
selected window titles, but the previous one is
actually selected, at least here probably window
manager dependent... 

anyhow it'd be nice if we could fix the order* methods
if anybody has any ideas



__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 
Index: Source/NSWindow.m
===================================================================
--- Source/NSWindow.m   (revision 23902)
+++ Source/NSWindow.m   (working copy)
@@ -1360,7 +1360,7 @@
       [GSServerForWindow(self) setinputfocus: _windowNum];
       [self resetCursorRects];
       [nc postNotificationName: NSWindowDidBecomeKeyNotification object: self];
-      NSDebugLLog(@"NSWindow", @"%@ is now key window", [self title]);
+      NSDebugLLog(@"NSWindow", @"%@(%i) is now key window", [self title], 
[self windowNumber]);
     }
 }
 
Index: Source/NSApplication.m
===================================================================
--- Source/NSApplication.m      (revision 23902)
+++ Source/NSApplication.m      (working copy)
@@ -1149,7 +1149,17 @@
       unsigned         count;
       unsigned         i;
       NSDictionary     *info;
-
+      id hidden;
+      
+      if (_hidden_key == nil)
+       {
+         hidden = [self keyWindow];
+       }
+      else 
+       {
+         hidden = _hidden_key;
+         _hidden_key = nil;
+       }
      /*
        * Menus should observe this notification in order to make themselves
        * visible when the application is active.
@@ -1157,7 +1167,6 @@
       [nc postNotificationName: NSApplicationWillBecomeActiveNotification
                        object: self];
 
-      _app_is_active = YES;
 
       /* Make sure to calculate count after the notification, since
         inactive status might be changed by a notifiee.  */
@@ -1167,17 +1176,14 @@
          [[_inactive objectAtIndex: i] orderFrontRegardless];
        }
       [_inactive removeAllObjects];
-      if ([self keyWindow] == nil && _hidden_key != nil
-       && [[self windows] indexOfObjectIdenticalTo: _hidden_key] != NSNotFound)
-       {
-         [_hidden_key makeKeyWindow];
-         _hidden_key = nil;
-       }
-
+      
       if (_unhide_on_activation)
        {
          [self unhide: nil];
        }
+      
+      [[NSRunLoop currentRunLoop] runUntilDate:[NSDate 
dateWithTimeIntervalSinceNow:0.2]];
+      [hidden makeKeyWindow];
 
       if ([self keyWindow] != nil)
        {
@@ -1197,6 +1203,7 @@
                              [menu_window windowNumber]];
         }
 
+      _app_is_active = YES;
       info = [self _notificationUserInfo];
       [nc postNotificationName: NSApplicationDidBecomeActiveNotification
                        object: self
@@ -1226,7 +1233,7 @@
 
       _app_is_active = NO;
 
-      if ([self keyWindow] != nil)
+      if ([self keyWindow] != nil && _hidden_key == nil)
        {
          _hidden_key = [self keyWindow];
          [_hidden_key resignKeyWindow];
@@ -2213,7 +2220,7 @@
       [nc postNotificationName: NSApplicationWillHideNotification
                        object: self];
 
-      if ([self keyWindow] != nil)
+      if ([self keyWindow] != nil && _hidden_key == nil)
        {
          _hidden_key = [self keyWindow];
          [_hidden_key resignKeyWindow];
@@ -2300,28 +2307,25 @@
       unsigned         count;
       unsigned         i;
 
+      if (_hidden_key == nil)
+        {
+          _hidden_key = [self keyWindow];
+        }
       [nc postNotificationName: NSApplicationWillUnhideNotification
                        object: self];
 
-      /* Make sure we set this before ordering windows to avoid possible
-        recursive loops (some methods window/backend methods check if
-        the app is hidden before ordering a window).  */
-      _app_is_hidden = NO;
-
       count = [_hidden count];
       for (i = 0; i < count; i++)
        {
          [[_hidden objectAtIndex: i] orderFrontRegardless];
        }
       [_hidden removeAllObjects];
-      if (_hidden_key != nil
-       && [[self windows] indexOfObjectIdenticalTo: _hidden_key] != NSNotFound)
-       {
-         [_hidden_key makeKeyAndOrderFront: self];
-         _hidden_key = nil;
-       }
+      [[NSRunLoop currentRunLoop] runUntilDate:[NSDate 
dateWithTimeIntervalSinceNow:0.2]];
+      [_hidden_key makeKeyAndOrderFront: self];
+      _hidden_key = nil;
       [[_app_icon_window contentView] setNeedsDisplay: YES];
 
+      _app_is_hidden = NO;
       info = [self _notificationUserInfo];
       [nc postNotificationName: NSApplicationDidUnhideNotification
                        object: self
Index: Source/x11/XGServerEvent.m
===================================================================
--- Source/x11/XGServerEvent.m  (revision 23902)
+++ Source/x11/XGServerEvent.m  (working copy)
@@ -1520,7 +1520,7 @@
   key_num = [key_win windowNumber];
   NSDebugLLog(@"Focus", @"take focus:%d (current=%d key=%d)",
              cWin->number, generic.currentFocusWindow, key_num);
-
+  
   /* Invalidate the previous request. It's possible the app lost focus
      before this request was fufilled and we are being focused again,
      or ??? */
@@ -1540,6 +1540,10 @@
         window to take focus after each one gets hidden. */
       NSDebugLLog(@"Focus", @"WM take focus while hiding");
     }
+  if (![NSApp isActive])
+    {
+      NSDebugLLog(@"Focus", @"WM take focus while not active");
+    }
   else if (cWin->number == key_num)
     {
       NSDebugLLog(@"Focus", @"Reasserting key window");

reply via email to

[Prev in Thread] Current Thread [Next in Thread]