LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Slackware (https://www.linuxquestions.org/questions/slackware-14/)
-   -   Choosing between multiple DEs/WMs to launch (https://www.linuxquestions.org/questions/slackware-14/choosing-between-multiple-des-wms-to-launch-4175625726/)

WBP 03-16-2018 10:05 PM

Choosing between multiple DEs/WMs to launch
 
I have both xfce and i3wm installed on my slackware machine. I'm know there are graphical "display managers" (not sure if that's the correct term) and "login managers" that will present the DEs or WMs that are installed and let you choose the one you'd like to launch. I would prefer to make the selection from the login shell, not graphically, by running startx. Everytime I want to switch between xfce and i3wm I have to comment out one of their entries in the .xinitrc file.

I'm wondering if there is a way to choose which one I'd like to launch with a bash script inside the .xinitrc file. I'm not familiar with bash but I'm sure I could learn what would be required for this task. I was thinking something along the lines of when startx or xinit is entered, the user would be prompted to enter a number, either 1 or 2. 1 corresponding to i3 and 2 corresponding to xfce. The following is pseudo code of course, but I thought it could work like:

Code:

prompt user for number

if ( number is 1 )
  exec xfce

if ( number is 2 )
  exec i3

To see if something like this would be possible I thought I would just try
Code:

echo 'HELLO XFCE'
into the .xinitrc file before the xfce section, but nothing printed to the screen. Maybe it displayed too fast for me to see it lol.

I was hoping that before I go and learn the bit of bash that's required for this task someone could tell me if I'm on the right path, or not? And, if not then tell me what I should be doing?

Thanks

Skaendo 03-16-2018 10:19 PM

I'm just guessing, but I think that would at least need a select function.

Something like:
Code:

options=("xfce" "i3wm" "Quit")
select opt in "${options[@]}"; do
  case $opt in
    "xfce")
      printf "You chose XFCE.\n"
      launch xfce
      break
      ;;
    "i3wm")
      printf "You chose i3wm.\n"
      launch i3wm
      break
      ;;
    "Quit")
      printf "Ok, stay here then.\n"
      exit 1
      ;;
    esac
done

NOTE: you would need to figure out the if ;then around it and the "launch de/wm"

montagdude 03-16-2018 10:31 PM

Isn't that what xwmconfig is for?

orbea 03-16-2018 10:59 PM

With just posix shell you could do something like this.

Code:

if [ $# -gt 0 ]; then
  case "$1" in
    xfce ) exec xfce ;;
    i3 ) exec i3 ;;
    * ) printf %s\\n "Unknown DE/wm '$1'"; exit 1 ;;
  esac
else
  exec xfce # this is the default choice without any arguments
fi


Richard Cranium 03-16-2018 11:53 PM

Quote:

Originally Posted by WBP (Post 5831900)
I would prefer to make the selection from the login shell, not graphically, by running startx.

If I may ask, why do you prefer that?

You can always select the runlevel when you boot; use 3 for a login shell and 4 for when you *know* that you will want a graphical environment and can then use kdm/xdm to select the environment. If you are in runlevel 3, you can nonetheless issue telinit 4 or (not tested) sudo telinit 4 to bring up kdm/xdm.

It's your system, of course, and you may certainly do things as you wish.

orbea 03-17-2018 12:01 AM

You didn't ask me, but I use startx too because I never really found the need for anything more. It works just fine and editing ~/.xinitrc is more than enough to start a minimal wm. :)

mralk3 03-17-2018 12:15 AM

Quote:

Originally Posted by montagdude (Post 5831905)
Isn't that what xwmconfig is for?

This! ^^^^

The xwmconfig command edits .xinitrc for you, but in an ncurses interface. You can run it in runlevel 3. After selecting the WM/DE you can run startx.

orbea 03-17-2018 12:18 AM

xwmconfig has the problem of wiping out any other changes that have been made to ~/.xinitrc.

Richard Cranium 03-17-2018 12:46 AM

Quote:

Originally Posted by orbea (Post 5831921)
You didn't ask me, but I use startx too because I never really found the need for anything more. It works just fine and editing ~/.xinitrc is more than enough to start a minimal wm. :)

Well, normally I run XFCE. When I want to connect my Android phone to the computer to download photos, I've found out that I *really* need to be running KDE to do that; Thunar times out every time.

I use kdm to log in every time; it's easy to log out of XFCE, select KDE, and log into that. When I'm done, reverse the process.

If you only use one wm, then startx is fine.

Didier Spaier 03-17-2018 01:27 AM

This should work.

Caveat: I didn't try in Slackware.

Code:

