3 # update_slim_wmlist, based on:
4 # update_wdm_wmlist, (c) 1998 Marcelo Magallón <mmagallo@debian.org>
5 # rewriten to use the x-window-manager alternative
6 # modified to also use the x-session-manager alternative by Arthur Korn
7 # Copyright 2000 Wichert Akkerman <wakkerma@debian.org>
8 # Modified to use the freedesktop.org .desktop like kdm and gdm
10 # This script will read the list of installed window managers from
11 # the freedesktop .desktop files in <etc>/X11/sessions/:<etc>/dm/Sessions/:
13 # and update the sessions line in /etc/slim.conf.
14 # BEWARE: It doesn't ask any questions about this. It just does it. It
15 # takes an optional list of window managers.
18 use File::DesktopEntry;
24 #my @wm_list = ('default');
26 foreach my $dir ('/etc/X11/sessions/','/etc/dm/Sessions/','/usr/share/xsessions/') {
27 next unless (opendir DIR, $dir);
29 @files = grep { /\.desktop$/ && -r "$dir/$_" } readdir(DIR);
30 foreach my $file (@files) {
31 push @{$desktop_files{$file}}, "$dir/$file";
34 DESKTOP: foreach my $desktop_file (keys(%desktop_files)) {
35 foreach my $file (@{$desktop_files{$desktop_file}}) {
36 my $entry = File::DesktopEntry->new_from_file($file);
37 next DESKTOP if (defined($entry->get_value('Hidden'))
38 and $entry->get_value('Hidden') eq 'true');
39 if ($entry->get_value('Name') =~ /^gnome$/i) {
40 push (@wm_list, 'gnome');
42 elsif ($entry->get_value('Name') =~ /^kde$/i) {
43 push (@wm_list, 'kde');
45 elsif (defined($entry->get_value('Exec'))) {
46 push (@wm_list, $entry->get_value('Exec'));
48 else { # not found, go to next file
51 # found, proceed to next destop file
55 $wm_list = join (',', sort @wm_list) . ',custom';
57 $wm_list = join (',', sort @ARGV);
60 open (SLIM_CONFIG_FILE, '</etc/slim.conf')
61 or die "Can't open /etc/slim.conf for reading: $!";
62 open (NEW_SLIM_CONFIG_FILE, '>/etc/slim.conf.new')
63 or die "Can't open /etc/slim.conf.new for writing: $!";
65 while (<SLIM_CONFIG_FILE>) {
66 s|^(sessions\s*).*|$1$wm_list|;
67 print NEW_SLIM_CONFIG_FILE;
70 close(SLIM_CONFIG_FILE);
71 close(NEW_SLIM_CONFIG_FILE);
73 rename '/etc/slim.conf.new', '/etc/slim.conf'
74 or die "Can't rename /etc/slim.conf.new: $!";