Subject: FVWM: How to remove all key bindings?

From: "Felix E. Klee" <[email-masked]>
Date: Fri, 25 Apr 2003 20:12:22 +0200

Hi,

I would like to remove all default FVWM keybindings. How could this be done?

Felix

--
Visit the official FVWM web page at <URL: http://www.fvwm.org/>.
To unsubscribe from the list, send "unsubscribe fvwm" in the body of a
message to [email-masked].
To report problems, send mail to [email-masked].

---

From: Dan Espen <[email-masked]>
Date: Fri, 25 Apr 2003 14:21:49 -0400

> I would like to remove all default FVWM keybindings. How could this be done?

Read this section of the man page:

BUILT-IN KEY AND MOUSE BINDINGS

-- 
Dan Espen                           E-mail: [email-masked]

---

From: "Felix E. Klee" <[email-masked]>
Date: Fri, 25 Apr 2003 23:00:05 +0200

> BUILT-IN KEY AND MOUSE BINDINGS

It only describes how to remove single bindings. However, I thought there is 
a command to remove all internal bindings. This would avoid problems when 
new bindings will be added in the future (or won't there?).

Felix

---

From: parv <[email-masked]>
Date: Fri, 25 Apr 2003 17:41:02 -0400

in message <[email-masked]>, wrote Felix E.
Klee thusly...
> It only describes how to remove single bindings. However,
> I thought there is a command to remove all internal bindings. This
> would avoid problems when new bindings will be added in the future
> (or won't there?).

A crude way is to create permutations (or is it combinations?) of
all the keys & mouse buttons mapping to '-'; stick them in a file of
its own; then 'Read' it in before normal key bindings.

Here is one untested way to generate the syntax which are bound by
single modifier & in single context for ASCII values in [33,126] ...

  #!perl -w

  use strict;

  my @context = qw/A R T F W D S/;
  my @modifiers = qw/M S C N A L 1 2 3 4 5/;
  my @characters = ( map( 'F' . $_ , (1..12) )
                   , map { chr $_ } ( 33 .. 126 )
                   );

  for my $context ( @context )
  { for my $mod ( @modifiers )
    { for my $char ( @characters )
      { printf "key  %s %s %s -\n" , $char , $context , $mod;
      }
    }
  }

  - parv

--

---

From: Dan Espen <[email-masked]>
Date: Fri, 25 Apr 2003 19:53:36 -0400

>       { printf "key  %s %s %s -\n" , $char , $context , $mod;

That would miss keys like "Help" (Sun keyboard).

A little less extreme is a PipeRead script reading and extracting
all the "Key" commands from ConfigFvwmDefaults, but its not like a
new builtin keybinding is added every day.

As far as I can see, there is no command to remove all key bindings.

---

From: parv <[email-masked]>
Date: Sat, 26 Apr 2003 01:06:38 -0400

in message <[email-masked]>,
wrote Dan Espen thusly...
> > single modifier & in single context for ASCII values in [33,126] ...

( some code )

> That would miss keys like "Help" (Sun keyboard).

That is true; as i said 'untested way'... here is slightly better
one (supply appropriate locale/font/keyboard type as they appear in
X11 keysymdef.h if 'latin1' default is not desired) ...

  #!/usr/local/bin/perl -w
  use strict;

  #  X11 file containing key symbol definitions
  my $keysym = '/usr/X11R6/include/X11/keysymdef.h';

  make_noop( find_keysym($keysym) );

  #  create no-op key bindings
  sub make_noop
  {
    #  see fvwm(1) man page for what it is context & what is modifier
    #  following collection is from version 2.5.6
    my @context = (0..9 , qw/A R T F W D S [ ] - _ < > ^ v I/);
    my @modifiers = (1..5 , qw/M S C N A L/);

    for my $context ( @context )
    { for my $mod ( @modifiers )
      { for my $key ( @{$_[0]} )
        { printf "key %s %s %s -\n" , $key , $context , $mod;
        }
      }
    }
  }

  #  set keyboard types to search for (as they occur in keysymdef.h)
  sub kbd_type
  { my $regex = shift;
    return ( scalar @ARGV
            ? map { s/$regex/$1/; $_; } @ARGV
            : qw(latin1)
          );
  }

  #  returns key symbols w/o 'XK_' prefix from a given file, most likely needs
  #  to be as X11 keysymdef.h
  sub find_keysym
  {
    my $keysym = shift;

    open KEYSYM , '<' , $keysym or die "cannot open $keysym: $!\n";

    #  save the key symbol matching pattern as it is used in more than one place
    my $sym = qr/[_[:alnum:]]+/;
    my $xk_sym   = qr/(?i:XK_) ($sym)/x;
    my $xk_opt_sym = qr/(?i:XK_)? ($sym)/x;

    #  create regex to find the (starting of) appropriate #ifdef section(s)
    my $start =
      '(?i:'
      .  join( '|'
            , map { 'XK_' . $_ } ('MISCELLANY', kbd_type($xk_opt_sym))
            )
      . ')';

    $start = qr/^ \#ifdef \s+ $start/x;

    #  regex to search & extract the 'XK_' lines/keys
    my $extract = qr/^ \#define \s+ $xk_sym/x;

    my @keys;
    while ( defined (my $line = <KEYSYM>) )
    { if ( ($line =~ /$start/) .. ($line =~ /^#endif/) )
      { next unless $line =~ m/$extract/;
        push @keys , $1;
      }
    }

    close KEYSYM or die "cannot close $keysym: $!\n";

    return \@keys;
  }
  __END__

...Mind you, if above is run over all the extracted '#define's in
keysymdef.h, about 11 MB output is generated.

> new builtin keybinding is added every day.

How about this then (just to remove the bindings)...

  #!/usr/local/bin/perl -w
  use strict;

  #  fvwm default key bindings
  my $key_file = '/usr/X11R6/share/fvwm/ConfigFvwmDefaults';

  make_noop( find_keys($key_file) );

  #  create no-op key bindings
  sub make_noop
  { printf "%s -\n" , $_ for @{$_[0]};
  }

  #  returns key bindings minus the binded action from fvwm default key
  #  bindings
  sub find_keys
  {
    my $key_file = shift;

    open FILE , '<' , $key_file or die "cannot open $key_file: $!\n";

    #  regex to extract (save) key binding (until the binded action)
    my $extract = qr{^\s*( (?:Silent \s+)?
                          (key|mouse) \s+ \w+ \s+ \w+ \s+ \w+
                        ) .+
                    }ix;

    my @keys;
    while ( defined (my $line = <FILE>) )
    { next unless $line =~ m/$extract/;
      chomp($line);
      push @keys , $1;
    }

    close FILE or die "cannot close $key_file: $!\n";

    return \@keys;
  }
  __END__

  - parv

--

---

From: "Felix E. Klee" <[email-masked]>
Date: Sat, 26 Apr 2003 13:44:42 +0200

> How about this then (just to remove the bindings)...

Hm, why not add a simple command like "ClearKeys" in the FVWM sources? I 
imagine that to be simpler and more reliable than all these Perl scripts. 
Maybe I'll check that out some day.

Anyways, thanks a lot for your effort, parv! These scripts look nice - I 
haven't tried them out yet, though.

Felix

-- 
To contact me personally don't reply but send email to 
  felix DOT klee AT inka DOT de
--
Visit the official FVWM web page at <URL: http://www.fvwm.org/>.
To unsubscribe from the list, send "unsubscribe fvwm" in the body of a
message to [email-masked].
To report problems, send mail to [email-masked].

---

From: parv <[email-masked]>
Date: Sat, 26 Apr 2003 17:05:10 -0400

in message <[email-masked]>, wrote Felix
E. Klee thusly...
> > > A little less extreme is a PipeRead script reading and
> > > extracting all the "Key" commands from ConfigFvwmDefaults, but
> > > its not like a new builtin keybinding is added every day.
> >
> Hm, why not add a simple command like "ClearKeys" in the FVWM
> sources?

For me not a fvwm developer. :)

Actually, i am in favour of the above wish list item, but i do not
care much as long as i can override default/built-in key bindings by
some other means w/o much effort.

> Anyways, thanks a lot for your effort, parv! These scripts look
> nice - I haven't tried them out yet, though.

(I would like to say "Thank You" but that would not mean much unless
you still retain the same impression as above after testing the
program(s).)

  - parv

--