all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: David Reitter <david.reitter@gmail.com>
To: Emacs-Devel devel <emacs-devel@gnu.org>
Subject: mouse position bug and half a fix
Date: Sat, 24 Jan 2009 22:15:13 -0500	[thread overview]
Message-ID: <F81A4165-786B-45C7-B05A-B29175BBF3EE@gmail.com> (raw)

[-- 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 --]

             reply	other threads:[~2009-01-25  3:15 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-01-25  3:15 David Reitter [this message]
2009-01-25 17:02 ` mouse position bug and half a fix 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=F81A4165-786B-45C7-B05A-B29175BBF3EE@gmail.com \
    --to=david.reitter@gmail.com \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.