FVWM: Perl5 version of fvwmperl.pl

From: Randy J. Ray <rjray_at_uswest.com>
Date: Sat, 15 Feb 1997 17:38:18 -0700

I have finished an alpha version of a re-write of fvwmperl.pl in Perl 5. The
new version features:

* Package structure, allowing inclusion via "use", selective symbol importing
        You would now utilize this via:

                use X11::Fvwm qw(list of synbols to use); # Or just ":all"

        See example below.

* Compiled code for the constants from fvwm.h and module.h
        I use an XS module to compile a C routine that uses fvwm.h and module.h
        directly to supply values for parameters such as M_WINDOW_NAME and
        C_ALL.

* Improved registering and activation of event handlers
        Event handlers are now stored in lists within a hash table keyed by
        an event mask. Handlers are passed as subroutine references rather than
        by names, allowing you to pass a closure rather than a "real"
        subroutine. No longer is there need for "GenerateHandlers", or for a
        code-eval that contains more if-comparisons than necessary. See below
        for sample code.

* Easy fit with other Perl 5 extensions such as Penguin and Tk
        Because of the namespace-protection, there is little hazard of names
        like "InitModule" and "EndModule" colliding with other utilities and/or
        libraries.

Here is the simple text-only window list example from fvwmperl.doc, re-written
for the new style:

#!/usr/bin/perl

# MiniPerl - small, instructive example of a fvwm module implemented
# in Perl.
# (c)1996 Dan Astoorian <djast_at_utopia.csas.com>

use X11::Fvwm qw(InitModule AddHandler SendInfo EventLoop EndModule
                 M_WINDOW_NAME M_END_WINDOWLIST);
use IO::File;

$fh = new IO::File "> /dev/console";

($winId, $context, _at_args) = InitModule(M_WINDOW_NAME | M_END_WINDOWLIST);

# Register the event handlers
AddHandler(M_WINDOW_NAME,
           sub {
               my ($type, $id, $frameid, $ptr, $name) = _at__;
               printf $::fh ("Window ID %8lx: %s\n", $id, $name);
               # return one, to signal we want the event loop to continue
               1;
           });
# This one returns 0 to sigal that it terminates the module.
AddHandler(M_END_WINDOWLIST,
           sub { print $::fh "---end of window list\n"; return 0; });

print $fh "---start of window list\n";
# Ask FVWM to send us its list of windows
SendInfo(0, "Send_WindowList");

# Enter the main loop
EventLoop;

# We're done; clean up.
EndModule;


Note that module-style usage and Perl 5 syntactic sugar make some things
clearer-- the imported names do not need their leading "&" when called (note
that the constants like M_END_WINDOWLIST are actually routines of the form
"sub M_END_WINDOWLIST { 16384; }" and thus would be referenced with & rather
than $). The handler routines were not pre-defined, but rather passed to
AddHandler on-the-fly. I also use IO::File to specifically send the output to
the console rather than the STDOUT of fvwm. One could, of course, remove that
and have it go to STDERR or STDOUT. Or to a pipe, or to a socket... :-)

Before I upload the alpha to a CPAN site (the Comprehensive Perl Archive
Network; don't fret, I'll post downloading instructions), I still intend to
port FvwmDebug.pl to this model (where it will be called X11::FvwmDebug),
and possibly (though this may wait for a later alpha release) a module called
X11::FvwmPipe to facilitate stand-alone modules that communicate with Fvwm2
via the FvwmPipe module in the extras directory. This isn't a high-priority,
because when I've run tests with FvwmPipe, I've found it to be of limited
usefuleness, and it hikes my workstations load noticably (could be a SIGIO-
related problem; I know that XEmacs has such an issue, and checks for it at
configuration time).

Anyway, this is mostly a heads-up kind of announcement. I expect to come in
some tomorrow for extra polish (and, unfortunately, to finish some paperwork
for the boss), but by Monday or Tuesday, I should have the alpha release out.

Randy
--
===============================================================================
Randy J. Ray -- U S WEST Technologies IAD/CSS/DPDS         Phone: (303)595-2869
                Denver, CO                                     rjray_at_uswest.com
"It's not denial. I'm just very selective about the reality I accept." --Calvin
===============================================================================
--
Visit the official FVWM web page at <URL:http://www.hpc.uh.edu/fvwm/>.
To unsubscribe from the list, send "unsubscribe fvwm" in the body of a
message to majordomo_at_hpc.uh.edu.
To report problems, send mail to fvwm-owner_at_hpc.uh.edu.
Received on Sat Feb 15 1997 - 18:39:07 GMT

This archive was generated by hypermail 2.3.0 : Mon Aug 29 2016 - 19:38:00 BST