FVWM: Re: Re: How to remove all key bindings?

From: parv <parv_fm_at_fastmail.fm>
Date: Sat, 26 Apr 2003 01:06:38 -0400

in message <20030425235341.01011CAA5_at_dane-2.cc.telcordia.com>,
wrote Dan Espen thusly...
>
> parv <parv_fm_at_fastmail.fm> writes:
> >
> > 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] ...

( 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 _at_context = (0..9 , qw/A R T F W D S [ ] - _ < > ^ v I/);
    my _at_modifiers = (1..5 , qw/M S C N A L/);

    for my $context ( _at_context )
    { for my $mod ( _at_modifiers )
      { for my $key ( _at_{$_[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 _at_ARGV
            ? map { s/$regex/$1/; $_; } _at_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 _at_keys;
    while ( defined (my $line = <KEYSYM>) )
    { if ( ($line =~ /$start/) .. ($line =~ /^#endif/) )
      { next unless $line =~ m/$extract/;
        push _at_keys , $1;
      }
    }

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

    return \_at_keys;
  }
  __END__


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


> 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.

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 _at_{$_[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 _at_keys;
    while ( defined (my $line = <FILE>) )
    { next unless $line =~ m/$extract/;
      chomp($line);
      push _at_keys , $1;
    }

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

    return \_at_keys;
  }
  __END__


  - parv

-- 
--
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 majordomo_at_fvwm.org.
To report problems, send mail to fvwm-owner_at_fvwm.org.
Received on Sat Apr 26 2003 - 00:05:35 BST

This archive was generated by hypermail 2.3.0 : Mon Aug 29 2016 - 19:37:54 BST