1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
#!/usr/bin/perl
# -*- Mode: cperl -*-
# Copyright (C) 2000 by Chmouel Boudjnah <chmouel@mandrakesoft.com>,
# MandrakeSoft Inc.
# Redistribution of this file is permitted under the terms of the GNU
# Public License (GPL)
######################
# Description: Launch window manager according to
# /etc/X11/window-manager with various options.
use Getopt::Long;
my ($wm, $command, $window_mgr_file);
my (@lf);
my @getopt_args = ('l|list-active-session',
'm|window-manager-file=s',
'g|with-file-manager=s',
'p|picture=s',
'x|with-xterm',
'h|help',
'F|fallback',
);
GetOptions(\%options, @getopt_args) || usage(1);
usage() if $options{h};
$window_mgr_file = $options{'m'} ? $options{'m'} : '/etc/X11/window-managers';
die "$window_mgr_file don't exist\n" unless -r $window_mgr_file;
parse_file($window_mgr_file);
if ($options{l}){
print "\t\t\tActive Sessions:\n";
list_sessions();
exit(0);
}
unless ($ARGV[0]) {
print STDERR "\n\t\tYou need to specify a Window Manager\n\n";
usage(1);
} else { $wm = $ARGV[0] }
if (!$exec{$wm} && !$options{F}) {
print STDERR "I can't find an entry for $wm\n";
print STDERR "This is the list of active sessions:\n\n";
list_sessions(1);
print STDERR "\nVerify your installation or adjust $window_mgr_file\n";
exit 1;
}
# Launching
if ($options{p} and $options{b}) {
print STDERR "option -p and -b are incompatible\n";
exit 1;
} else {
system("xsetroot", "-solid", $options{b}) if $options{b};
}
if ($options{g} =~ /KFM/i) {
system("kfm &");
} elsif ($options{g} =~ /GMC/i) {
system("gmc &");
} elsif ($options{g} =~ /SFM/i) { #Special Pixel.
system("sfm &");
} else {
if ($options{g}) {
print STDERR "You need to specify KFM or GMC to --with-filemanager";
exit(1);
}
}
if ( $options{p} and ! -x '/usr/X11R6/bin/xsetbg') {
print STDERR "Can't find xli installed, please adjust your installation\n";
exit(1);
} else { system("xsetbg", $options{p}) if $options{p}; }
if ($options{x}) {
my $xterm = $ENV{XTERM} ? $ENV{XTERM} : "xterm -bg black -fg white";
system("$xterm &");
}
# END
$command = $script{$wm} ? $script{$wm} : $script{shift @lf};
exec ("/bin/sh", "-c", "$command");
sub parse_file {
my $f=shift @_;
local *F;
my ($e, $s, $n, $i, $d);
open F, $f or die "Can't open $f\n";
local $/ = "--@@--";
while (<F>) {
$n = $1 if /^NAME=(.*)/m;
$e = $1 if /^EXEC=(.*)/m;
$d = $1 if /^DESC=(.*)/m;
$i = $1 if /^ICON=(.*)/m;
$s = $1 while /SCRIPT:(.*?)$/gs;
if (-x $e) { $script{$n} = $s; $exec{$n} = $e; push @lf, $n; }
}
}
sub list_sessions{my $e=shift @_;for(@lf){print{$e ? STDERR : STDOUT}"$_\n";}}
sub usage {
my $e = shift @_;
(my $basename = $0) =~ s|.*/||;
print { $e ? STDERR : STDOUT } << "EOF";
Usage: $0 [-Fxh] [ -b color ] [ window-manager session]
Window-Manager launcher
-b=COLOR --background=COLOR: Specify a background color.
-g --with-file-manager: Launch with a filemanager [ KFM | GMC ]
-x --with-xtermM: Display an xterm.
-p=PIC --picture=PIC: Pictures to display in background.
-l --list-active-session: List active sessions.
-F --fallback: Try to fallback between window-managers
if failing to launch the specified one.
-h --help: Display this message.
EOF
exit($e);
}
|