From: feit@ERA.COM (Mark Feit)
Newsgroups: fj.mail-lists.x-window
Subject: Re: How to make mouse button 2 act like mouse button 1
Date: 2 Oct 92 02:26:11 GMT
Distribution: fj
Organization: Engineering Research Associates, Vienna, VA

Date: Tue, 29 Sep 1992 19:19:26 GMT
Message-Id: <1992Sep29.191926.9364@ERA.COM>
Newsgroups: comp.windows.x.motif,comp.windows.x

On comp.windows.x.motif, jxt@stc06.ctd.ornl.gov (TOLLIVER J S) posts:
 > 
 > Hi. I have a need to make mouse button 2 act identically to mouse button 1
 > in a Motif application.
 >
 > [Translation stuff discussed below]
 >
 > I have several questions:
 > 
 > 1. Most importantly, how can I make MB2 function EXACTLY like MB1,
 > to the user?
 > 4. How can this be fixed so that it works universally?

Universally? With translations?  Can't be done.  The trick here is not
to modify any of your clients, because inevitably you're going find a
few that you won't have source for or will be running from another
host.  Once you start trying to tweak your clients, you've pretty much
demolished some of the things that make X stand out from other
environments.  So leave the clients alone and concentrate on how to
make the environment do what you want.

I can think of three solutions, two software and one hardware:

The best bet is to tweak your server so that anything that comes from
button 2 gets reported as button 1.  You'll need to decide how you
want to handle clicks on button 2 when button 1 is already being held
down and vice versa.  Implementation is trivial, but defining the
behavior in advance is a good idea.  Pros: The change only takes a
couple of hours to make and can be easily reversed.  With a little
work, it could be toggled with a command line option so "normal"
operation is still possible.  Cons: Neither HP or SGI sample server
sources are provided on the MIT R5 tape, so I can't tell you exactly
where to look.  (See the mit/server/ddx tree for some ideas.)  HP and
SGI sources may be available elsewhere, though.

Second best (and certainly acceptable, although possibly more
cumbersome) is a filter program that sits between the server and
clients and translates events so anything reported on Button 2 gets
changed to Button 1.  The problem with handling multiple clicks I
mentioned above applies here, too.  Pros: Works in situations where
you can't modify your server (such as X terminals) and will allow you
to selectively enable the translation for each client.  Cons: Slight
tradeoff in speed and knowledge of how to program with sockets and how
the X protocol works is also required (If you're not up to it the
server mod will be less painful).  The XTV program on the R5 contrib
tape is such a filter, albeit a complex one.  If there's sufficient
interest in how something like this is done, we could start a thread
about it on comp.windows.x and explore it piece by piece.

Third (and worst, IMHO) is a customized mouse with Button 2 hardwired
to Button 1.  I won't go into that one, 'cause a software solution is
always a better deal if you can swing it.  Pros: Requires no software
mods, a plus if the other two solutions aren't possible for some
reason.  Cons: Requires customization of hardware.  Not cheap.

 > The closest I've come so far is this translation,
 > which I don't even fully understand:
 > 
 > *XmPushButton.translations: #augment\
 > 			       <Btn2Down>: Arm()\n\
 > 			       <Btn2Up>: Activate() Disarm()\n\
 > 			       <EnterWindow>: Enter()\n\
 > 			       <LeaveWindow>: Disarm(NoRedisplay) Leave()
 > 
 > 2. What's wrong with the above resource specification?

Well, for starters it only works with Motif PushButtons.  That's all
good and fine if all the world's a Motif PushButton, but there are
other widgets in the world that won't honor the translation.

 > 5. Arm, Activate, and Disarm are PushButton action routines? Where are
 > the Enter and Leave action routines? Where are they documented?

XmPushButtons don't have Enter() and Leave() actions; these are simply
"additional behaviors" defined by the widget.  There probably should
be Enter() and Leave() actions, but there's probably some reason there
aren't.  (Anybody know why?)

 > 3. Why the difference on HP vs SG?

Dunno.  Any takers?

 > 7. And better yet, exactly what does the universally correct resource
 > do?                                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^

There is no such animal.  Most programs written with Xlib don't even
_use_ resources, and those which use Xt won't all recognize the same
translation.

						- Mark

 ................................. .................................
: Mark A. Feit             KD4TAJ : Internet: feit@era.com          :
: Engineering Research Associates : USENET: ...!uunet!era!feit      :
 ................................. .................................
		   "Keep BSD Free -- Boycott AT&T"