Made handling of focus in and out more explicit.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/back/trunk@25403 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
fredkiefer 2007-08-20 22:31:09 +00:00
parent 86a9213e9f
commit 5e75161bf3
2 changed files with 135 additions and 124 deletions

View file

@ -1,3 +1,8 @@
2007-08-21 Fred Kiefer <FredKiefer@gmx.de>
* Source/x11/XGServerEvent.m (-processEvent:): Made handling of
focus in and out more explicit.
2007-08-16 Fred Kiefer <FredKiefer@gmx.de> 2007-08-16 Fred Kiefer <FredKiefer@gmx.de>
* Source/xlib/XGFontManager.m (load_cache), * Source/xlib/XGFontManager.m (load_cache),

View file

@ -982,116 +982,121 @@ static int check_modifier (XEvent *xEvent, KeySym key_sym,
break; break;
} }
// keyboard focus entered a window // keyboard focus entered a window
case FocusIn: case FocusIn:
NSDebugLLog(@"NSEvent", @"%d FocusIn\n", NSDebugLLog(@"NSEvent", @"%d FocusIn\n",
xEvent.xfocus.window); xEvent.xfocus.window);
if (cWin == 0 || xEvent.xfocus.window != cWin->ident) if (cWin == 0 || xEvent.xfocus.window != cWin->ident)
{ {
generic.cachedWindow generic.cachedWindow
= [XGServer _windowForXWindow:xEvent.xfocus.window]; = [XGServer _windowForXWindow:xEvent.xfocus.window];
} }
if (cWin == 0) if (cWin == 0)
break; break;
NSDebugLLog(@"Focus", @"%d got focus on %d\n", NSDebugLLog(@"Focus", @"%d got focus on %d\n",
xEvent.xfocus.window, cWin->number); xEvent.xfocus.window, cWin->number);
generic.currentFocusWindow = cWin->number; // Store this for debugging, may not be the real focus window
if (xEvent.xfocus.serial == generic.focusRequestNumber) generic.currentFocusWindow = cWin->number;
{ if (xEvent.xfocus.serial == generic.focusRequestNumber)
/* {
* This is a response to our own request - so we mark the /*
* request as complete. * This is a response to our own request - so we mark the
*/ * request as complete.
generic.desiredFocusWindow = 0; */
generic.focusRequestNumber = 0; generic.desiredFocusWindow = 0;
} generic.focusRequestNumber = 0;
break; }
break;
// keyboard focus left a window // keyboard focus left a window
case FocusOut: case FocusOut:
{ {
Window fw; Window fw;
int rev; int rev;
/*
* See where the focus has moved to -
* If it has gone to 'none' or 'PointerRoot' then
* it's not one of ours.
* If it has gone to our root window - use the icon window.
* If it has gone to a window - we see if it is one of ours.
*/
XGetInputFocus(xEvent.xfocus.display, &fw, &rev);
NSDebugLLog(@"NSEvent", @"%d FocusOut\n",
xEvent.xfocus.window);
if (fw != None && fw != PointerRoot)
{
generic.cachedWindow = [XGServer _windowForXWindow: fw];
if (cWin == 0)
{
generic.cachedWindow = [XGServer _windowForXParent: fw];
}
if (cWin == 0)
{
nswin = nil;
}
else
{
nswin = GSWindowWithNumber(cWin->number);
}
}
else
{
nswin = nil;
}
NSDebugLLog(@"Focus", @"Focus went to %d (xwin %d)\n",
(nswin != nil) ? cWin->number : 0, fw);
/* // Focus went to a window not in this application.
* See where the focus has moved to - if (nswin == nil)
* If it has gone to 'none' or 'PointerRoot' then {
* it's not one of ours. [NSApp deactivate];
* If it has gone to our root window - use the icon window. }
* If it has gone to a window - we see if it is one of ours.
*/ // Clean up old focus request
XGetInputFocus(xEvent.xfocus.display, &fw, &rev); generic.cachedWindow
NSDebugLLog(@"NSEvent", @"%d FocusOut\n", = [XGServer _windowForXWindow: xEvent.xfocus.window];
xEvent.xfocus.window); NSDebugLLog(@"Focus", @"%d lost focus on %d\n",
generic.cachedWindow = [XGServer _windowForXWindow: fw]; xEvent.xfocus.window, (cWin) ? cWin->number : 0);
if (cWin == 0) generic.currentFocusWindow = 0;
{ if (cWin && generic.desiredFocusWindow == cWin->number)
generic.cachedWindow = [XGServer _windowForXParent: fw]; {
} /* Request not valid anymore since we lost focus */
if (cWin == 0) generic.focusRequestNumber = 0;
{ }
nswin = nil; }
} break;
else
{
nswin = GSWindowWithNumber(cWin->number);
}
NSDebugLLog(@"Focus", @"Focus went to %d (xwin %d)\n",
(cWin) ? cWin->number : 0, fw);
if (nswin == nil)
{
if (fw == 0)
{
/* What? This is bogus. Focus has to go somewhere. */
}
else
{
[NSApp deactivate];
}
}
generic.cachedWindow
= [XGServer _windowForXWindow: xEvent.xfocus.window];
NSDebugLLog(@"Focus", @"%d lost focus on %d\n",
xEvent.xfocus.window, (cWin) ? cWin->number : 0);
generic.currentFocusWindow = 0;
if (cWin && generic.desiredFocusWindow == cWin->number)
{
/* Request not valid anymore since we lost focus */
generic.focusRequestNumber = 0;
}
}
break;
case GraphicsExpose: case GraphicsExpose:
NSDebugLLog(@"NSEvent", @"%d GraphicsExpose\n", NSDebugLLog(@"NSEvent", @"%d GraphicsExpose\n",
xEvent.xexpose.window); xEvent.xexpose.window);
break; break;
case NoExpose: case NoExpose:
NSDebugLLog(@"NSEvent", @"NoExpose\n"); NSDebugLLog(@"NSEvent", @"NoExpose\n");
break; break;
// window is moved because of a change in the size of its parent // window is moved because of a change in the size of its parent
case GravityNotify: case GravityNotify:
NSDebugLLog(@"NSEvent", @"%d GravityNotify\n", NSDebugLLog(@"NSEvent", @"%d GravityNotify\n",
xEvent.xgravity.window); xEvent.xgravity.window);
break; break;
// a key has been pressed // a key has been pressed
case KeyPress: case KeyPress:
NSDebugLLog(@"NSEvent", @"%d KeyPress\n", NSDebugLLog(@"NSEvent", @"%d KeyPress\n",
xEvent.xkey.window); xEvent.xkey.window);
generic.lastTime = xEvent.xkey.time; generic.lastTime = xEvent.xkey.time;
e = process_key_event (&xEvent, self, NSKeyDown, event_queue); e = process_key_event (&xEvent, self, NSKeyDown, event_queue);
break; break;
// a key has been released // a key has been released
case KeyRelease: case KeyRelease:
NSDebugLLog(@"NSEvent", @"%d KeyRelease\n", NSDebugLLog(@"NSEvent", @"%d KeyRelease\n",
xEvent.xkey.window); xEvent.xkey.window);
generic.lastTime = xEvent.xkey.time; generic.lastTime = xEvent.xkey.time;
e = process_key_event (&xEvent, self, NSKeyUp, event_queue); e = process_key_event (&xEvent, self, NSKeyUp, event_queue);
break; break;
// reports the state of the keyboard when pointer or // reports the state of the keyboard when pointer or
// focus enters a window // focus enters a window
@ -1164,34 +1169,34 @@ static int check_modifier (XEvent *xEvent, KeySym key_sym,
// when a window changes state from ummapped to // when a window changes state from ummapped to
// mapped or vice versa // mapped or vice versa
case MapNotify: case MapNotify:
NSDebugLLog(@"NSEvent", @"%d MapNotify\n", NSDebugLLog(@"NSEvent", @"%d MapNotify\n",
xEvent.xmap.window); xEvent.xmap.window);
if (cWin == 0 || xEvent.xmap.window != cWin->ident) if (cWin == 0 || xEvent.xmap.window != cWin->ident)
{ {
generic.cachedWindow generic.cachedWindow
= [XGServer _windowForXWindow:xEvent.xmap.window]; = [XGServer _windowForXWindow:xEvent.xmap.window];
} }
if (cWin != 0) if (cWin != 0)
{ {
cWin->map_state = IsViewable; cWin->map_state = IsViewable;
/* /*
* if the window that was just mapped wants the input * if the window that was just mapped wants the input
* focus, re-do the request. * focus, re-do the request.
*/ */
if (generic.desiredFocusWindow == cWin->number if (generic.desiredFocusWindow == cWin->number
&& generic.focusRequestNumber == 0) && generic.focusRequestNumber == 0)
{ {
NSDebugLLog(@"Focus", @"Refocusing %d on map notify", NSDebugLLog(@"Focus", @"Refocusing %d on map notify",
cWin->number); cWin->number);
[self setinputfocus: cWin->number]; [self setinputfocus: cWin->number];
} }
/* /*
* Make sure that the newly mapped window displays. * Make sure that the newly mapped window displays.
*/ */
nswin = GSWindowWithNumber(cWin->number); nswin = GSWindowWithNumber(cWin->number);
[nswin update]; [nswin update];
} }
break; break;
// Window is no longer visible. // Window is no longer visible.
case UnmapNotify: case UnmapNotify:
@ -1553,7 +1558,7 @@ static int check_modifier (XEvent *xEvent, KeySym key_sym,
* WM is asking us to take the keyboard focus * WM is asking us to take the keyboard focus
*/ */
- (NSEvent *)_handleTakeFocusAtom: (XEvent)xEvent - (NSEvent *)_handleTakeFocusAtom: (XEvent)xEvent
forContext: (NSGraphicsContext *)gcontext forContext: (NSGraphicsContext *)gcontext
{ {
int key_num; int key_num;
NSWindow *key_win; NSWindow *key_win;
@ -1564,7 +1569,8 @@ static int check_modifier (XEvent *xEvent, KeySym key_sym,
cWin->number, generic.currentFocusWindow, key_num); cWin->number, generic.currentFocusWindow, key_num);
/* Sometimes window managers lose the setinputfocus on the key window /* Sometimes window managers lose the setinputfocus on the key window
* e.g. when ordering out a window with focus then ordering in the key window. * it might search for a window until one accepts its take focus request. * e.g. when ordering out a window with focus then ordering in the key window.
* it might search for a window until one accepts its take focus request.
*/ */
if (key_num == cWin->number) if (key_num == cWin->number)
cWin->ignore_take_focus = NO; cWin->ignore_take_focus = NO;