You are not logged in.

#1 2012-04-10 11:35:29

sheomualjy
Member
Registered: 2011-12-23
Posts: 37

How do I set up my .xinitrc for multiple DE/WM?

Hi

In a previous forum thread, I got a reply that interested me. The user was talking about setting up the ~/.xinitrc file so that, depending on the argument passed to startx, different desktop environments or window managers could be started.

An example .xinitrc file that the user gave was as follows:

case "$1" in
	openbox)
		exec dbus-launch --exit-with-session openbox-session
		;;
	*)
		~/.dwm_status &
		exec dbus-launch --exit-with-session dwm
		;;
esac

How would I rewrite this so that I can start an LXDE session with "startx lxde" and a fluxbox session with "startx flux"? Everything that I try seems to not work, the x-server does not start. Instead, it says, at the bottom of the output,

xinit: connection to X server lost

Thanks

Last edited by sheomualjy (2012-04-10 11:44:53)

Offline

#2 2012-04-10 11:52:48

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,344
Website

Re: How do I set up my .xinitrc for multiple DE/WM?

What's in the .xinitrc you are currently using?  What you had on the other thread looked right.  Using my .xinitrc as is would not work ... unless you have dwm installed.


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#3 2012-04-10 12:04:28

sheomualjy
Member
Registered: 2011-12-23
Posts: 37

Re: How do I set up my .xinitrc for multiple DE/WM?

I rewrote your .xinitrc so that the commands and words matched mine. My .xinitrc is as follows, currently:

case "$1" in
        lxde)
                exec ck-launch-session startlxde
                ;;
        flux)
                exec ck-launch-session startfluxbox
                ;;
esac

Basically, I took your .xinitrc format, changed the cases to match what I would like to type, and put in the alternative commands for each case (which I copied of the arch wiki).

By themselves, the exec commands work fine in the .xinitrc, meaning I can merely type "startx" to get the DE/WM to start. However, when I put it in the case switch, as I have written above, typing "startx lxde" or "startx flux" does not work. xinit loses connection to the X server.

I noticed, after posting the above message, that if i add dbus-launch to the commands, I can type "xinit lxde" to start lxde, and "xinit flux" to start fluxbox. Is this different to the startx command? Because startx still doesn't work, even with dbus-launch.

Thanks for the reply though smile

Offline

#4 2012-04-10 13:00:57

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,344
Website

Re: How do I set up my .xinitrc for multiple DE/WM?

Odd.  I guess I don't know exactly what startx does.  I've always just used xinit.  I thought startx just did some ran some other startup scripts then handed off it's parameters to xinit.

Perhaps there is something in one of the scripts ran by startx that causes an error.  In the system xinitrc there is a call to xterm.  If xterm is not installed and that file is being sourced, it could cause such errors.

Perhaps someone who uses startx more could chime in.  Frankly this is one of the reasons I prefer using xinit: it's more streamlined, and for my purposes I don't need any of the startup done by startx.


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#5 2012-04-10 14:34:20

prasinoulhs
Member
From: Greece
Registered: 2011-10-30
Posts: 53

Re: How do I set up my .xinitrc for multiple DE/WM?

You need to give the full path for the client to startx or it will default to xterm.
Since it doesn't now what lxde of flux stand for it looks for a .xinitrc file in the users home directory and defaults to xterm, so your first argument($1) is now xterm. You can access the argument to startx as the second argument ($2).

So if you call

startx lxde

$1 contains xterm and $2 contains lxde in your .xinitrc file.

Take a look at the man page for startx and xinit for details.

Offline

#6 2012-04-10 23:16:59

cfr
Member
From: Cymru
Registered: 2011-11-27
Posts: 7,159

Re: How do I set up my .xinitrc for multiple DE/WM?

If that's the case, why would the example have worked for the user who posted that? That used $1 as well, didn't it?


CLI Paste | How To Ask Questions

Arch Linux | x86_64 | GPT | EFI boot | refind | stub loader | systemd | LVM2 on LUKS
Lenovo x270 | Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz | Intel Wireless 8265/8275 | US keyboard w/ Euro | 512G NVMe INTEL SSDPEKKF512G7L

Offline

#7 2012-04-11 00:58:14

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,344
Website

Re: How do I set up my .xinitrc for multiple DE/WM?

man startx wrote:

Arguments  immediately  following the startx command are used to start a client in the same manner as xinit(1)

It seems there should be no difference between the two in this regard.

