[comp.windows.x] How to constrain pointer movement

warren@cbnewsh.att.com (warren.a.montgomery) (01/21/91)

Is there a way using Xlib of constraining the mouse motion so that
it will be entirely horizontal or vertial?  In other words, if the
mouse is moved 5 pixels up and 15 pixels to the right, the pointer
image and reported position should be 0 pixels up and 15 pixels
right.  Whichever direction, horizontal or vertical, had the
lesser movement since last observation is locked at 0.  

I have ported an application that did this on an AT&T 5620
graphics terminal to run under X, and the naive port of the
pointer handling code that was used to achieve the above effect
simply did a lot of calls to XWarpPointer to keep it from moving
off course.  Aside from being rather inefficient, this causes
trouble if there is any signifcant delay in the reporting and
processing of events, as the user's pointer motions keep getting
wiped out by moving the pointer back to an obsolete position.
Getting this behavior to work would really seem to require
constraining the motion at the server.  I can't off hand see how
to do this, though the motion constraint is useful for many
applications that require the user to make precise horizontal or
vertical movements and I suspect that there may be some subtle way
of achieving this result.  Any suggestions?

-- 

	Warren Montgomery
	att!ihlpf!warren

chuck@Morgan.COM (Chuck Ocheret) (02/05/91)

> Is there a way using Xlib of constraining the mouse motion so that
> it will be entirely horizontal or vertial?  In other words, if the
> mouse is moved 5 pixels up and 15 pixels to the right, the pointer
> image and reported position should be 0 pixels up and 15 pixels
> right.  Whichever direction, horizontal or vertical, had the
> lesser movement since last observation is locked at 0.

The way I have done this is to turn off the cursor for the particular
window and to draw in my own cursor which I constrain.  If you are
constraining in the horizontal direction, the actual vertical position
of the invisible cursor is unknown, so the user can wander out of the
window and loose the pointer.  Therefore, I do a passive grab to keep
reading the pointer even if it wanders off.

~chuck
-- 
+--------------------+   Chuck Ocheret, Sr. Staff Engineer   +---------------+
|chuck@fid.Morgan.COM|       Morgan Stanley & Co., Inc.      |(212) 703-4474 |
|    Duty now ...    |19th Floor, 1251 Avenue of the Americas|for the future.|
+--------------------+      New York, N.Y.  10020 USA        +---------------+