diff options
author | Sven Gothel <[email protected]> | 2011-10-22 15:54:58 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2011-10-22 15:54:58 +0200 |
commit | cba9a070f9649bec42627631d393963d548e320c (patch) | |
tree | cda7fb5c364afd86779a756132ddec023131bb3a | |
parent | a9494e62a039d2b4bb0c8f7492e273aad44531c5 (diff) |
NEWT/Native RequestFocus: Even if owning focus, run the focusAction() call incl. native focus request (X11, Windows, OSX)
-rw-r--r-- | src/newt/native/MacWindow.m | 18 | ||||
-rw-r--r-- | src/newt/native/WindowsWindow.c | 25 | ||||
-rw-r--r-- | src/newt/native/X11Window.c | 26 |
3 files changed, 35 insertions, 34 deletions
diff --git a/src/newt/native/MacWindow.m b/src/newt/native/MacWindow.m index eaad388c3..5b7b47786 100644 --- a/src/newt/native/MacWindow.m +++ b/src/newt/native/MacWindow.m @@ -478,15 +478,15 @@ JNIEXPORT void JNICALL Java_jogamp_newt_driver_macosx_MacWindow_requestFocus0 DBG_PRINT( "requestFocus - window: %p, force %d, hasFocus %d (START)\n", win, force, hasFocus); - if( JNI_TRUE==force || !hasFocus ) { - if( JNI_TRUE==force || JNI_FALSE == (*env)->CallBooleanMethod(env, window, focusActionID) ) { - DBG_PRINT( "makeKeyWindow win %p\n", win); - // [win performSelectorOnMainThread:@selector(orderFrontRegardless) withObject:nil waitUntilDone:YES]; - // [win performSelectorOnMainThread:@selector(makeKeyWindow) withObject:nil waitUntilDone:YES]; - [win orderFrontRegardless]; - [win makeKeyWindow]; - [win makeFirstResponder: nil]; - } + // even if we already own the focus, we need the 'focusAction()' call + // and the other probably redundant NS calls don't harm. + if( JNI_TRUE==force || JNI_FALSE == (*env)->CallBooleanMethod(env, window, focusActionID) ) { + DBG_PRINT( "makeKeyWindow win %p\n", win); + // [win performSelectorOnMainThread:@selector(orderFrontRegardless) withObject:nil waitUntilDone:YES]; + // [win performSelectorOnMainThread:@selector(makeKeyWindow) withObject:nil waitUntilDone:YES]; + [win orderFrontRegardless]; + [win makeKeyWindow]; + [win makeFirstResponder: nil]; } DBG_PRINT( "requestFocus - window: %p, force %d (END)\n", win, force); diff --git a/src/newt/native/WindowsWindow.c b/src/newt/native/WindowsWindow.c index 0d969e670..df4141169 100644 --- a/src/newt/native/WindowsWindow.c +++ b/src/newt/native/WindowsWindow.c @@ -600,19 +600,20 @@ static void NewtWindows_requestFocus (JNIEnv *env, jobject window, HWND hwnd, jb current = GetFocus(); DBG_PRINT("*** WindowsWindow: requestFocus.S parent %p, window %p, isCurrent %d\n", (void*) pHwnd, (void*)hwnd, current==hwnd); - if( JNI_TRUE==force || current!=hwnd) { - if( JNI_TRUE==force || JNI_FALSE == (*env)->CallBooleanMethod(env, window, focusActionID) ) { - UINT flags = SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE; - SetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0, flags); - SetForegroundWindow(hwnd); // Slightly Higher Priority - SetFocus(hwnd);// Sets Keyboard Focus To Window - if(NULL!=pHwnd) { - SetActiveWindow(hwnd); - } - DBG_PRINT("*** WindowsWindow: requestFocus.X1\n"); - } else { - DBG_PRINT("*** WindowsWindow: requestFocus.X0\n"); + + // even if we already own the focus, we need the 'focusAction()' call + // and the other probably redundant GDI calls don't harm. + if( JNI_TRUE==force || JNI_FALSE == (*env)->CallBooleanMethod(env, window, focusActionID) ) { + UINT flags = SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE; + SetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0, flags); + SetForegroundWindow(hwnd); // Slightly Higher Priority + SetFocus(hwnd);// Sets Keyboard Focus To Window + if(NULL!=pHwnd) { + SetActiveWindow(hwnd); } + DBG_PRINT("*** WindowsWindow: requestFocus.X1\n"); + } else { + DBG_PRINT("*** WindowsWindow: requestFocus.X0\n"); } DBG_PRINT("*** WindowsWindow: requestFocus.XX\n"); } diff --git a/src/newt/native/X11Window.c b/src/newt/native/X11Window.c index 6b6c1ff6c..fcdd28305 100644 --- a/src/newt/native/X11Window.c +++ b/src/newt/native/X11Window.c @@ -531,20 +531,20 @@ static void NewtWindows_requestFocus (JNIEnv *env, jobject window, Display *dpy, Window focus_return; int revert_to_return; - DBG_PRINT( "X11: requestFocus dpy %p,win %p, force %d\n", dpy, (void*)w, force); - XGetInputFocus(dpy, &focus_return, &revert_to_return); - if( JNI_TRUE==force || focus_return!=w) { - if( JNI_TRUE==force || JNI_FALSE == (*env)->CallBooleanMethod(env, window, focusActionID) ) { - DBG_PRINT( "X11: XRaiseWindow dpy %p, win %p\n", dpy, (void*)w); - XRaiseWindow(dpy, w); - NewtWindows_setCWAbove(dpy, w); - // Avoid 'BadMatch' errors from XSetInputFocus, ie if window is not viewable - XGetWindowAttributes(dpy, w, &xwa); - if(xwa.map_state == IsViewable) { - DBG_PRINT( "X11: XSetInputFocus dpy %p,win %pd\n", dpy, (void*)w); - XSetInputFocus(dpy, w, RevertToParent, CurrentTime); - } + DBG_PRINT( "X11: requestFocus dpy %p,win %p, force %d, hasFocus %d\n", dpy, (void*)w, force, focus_return==w); + + // even if we already own the focus, we need the 'focusAction()' call + // and the other probably redundant X11 calls don't harm. + if( JNI_TRUE==force || JNI_FALSE == (*env)->CallBooleanMethod(env, window, focusActionID) ) { + DBG_PRINT( "X11: XRaiseWindow dpy %p, win %p\n", dpy, (void*)w); + XRaiseWindow(dpy, w); + NewtWindows_setCWAbove(dpy, w); + // Avoid 'BadMatch' errors from XSetInputFocus, ie if window is not viewable + XGetWindowAttributes(dpy, w, &xwa); + if(xwa.map_state == IsViewable) { + DBG_PRINT( "X11: XSetInputFocus dpy %p,win %pd\n", dpy, (void*)w); + XSetInputFocus(dpy, w, RevertToParent, CurrentTime); } } DBG_PRINT( "X11: requestFocus dpy %p,win %p, force %d - FIN\n", dpy, (void*)w, force); |