Sheomualjy, this .xinitrc is in your home directory correct?


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#8 2012-04-11 01:57:10

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 20,360

Re: How do I set up my .xinitrc for multiple DE/WM?

I do it like this:

#xset b off
setxkbmap -option ctrl:nocaps

case $WM in
kde)
	ck-launch-session dbus-launch startkde
	;;
gnome)
	ck-launch-session dbus-launch gnome-session
	;;
compiz)
	~/bin/compiz&
	ck-launch-session dbus-launch compiz ccp
	#ck-launch-session dbus-launch fusion-icon
	;;
lxde)
	~/bin/lxde&
	ck-launch-session dbus-launch startlxde
	;;
openbox)
	~/bin/openbox&
	ck-launch-session dbus-launch openbox
	;;
e17)
	ck-launch-session dbus-launch
    enlightenment_start
    ;;
vb)
    VirtualBox -startvm "Windows XP" -fullscreen
    ;;
xfce4)
	ck-launch-session dbus-launch startxfce4
	;;
i3)
	ck-launch-session dbus-launch i3
	;;
*)
	ck-launch-session dbus-launch startxfce4
	;;
esac

Then I start, for example Openbox,  with

WM=openbox startx

edit:  Note the vb entry smile

Last edited by ewaller (2012-04-11 01:58:00)


Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
The shortest way to ruin a country is to give power to demagogues.— Dionysius of Halicarnassus
---
How to Ask Questions the Smart Way

Offline

#9 2012-04-11 04:23:58

sheomualjy
Member
Registered: 2011-12-23
Posts: 37

Re: How do I set up my .xinitrc for multiple DE/WM?

Thanks all!
ewaller, that worked perfectly! I particularly liked the vb entry, and am using it myself!

Offline

#10 2012-04-11 07:35:50

Nilithus
Member
Registered: 2012-04-11
Posts: 2

Re: How do I set up my .xinitrc for multiple DE/WM?

I noticed in the first script in the thread sheomualjy had "exec" in all his statements but ewaller you don't. Obviously yours works but I was just wondering why you don't need it, does the " WM/DE) " line imply exec?

not really that important, just curious.

Offline

#11 2012-04-11 11:56:44

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,344
Website

Re: How do I set up my .xinitrc for multiple DE/WM?

Nilithus wrote:

I noticed in the first script in the thread sheomualjy had "exec"

Ah, that may be the important difference.   Perhaps exec and consolekit don't work together.  I use the exec lines, but I don't use consolekit.


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#12 2012-04-11 15:20:05

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 20,360

Re: How do I set up my .xinitrc for multiple DE/WM?

Nilithus wrote:

I noticed in the first script in the thread sheomualjy had "exec" in all his statements but ewaller you don't. Obviously yours works but I was just wondering why you don't need it, does the " WM/DE) " line imply exec?

not really that important, just curious.

To be honest, I had never considered using exec.  I am at $DAYJOB right now, but I'll take a look at that when I get home tonight (GMT-7).


Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
The shortest way to ruin a country is to give power to demagogues.— Dionysius of Halicarnassus
---
How to Ask Questions the Smart Way

Offline

#13 2012-04-11 17:07:08

Nilithus
Member
Registered: 2012-04-11
Posts: 2

Re: How do I set up my .xinitrc for multiple DE/WM?

yeah seems like exec is not needed I just tried putting exec into my statements and it worked with and without them
looked like this with them in:

DEFAULT_SESSION =kde

case $1 in 

kde)
          exec ck-launch-session startkde
          ;;
gnome)
          exec ck-launch-session gnome-session
          ;;
*)
         exec ck-launch-session startkde
          ;;
esac

It worked with and without them, I do have consolekit 0.4.5-2

EDIT:
probably don't need the "DEFAULT_SESSION= " if I have the " *) "

Last edited by Nilithus (2012-04-11 17:09:04)

Offline

#14 2012-04-11 19:00:14

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,426
Website

Re: How do I set up my .xinitrc for multiple DE/WM?

Nilithus wrote:

I noticed in the first script in the thread sheomualjy had "exec" in all his statements but ewaller you don't. Obviously yours works but I was just wondering why you don't need it, does the " WM/DE) " line imply exec?

not really that important, just curious.

When I moved to logging straight into X, I tinkered around a bit with these options. I moved all my environment variables out of .bashrc and put them in .profile -- and found they would only be inherited by interactive shells if xinit was started with exec. I don't think it would make any difference in an .xinitrc file...


Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

