查看“定制X会话”的源代码
来自Ubuntu中文
←
定制X会话
跳到导航
跳到搜索
因为以下原因,您没有权限编辑该页面:
您请求的操作仅限属于该用户组的用户执行:
用户
您可以查看和复制此页面的源代码。
{{Translation}} {{From|https://wiki.ubuntu.com/CustomXSession}} {{Translator|Hjhee}} {{Languages|UbuntuWiki:CustomXSession}} 本页面将会教你如何通过编辑shell脚本设计出属于自己的个性化X(图形桌面)会话。桌面环境像[http://www.gnome.org GNOME]通常有它们自己的会话管理器。这些会话管理器允许你设定在开始时会装载什么样附加程序,通过提供的一个图形界面。然而,知道如何去创建X会话脚本能允许你在定义你的桌面环境时有更大的灵活性,无论你使用GNOME、[http://www.kde.org KDE]、[http://www.xfce.org XFCE]、[[UbuntuWiki:Openbox|Openbox]],或任何少为人知的窗口管理器,像[http://blackboxwm.sourceforge.net/ Blackbox]或[[UbuntuWiki:FVWM|FVWM]]。此外,能够创建X会话允许你运行一个图形桌面即使图形登录管理器,GDM,损坏或者没有安装。 === 解剖一个简单的X会话脚本 === 最简单的X会话脚本由两行命令组成,就像下面展示的例子一样: <pre><nowiki> #!/usr/bin/env bash exec gnome-session </nowiki></pre> 第一行和所有的Linux shell脚本一样;它指定运行该脚本要使用的shell。就上面展示的例子来说,bash(Bourne Again Shell)是被指定的shell。 第二行指定驱动X会话的应用程序。有时会称之为“magic process”,因为当该程序停止运行时X会话就会终结。在上面展示的例子里,“gnome-session”是“magic process”,它用于运行GNOME桌面环境。 === 如何创建一个X会话脚本 === 你不必拥有root权限去创建你自己的X会话脚本。 ⒈#1 从'''应用程序'''菜单里,选择'''附件''',然后点击'''终端''',从而打开一个终端。 ⒈#2 要想开始编辑你的脚本,就在提示符内输入下面的命令: <pre><nowiki> gedit ~/.xinitrc </nowiki></pre> You should now have an empty text editor window on your screen. Any changes you make will be saved to the file '''.xinitrc''', which will be hidden in your home directory. ('''Note:''' In Linux, all files that begin with a period are treated by the system as hidden files.) 1.#3 Specify the shell on the first line: <pre><nowiki> #!/usr/bin/env bash </nowiki></pre> 1.#4 Type in any commands you want to run before launching your desktop environment or window manager. Use one command per line, and place a '''&''' after each command. Placing an ampersand (&) after each command tells the shell to run the command in the ''background'' and move immediately to the next command. Not having commands run in the background will lead to your X session script getting stuck on the first command listed in the file, so that all you see is an empty desktop. For example, if you always want to have a terminal open when you first login, include a line that says: <pre><nowiki> gnome-terminal & </nowiki></pre> 1.#5 On the last line, type in the word '''exec''' and then the name of the window manager or desktop environment you want to use as shown in the example below: <pre><nowiki> # for GNOME, use this command exec gnome-session # for KDE, us this command instead. exec startkde # Note that if you have two "exec" lines, X will only process the first, and ignore all others. Also, any line # that begins with a # will be treated by the shell as a comment and ignored. Use this to your advantage # by placing notes in your script or disabling commands that you do not currently wish to run. </nowiki></pre> 1.#6 When you are satisfied, save your file and close the text editor. 1.#7 Now make your X session script executable. To do this, type the following command into your terminal: <pre><nowiki> chmod +x ~/.xinitrc </nowiki></pre> 1.#8 Now that you have made your X session script executable, you are ready to try it out. To do so, save all documents you might have open, and close all applications. Log out of GNOME. Press CTRL+ALT+F1 to access a text console, and login. Once you have logged in, you have to temporarily disable your graphical login. To do this, enter the command <pre><nowiki> sudo /etc/init.d/gdm stop </nowiki></pre> 1.#9 Once you have done this, you will be ready to test your X session script. To test it, enter the following command: <pre><nowiki> startx </nowiki></pre> 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: <pre><nowiki> nano -w </nowiki></pre> Or you can restart the graphical login manager with the following command, login, and perform steps 1 and 2: <pre><nowiki> sudo /etc/init.d/gdm start </nowiki></pre> 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: <pre><nowiki> ln -s ~/.xinitrc ~/.xsession </nowiki></pre> 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: <pre><nowiki> sudo /etc/init.d/gdm start </nowiki></pre> 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样例文件的问题,请在论坛里询问。 <pre><nowiki> #!/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 </nowiki></pre> === 问题与意见 === 如果你有任何有关此教程的意见或问题,请将它们发送到[http://ubuntuforums.org/showthread.php?p=427953 论坛]上。谢谢。 ---- [[category:CategoryDocumentation]] [[category:CategoryCleanup]] [[category:UbuntuWiki]]
该页面使用的模板:
模板:Copyedit translation
(
查看源代码
)
模板:From
(
查看源代码
)
模板:Languages
(
查看源代码
)(受保护)
模板:Languages/Lang
(
查看源代码
)(受保护)
模板:Translator
(
查看源代码
)
返回
定制X会话
。
导航菜单
页面操作
页面
讨论
阅读
查看源代码
历史
页面操作
页面
讨论
更多
工具
个人工具
登录
导航
首页
最近更改
随机页面
页面分类
帮助
搜索
编辑
编辑指南
沙盒
新闻动态
字词处理
工具
链入页面
相关更改
特殊页面
页面信息