all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* mouse position bug and half a fix
@ 2009-01-25  3:15 David Reitter
  2009-01-25 17:02 ` Chong Yidong
  0 siblings, 1 reply; 4+ messages in thread
From: David Reitter @ 2009-01-25  3:15 UTC (permalink / raw)
  To: Emacs-Devel devel

[-- Attachment #1: Type: text/plain, Size: 3553 bytes --]

Demonstration first:

emacs -Q
(split-window)
(find-file "~/.emacs")  ;; any file will do, or switch to another buffer
(set (make-local-variable 'face-remapping-alist) '((default . variable- 
pitch)))

The two buffers should now be shown in different faces.  Now click  
(don't drag) into the windows, alternating between the two of them.   
You will see that various regions are marked, each of them between  
some seemingly arbitrary point near the mouse click (=mark), and the  
the point under the mouse.  This shouldn't be.  Instead, we would  
expect to only set the point, as is the case without the `face- 
remapping-alist' use above.

This seems to happen whenever a click into a non-selected window is  
evaluated, and the faces differ in the two windows due to an entry in  
`face-remapping-alist'.

Some analysis:

The problem is that  (posn-point (event-start start-event))  in mouse- 
drag-region does not give us the correct location; in fact, the xy  
coordinates in the event are wrong.

My guess is that whatever algorithm determines the character position  
under the mouse cursor forgets to switch to the appropriate window  
buffer before looking up the faces when iterating over the window  
contents.  I could probably fix this myself if I knew where this bit  
of code is... remember_mouse_glyph() probably doesn't have a part in  
this (because that one should work as is).

For what its worth, I am using the code below (in xfaces.c) in some  
time-critical places to lookup a face in a buffer without having to  
make this buffer temporarily current.  This may come in handy in order  
to fix this.




int
lookup_basic_face_for_buffer (f, face_id, buffer)
      struct frame *f;
      int face_id;
      Lisp_Object buffer;
{
   Lisp_Object name, mapping;
   int remapped_face_id;

   Lisp_Object Vlocal_remapping_alist = Fbuffer_local_value  
(intern("face-remapping-alist"), buffer);


   if (NILP (Vlocal_remapping_alist))
     return face_id;		/* Nothing to do.  */

   switch (face_id)
     {
     case DEFAULT_FACE_ID:		name = Qdefault;		break;
     case MODE_LINE_FACE_ID:		name = Qmode_line;		break;
     case MODE_LINE_INACTIVE_FACE_ID:	name = Qmode_line_inactive;	break;
     case HEADER_LINE_FACE_ID:		name = Qheader_line;		break;
     case TOOL_BAR_FACE_ID:		name = Qtool_bar;		break;
     case FRINGE_FACE_ID:		name = Qfringe;			break;
     case SCROLL_BAR_FACE_ID:		name = Qscroll_bar;		break;
     case BORDER_FACE_ID:		name = Qborder;			break;
     case CURSOR_FACE_ID:		name = Qcursor;			break;
     case MOUSE_FACE_ID:			name = Qmouse;			break;
     case MENU_FACE_ID:			name = Qmenu;			break;

     default:
       abort ();	    /* the caller is supposed to pass us a basic face  
id */
     }

   /* Do a quick scan through Vface_remapping_alist, and return  
immediately
      if there is no remapping for face NAME.  This is just an  
optimization
      for the very common no-remapping case.  */
   mapping = assq_no_quit (name, Vlocal_remapping_alist);
   if (NILP (mapping))
     return face_id;		/* Give up.  */

   /* If there is a remapping entry, lookup the face using NAME, which  
will
      handle the remapping too.
      Avoid setting current buffer (slow).
   */
   Lisp_Object old_face_remapping_alist = Vface_remapping_alist;
   Vface_remapping_alist = Vlocal_remapping_alist;

   remapped_face_id = lookup_named_face (f, name, 0, 0);
   Vface_remapping_alist = old_face_remapping_alist;

   if (remapped_face_id < 0)
     return face_id;		/* Give up. */

   return remapped_face_id;
}



[-- Attachment #2: smime.p7s --]
[-- Type: application/pkcs7-signature, Size: 2193 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2009-01-25 17:10 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-01-25  3:15 mouse position bug and half a fix David Reitter
2009-01-25 17:02 ` Chong Yidong
2009-01-25 14:39   ` bug#2044: posn-point wrong when face-remapping-alist used David Reitter
2009-01-25 17:10     ` bug#2044: marked as done (posn-point wrong when face-remapping-alist used) Emacs bug Tracking System

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.