Re: FVWM: Parsing window_flags in perl

From: Salvatore Domenick Desiano <sal_at_email.arc.nasa.gov>
Date: Thu, 16 Sep 2004 15:11:56 -0400 (EDT)

o But I really like your suggestion about a C program which will
o generate a perl only FVWM::WindowFlags, and I will look into doing so.

I reiterate the suggestion that this be done on module startup, rather
than by file generation. Then, rather than adding a file to the
distribution, you simply generate a set of M_CONFIG_INFO messages

M_CONFIG_INFO FlagBit WINDOW_HAS_TITLE 134
M_CONFIG_INFO FlagBit WINDOW_IS_STICKY_ACROSS_DESKS 0
M_CONFIG_INFO FlagBit STYLE_IS_TRANSIENT 150

The Perl code to record and decode things this way is obscenly short:

$module->addHandler(M_CONFIG_INFO,\&config_info_handler);

sub config_info_handler($)
{
  my ($self, $event) = _at__;
  my _at_tokens = getTokens($event->_text);
  $flag_bits{$tokens[1]} = $tokens[2] if ($tokens[0] eq 'FlagBit');
}

sub flag_bit($$)
{
  my ($event,$flag_name) = _at__;
  return undef if (!exists($flag_bits{$flag_name}));
  my $bit = $flag_bits{$flag_name};
  return ord(substr($event->_window_flags,int($bit/8),1))>>($bit%8))&0x1;
}

The C code is the same as what Mark has been talked about for a C -> Perl
module, and I've written it already for another project, although it's not
to Fvwm coding standards. It's not elegant, but brute force is all we can
get because of the implementation-dependent style of the C standard.

#define FIND_BIT(x) \
   { SET_##x(with,1); \
     find_bit(##x,with,without); \
     SET_##x(with,0); }

unsigned find_bit(char * name,
                  window_flags * with,
                  window_flags * without)
{
  for (i = 0; i < (sizeof(wf) * 8); ++i)
  {
    unsigned bitIndex = i % 8;
    unsigned byteIndex = i / 8;
    unsigned char byte = ((unsigned char *)&wf)[byteIndex];
    unsigned char bit = (byte >> bitIndex) & 0x1;
    unsigned char bytet = ((unsigned char *)&wft)[byteIndex];
    unsigned char bitt = (bytet >> bitIndex) & 0x1;
    if (bit != bitt)
      printf("M_CONFIG_INFO FlagBit %s %d\n",name,bit);
  }
}

unsigned dump_window_flags()
{
  FvwmWindow with;
  FvwmWindow without;
  FIND_BIT(DO_SHRINK_WINDOWSHADE);
  FIND_BIT(DO_LOWER_TRANSIENT);
  FIND_BIT(DO_STACK_TRANSIENT_PARENT);

  ...

}


-- Sal
smile.

--------------
  Salvatore Domenick Desiano
    Research Scientist
      NASA Ames Research Center (QSS Group, Inc.)

--
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 Thu Sep 16 2004 - 14:12:52 BST

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