#15 2012-04-11 22:05:36

prasinoulhs
Member
From: Greece
Registered: 2011-10-30
Posts: 53

Re: How do I set up my .xinitrc for multiple DE/WM?

cfr wrote:

If that's the case, why would the example have worked for the user who posted that? That used $1 as well, didn't it?

He said that he uses xinit not startx.

If you look at startx you can see, around line 85, that it checks if client (the argument to startx) exists. Now if i say startx openbox the check fails since openbox doesn't exist (/usr/bin/openbox exists), so startx fails to the defaults (xterm) and passes openbox as an argument to it. Now xterm openbox is passed to xinit that's why $1 is xterm in the .xinitrc.

Offline

#16 2012-04-11 22:53:30

cfr
Member
From: Cymru
Registered: 2011-11-27
Posts: 7,159

Re: How do I set up my .xinitrc for multiple DE/WM?

prasinoulhs wrote:
cfr wrote:

If that's the case, why would the example have worked for the user who posted that? That used $1 as well, didn't it?

He said that he uses xinit not startx.

If you look at startx you can see, around line 85, that it checks if client (the argument to startx) exists. Now if i say startx openbox the check fails since openbox doesn't exist (/usr/bin/openbox exists), so startx fails to the defaults (xterm) and passes openbox as an argument to it. Now xterm openbox is passed to xinit that's why $1 is xterm in the .xinitrc.

You mean the original post at the top of the thread is wrong? (That's not what was said in the other thread?)


CLI Paste | How To Ask Questions

Arch Linux | x86_64 | GPT | EFI boot | refind | stub loader | systemd | LVM2 on LUKS
Lenovo x270 | Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz | Intel Wireless 8265/8275 | US keyboard w/ Euro | 512G NVMe INTEL SSDPEKKF512G7L

Offline

#17 2012-04-11 23:15:15

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,344
Website

Re: How do I set up my .xinitrc for multiple DE/WM?

As this was new to me, and did not seem to be indicated in `man startx`, I did a quick test by adding the following lines to the top of my .xinitrc

echo "1: $1"
echo "All: $@"
exit

As expected `xinit dwm` (after starting and quickly ending X) echoed the following:

1: dwm
All: dwm

while `startx dwm` echoed

1: urxvt
All: urxvt dwm

At least it seems I was smart enough once to change xterm to urxvt in one of those startx scripts.  But once again this reminds me why I prefer xinit: Keep it simple.

As for whether to exec or not to exec, exec replaces the calling process with the window manager, rather than having the WM be a child of the xinit/startx.  Really the only difference I've noticed is that using exec make your pstree look a little cleaner.

EDIT: I suppose another difference is if you use exec, when you close your WM, X ends as well.  This would generally be the case anyways, but it is possible to have lines in your xinitrc after the WM line.  If for example you had this:

startlxde
startkde

then when you exited lxde X would seemlessly transition into a KDE session.  I did tinker with this once for some nifty ways of rotating through different sessions without having to rely on WM "--replace" options which not all WM's have.  If, however, those lines started with 'exec' then the second WM would never launch as the parent process - AKA the xinitrc script - had been replaced (I THINK).

Last edited by Trilby (2012-04-11 23:19:28)


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#18 2012-04-12 00:00:45

prasinoulhs
Member
From: Greece
Registered: 2011-10-30
Posts: 53

Re: How do I set up my .xinitrc for multiple DE/WM?

cfr wrote:

...
You mean the original post at the top of the thread is wrong? (That's not what was said in the other thread?)

With the script on the first post (which is the same as in the other thread) you can use xinit and select what DE/WM you wan't to start. In order to use startx you either have to change $1 to $2, or un/comment the DE/WM that you wan't to start, or give startx the full path to the DE/WM.

startx /usr/bin/openbox

Offline

#19 2012-04-12 01:32:23

cfr
Member
From: Cymru
Registered: 2011-11-27
Posts: 7,159

Re: How do I set up my .xinitrc for multiple DE/WM?

OK. The post said the arguments were being passed to startx and not xinit and obviously that bit must be wrong. (Or "arguments" are full pats.)


CLI Paste | How To Ask Questions

Arch Linux | x86_64 | GPT | EFI boot | refind | stub loader | systemd | LVM2 on LUKS
Lenovo x270 | Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz | Intel Wireless 8265/8275 | US keyboard w/ Euro | 512G NVMe INTEL SSDPEKKF512G7L

Offline

Board footer

Powered by FluxBB