[net.emacs] emacs mouse support-sbm@Purdue.EDU

tower@prep.ai.mit.edu (01/11/86)

From: tower@prep.ai.mit.edu (Leonard H. Tower Jr.)
To: horswill@loon.ai.mit.edu
Subject: Re: emacs mouse support
Cc: info-gnu-emacs@mit-prep.arpa
In-Reply-To: Your message of 09 Jan 86 12:49:30 CST (Thu).
	     <8601091849.AA00277@loon.UMN>
Date: 10 Jan 86 08:43:11 EST (Fri)
From: "Steven B. Munson" <sbm@Purdue.EDU>

     Since you mentioned the Macintosh, I guess it's appropriate to
mention that there is already a public domain multiple window terminal
emulator for the Macintosh called UW that supports mouse operations.
The mouse protocol is very simple.  Each mouse button event (mouse up
or mouse down) causes the following five-character sequence to be sent
to emacs:

     <ESC> m <y> <x> <b>

where <y>, <x>, and <b> are integers encoded as characters with 32 added
to their value to make them printable.  <y> and <x> are the row and
column where the event occurred, and <b> is a number that indicates
whether it was a mouse up or mouse down and what modifier keys were
used.  The Macintosh has four modifier keys, the shift and caps lock
keys and two others, called the option key and the command key (the
keyboard can be mapped to use either one as a control key).  The bits in
<b> indicate whether it was a mouse up or a mouse down and the state of
the modifier keys when the event happened.  From most significant to
least significant, the bits mean:

     6	  5	    4	      3		2	  1
     up	  down	    option    lock	shift	  command

Don't ask me why two separate bits were used to indicate whether it was
a mouse up or a mouse down; I didn't design the protocol.  Also, the
Macintosh has a one-button mouse; if bit 5 indicated whether it was an
up or a down and 32 wasn't added to the character before transmission,
then there would be 2 more bits in a 7-bit character to indicate which
button was used on a multiple button mouse.

     Notice that the terminal emulator itself doesn't decide in any way
what the mouse events mean; it just sends the raw events to the host.
Since emacs gets both mouse down and mouse up events, it is possible not
only to position the cursor by clicking, but also to do things like
selecting or deleting a range of characters by clicking and dragging
over them (in my case, drag selects them, or copies them to the Kill
buffer, and shift-drag deletes them) and resizing emacs windows by
dragging their mode lines.  This requires that the mlisp package keep
the last value of <x>, <y> and <b> to determine whether the action was a
click or a drag (whether the mouse moved between mouse down and mouse
up).  The mlisp package can also detect whether the mouse event was in
the scroll bar of the Macintosh window and scroll by pages or lines or
do goto-percent-of-file, depending on the state of the modifier keys.

					Steve Munson
					sbm@Purdue.EDU
					sbm@Purdue.CSNET
----------