[Wine] fix focus and alsa for gps software

andrea at cpushare.com andrea at cpushare.com
Thu Nov 6 21:00:57 CST 2008


I'm going to use wine to use a gps software on my carpc.

The GPS software runs great but when the window loses focus it hangs
until the windows gets focus back. I guess this is really a fault of
the application, I assume it does the same without wine (I actually
never tried it outside wine so I don't know).

Anyway because it's under wine it's easy to workaround it. I want to
iconize the gps software and go back in elisa media player and still
hear the directions in the speakers mixed with the music by alsa.

First I just uncommented the focusout event (same as WoW) but that
wasn't enough. When I iconize elisa and I return into the gps, the
windows doesn't redraw and I have to click some random button to
trigger a redraw. So I forced a focusout/focusin event inside the x11
focusin handler. That fixed all my troubles with the focus

So this is the workaround:

Index: wine-1.1.7/dlls/winex11.drv/event.c
--- wine-1.1.7/dlls/winex11.drv/event.c.orig	2008-10-24 17:55:14.000000000 +0200
+++ wine-1.1.7/dlls/winex11.drv/event.c	2008-11-06 00:25:37.000000000 +0100
@@ -620,6 +620,8 @@ static void X11DRV_FocusIn( HWND hwnd, X
         XSetICFocus( xic );
+    SetForegroundWindow( GetDesktopWindow() );
+    SetForegroundWindow( hwnd );
     if (use_take_focus) return;  /* ignore FocusIn if we are using take focus */
     if (!can_activate_window(hwnd))
@@ -685,7 +687,7 @@ static void X11DRV_FocusOut( HWND hwnd, 
         if (hwnd == GetForegroundWindow())
             TRACE( "lost focus, setting fg to desktop\n" );
-            SetForegroundWindow( GetDesktopWindow() );
+            //SetForegroundWindow( GetDesktopWindow() );

Second problem was sound. Sounds is garbled with the alsa driver (oss
works but that doesn't allow mixing, aoss used to work around it, but
not anymore). I could use tricks with .asoundrc to fix it:

pcm.!default {
    type plug
    slave.pcm "dmixer"
pcm.dmixer {
    type dmix
    ipc_key 1024
    slave {
        pcm "hw:0,0"          # change this if you use other sound
        period_size 256
        buffer_size 8192

The trouble is wine trying to force weird defaults on alsa on two
params that renders period_size/buffer_size not power of 2 inside the
driver and that makes the app sound ring it go out of sync. Since I've
to rebuild wine for the focus problem I preferred to fix this as well
in wine instead of in .asoundrc:

Index: wine-1.1.7/dlls/winealsa.drv/waveout.c
--- wine-1.1.7/dlls/winealsa.drv/waveout.c.orig	2008-10-24 17:55:14.000000000 +0200
+++ wine-1.1.7/dlls/winealsa.drv/waveout.c	2008-11-05 19:49:37.000000000 +0100
@@ -577,8 +577,8 @@ static DWORD wodOpen(WORD wDevID, LPWAVE
     snd_pcm_access_t            access;
     snd_pcm_format_t            format = -1;
     unsigned int                rate;
-    unsigned int                buffer_time = 120000;
-    unsigned int                period_time = 20000;
+    //unsigned int                buffer_time = 120000;
+    //unsigned int                period_time = 20000;
     snd_pcm_uframes_t           buffer_size;
     snd_pcm_uframes_t           period_size;
     int                         flags;
@@ -753,9 +753,9 @@ static DWORD wodOpen(WORD wDevID, LPWAVE
-    EXIT_ON_ERROR( snd_pcm_hw_params_set_buffer_time_near(pcm, hw_params, &buffer_time, &dir), MMSYSERR_INVALPARAM, "unable to set buffer time");
+    //EXIT_ON_ERROR( snd_pcm_hw_params_set_buffer_time_near(pcm, hw_params, &buffer_time, &dir), MMSYSERR_INVALPARAM, "unable to set buffer time");
-    EXIT_ON_ERROR( snd_pcm_hw_params_set_period_time_near(pcm, hw_params, &period_time, &dir), MMSYSERR_INVALPARAM, "unable to set period time");
+    //EXIT_ON_ERROR( snd_pcm_hw_params_set_period_time_near(pcm, hw_params, &period_time, &dir), MMSYSERR_INVALPARAM, "unable to set period time");
     EXIT_ON_ERROR( snd_pcm_hw_params(pcm, hw_params), MMSYSERR_INVALPARAM, "unable to set hw params for playback");

The second patch perhaps could be considered to be merged, I've no
idea about the first patch (but a workaround for the focus problem
being available in winecfg surely would be nice considering WoW needs
it too, and no I'm not wasting time with videogames, I simply found
about it while searching for 'wine focus').

Hope this helps in case somebody had similar issues. I'm offlist so
keep me in CC if you want to contact me.

More information about the wine-users mailing list