#!/bin/sh
# This script sets the X session started with the startx command or
# with a display manager, unless the session be set from the display
# manager's greeter.
# Tested with xdm, lightdm, lxdm, kdm and gdm2
# Known issue: with some sessions xdm respawns
# The script user-xsession.py needs accountsservice and is shipped in
# the accountsservice package in Slint.
# Didier Spaier <didier~at~slint~dot~fr> 25 November 2017

if [ $(id -u) -eq 0 ]; then
    echo "Running a graphical session as root is not allowed."
    exit
fi
liste="$(ls /usr/share/xsessions/|sed s/.desktop//)"
listew=". $liste ."

usage() {
    echo "Usage: $0 <desktop session>"
    echo "Available desktop sessions:"
    echo "$liste"
    printf "The session is currently set for $USER to "
    user_xsession.py --user-name $USER get
exit
}
 
[ $# -ne 1 ] && usage

if [ "$(echo $1|tr [:lower:] [:upper:])" = "LXDE" ]; then
    thissession="LXDE"
else
    thissession=$(echo $1|tr [:upper:] [:lower:])
fi

if [ "$(echo $listew|grep " $thissession ")" = "" ]; then
    echo "\"$1\" not found among the available sessions"
    echo "$liste"
    printf "The current session is "
    user_xsession.py --user-name $USER get
    exit
fi

user_xsession.py --user-name $USER set $thissession

# This is for xdm
case $thissession in
    kde-plasma) session=/usr/bin/startkde;;
    kde-plasma-safe) session="/usr/bin/startkde --failsafe";;
    LXDE) session=/usr/bin/lxsession;;
    gnome) session=/usr/bin/gnome-session;;
    xfce) session=/usr/bin/startxfce4;;
    icewm) session=/usr/bin/icewm-session;;
    mate) session=/usr/bin/mate-session;;
    wmaker) session=/usr/bin/startwmaker;;
    e16) session=/usr/share/e16/misc/starte16;;
    enlightenment) session=/usr/bin/enlightenment_start;;
    blackbox) session=/usr/bin/startblackbox;;
    fluxbox) session=/usr/bin/startfluxbox;;
    twm) session=/usr/bin/starttwm;;
    awesome) session=/usr/bin/awesome;;
esac

echo $session > $HOME/.xsession

# This is for lxdm and gdm2.
echo '[Desktop]' > $HOME/.dmrc
echo "Session=$thissession" >> $HOME/.dmrc

xsession=$thissession
[ "$xsession" = "LXDE" ] && xsession=lxde
[ "$xsession" = "kde-plasma" ] && xsession=kde
[ "$xsession" = "kde-plasma-safe" ] && xsession=kde

# This is mostly for startx , borrowed from xwmconfig.
if [ -r /etc/X11/xinit/xinitrc.$xsession ]; then
  if [ -r $HOME/.xinitrc ]; then
    rm -f $HOME/.xinitrc-backup
    mv $HOME/.xinitrc $HOME/.xinitrc-backup
  fi
  cat /etc/X11/xinit/xinitrc.$xsession > $HOME/.xinitrc
fi

echo "A default session $thissession has been set for ${USER}."

Source: http://slackware.uk/slint/x86_64/sli...ce/slint-misc/
Needs: http://slackware.uk/slint/x86_64/sli...countsservice/

WBP 03-17-2018 02:41 AM

Thank you everyone for your replies.

@Skaendo @orbea @Didier Spaier - Thanks for the code. I'm learning my first programming language right now, which has allowed me to follow the logic of these scripts quite a bit, but I will have to study bash to understand the finer points.

@montagdude @mralk3 - Thanks for info about xwmconfig. I do have dmps settings in .xinitrc for when i3 is launched that would be wiped out if I were to switch to a different de/wm.

@Richard Cranium - Nice to hear from you again. Well, to be honest besides the different run levels I wasn't aware of the other options you mentioned, including being able to select different run levels upon booting (I'll look into that). Since I started using Slackware I've just left it at run level 3 and used startx, I was only using one wm at the time, though. Now that I have two, I basically just thought of a solution building on what I already knew; startx. Since all that was in my .xinitrc file to start i3 was one line: exec i3, I thought I would try to see if I could add a script to that file with a simple if-else construct and may or may not prompt the user for input. So, instead of issuing "startx" I would just type "startx i3" or "startx xfce", or after issuing "startx" I would be prompted to make a selection, which if worked, wouldn't be much trouble at all. Also, I thought it would be cool :D

Thanks again for the support. It's much appreciated.

igadoter 03-20-2018 08:49 PM

xwmconfig does not wipe out .xinitrc - before it creates backup .xinitrc-backup. So any custom settings are safe.


All times are GMT -5. The time now is 08:56 PM.