Getting Tk mouse event bindings right

9 views
Skip to first unread message

clasp126...@icebubble.org

unread,
Jan 20, 2022, 8:42:06 PM1/20/22
to infer...@googlegroups.com
Hey, all,

I'm trying to figure out how the correct way (or if it's even possible)
to specify mouse bindings with the Inferno bind(9) Tk command. My
problems are that (1) the bindings that I specify appear to behave too
non-specifically, and (2) the man page is too vague to figure out how
it's "supposed" to be done.

For example, when I specify the binding <Button-2>, it delivers events
when Button 2 is pressed, but it also delivers Motion events when the
mouse is moved with Button 2 down. (Which is not what I asked for.)
I've tried diverting the motion events to the bitbucket by defining a
more specific binding, i.e., <Motion-Button-2>, and discarding the
events, but the <Button-2> binding still captures all the
<Motion-Button-2> events. The only way I can distinguish the clicks
from the drags is to add a "%b %s" to the "send" value, then parse and
analyze them on the receiving end to figure out which represent the
actual clicks.

I also can't figure out how to specify chording, i.e., clicking Button 2
while Button 1 is pressed. You'd think that would be something like
<Button-1-ButtonPress-2> or {<Button-1> <Button-2>}, but such constructs
don't work.

Looking at the source code in /libtk/ebind.c, it looks like the code
actually only parses bindings up to the first ">" character. This seems
to contradict the description in the man page bind(9), which seems to
say that multiple "<...>" patterns can be specified in a "sequence."

The code in /libtk/utils.c suggests that a particular binding is used if
it exactly matches the event, and that a more general binding matches
ONLY if there is no exact match. But that's not the way it behaves in
practice. In actual practice, an event specification appears to match
if ANY of the specifiers in it match (which is pretty much useless as
pattern languages go). I should be able to specify something like
<NotMotion-ButtonDown-1-ButtonUp-3-ButtonPress-2> to specify a middle
(Button 2) click while Button 1 is down and Button 3 is up. Or even
{<ButtonDown-1-ButtonUp-3> <NotMotion> <ButtonPress-2>}. Pattern-
matching mechanism like that would actually be useful.

So, what's the right way to do this? Right now, I have to gulp down an
overly broad stream of events and check "%b %s" for the buttons I want.
I find myself thinking there's got to be a better way to do this.
Reply all
Reply to author
Forward
0 new messages