PDA

View Full Version : .xinitrc and WindowManager


bluehz
01-21-2003, 07:30 AM
My shell scripting isn't quite good enough to figure this out - but I suspect its rather easy...

In playing with Apple X11 I have been trying various WindowManagers (WM). In order to switch back and forth between various WM I just open and manually edit my .xinitrc file. Currently a portion of my .xinitrc file looks like this:
# start some nice programs
source /sw/bin/init.sh
xterm -j -rightbar -sb -sl 1000 -bg black -fg green -geometry 80x35+584+20 &

##############################
# WINDOWMANAGERS #
##############################

#
# Quartz-WM
#

#exec /usr/X11R6/bin/quartz-wm

#
# use Blackbox
#

xroot -display :0 -geometry 100x25+0-0 -color gray &
exec /sw/bin/blackbox

#
# Enlightenment
#

#xroot -display :0 -geometry 100x25+0-0 -color gray &
#exec /sw/bin/enlightenment

#
# KDE
#

#KDEWM=quartz-wm
#exec /sw/bin/startkde

You will notice I just comment/uncomment to use various WM.

What I want to know is it possible to modify this so that I might use a command line switch when launching to pick a specified WM - something like:

startx -kde or starx -bbox

Also - currently - if you launch Apple X11 via startx - it only launches a portion of if - I guess just the XServer portion. I have been using

exec /Applications/X11.app/Contents/MacOS/X11 &

and that works - with the added benefit that the overall System $PATH seems to transfer properly. Is this an acceptable method of launching Apple X11 or is there some caveat I am missing?

I guess what I am getting at - is I would like to be able to quickly launch and choose my WM form the CLI using Apple X11 - is this possible?

sao
01-21-2003, 11:27 AM
bluehz,

You can try the following:

Create the file .xinitrc.blackbox

pico .xinitrc.blackbox

#To use blackbox wmanager with X11

source /sw/bin/init.sh
xterm -j -rightbar -sb -sl 1000 -bg black -fg green -geometry 80x35+584+20 &

xroot -display :0 -geometry 100x25+0-0 -color gray &
exec blackbox
Then, create a file in ~/bin to launch X11 with blackbox, call it "bbox"

pico bbox

#!/bin/sh
exec cp .xinitrc.blackbox .xinitrc &
exec launch /Applications/X11.app &
Give it the right execute permissions
chmod +x bbox

Then, repeat to create other files to launch X11 with different window managers.


PS: I got the idea from Michele Garoche setup to call either XDarwin or Apple X11, posted at the x11-users list.

bluehz
01-21-2003, 12:55 PM
Thanks sao - will give that a try - would still like a cleaner command line switch though. May try to brush up on my shell scripting and give it a go myself...

ClarkGoble
01-21-2003, 01:10 PM
I had done something similar to this back under XDarwin. Sometimes I wanted to start with OroboxX, other times with KDE, and other times with Gnome. So I wrote an Applescript that modified my .xinitrc and then started up XDarwin accordingly.

You could easily follow the thinking in the above and put it into an Applescript you put somewhat. My Applescript brought up a list of X11 Managers and started the appropriate one.

Perhaps, if I have time, I'll clean things up tonight and post it here.

mnewman
01-21-2003, 01:26 PM
You should be able to use command line arguments. In your script $1 refers to the first command line argument, $2 the second, etc.

So, how about a case statement that branches based on the value of $1 and defaults to quartz if there is none?

bluehz
01-21-2003, 04:07 PM
mnewman - the case statement thing is exactly what I was talking about - I have seen that used before.... unfortunately I am a sheel script beginner so I can't rattle it off teh top of my head. But with a little research I think I can figure it out.

mnewman
01-21-2003, 04:46 PM
I think ClarkGoble's AppleScript might be a better bet.

Clark, can you post the script "as is" so we can get a look at it?

ClarkGoble
01-21-2003, 05:07 PM
I don't have time to clean this up. I'm at work so I just nabbed this off the MacNN Forum post where I had given an early version. I've tweaked it a fair bit on my system.

Basically make a copy of .xinitrc called .xinitrc.orig. Delete the line with "exec startkde" or related lines. Run this Applescript.

You can easily add lines for each window manager if you want them to start up with various x11 applications. I could have made it fancier, but this was more than sufficient for me.

To modify the below, as for Apple's X11.app, simply add more "echo" lines in the "do shell script part." There are of course more elegant ways to do that for longer lines.


set winmanager to (choose from list {"WindowMaker",
"KDE", "Gnome", "OrorbosX", "Blackbox"})

if "WindowMaker" is in winmanager then
do shell script "cp ~/.xinitrc.orig ~/.xinitrc"
do shell script "echo 'exec wmaker' >> ~/.xinitrc"
tell application "XDarwin"
activate
end tell
return
end if

if "OrorbosX" is in winmanager then
tell application "OroborOSX"
activate
end tell
end if

if "KDE" is in winmanager then
do shell script "cp ~/.xinitrc.orig ~/.xinitrc"
do shell script "echo 'exec startkde' >> ~/.xinitrc"
tell application "XDarwin"
activate
end tell
return
end if

if "Blackbox" is in winmanager then
do shell script "cp ~/.xinitrc.orig ~/.xinitrc"
do shell script "echo 'exec blackbox' >> ~/.xinitrc"
tell application "XDarwin"
activate
end tell
return
end if


This was originally a quick and dirty hack as I didn't want to spend much time on it. So I apologize for the Q&D nature of it.

sao
01-31-2003, 02:21 PM
Cool tip by Russell Stephany at the x11-users list:

<<<...sometimes i want to use Xdarwin (with blackbox or afterstep), and sometimes X11 (with quartz-wm), so i have put this at the bottom of my ~/.xinitrc to start the correct window manager >>>
----------
xdar="`ps xo command | grep XDarwin.app | grep -v grep | wc -l`"

if [ $xdar -eq 1 ]; then
exec blackbox
else
exec quartz-wm
fi
----------

(i'm sure there are better ways of telling whether XDarwin is running, but...)