Merge from emacs-23 branch
[bpt/emacs.git] / lisp / xt-mouse.el
index 6654257..eca5f81 100644 (file)
@@ -50,7 +50,7 @@
                              M-down-mouse-1 M-down-mouse-2 M-down-mouse-3))
   (put event-type 'event-kind 'mouse-click))
 
-(defun xterm-mouse-translate (event)
+(defun xterm-mouse-translate (_event)
   "Read a click and release event from XTerm."
   (save-excursion
     (save-window-excursion
 
 ;; read xterm sequences above ascii 127 (#x7f)
 (defun xterm-mouse-event-read ()
+  ;; We get the characters decoded by the keyboard coding system.  Try
+  ;; to recover the raw character.
   (let ((c (read-char)))
-    (if (> c #x3FFF80)
-        (+ 128 (- c #x3FFF80))
-      c)))
+    (cond ;; If meta-flag is t we get a meta character
+         ((>= c ?\M-\^@)
+          (- c (- ?\M-\^@ 128)))
+         ;; Reencode the character in the keyboard coding system, if
+         ;; this is a non-ASCII character.
+         ((>= c #x80)
+          (aref (encode-coding-string (string c) (keyboard-coding-system)) 0))
+         (t c))))
 
 (defun xterm-mouse-truncate-wrap (f)
   "Truncate with wrap-around."
@@ -228,7 +235,7 @@ down the SHIFT key while pressing the mouse button."
   (dolist (terminal (terminal-list))
     (turn-on-xterm-mouse-tracking-on-terminal terminal)))
 
-(defun turn-off-xterm-mouse-tracking (&optional force)
+(defun turn-off-xterm-mouse-tracking (&optional _force)
   "Disable Emacs mouse tracking in xterm."
   (dolist (terminal (terminal-list))
     (turn-off-xterm-mouse-tracking-on-terminal terminal)))