home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / alt / lucidem / bug / 64 < prev    next >
Encoding:
Text File  |  1992-07-28  |  3.7 KB  |  76 lines

  1. Newsgroups: alt.lucid-emacs.bug
  2. Sender: bug-lucid-emacs-request@lucid.com
  3. Date: Tue, 28 Jul 92 09:06:59 PDT
  4. From: devin%scylla@lucid.com (Matthieu Devin)
  5. Message-ID: <9207281606.AA06384@scylla.lucid>
  6. Subject: Re: lemacs is grabbing window focus when it isn't supposed to
  7. References: <199207280832.AA14324@bagheera.inria.fr>
  8. Path: sparky!uunet!wendy-fate.uu.net!bug-lucid-emacs
  9. Lines: 65
  10.  
  11. Colas is wondering why Emacs takes the focus.  This is necessary to implement
  12. select-screen: a lisp function that makes another Emacs screen be selected
  13. meaning that the typed characters go to this screen.  The semantic of
  14. select-screen is really to move the keyboard focus from one Emacs screen to the
  15. other.  
  16.  
  17. The advantage of setting the focus is that the WM can show you with some kind
  18. of highlight where is the focus.  Otherwise you end-up with one Emacs screen
  19. highlighted and the characters going into and other screen.  Confusion!
  20.  
  21. Explicitely taking the focus is the ICCCCCCCCCM way to do this.  It does not
  22. work with bogus window managers, but it is supposed to work.  (At least in
  23. our understanding of the ICCCM, if WM persons like Colas have a better
  24. understanding please, please correct me).  By "does not work" I mean that
  25. Emacs sometimes steals the focus after the user thought it moved it to
  26. another window, like an xterm.  We beleive we are having all those problems
  27. because Lucid Emacs seems to be the first large client to use WM_TAKE_FOCUS.
  28.  
  29. First, what the ICCCM says (in my own words):
  30.   
  31.   When a client as WM_TAKE_FOCUS set the WM has to send a WM_TAKE_FOCUS
  32.   message to ask the client if it wants the keyboard.  This message has a
  33.   timestamp in arg[1] (or 0?) which is most likely to be the timestamp of the
  34.   XEvent that caused the WM to decide that Emacs could take the focus (an
  35.   EnterWindow event, an explicit click in a title bar, etc.).
  36.  
  37.   The client has to answer by explicitely setting the focus to one of its
  38.   windows, i.e. by calling XSetInputFocus with the timestamp passed in the
  39.   event.  The timestamp is the key here, it is used to solve race conditions
  40.   when the WM_TAKE_FOCUS client is too slow to answer, like Emacs can be when
  41.   swapped out, garbage collecting, etc.  XSetInputFocus is defined as a noop
  42.   if the timestamp is earlier than the timestamp of the last call to
  43.   XSetInputFocus.
  44.  
  45.   For the timestamp to correctly solve the race condition problems a real
  46.   estate driven WM has to explicitely set the Focus back to PointerRoot when
  47.   the focus has to move from a WM_TAKE_FOCUS client to a non WM_TAKE_FOCUS
  48.   client.
  49.  
  50. Example: in a real estate driven WM, the mouse goes from an xterm to Emacs to
  51. an xterm again.  The WM sends WM_TAKE_FOCUS with time t1 to Emacs and
  52. then do XSetInputFocus (t2, PointerRoot) for the xterm.  When Emacs wakes up
  53. and answers the TAKE_FOCUS its call to XSetInputFocus is ignored because t1
  54. is less than t2.  So Emacs does not steal the focus.
  55.  
  56. Now, the benefits:
  57.  
  58.   As Emacs is a WM_TAKE_FOCUS client it can explicitely switch the focus to
  59.   any of its windows as long as it already has the focus when it does it and
  60.   use valid timestamps in the call to XSetInputFocus (using CurrentTime here
  61.   would clearly lose).
  62.   
  63.   The WM can track the focus changes and correctly highlight the focus
  64.   window.  Some WM could even decide to raise the window if the user had said
  65.   that the focus window should always be on top.
  66.  
  67. So unless I'm totally confused (which is extremely possible as ICCCM stuff is
  68. really hard) Emacs is doing the right thing.  I know that most WM do not do
  69. the right thing yet but my guess is that it's because they did not have test
  70. cases for the full WM_TAKE_FOCUS stuff.  If we disable this feature the WM
  71. will never be fixed.
  72.  
  73. Colas what do you think?  Can gwm do the right thing?
  74.  
  75. Matthieu
  76.