]> Frank Brehm's Git Trees - my-stuff/x-session-select.git/commitdiff
Initial
authorFrank Brehm <frank@brehm-online.com>
Sun, 15 Jun 2008 11:33:25 +0000 (11:33 +0000)
committerFrank Brehm <frank@brehm-online.com>
Sun, 15 Jun 2008 11:33:25 +0000 (11:33 +0000)
git-svn-id: http://svn.brehm-online.com/svn/my-stuff/X-session-select/trunk@13 ec8d2aa5-1599-4edb-8739-2b3a1bc399aa

get-sessions-dialog.pl [new file with mode: 0755]
set-default-session.pl [new file with mode: 0755]
x [new file with mode: 0755]

diff --git a/get-sessions-dialog.pl b/get-sessions-dialog.pl
new file mode 100755 (executable)
index 0000000..2fcc3b0
--- /dev/null
@@ -0,0 +1,83 @@
+#!/usr/bin/perl
+
+# $Id$
+# $URL$
+
+use strict;
+use warnings;
+
+use File::Spec::Functions;
+use File::Basename;
+use Config::IniFiles;
+
+my $session_dir = '/etc/X11/Sessions';
+my $back_title  = 'Auswahl der X-Umgebung';
+my $menu_title  = 'Wählen Sie bitte eine X-Umgebung aus:';
+
+my $inifile = catfile( $ENV{'HOME'}, '.dmrc' );
+my $default = undef;
+
+if ( -f $inifile ) {
+    my $cfg = new Config::IniFiles( -file => $inifile, '-nocase' => 1, );
+    $default = $cfg->val( 'Desktop', 'Session' );
+}
+
+my ($session_file);
+my @SessionsArray;
+my $max = length($menu_title) + 3;
+my ( $height, $items );
+
+for $session_file ( glob( catfile( $session_dir, '*' ) ) ) {
+
+    next unless -f $session_file and -x $session_file;
+
+    my $session_name = basename($session_file);
+    my $session_title = basename($session_file);
+
+    if ( $session_name =~ /^Gnome$/i ) {
+        $session_title = "Gnome-Desktop-Umgebung";
+    }
+    elsif ( $session_name =~ /^kde-(\d\.\d)$/i ) {
+        $session_title = "KDE-Desktop " . $1;
+    }
+    elsif ( $session_name =~ /^wmaker$/i ) {
+        $session_title = "Windowmaker-Desktop";
+    }
+    elsif ( $session_name =~ /^Xsession$/i ) {
+        $session_title = "Standard X-Desktop";
+    }
+
+    push @SessionsArray, $session_name;
+    push @SessionsArray, $session_title;
+
+    my $length = length($session_name) + length($session_title) + 2;
+    $max = ( $length + 9 ) if ( $length + 9 ) > $max;
+
+}
+
+$items = int( scalar(@SessionsArray) / 2 );
+$height = $items + 7;
+
+my @DialogArgs = (
+    '--stdout',
+    '--backtitle',
+    $back_title,
+    '--menu',
+    $menu_title,
+    $height,
+    $max,
+    $items,
+    @SessionsArray,
+);
+
+if ( $default ) {
+    unshift @DialogArgs, $default;
+    unshift @DialogArgs, '--default-item';
+}
+
+my $cmd = '/usr/bin/dialog "' . join( '" "', @DialogArgs ) . '"';
+
+print $cmd . "\n";
+
+exit 0;
+
diff --git a/set-default-session.pl b/set-default-session.pl
new file mode 100755 (executable)
index 0000000..fea4eba
--- /dev/null
@@ -0,0 +1,39 @@
+#!/usr/bin/perl
+
+# $Id$
+# $URL$
+
+use strict;
+use warnings;
+
+use File::Spec::Functions;
+use File::Basename;
+use Config::IniFiles;
+
+my $session = shift;
+
+return 1 unless $session;
+
+my $inifile = catfile( $ENV{'HOME'}, '.dmrc' );
+
+unless ( -f $inifile ) {
+    unless ( open INI, ">>", $inifile ) {
+        die "Konnte '" . $inifile . "' nicht erzeugen: " . $! . "\n";
+    }
+    print INI <<ENDE;
+[Desktop]
+Session=uhu
+Language=de_DE.UTF-8
+ENDE
+    close INI;
+    chmod 0600, $inifile;
+}
+
+my $cfg = new Config::IniFiles( -file => $inifile );
+$cfg->SetWriteMode('0600');
+$cfg->AddSection('Desktop') unless $cfg->SectionExists('Desktop');
+$cfg->newval( 'Desktop', 'Session', $session );
+$cfg->RewriteConfig() || exit 5;
+
+exit 0;
+
diff --git a/x b/x
new file mode 100755 (executable)
index 0000000..b81dc2b
--- /dev/null
+++ b/x
@@ -0,0 +1,43 @@
+#!/bin/sh
+
+# $Id$
+# $URL$
+
+TMPFILE=`mktemp` || exit 5
+
+PL_SCRIPT=`dirname $0`"/get-sessions-dialog.pl"
+echo ${PL_SCRIPT}
+SET_PL_SCRIPT=`dirname $0`"/set-default-session.pl"
+echo ${SET_PL_SCRIPT}
+
+DIALOG_CMD=`${PL_SCRIPT}`" >${TMPFILE}"
+echo ${DIALOG_CMD}
+
+eval ${DIALOG_CMD}
+RES=$?
+
+if [ "${RES}" != "0" ]; then
+    rm -f $TMPFILE
+    exit ${RES} 
+fi
+
+echo
+echo
+echo
+cat $TMPFILE
+echo
+
+#ls -l $TMPFILE
+#rm -f $TMPFILE
+#exit 0
+
+
+XSESSION=`cat ${TMPFILE}`
+${SET_PL_SCRIPT} ${XSESSION}
+#export XSESSION
+rm -f $TMPFILE
+
+echo XSESSION=$XSESSION startx
+XSESSION=$XSESSION startx
+
+