定制X会话
文章出处: |
{{#if: | {{{2}}} | https://wiki.ubuntu.com/CustomXSession }} |
点击翻译: |
English {{#ifexist: {{#if: UbuntuWiki:CustomXSession | UbuntuWiki:CustomXSession | {{#if: | :}}定制X会话}}/af | • {{#if: UbuntuWiki:CustomXSession|Afrikaans| [[::定制X会话/af|Afrikaans]]}}|}} {{#ifexist: {{#if: UbuntuWiki:CustomXSession | UbuntuWiki:CustomXSession | {{#if: | :}}定制X会话}}/ar | • {{#if: UbuntuWiki:CustomXSession|العربية| [[::定制X会话/ar|العربية]]}}|}} {{#ifexist: {{#if: UbuntuWiki:CustomXSession | UbuntuWiki:CustomXSession | {{#if: | :}}定制X会话}}/az | • {{#if: UbuntuWiki:CustomXSession|azərbaycanca| [[::定制X会话/az|azərbaycanca]]}}|}} {{#ifexist: {{#if: UbuntuWiki:CustomXSession | UbuntuWiki:CustomXSession | {{#if: | :}}定制X会话}}/bcc | • {{#if: UbuntuWiki:CustomXSession|جهلسری بلوچی| [[::定制X会话/bcc|جهلسری بلوچی]]}}|}} {{#ifexist: {{#if: UbuntuWiki:CustomXSession | UbuntuWiki:CustomXSession | {{#if: | :}}定制X会话}}/bg | • {{#if: UbuntuWiki:CustomXSession|български| [[::定制X会话/bg|български]]}}|}} {{#ifexist: {{#if: UbuntuWiki:CustomXSession | UbuntuWiki:CustomXSession | {{#if: | :}}定制X会话}}/br | • {{#if: UbuntuWiki:CustomXSession|brezhoneg| [[::定制X会话/br|brezhoneg]]}}|}} {{#ifexist: {{#if: UbuntuWiki:CustomXSession | UbuntuWiki:CustomXSession | {{#if: | :}}定制X会话}}/ca | • {{#if: UbuntuWiki:CustomXSession|català| [[::定制X会话/ca|català]]}}|}} {{#ifexist: {{#if: UbuntuWiki:CustomXSession | UbuntuWiki:CustomXSession | {{#if: | :}}定制X会话}}/cs | • {{#if: UbuntuWiki:CustomXSession|čeština| [[::定制X会话/cs|čeština]]}}|}} {{#ifexist: {{#if: UbuntuWiki:CustomXSession | UbuntuWiki:CustomXSession | {{#if: | :}}定制X会话}}/de | • {{#if: UbuntuWiki:CustomXSession|Deutsch| [[::定制X会话/de|Deutsch]]}}|}} {{#ifexist: {{#if: UbuntuWiki:CustomXSession | UbuntuWiki:CustomXSession | {{#if: | :}}定制X会话}}/el | • {{#if: UbuntuWiki:CustomXSession|Ελληνικά| [[::定制X会话/el|Ελληνικά]]}}|}} {{#ifexist: {{#if: UbuntuWiki:CustomXSession | UbuntuWiki:CustomXSession | {{#if: | :}}定制X会话}}/es | • {{#if: UbuntuWiki:CustomXSession|español| [[::定制X会话/es|español]]}}|}} {{#ifexist: {{#if: UbuntuWiki:CustomXSession | UbuntuWiki:CustomXSession | {{#if: | :}}定制X会话}}/fa | • {{#if: UbuntuWiki:CustomXSession|فارسی| [[::定制X会话/fa|فارسی]]}}|}} {{#ifexist: {{#if: UbuntuWiki:CustomXSession | UbuntuWiki:CustomXSession | {{#if: | :}}定制X会话}}/fi | • {{#if: UbuntuWiki:CustomXSession|suomi| [[::定制X会话/fi|suomi]]}}|}} {{#ifexist: {{#if: UbuntuWiki:CustomXSession | UbuntuWiki:CustomXSession | {{#if: | :}}定制X会话}}/fr | • {{#if: UbuntuWiki:CustomXSession|français| [[::定制X会话/fr|français]]}}|}} {{#ifexist: {{#if: UbuntuWiki:CustomXSession | UbuntuWiki:CustomXSession | {{#if: | :}}定制X会话}}/gu | • {{#if: UbuntuWiki:CustomXSession|ગુજરાતી| [[::定制X会话/gu|ગુજરાતી]]}}|}} {{#ifexist: {{#if: UbuntuWiki:CustomXSession | UbuntuWiki:CustomXSession | {{#if: | :}}定制X会话}}/he | • {{#if: UbuntuWiki:CustomXSession|עברית| [[::定制X会话/he|עברית]]}}|}} {{#ifexist: {{#if: UbuntuWiki:CustomXSession | UbuntuWiki:CustomXSession | {{#if: | :}}定制X会话}}/hu | • {{#if: UbuntuWiki:CustomXSession|magyar| [[::定制X会话/hu|magyar]]}}|}} {{#ifexist: {{#if: UbuntuWiki:CustomXSession | UbuntuWiki:CustomXSession | {{#if: | :}}定制X会话}}/id | • {{#if: UbuntuWiki:CustomXSession|Bahasa Indonesia| [[::定制X会话/id|Bahasa Indonesia]]}}|}} {{#ifexist: {{#if: UbuntuWiki:CustomXSession | UbuntuWiki:CustomXSession | {{#if: | :}}定制X会话}}/it | • {{#if: UbuntuWiki:CustomXSession|italiano| [[::定制X会话/it|italiano]]}}|}} {{#ifexist: {{#if: UbuntuWiki:CustomXSession | UbuntuWiki:CustomXSession | {{#if: | :}}定制X会话}}/ja | • {{#if: UbuntuWiki:CustomXSession|日本語| [[::定制X会话/ja|日本語]]}}|}} {{#ifexist: {{#if: UbuntuWiki:CustomXSession | UbuntuWiki:CustomXSession | {{#if: | :}}定制X会话}}/ko | • {{#if: UbuntuWiki:CustomXSession|한국어| [[::定制X会话/ko|한국어]]}}|}} {{#ifexist: {{#if: UbuntuWiki:CustomXSession | UbuntuWiki:CustomXSession | {{#if: | :}}定制X会话}}/ksh | • {{#if: UbuntuWiki:CustomXSession|Ripoarisch| [[::定制X会话/ksh|Ripoarisch]]}}|}} {{#ifexist: {{#if: UbuntuWiki:CustomXSession | UbuntuWiki:CustomXSession | {{#if: | :}}定制X会话}}/mr | • {{#if: UbuntuWiki:CustomXSession|मराठी| [[::定制X会话/mr|मराठी]]}}|}} {{#ifexist: {{#if: UbuntuWiki:CustomXSession | UbuntuWiki:CustomXSession | {{#if: | :}}定制X会话}}/ms | • {{#if: UbuntuWiki:CustomXSession|Bahasa Melayu| [[::定制X会话/ms|Bahasa Melayu]]}}|}} {{#ifexist: {{#if: UbuntuWiki:CustomXSession | UbuntuWiki:CustomXSession | {{#if: | :}}定制X会话}}/nl | • {{#if: UbuntuWiki:CustomXSession|Nederlands| [[::定制X会话/nl|Nederlands]]}}|}} {{#ifexist: {{#if: UbuntuWiki:CustomXSession | UbuntuWiki:CustomXSession | {{#if: | :}}定制X会话}}/no | • {{#if: UbuntuWiki:CustomXSession|norsk| [[::定制X会话/no|norsk]]}}|}} {{#ifexist: {{#if: UbuntuWiki:CustomXSession | UbuntuWiki:CustomXSession | {{#if: | :}}定制X会话}}/oc | • {{#if: UbuntuWiki:CustomXSession|occitan| [[::定制X会话/oc|occitan]]}}|}} {{#ifexist: {{#if: UbuntuWiki:CustomXSession | UbuntuWiki:CustomXSession | {{#if: | :}}定制X会话}}/pl | • {{#if: UbuntuWiki:CustomXSession|polski| [[::定制X会话/pl|polski]]}}|}} {{#ifexist: {{#if: UbuntuWiki:CustomXSession | UbuntuWiki:CustomXSession | {{#if: | :}}定制X会话}}/pt | • {{#if: UbuntuWiki:CustomXSession|português| [[::定制X会话/pt|português]]}}|}} {{#ifexist: {{#if: UbuntuWiki:CustomXSession | UbuntuWiki:CustomXSession | {{#if: | :}}定制X会话}}/ro | • {{#if: UbuntuWiki:CustomXSession|română| [[::定制X会话/ro|română]]}}|}} {{#ifexist: {{#if: UbuntuWiki:CustomXSession | UbuntuWiki:CustomXSession | {{#if: | :}}定制X会话}}/ru | • {{#if: UbuntuWiki:CustomXSession|русский| [[::定制X会话/ru|русский]]}}|}} {{#ifexist: {{#if: UbuntuWiki:CustomXSession | UbuntuWiki:CustomXSession | {{#if: | :}}定制X会话}}/si | • {{#if: UbuntuWiki:CustomXSession|සිංහල| [[::定制X会话/si|සිංහල]]}}|}} {{#ifexist: {{#if: UbuntuWiki:CustomXSession | UbuntuWiki:CustomXSession | {{#if: | :}}定制X会话}}/sq | • {{#if: UbuntuWiki:CustomXSession|shqip| [[::定制X会话/sq|shqip]]}}|}} {{#ifexist: {{#if: UbuntuWiki:CustomXSession | UbuntuWiki:CustomXSession | {{#if: | :}}定制X会话}}/sr | • {{#if: UbuntuWiki:CustomXSession|српски / srpski| [[::定制X会话/sr|српски / srpski]]}}|}} {{#ifexist: {{#if: UbuntuWiki:CustomXSession | UbuntuWiki:CustomXSession | {{#if: | :}}定制X会话}}/sv | • {{#if: UbuntuWiki:CustomXSession|svenska| [[::定制X会话/sv|svenska]]}}|}} {{#ifexist: {{#if: UbuntuWiki:CustomXSession | UbuntuWiki:CustomXSession | {{#if: | :}}定制X会话}}/th | • {{#if: UbuntuWiki:CustomXSession|ไทย| [[::定制X会话/th|ไทย]]}}|}} {{#ifexist: {{#if: UbuntuWiki:CustomXSession | UbuntuWiki:CustomXSession | {{#if: | :}}定制X会话}}/tr | • {{#if: UbuntuWiki:CustomXSession|Türkçe| [[::定制X会话/tr|Türkçe]]}}|}} {{#ifexist: {{#if: UbuntuWiki:CustomXSession | UbuntuWiki:CustomXSession | {{#if: | :}}定制X会话}}/vi | • {{#if: UbuntuWiki:CustomXSession|Tiếng Việt| [[::定制X会话/vi|Tiếng Việt]]}}|}} {{#ifexist: {{#if: UbuntuWiki:CustomXSession | UbuntuWiki:CustomXSession | {{#if: | :}}定制X会话}}/yue | • {{#if: UbuntuWiki:CustomXSession|粵語| [[::定制X会话/yue|粵語]]}}|}} {{#ifexist: {{#if: UbuntuWiki:CustomXSession | UbuntuWiki:CustomXSession | {{#if: | :}}定制X会话}}/zh | • {{#if: UbuntuWiki:CustomXSession|中文| [[::定制X会话/zh|中文]]}}|}} {{#ifexist: {{#if: UbuntuWiki:CustomXSession | UbuntuWiki:CustomXSession | {{#if: | :}}定制X会话}}/zh-hans | • {{#if: UbuntuWiki:CustomXSession|中文(简体)| [[::定制X会话/zh-hans|中文(简体)]]}}|}} {{#ifexist: {{#if: UbuntuWiki:CustomXSession | UbuntuWiki:CustomXSession | {{#if: | :}}定制X会话}}/zh-hant | • {{#if: UbuntuWiki:CustomXSession|中文(繁體)| [[::定制X会话/zh-hant|中文(繁體)]]}}|}} |
{{#ifeq:UbuntuWiki:CustomXSession|:定制X会话|请不要直接编辑翻译本页,本页将定期与来源同步。}} |
{{#ifexist: :定制X会话/zh | | {{#ifexist: 定制X会话/zh | | {{#ifeq: {{#titleparts:定制X会话|1|-1|}} | zh | | }} }} }} {{#ifeq: {{#titleparts:定制X会话|1|-1|}} | zh | | }}
本页面将会教你如何通过编辑shell脚本设计出属于自己的个性化X(图形桌面)会话。桌面环境像GNOME通常有它们自己的会话管理器。这些会话管理器允许你设定在开始时会装载什么样附加程序,通过提供的一个图形界面。然而,知道如何去创建X会话脚本能允许你在定义你的桌面环境时有更大的灵活性,无论你使用GNOME、KDE、XFCE、Openbox,或任何少为人知的窗口管理器,像Blackbox或FVWM。此外,能够创建X会话允许你运行一个图形桌面即使图形登录管理器,GDM,损坏或者没有安装。
解剖一个简单的X会话脚本
最简单的X会话脚本由两行命令组成,就像下面展示的例子一样:
#!/usr/bin/env bash exec gnome-session
第一行和所有的Linux shell脚本一样;它指定运行该脚本要使用的shell。就上面展示的例子来说,bash(Bourne Again Shell)是被指定的shell。 第二行指定驱动X会话的应用程序。有时会称之为“magic process”,因为当该程序停止运行时X会话就会终结。在上面展示的例子里,“gnome-session”是“magic process”,它用于运行GNOME桌面环境。
如何创建一个X会话脚本
你不必拥有root权限去创建你自己的X会话脚本。 ⒈#1 从应用程序菜单里,选择附件,然后点击终端,从而打开一个终端。 ⒈#2 要想开始编辑你的脚本,就在提示符内输入下面的命令:
gedit ~/.xinitrc
现在你的屏幕上应该有了一个空的文本编辑器。你所做的所有动作都会保存至.xinitrc文件,隐藏于你的家目录。(注解:在Linux中,所有用点开头的文件都会被系统隐藏。) 1.#3 在第一行指定shell: 1.#3 Specify the shell on the first line:
#!/usr/bin/env bash
1.#4 输入任何你想在启动桌面环境或窗口管理器前运行的命令。一个命令一行,并在每行命令末尾加上&。在每行命令末尾加上"&"号将告诉shell让命令在后台运行,并且立即执行下一行命令。若命令不在后台运行,那么会让你的X会话脚本停滞于文件的第一行命令,因此你将会看到一个空的桌面。例如,如果你想要在登录之后显示一个终端,把这一行写入文件:
gnome-terminal &
1.#5 在末行键入exec,接着是要使用的窗口管理器或桌面环境的名字,就像下面的样例:
# 欲使用GNOME,使用这行命令 exec gnome-session # 欲使用KDE,用这行命令代替 exec startkde # 要注意如果你有两行"exec",X只会运行第一行,并忽略其他的。而且,所有用#开头的行 # 将被shell当作注解并忽略。这有利于在脚本中放置注解或禁用不想运行的命令。
1.#6 当你满足后,保存文件并退出文字编辑器。 1.#7 现在让你的X会话脚本可运行。在终端键入下面的命令以达到这一点:
chmod +x ~/.xinitrc
1.#8 现在你让脚本可运行了。你已经准备就绪,可以试运行了。想这样的话,保存所有可能打开的文档和关闭所有的应用程序。登出GNOME,按下CTRL+ALT+F1去访问字符控制台并登录。一旦你登录了,你必须临时禁用你的图形登录。这需要键入下面的命令:
sudo /etc/init.d/gdm stop
1.#9 Once you have done this, you will be ready to test your X session script. To test it, enter the following command:
startx
1.#10 If you have not mispelled the names of any commands, then you should have a graphical desktop. If not, then you will have to correct your script. The shell will tell give you the line number if a command fails to make fixing your script easier. To fix your script, you can either edit your file with nano:
nano -w
Or you can restart the graphical login manager with the following command, login, and perform steps 1 and 2:
sudo /etc/init.d/gdm start
Otherwise, log out of the graphical desktop you brought up with the startx command. 1.#11 Your login script, .xinitrc, works with startx, but graphical login managers like GDM do not look for .xinitrc. Instead, they look for a file named .xsession in your home directory. To make GDM run your .xinitrc script, you have to link it to .xsession with the following command:
ln -s ~/.xinitrc ~/.xsession
Using the above command creates a symbolic link named .xsession that points to .xinitrc. If you are familiar with Windows, it may help to think of a symbolic link (or symlink), as a kind of non-graphical shortcut. 1.#12 Once you have linked .xsession to .xinitrc, you are ready to make your graphical login manager run your custom environment instead of a default session. To do, begin by restarting the graphical login manager:
sudo /etc/init.d/gdm start
1.#13 Enter your user name, and then click on the Sessions button. The appearance of the Sessions button depends on whether you are using a themed greeter or not, and which greeter theme you are using. 1.#14 From the Sessions menu, select Default System Session. This will make GDM run your X session script instead of one of the predefined sessions. 1.#15 Enter your password. 1.#16 Once you have entered your password, GDM will notify you that you have chosen a session different from the default and ask you if you want to use the session you've chosen once, or make it the default. If you make your custom session the default, you can select a different session at your next login.
一个~/.xinitrc文件样例
下面是此HOWTO的作者,Stormy Eyes,在家中使用的.xinitrc文件。它利用非默认安装的应用程序,比如xcompmgr来合成特效还有feh来设置壁纸。如果你有任何关于这.xinitrc样例文件的问题,请在论坛里询问。
#!/usr/bin/env bash xcompmgr -fF -I-.002 -O-.003 -D1 & devilspie & sudo killall -9 esd sh ./.fehbg & xrdb -merge .Xdefaults & export OOO_FORCE_DESKTOP=gnome export LANG="en_US.UTF-8" export LC_ALL="en_US.UTF-8" export LANGUAGE="en_US.UTF-8" export LC_CTYPE="en_US.UTF-8" gnome-settings-daemon & gnome-volume-manager & conky & exec openbox
问题与意见
如果你有任何有关此教程的意见或问题,请将它们发送到论坛上。谢谢。