|
afb |
a753354 |
#!/usr/bin/perl -w
|
|
afb |
a753354 |
#
|
|
afb |
a753354 |
# update_slim_wmlist, based on:
|
|
afb |
a753354 |
# update_wdm_wmlist, (c) 1998 Marcelo Magallón <mmagallo@debian.org>
|
|
afb |
a753354 |
# rewriten to use the x-window-manager alternative
|
|
afb |
a753354 |
# modified to also use the x-session-manager alternative by Arthur Korn
|
|
afb |
a753354 |
# Copyright 2000 Wichert Akkerman <wakkerma@debian.org>
|
|
afb |
a753354 |
# Modified to use the freedesktop.org .desktop like kdm and gdm
|
|
afb |
a753354 |
#
|
|
afb |
a753354 |
# This script will read the list of installed window managers from
|
|
afb |
a753354 |
# the freedesktop .desktop files in <etc>/X11/sessions/:<etc>/dm/Sessions/:
|
|
afb |
a753354 |
# <share>/xsessions/
|
|
afb |
a753354 |
# and update the sessions line in /etc/slim.conf.
|
|
afb |
a753354 |
# BEWARE: It doesn't ask any questions about this. It just does it. It
|
|
afb |
a753354 |
# takes an optional list of window managers.
|
|
afb |
a753354 |
|
|
afb |
a753354 |
use strict;
|
|
afb |
a753354 |
use File::DesktopEntry;
|
|
afb |
a753354 |
|
|
afb |
a753354 |
my $wm_list='';
|
|
afb |
a753354 |
my %desktop_files;
|
|
afb |
a753354 |
|
|
afb |
a753354 |
unless (@ARGV) {
|
|
afb |
a753354 |
#my @wm_list = ('default');
|
|
afb |
a753354 |
my @wm_list;
|
|
afb |
a753354 |
foreach my $dir ('/etc/X11/sessions/','/etc/dm/Sessions/','/usr/share/xsessions/') {
|
|
afb |
a753354 |
next unless (opendir DIR, $dir);
|
|
afb |
a753354 |
my @files;
|
|
afb |
a753354 |
@files = grep { /\.desktop$/ && -r "$dir/$_" } readdir(DIR);
|
|
afb |
a753354 |
foreach my $file (@files) {
|
|
afb |
a753354 |
push @{$desktop_files{$file}}, "$dir/$file";
|
|
afb |
a753354 |
}
|
|
afb |
a753354 |
}
|
|
afb |
a753354 |
DESKTOP: foreach my $desktop_file (keys(%desktop_files)) {
|
|
afb |
a753354 |
foreach my $file (@{$desktop_files{$desktop_file}}) {
|
|
afb |
a753354 |
my $entry = File::DesktopEntry->new_from_file($file);
|
|
afb |
a753354 |
next DESKTOP if (defined($entry->get_value('Hidden'))
|
|
afb |
a753354 |
and $entry->get_value('Hidden') eq 'true');
|
|
afb |
a753354 |
if ($entry->get_value('Name') =~ /^gnome$/i) {
|
|
afb |
a753354 |
push (@wm_list, 'gnome');
|
|
afb |
a753354 |
}
|
|
afb |
a753354 |
elsif ($entry->get_value('Name') =~ /^kde$/i) {
|
|
afb |
a753354 |
push (@wm_list, 'kde');
|
|
afb |
a753354 |
}
|
|
afb |
a753354 |
elsif (defined($entry->get_value('Exec'))) {
|
|
afb |
a753354 |
push (@wm_list, $entry->get_value('Exec'));
|
|
afb |
a753354 |
}
|
|
afb |
a753354 |
else { # not found, go to next file
|
|
afb |
a753354 |
next;
|
|
afb |
a753354 |
}
|
|
afb |
a753354 |
# found, proceed to next destop file
|
|
afb |
a753354 |
next DESKTOP;
|
|
afb |
a753354 |
}
|
|
afb |
a753354 |
}
|
|
afb |
a753354 |
$wm_list = join (',', sort @wm_list) . ',custom';
|
|
afb |
a753354 |
} else {
|
|
afb |
a753354 |
$wm_list = join (',', sort @ARGV);
|
|
afb |
a753354 |
}
|
|
afb |
a753354 |
|
|
afb |
a753354 |
open (SLIM_CONFIG_FILE, '
|
|
afb |
a753354 |
or die "Can't open /etc/slim.conf for reading: $!";
|
|
afb |
a753354 |
open (NEW_SLIM_CONFIG_FILE, '>/etc/slim.conf.new')
|
|
afb |
a753354 |
or die "Can't open /etc/slim.conf.new for writing: $!";
|
|
afb |
a753354 |
|
|
afb |
a753354 |
while (<SLIM_CONFIG_FILE>) {
|
|
afb |
a753354 |
s|^(sessions\s*).*|$1$wm_list|;
|
|
afb |
a753354 |
print NEW_SLIM_CONFIG_FILE;
|
|
afb |
a753354 |
}
|
|
afb |
a753354 |
|
|
afb |
a753354 |
close(SLIM_CONFIG_FILE);
|
|
afb |
a753354 |
close(NEW_SLIM_CONFIG_FILE);
|
|
afb |
a753354 |
|
|
afb |
a753354 |
rename '/etc/slim.conf.new', '/etc/slim.conf'
|
|
afb |
a753354 |
or die "Can't rename /etc/slim.conf.new: $!";
|
|
afb |
a753354 |
|
|
afb |
a753354 |
exit 0;
|