Chinaunix首页 | 论坛 | 博客
  • 博客访问: 4177022
  • 博文数量: 601
  • 博客积分: 15410
  • 博客等级: 上将
  • 技术积分: 6884
  • 用 户 组: 普通用户
  • 注册时间: 2007-05-16 08:11
个人简介

独学而无友,则孤陋而寡闻!

文章分类

全部博文(601)

文章存档

2020年(1)

2018年(4)

2017年(7)

2016年(42)

2015年(25)

2014年(15)

2013年(36)

2012年(46)

2011年(117)

2010年(148)

2009年(82)

2008年(37)

2007年(41)

分类: BSD

2009-02-02 16:50:40

Setting up .xinitrc/.xsession

Contributed by Verin.

The place of xinit in things

A window manager is just one more application for X11, like netscape or gimp or xterm. Many people new to X11 come to believe that X11 runs the window manager and the window manager runs programs. But that's not true. If configured right, you can run all your applications under X11, kill the window manager, and start another window manager up.

The real program that X11 runs, that runs other programs, is your .xinitrc or .xsession script. When X11 is started, your .xinitrc or .xsession script is run, and when the script is done, X11 comes down. Let me repeat that, its important: when .xinitrc is finished, that is when X ends. It isn't when your window manager exits.

Script layout

Well, first realize something you already know. When you type a command in a shell, you can't do anything else until that command is done, when it exits. Your .xinitrc or .xsession script is just the same. When it starts going through it, if it hits any program that takes a long time to run (like most X11 programs), it stops right there until that program is finished.

Ideally, you should only have one place where the script 'hangs'. And usually you want this to be at the end. So, if you have any programs you want to run under X11 before you get to this 'hang' spot, you should background them. You put an & at the end of the line. So, say you want xclock to run in addition to other things, put this line before your 'hang' spot:

    xclock &

Now, the next thing is the exec thing you see, where lots of sources recommend how to add your window manager to your script. But honestly, its not really necessary, if you put your window manager on the last line of your script, it will hang there just fine without the exec.

So why the exec? Well, lets say you want to put lots of window manager start lines in your script, and you want only one to work. Well, with exec you can put your chosen start-line at the top. Because this is what exec means:

"Replace myself with this program, i.e. start it and terminate myself immediately when it finishes. "

So if you put an exec wmaker line atop of a exec enlightenment line, when wmaker is done, so is the script, it never gets to the next line.

See what I mean by being unnecessary? You could just put a bunch of commented-out window manager lines, and it would work just the same.

Another way to do things

As an alternative, you could start up your window manager first, and store the process ID in a environment variable:

        wmaker & wmpid=$!

that puts it in the background (&) and puts the process id ($!) in a variable (wmpid). Then, to make your hang point, you can wait:

    wait $wmpid

or you could hang on a program you always want to use, like maybe gkrellm, by just not backgrounding it. But remember that as soon as you terminate it, so will your X11 session.

Now, I use the wait method, because I like picking my window manager before I launch my dockapps and stuff. Also, before doing anything else, I like to change the settings on my X11 server, like the dpms, the screen saver, and even add some directories to my font path (fonts I don't want to install universally). And then after everything is done, I like to clean up my fontpath, mainly because if I ran a display manager, its not good at resetting the font path all the time.

Example A-1. .xinitrc

    # turn off screen blanking and turn on energy star features
xset s off
xset dpms 600 60 60

# add my optional fonts to the font path
xset +fp "$X_FONTPATH"
xset fp rehash

# export the current environment, in case it needs to be debugged
env > ~/.xenv

# window manager
fluxbox & wmpid=$!

bbrun &
wmCalClock &
wmxmms &

# HANG POINT - wait for window manager to exit
wait $wmpid

# restore the x fontpath
xset fp default
阅读(2906) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~