[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

[Fwd: solution for /etc/X11/window-managers]



I sent this to wmpeople and branden@debian.org yesterday.

Shaleh wrote:
> 
> Currently Debian supports /etc/X11/window-managers as a place to
> register window managers w/ X.  The first window manager in the list is
> run as default unless the user specifies on when X starts (in .xinitrc
> or what not).  However there is no way to modify this file short of hand
> editing or programs like cat/sed/awk.  Also no package claims this file
> either.
> 
> What Marcelo and I have done is write an update-windowmangers script
> which behaves in a manner similar to the other update* scripts in
> Debian.  It can add, remove, or set a particular wm as default.  It also
> supports silent or queried running.  The syntax is:
> 
> update-windowmanagers {--add|--remove--default} [--ask] wm.  It appends
> /usr/X11R6/bin to the name unless full path is given.  So users can also
> use this to add their own wm's that may live in /usr/local or somewhere
> else.
> 
> The add and remove is straight forward.  The default option adds the wm
> if needed, or simply places it first in the list otherwise.
> 
> I intend on submitting a wishlist bug on xbase for this to be included
> there.  Once it is part of Debian, all wm's can simply call this script
> in their postinst/postrm scripts.  Analogous to update-menus.
> 
> Comments or suggestions welcome.  As is code changes or additions.
> 
> (Apologies for the attachment, I was at work when this was sent -- darn
> M$)
> 
>   ------------------------------------------------------------------------
> #! /usr/bin/perl
> ###
> #
> # written by Shaleh <shaleh@debian.org>
> # cleaned up arg checking and --ask option by
> #            "Marcelo E. Magallon" <mmagallo@efis.ucr.ac.cr>
> #
> ###
> 
> while ($ARGV[0] =~ m/^--/) {
>         $_ = shift(@ARGV);
>         if (/--add/) {
>                 $mode='add';
>         } elsif (/--remove/) {
>                 $mode='remove';
>         } elsif (/--default/) {
>                 $mode='default';
>         } elsif (/--ask/) {
>                 $ask='true';
>         } else {
>                 &usage;
>         }
> }
> 
> unless( @ARGV == 0 ) {
>         &usage;
> }
> 
> if( $ARGV[0] !~ m/^\// ) {
>         $WM = '/usr/X11R6/bin/' . $ARGV[0];
> }
> else {
>         $WM = $ARGV[0];
> }
> 
> if ( $ask eq 'true') {
>         &ask($mode, $WM);
> }
> 
> if( $mode eq 'add' ) {
>         &add_to_file($WM);
> }
> elsif( $mode eq 'default' ) {
>         &make_default($WM);
> }
> elsif( $mode eq 'remove' ) {
>         &rm_from_file($WM);
> }
> 
> ###
> #
> # Usage information
> #
> ###
> sub usage {
>         print <<EOT;
> Usage: $0 [--ask] {--add|--default|--remove} <wm>
> 
> Options:
>   --ask            Asks for confimation of the requested action
> 
> Actions:
>   --add            Adds the specified window manager to the bottom of the
>                    /etc/X11/window-managers file
>   --remove         Removes the specified window manager
>   --default        Adds the specified window manager to the top of the
>                    /etc/X11/window-managers file, thus making it the system
>                    default
> 
> <wm> can the the full path to the window manager excecutable, or just the
> filename (/usr/X11R6/bin/ will be prepended to it).
> 
> EOT
>         exit(0);
> }
> 
> ###
> #
> # Asks for confirmation of the requested action
> #
> ###
> sub ask {
>         ($mode, $WM)   = @_;
> 
>         if (open(WMFILE, '/etc/X11/window-managers')) {
>                 @WMS = <WMFILE>;
>                 close(WMFILE);
>                 print "The following window managers are listed in /etc/X11/window-managers:\n\n";
>                 foreach (@WMS) {
>                         if (m/\//) {
>                                 print "\t" . $_;
>                         }
>                 }
>                 print "\n";
>         }
> 
>         if ($mode eq 'add') {
>                 $prompt = "Do you want to add $WM to the list";
>         } elsif ($mode eq 'remove') {
>                 $prompt = "Do you want to remove $WM from the list";
>         } elsif ($mode eq 'default') {
>                 $prompt = "Do you want make $WM the default";
>         }
> 
>         &ask_n($prompt) || exit(0);
> }
> 
> ###
> #
> # Asks a question, "No" is the default
> #
> ###
> sub ask_n {
>         my $answer;
>         print @_,"? [No] ";
>         $answer=<STDIN>;
>         return ( $answer =~ /^\s*y/i );
> }
> 
> ###
> #
> # Adds window manager passed to the end of window-managers file
> #
> ###
> sub add_to_file {
>         ($wm) = @_;
> 
>         return unless( &ifexists($wm) eq 'false' );
> 
>         open(WMFILE, '>>/etc/X11/window-managers') ||
>                 die("Could not open /etc/X11/window-managers for writing\n");
>         print WMFILE "$wm\n";
>         close(WMFILE);
> }
> 
> ###
> #
> # Makes window manager passed the default by putting it first
> #
> ###
> sub make_default {
>         ($wm) = @_;
>         my $found = 0;
> 
>         if( &ifexists($wm) eq 'true' ) {
>                 &rm_from_file($wm);
>         }
> 
>         open(WMFILE, '/etc/X11/window-managers') ||
>                 die("Could not open /etc/X11/window-managers\n");
>         @WMS = <WMFILE>;
>         close(WMFILE);
>         open(WMFILE, '>/etc/X11/window-managers') ||
>                 die("Could not open /etc/X11/window-managers for writing\n");
>         foreach (@WMS) {
>                 if( m/^\// && $found == 0 ) {
>                         print WMFILE "$wm\n";
>                         $found = 1;
>                 }
>                 print WMFILE;
>         }
>         close(WMFILE);
> }
> 
> ###
> #
> # Removes passed window manager from window-managers file
> #
> ###
> sub rm_from_file {
>         ($wm) = @_;
> 
>         return unless( &ifexists($wm) eq 'true' );
> 
>         open(WMFILE, '/etc/X11/window-managers') ||
>                 die("Could not open /etc/X11/window-managers\n");
>         @WMS = <WMFILE>;
>         close(WMFILE);
>         open(WMFILE, '>/etc/X11/window-managers') ||
>                 die("Could not open /etc/X11/window-managers for writing\n");
> 
>         foreach (@WMS) {
>                 print WMFILE unless( m/$wm/ );
>         }
> }
> 
> ###
> #
> # returns 'true' if window manager exists in the file, 'false' otherwise
> #
> ###
> sub ifexists {
>         ($wm) = @_;
> 
>         open(WMFILE, '/etc/X11/window-managers') ||
>                 die("Could not open /etc/X11/window-managers\n");
> 
>         @WMS = <WMFILE>;
>         close WMFILE;
>         foreach (@WMS) {
>                 unless( m/^#/ ) {
>                         if( m/$wm/ ) {
>                                 return 'true';
>                         }
>                 }
>         }
>         return 'false';
> }


Reply to: