LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 03-16-2018, 11:05 PM   #1
WBP
Member
 
Registered: Dec 2017
Location: Canada
Distribution: Slackware
Posts: 60

Rep: Reputation: Disabled
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
 
Old 03-16-2018, 11:19 PM   #2
Skaendo
Member
 
Registered: Dec 2014
Location: West Texas, USA
Distribution: Slackware64-14.2
Posts: 795

Rep: Reputation: Disabled
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"

Last edited by Skaendo; 03-17-2018 at 12:15 AM.
 
1 members found this post helpful.
Old 03-16-2018, 11:31 PM   #3
montagdude
Senior Member
 
Registered: Apr 2016
Distribution: Slackware
Posts: 1,292

Rep: Reputation: 980Reputation: 980Reputation: 980Reputation: 980Reputation: 980Reputation: 980Reputation: 980Reputation: 980
Isn't that what xwmconfig is for?
 
1 members found this post helpful.
Old 03-16-2018, 11:59 PM   #4
orbea
Senior Member
 
Registered: Feb 2015
Distribution: Slackware64-current
Posts: 1,474

Rep: Reputation: Disabled
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

Last edited by orbea; 03-17-2018 at 12:01 AM.
 
2 members found this post helpful.
Old 03-17-2018, 12:53 AM   #5
Richard Cranium
Senior Member
 
Registered: Apr 2009
Location: Carrollton, Texas
Distribution: Slackware64 14.2
Posts: 3,094

Rep: Reputation: 1472Reputation: 1472Reputation: 1472Reputation: 1472Reputation: 1472Reputation: 1472Reputation: 1472Reputation: 1472Reputation: 1472Reputation: 1472
Quote:
Originally Posted by WBP View Post
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.
 
1 members found this post helpful.
Old 03-17-2018, 01:01 AM   #6
orbea
Senior Member
 
Registered: Feb 2015
Distribution: Slackware64-current
Posts: 1,474

Rep: Reputation: Disabled
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.
 
1 members found this post helpful.
Old 03-17-2018, 01:15 AM   #7
mralk3
Senior Member
 
Registered: May 2015
Location: Utah, USA
Distribution: Slackware 14.2 || Slackware-current && CentOS
Posts: 1,322

Rep: Reputation: 697Reputation: 697Reputation: 697Reputation: 697Reputation: 697Reputation: 697
Quote:
Originally Posted by montagdude View Post
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.

Last edited by mralk3; 03-17-2018 at 01:16 AM.
 
1 members found this post helpful.
Old 03-17-2018, 01:18 AM   #8
orbea
Senior Member
 
Registered: Feb 2015
Distribution: Slackware64-current
Posts: 1,474

Rep: Reputation: Disabled
xwmconfig has the problem of wiping out any other changes that have been made to ~/.xinitrc.
 
2 members found this post helpful.
Old 03-17-2018, 01:46 AM   #9
Richard Cranium
Senior Member
 
Registered: Apr 2009
Location: Carrollton, Texas
Distribution: Slackware64 14.2
Posts: 3,094

Rep: Reputation: 1472Reputation: 1472Reputation: 1472Reputation: 1472Reputation: 1472Reputation: 1472Reputation: 1472Reputation: 1472Reputation: 1472Reputation: 1472
Quote:
Originally Posted by orbea View Post
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.
 
1 members found this post helpful.
Old 03-17-2018, 02:27 AM   #10
Didier Spaier
LQ Addict
 
Registered: Nov 2008
Location: Paris, France
Distribution: Slint64-14.2.1 on Lenovo Thinkpad W520
Posts: 8,631

Rep: Reputation: Disabled
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/
 
1 members found this post helpful.
Old 03-17-2018, 03:41 AM   #11
WBP
Member
 
Registered: Dec 2017
Location: Canada
Distribution: Slackware
Posts: 60

Original Poster
Rep: Reputation: Disabled
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

Thanks again for the support. It's much appreciated.
 
Old 03-20-2018, 09:49 PM   #12
igadoter
Senior Member
 
Registered: Sep 2006
Location: wroclaw, poland
Distribution: many, primary Slackware
Posts: 1,148
Blog Entries: 1

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


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Multiple DEs on Ubuntu - Only Recently Tested Answers, Please supusr Ubuntu 6 04-18-2016 08:07 AM
[SOLVED] Arch- Multiple DEs- switch without editing ~/.xinitrc? maples Linux - Newbie 7 04-14-2014 08:44 PM
gdm and multiple WMs/DEs Vigacmoe Linux - Software 2 03-15-2006 11:20 PM
Using Multiple WMs ncf Slackware 4 11-03-2005 11:00 PM
DEs and WMs KptnKrill Linux - General 3 06-22-2003 06:20 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 06:31 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration