[gnu.emacs.bug] X11 focus management

victor@MIZAR.DOCS.UU.SE (Bjorn Victor) (12/15/89)

In GNU Emacs 18.55.5 of Thu Dec  7 1989 on mizar (berkeley-unix)

Emacs doesn't do focus management (for highlighting the cursor), as
src/x11term.c states in function internal_socket_read().  Instead it
does Enter/Leave window management, which is not really relevant.
Well, I got irritated on it (since I use twm with TitleFocus), and
looked at it.

I'm no Xpert, but it seems to work if you simply change the case
EnterNotify/LeaveNotify pair with FocusIn/FocusOut, and change the
XSelectInput call in XInitWindow to use FocusChangeMask instead of
EnterWindowMask | LeaveWindowMask.  Perhaps some Xpert can tell me if
this is the wrong way of doing things, or if I'll get bitten by some
evil side effect?

-- Bjorn Victor			victor@DoCS.UU.SE
Dept. of Computer Systems    or victor%DoCS.UU.SE@uunet.UU.NET
Uppsala University, Sweden	"I'd rather hack a Lisp Machine!"


The patch:
*** /usr/share/local/src/gnu/emacs-18.55/src/x11term.c	Thu Aug  3 04:56:42 1989
--- /home/mizar/docs/victor/emacs/18.55/src/x11term.c	Thu Dec 14 18:15:59 1989
***************
*** 1314,1326 ****
         * still show a filled cursor whenever the pointer
         * enters the emacs window.
         */
!     case EnterNotify:
        CursorToggle ();
        CursorOutline = 0;
        CursorToggle ();
        break;
  
!     case LeaveNotify:
        CursorToggle ();
        CursorOutline = 1;
        CursorToggle ();
--- 1314,1328 ----
         * still show a filled cursor whenever the pointer
         * enters the emacs window.
         */
! /*    case EnterNotify: */
!     case FocusIn:		/* Focus management *seems* this simple... */
        CursorToggle ();
        CursorOutline = 0;
        CursorToggle ();
        break;
  
! /*    case LeaveNotify: */
!     case FocusOut:		/* Focus management... */
        CursorToggle ();
        CursorOutline = 1;
        CursorToggle ();
***************
*** 2386,2392 ****
  
      XSelectInput(XXdisplay, XXwindow, KeyPressMask |
  		 ExposureMask | ButtonPressMask | ButtonReleaseMask |
! 		 EnterWindowMask | LeaveWindowMask |
  		 StructureNotifyMask);
  
      XMapWindow (XXdisplay, XXwindow);
--- 2388,2395 ----
  
      XSelectInput(XXdisplay, XXwindow, KeyPressMask |
  		 ExposureMask | ButtonPressMask | ButtonReleaseMask |
! /*		 EnterWindowMask | LeaveWindowMask | */
! 		 FocusChangeMask | 		/* Focus management */
  		 StructureNotifyMask);
  
      XMapWindow (XXdisplay, XXwindow);

carroll@s.cs.uiuc.edu (12/17/89)

/* Written 11:48 am  Dec 14, 1989 by victor@MIZAR.DOCS.UU.SE in s.cs.uiuc.edu:gnu.emacs.bug */
/* ---------- "X11 focus management" ---------- */
>In GNU Emacs 18.55.5 of Thu Dec  7 1989 on mizar (berkeley-unix)

>Emacs doesn't do focus management (for highlighting the cursor), as
>src/x11term.c states in function internal_socket_read().  Instead it
>does Enter/Leave window management, which is not really relevant.
It's sort of relevant, see below

>I'm no Xpert, but it seems to work if you simply change the case
>EnterNotify/LeaveNotify pair with FocusIn/FocusOut, and change the
>XSelectInput call in XInitWindow to use FocusChangeMask instead of
>EnterWindowMask | LeaveWindowMask.
No, that doesn't work. I tried it. The problem is that if the focus is not
explicitly set, then Emacs never thinks it has the focus (which it does if
the cursor is in the window). I've fixed this problem in Epoch, but the
code should still work in 18.55: (The if statements are the key difference
between your version and mine)

    case EnterNotify :
    case FocusIn :
	if (event.type == FocusIn || event.xcrossing.focus)
	    {
	    CursorToggle ();
	    CursorOutline = 0;
	    CursorToggle ();
	    }
	break;

    case LeaveNotify :
    case FocusOut :
	if (event.type == FocusOut || event.xcrossing.focus)
	    {
	    CursorToggle ();
	    CursorOutline = 1;
	    CursorToggle ();
	    }
	break;

The XSelectInput call must still be modified to accept Focus events _in
addition to_ Enter and Leave events.

/* End of text from s.cs.uiuc.edu:gnu.emacs.bug */

Alan M. Carroll                "Oh goody, the Illudium Q-36 Explosive
carroll@s.cs.uiuc.edu           Space Modulator!"
CS Grad / U of Ill @ Urbana    ...{ucbvax,pur-ee,convex}!s.cs.uiuc.edu!carroll