emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

mouse position bug and half a fix


From: David Reitter
Subject: mouse position bug and half a fix
Date: Sat, 24 Jan 2009 22:15:13 -0500

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: smime.p7s
Description: S/MIME cryptographic signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]