Removing focus from X

Harold L Hunt II huntharo@msu.edu
Thu Nov 14 11:28:00 GMT 2002


Jerry,

Yeah, a mistaken flag got checked into CVS... be sure to look in win.h 
and set WIN_LAYER_SUPPORT (or something similar) to NO.  Then do a 
``make clean all'' in xc/programs/Xserver/hw/xwin followed by a ``make 
XWin.exe'' in xc/programs/Xserver.

I can see two problems with the patch right off the bat:
1) You are leaking memory like crazy because you create a display each 
time that code is executed but you never close the display.

2) Because you never close the display, XWin.exe will be terminated if 
the server ever resets.  Try it by running XWin.exe, then xterm.exe, and 
``exit'' the xterm.  The server should kill it self.

Harold

Gerald S. Williams wrote:

>I had meant to try this, but I'm having some build problems
>at the moment. I backed out my patch, and found that the
>build still fails on the CVS snapshot I took 2 weeks ago. It
>reports this error when I run "make" in xc/programs/Xserver:
>
>[...]
>gcc -o XWin.exe -O2 -fno-strength-reduce -Wall -Wpointer-arith  -mwindows -e _ma
>inCRTStartup   -L../../exports/lib   hw/xwin/stubs.o hw/xwin/XWin.res        dix
>/libdix.a os/libos.a ../../exports/lib/libXau.a ../../exports/lib/libXdmcp.a  hw
>/xwin/libXwin.a fb/libfb.a dix/libxpstubs.a mi/libmi.a Xext/libext.a xkb/libxkb.
>a Xi/libxinput.a                    lbx/liblbx.a                   ../../lib/lbx
>util/liblbxutil.a dbe/libdbe.a record/librecord.a                    XTrap/libxt
>rap.a  GL/glx/libglx.a                GL/mesa/GLcore/libGLcore.a                
>  render/librender.a miext/shadow/libshadow.a            hw/xfree86/parser/libxf
>86config.a   -L/usr/X11R6/lib    ../../lib/font/libXfont.a dix/libxpstubs.a -lfr
>eetype -L../../exports/lib   -lXext -lX11 -lz.dll                   -lgdi32 -Wl,
>--enable-auto-import
>hw/xwin/libXwin.a(winscrinit.o)(.text+0x9ce):winscrinit.c: undefined reference to `_LayerStartInit'
>hw/xwin/libXwin.a(winscrinit.o)(.text+0xa2e):winscrinit.c: undefined reference to `_LayerFinishInit'
>hw/xwin/libXwin.a(winlayer.o)(.text+0xa9):winlayer.c: undefined reference to `_LayerCreate'
>hw/xwin/libXwin.a(winlayer.o)(.text+0xfd):winlayer.c: undefined reference to `_LayerWindowAdd'
>hw/xwin/libXwin.a(winlayer.o)(.text+0x15d):winlayer.c: undefined reference to `_LayerWindowRemove'
>collect2: ld returned 1 exit status
>make: *** [XWin.exe] Error 1
>
>Was there a problem with the CVS snapshot, or am I just
>doing something wrong? Any ideas?
>
>========================
>
>Anyway, here are the changes that I had made to the file
>xc/programs/Xserver/hw/xwin/winwndproc.c:
>
>Index: xc/programs/Xserver/hw/xwin/winwndproc.c
>===================================================================
>RCS file: /cvs/xc/programs/Xserver/hw/xwin/winwndproc.c,v
>retrieving revision 1.23
>diff -u -1 -0 -r1.23 winwndproc.c
>--- xc/programs/Xserver/hw/xwin/winwndproc.c	2002/10/17 08:18:25	1.23
>+++ xc/programs/Xserver/hw/xwin/winwndproc.c	2002/11/14 17:36:39
>@@ -29,20 +29,40 @@
>  *		Suhaib M Siddiqi
>  *		Peter Busch
>  *		Harold L Hunt II
>  *		MATSUZAKI Kensuke
>  */
> /* $XFree86: xc/programs/Xserver/hw/xwin/winwndproc.c,v 1.23 2002/10/17 08:18:25 alanh Exp $ */
> 
> #include "win.h"
> #include <commctrl.h>
> 
>+#define KILL_FOCUS_ENHANCEMENT
>+#ifdef KILL_FOCUS_ENHANCEMENT
>+
>+#define INCLUDE_XLIB_WORKAROUND
>+#ifdef INCLUDE_XLIB_WORKAROUND
>+typedef void Display;
>+
>+extern Display *XOpenDisplay(
>+    const char*	/* display_name */
>+);
>+
>+extern void XSetInputFocus(
>+    Display*		/* display */,
>+    Window		/* focus */,
>+    int			/* revert_to */,
>+    Time		/* time */
>+);
>+#endif /* INCLUDE_XLIB_WORKAROUND */
>+#endif /* KILL_FOCUS_ENHANCEMENT */
>+
> BOOL CALLBACK
> winChangeDepthDlgProc (HWND hDialog, UINT message,
> 		       WPARAM wParam, LPARAM lParam);
> 
> 
> /*
>  * Called by winWakeupHandler
>  * Processes current Windows message
>  */
> 
>@@ -831,20 +851,33 @@
> 
>     case WM_KILLFOCUS:
>       if (s_pScreenPriv == NULL || s_pScreenInfo->fIgnoreInput)
> 	break;
> 
>       /* Store the state of all mode keys */
>       winStoreModeKeyStates (s_pScreen);
> 
>       /* Release any pressed keys */
>       winKeybdReleaseKeys ();
>+
>+#ifdef KILL_FOCUS_ENHANCEMENT
>+      /* Remove focus from all X windows (crude implementation) */
>+      {
>+          Display *display = XOpenDisplay(NULL);
>+
>+          if (display)
>+          {
>+              /* Revert is ignored... */
>+              XSetInputFocus(display,None,RevertToNone,CurrentTime);
>+          }
>+      }
>+#endif /* KILL_FOCUS_ENHANCEMENT */
>       return 0;
> 
> #if WIN_NEW_KEYBOARD_SUPPORT
>     case WM_SYSKEYDOWN:
>     case WM_KEYDOWN:
>     case WM_SYSKEYUP:
>     case WM_KEYUP:
>       if (s_pScreenPriv == NULL || s_pScreenInfo->fIgnoreInput)
> 	break;
> 
>========================
>
>As you can see, it simply sets the input focus to NONE when
>the KILLFOCUS event is received. Does this sound like a
>reasonable approach? Sorry about the weird declarations at
>the top--if you try to #include <X11/Xlib.h> in this file,
>you get some duplicate declarations (another thing for me
>to look into).
>
>I'm not sure if anything needs to be done with the SETFOCUS
>event or not--I figured I'd try this change out first. For
>mouse-initiated focus changes, I would expect the focus to
>be updated anyway. I suppose alt-tab initiated changes may
>not get the focus updated (I haven't tracked it through).
>Perhaps a WarpCursor call could be added to SETFOCUS (if
>needed).
>
>-Jerry
>  
>



More information about the Cygwin-xfree mailing list