aboutsummaryrefslogtreecommitdiffstats
path: root/meta-oe/recipes-graphics/slim/slim/update_slim_wmlist
blob: 0f116537fdb74d909b7b8c80a498214ac28a45a9 (plain)
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
#!/usr/bin/perl -w
#
# update_slim_wmlist, based on:
# update_wdm_wmlist, (c) 1998 Marcelo Magall�n <mmagallo@debian.org>
# rewriten to use the x-window-manager alternative
# modified to also use the x-session-manager alternative by Arthur Korn
# Copyright 2000 Wichert Akkerman <wakkerma@debian.org>
# Modified to use the freedesktop.org .desktop like kdm and gdm
#
# This script will read the list of installed window managers from
# the freedesktop .desktop files in <etc>/X11/sessions/:<etc>/dm/Sessions/:
# <share>/xsessions/
# and update the sessions line in /etc/slim.conf.
# BEWARE: It doesn't ask any questions about this. It just does it. It
# takes an optional list of window managers.

use strict;
use File::DesktopEntry;

my $wm_list='';
my %desktop_files;

unless (@ARGV) {
    #my @wm_list = ('default');
    my @wm_list;
    foreach my $dir ('/etc/X11/sessions/','/etc/dm/Sessions/','/usr/share/xsessions/') {
	    next unless (opendir DIR, $dir);
	    my @files;
	    @files = grep { /\.desktop$/ && -r "$dir/$_" } readdir(DIR);
	    foreach my $file (@files) {
		   push @{$desktop_files{$file}}, "$dir/$file";
	    }
    }
    DESKTOP: foreach my $desktop_file (keys(%desktop_files)) {
	    foreach my $file (@{$desktop_files{$desktop_file}}) {
		    my $entry = File::DesktopEntry->new_from_file($file);
		    next DESKTOP if (defined($entry->get_value('Hidden'))
			and $entry->get_value('Hidden') eq 'true');
		    if ($entry->get_value('Name') =~ /^gnome$/i) {
			    push (@wm_list, 'gnome');
		    }
		    elsif ($entry->get_value('Name') =~ /^kde$/i) {
			    push (@wm_list, 'kde');
		    }
		    elsif (defined($entry->get_value('Exec'))) {
			    push (@wm_list, $entry->get_value('Exec'));
		    }
		    else { # not found, go to next file
			    next;
		    }
		    # found, proceed to next destop file
		    next DESKTOP;
	    }
    }
   $wm_list = join (',', sort @wm_list) . ',custom';
} else {
    $wm_list = join (',', sort @ARGV);
}

open (SLIM_CONFIG_FILE, '</etc/slim.conf')
    or die "Can't open /etc/slim.conf for reading: $!";
open (NEW_SLIM_CONFIG_FILE, '>/etc/slim.conf.new')
    or die "Can't open /etc/slim.conf.new for writing: $!";

while (<SLIM_CONFIG_FILE>) {
    s|^(sessions\s*).*|$1$wm_list|;
    print NEW_SLIM_CONFIG_FILE;
}

close(SLIM_CONFIG_FILE);
close(NEW_SLIM_CONFIG_FILE);

rename '/etc/slim.conf.new', '/etc/slim.conf'
    or die "Can't rename /etc/slim.conf.new: $!";

exit 0;