3 # Copyright (c) 2001 Damien Tougas <damien@tougas.net>. USA.
4 # Copyright (c) 2001 Jason 'vanRijn' Kasper <vR at movingparts dot net>
7 # Redistribution and use in source and binary forms, with or without
8 # modification, are permitted provided that the following conditions
10 # 1. Redistributions of source code must retain the above copyright
11 # notice, this list of conditions and the following disclaimer.
12 # 2. Redistributions in binary form must reproduce the above copyright
13 # notice, this list of conditions and the following disclaimer in the
14 # documentation and/or other materials provided with the distribution.
16 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 print "\nbbkeysconf.pl version @VERSION@\n";
32 print "Usage: bbkeysconf.pl [options]\n";
34 print " -rc[file] <filename> Alternate keygrab definition file.\n";
35 print " (default is ~/.bbkeysrc)\n";
36 print " -h[elp] Display this help\n";
40 # do math in integer rather than double mode--we rely on this for rounding
46 my $bbkeysrc = $ENV{HOME
} . "/.bbkeysrc";
48 # get the keyconfig file from the commandline, or use the default
49 for ( $i=0; $i< @ARGV; $i++) {
50 if ($ARGV[$i] =~ /^-rc(|file)$/) {
51 $bbkeysrc = $ARGV[++$i];
52 } elsif ($_ =~ /^-h(|elp)$/) {
57 die "unknown command. exiting\n\n";
79 "HorizontalDecrement",
80 "HorizontalIncrement",
117 if (open(R
, "$bbkeysrc")) {
119 # skip blank lines or comments
121 next if ($_ =~ /^$/ or $_ =~ /^#/) ;
122 $config[$count++] = $_;
131 print "\n*** BBKeys Configuration Tool ***\n";
135 print "\n[A]dd [D]elete [L]ist [S]ave [Q]uit\n";
136 print "Menu: Select> ";
139 $command =~ s/\s*//g;
141 &add
if ($command =~ /^a$/i);
142 &delete if ($command =~ /^d$/i);
143 &list
if ($command =~ /^l$/i);
144 &save
if ($command =~ /^s$/i);
145 &quit
if ($command =~ /^q$/i);
162 print "\nList:> Current Configuration\n";
163 print "-----------------------------------------------------------------\n";
165 open(CONFIG_LIST
, ">-");
166 for ($i = 0; $i < $count; $i++) {
168 if ($config[$i] =~ /KeyToGrab.*?Action\(ExecCommand\)/) {
169 $config[$i] =~ m/Grab\((.*)\).*Modifier\((.*)\).*Action\((.*)\).*This\((.*)\)/;
172 } elsif ($config[$i] =~/KeyToGrab/ ) {
173 $config[$i] =~ m/Grab\((.*)\).*Modifier\((.*)\).*Action\((.*)\)/;
182 print "-----------------------------------------------------------------\n";
188 print "\nAdd: Choose Key> Up, Down, R, L, etc.\n";
189 print "Add: Choose Key> ";
194 print ("\nERROR: Must enter valid key.\n");
198 print "Add: Select Modifier> Modifier List\n";
199 print "-----------------------------------------------------------------\n";
200 open(MODIFIER_LIST
, ">-");
201 for ($i = 0; $i <= $#modifiers; $i++) {
202 write(MODIFIER_LIST
);
204 close(MODIFIER_LIST
);
205 print "-----------------------------------------------------------------\n";
206 my $mod = $modifiers[&get_num
("Add: Select Modifier> ", $#modifiers)];
208 print "Add: Choose Action> Action List\n";
209 print "-----------------------------------------------------------------\n";
210 # okay. $#actions refers to the last index of the array, not the
211 # count. so add 1 more to it and divide by 3 and with the "user
212 # integer" line up time, we get an even number of rows
213 $action_rows = ($#actions +1)/ 3;
214 open(ACTION_LIST
, ">-");
215 for ($i = 0; $i <= $action_rows; $i++) {
217 $index2=$i + $action_rows +1;
218 $index3=$index2 + $action_rows +1;
222 print "-----------------------------------------------------------------\n";
223 my $action = $actions[&get_num
("Add: Select Action> ", $#actions)];
225 $config[$count] = "KeyToGrab($grab), WithModifier($mod), " .
226 "WithAction($action)";
227 if ($action =~ /ExecCommand/) {
228 print "Add: Command To Execute> ";
229 my $dothis = <STDIN
>;
231 $config[$count] .= ", DoThis($dothis)";
236 print "Add:> Finished\n";
243 $item = &get_num
("Delete: Select Item> ", $count - 1);
245 for ($i = 0; $i < $count - 1; $i++) {
246 $config[$i] = $config[$i + 1] if ($i >= $item);
251 print "Delete:> Finished\n";
257 print "Save: Confirm> Save the current configuration?\n";
258 print "Save: Confirm> ";
259 my $confirm = <STDIN
>;
261 $confirm =~ s/\s*//g;
263 if ($confirm =~ /^(y|yes)$/i) {
264 open(W
, ">$bbkeysrc");
265 print W
"#~/.bbkeysrc, automagically configured by bbkeysconf.pl\n\n\n";
266 for ($i = 0; $i < $count; $i++) {
267 print W
$config[$i] . "\n";
271 print "Save:> Finished\n";
274 print "Save:> Aborted\n";
281 if ($save_state == 1) {
282 print "Quit: Notice> Configuration has been changed\n";
285 print "Quit:> Finished\n";
297 print $prompt . "Enter a number between 0 and $maxnum\n";
298 while ($validnum == 0) {
303 if (($input =~ /^\d+$/) && ($input <= $maxnum)) {
307 print "\nERROR: Invalid selection, please try again\n\n";
316 @
> @
<<<<<<<<<<<<<<<<<<<<<<<<<<< = @
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
317 $i, $key_seq, $result
320 format MODIFIER_LIST
=
321 @
> @
<<<<<<<<<<<<<<<<<<<<<<
326 @
> @
<<<<<<<<<<<<<<<<<<<< @
> @
<<<<<<<<<<<<<<<<<<< @
> @
<<<<<<<<<<<<<<<<<<<
327 $index1, $actions[$index1], {$actions[$index2] ?
($index2) : ""}, {$actions[$index2] ?
$actions[$index2] : ""}, {$actions[$index3] ?
($index3) : ""}, {$actions[$index3] ?
$actions[$index3] : ""}