1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
|
#!/usr/bin/env perl
# $XTermId: mouse-codes,v 1.7 2020/12/13 15:07:02 tom Exp $
# -----------------------------------------------------------------------------
# this file is part of xterm
#
# Copyright 2018-2019,2020 by Thomas E. Dickey
#
# All Rights Reserved
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
# IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR ANY
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#
# Except as contained in this notice, the name(s) of the above copyright
# holders shall not be used in advertising or otherwise to promote the
# sale, use or other dealings in this Software without prior written
# authorization.
# -----------------------------------------------------------------------------
# Imitate xterm's BtnCode() function, to enumerate the possible inputs (button,
# event state) versus output (xterm mouse-code).
use strict;
use warnings;
use Getopt::Std;
our ( $opt_b, $opt_i, $opt_x );
# Typically,
# - Buttons 1, 2, and 3 are left-to-right assignments on a 3-button mouse.
# - Buttons 4 and 5 are (by convention) assigned to a wheel mouse's
# up/down events.
# - Buttons 6 and 7 may happen to work, e.g., as left/right events from a
# tiltable wheel mouse. There is no explicit support for these (there
# are no related symbols in Xt), so it is not possible to use them in the
# translations resource.
our $maxbutton = 7;
# xterm uses code 3 internally for release-events.
sub ButtonName($) {
my $code = shift;
my $result = "";
if ( $code < 0 ) {
$result = "release";
}
else {
$result = sprintf "Button%d", ( $code > 3 ) ? $code : ( $code + 1 );
}
return $result;
}
# Combine the modifier state as bits:
# shift key -> 1
# meta key -> 2 (Mod1 came from X11R1, but was adapted from X10)
# control key -> 4
our $maxstates = 7;
sub KeyState($) {
my $mask = shift;
my $result = "";
$result .= " + shift" if ( ( $mask & 1 ) != 0 );
$result .= " + meta" if ( ( $mask & 2 ) != 0 );
$result .= " + control" if ( ( $mask & 4 ) != 0 );
return $result;
}
sub Motion($) {
my $code = shift;
my $result = "";
$result = " + motion" if ( $code != 0 );
return $result;
}
sub report() {
my $button;
my $states;
my $motion;
my %encoded;
my %reports;
for $states ( 0 .. $maxstates ) {
for $motion ( 0 .. 1 ) {
for $button ( -1 .. $maxbutton ) {
next if ( $button == 3 );
my $result = ( 32 + ( $states << 2 ) );
$result += 32 if ( $motion != 0 );
if ( $button < 0 ) {
$result += 3;
}
else {
$result += $button & 3;
if ( $button & 4 ) {
$result += 64;
}
if ( $button & 8 ) {
$result += 128;
}
}
my $code = sprintf "%3d", $result;
my $report = sprintf "%s%s%s", &ButtonName($button),
&KeyState($states), &Motion($motion);
if ( defined $encoded{$code} ) {
printf "OOPS %s ->%s versus %s\n", $code, $report,
$encoded{$code};
}
elsif ( $result > 255 and not defined $opt_x ) {
printf "OOPS %s ->%s\n", $code, $report;
}
$encoded{$code} = $report;
$reports{$report} = $result;
}
}
}
if ($opt_i) {
foreach my $report ( sort keys %reports ) {
printf "%s = %s\n", $report, $reports{$report};
}
}
else {
foreach my $code ( sort keys %encoded ) {
printf "%s = %s\n", $code, $encoded{$code};
}
}
}
sub main::HELP_MESSAGE() {
printf STDERR <<EOF
Usage: $0 [options]
Options:
-b NUM set the number of buttons (default: 7)
-i invert the report to show code for each combination
-x eliminate 1-byte limit for codes
EOF
;
exit 1;
}
$Getopt::Std::STANDARD_HELP_VERSION = 1;
&getopts('b:ix') || &main::HELP_MESSAGE;
$maxbutton = $opt_b if ( defined $opt_b );
&main::HELP_MESSAGE if ( $maxbutton !~ /^\d+$/ );
$#ARGV < 0 || &main::HELP_MESSAGE;
&report;
1;
|