Focus problems

Pavel Roskin proski at gnu.org
Mon Oct 6 17:19:48 CDT 2003


Hello!

My patch for fixing the focus of some programs (notepad, winecfg) on
startup hasn't been applied, so I'm guessing what the reason might be.

One reason may be that the testing could have found another bug that might
seem to be related.  When Wine uses non-managed windows without desktop,
they don't get the keyboard focus initially.  It affects even programs
what show active captions, such as Winemine.

When Winemine is started, the keyboard events go to the original window.
The same happens after the "About" dialog is run.  But when the "About"
dialog is dismissed, the main window of Winemine gets keyboard focus.  It
seems to be another example of not doing something because the initial
window is "already focused".

This is a separate problem, it affects a wider class of programs and
doesn't affect Wine in the desktop mode.  If fixing this is considered
precondition to fixing all other focus problems, I'd like to know that.

Another possible reason I can think of is because SetFocus is supposed to
affect widgets before the application window is shown.  That's something
that needs testing.  I've made a patch that only disables activation of
the parent window if it's invisible, but still focuses the window for
which SetFocus() was called.

The patch is attached.  Before I start time-consuming verification, I'd
like to know if I going in the right direction.

There is another, third focus problem.  Windows should not cover modal
dialogs.  Shareware Windows Commander 5.0 is useless in the desktop mode
because the main window covers the "nag screen" on startup.  The
workaround is to enter "foo" in the command line and press Enter - there
will be an error message, and after it's dismissed, the "nag screen" will
pop up.  Again, it's a separate problem that I'm not trying to solve at
this point.

I'll appreciate an advise in which order to proceed and what kind of
verification is expected for the changes in the focus code.

-- 
Regards,
Pavel Roskin
-------------- next part --------------
--- dlls/user/focus.c
+++ dlls/user/focus.c
@@ -257,7 +257,13 @@ HWND WINAPI SetFocus( HWND hwnd )
         {
             HWND parent;
             LONG style = GetWindowLongW( hwndTop, GWL_STYLE );
-            if (style & (WS_MINIMIZE | WS_DISABLED)) return 0;
+            if ((style & (WS_MINIMIZE | WS_DISABLED)) ||
+                !(style & WS_VISIBLE))
+            {
+                /* Don't activate the window */
+                hwndTop = NULL;
+                break;
+            }
             parent = GetAncestor( hwndTop, GA_PARENT );
             if (!parent || parent == GetDesktopWindow()) break;
             hwndTop = parent;
@@ -267,11 +273,12 @@ HWND WINAPI SetFocus( HWND hwnd )
         if (HOOK_CallHooks( WH_CBT, HCBT_SETFOCUS, (WPARAM)hwnd, (LPARAM)previous, TRUE )) return 0;
 
         /* activate hwndTop if needed. */
-        if (hwndTop != GetActiveWindow())
+        if (hwndTop && (hwndTop != GetActiveWindow()))
         {
             if (!set_active_window( hwndTop, NULL, FALSE, FALSE )) return 0;
-            if (!IsWindow( hwnd )) return 0;  /* Abort if window destroyed */
         }
+
+        if (!IsWindow( hwnd )) return 0;  /* Abort if window destroyed */
     }
     else /* NULL hwnd passed in */
     {


More information about the wine-devel mailing list