<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>idv2 &#187; gnome</title>
	<atom:link href="http://tech.idv2.com/tag/gnome/feed/" rel="self" type="application/rss+xml" />
	<link>http://tech.idv2.com</link>
	<description>关注Web开发技术，关注Internet。</description>
	<lastBuildDate>Tue, 27 Jul 2010 12:54:54 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.5</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>使用Devil&#8217;s Pie自动化你的Gnome</title>
		<link>http://tech.idv2.com/2006/09/22/use-devilspie-to-automatic-your-gnome/</link>
		<comments>http://tech.idv2.com/2006/09/22/use-devilspie-to-automatic-your-gnome/#comments</comments>
		<pubDate>Thu, 21 Sep 2006 17:26:02 +0000</pubDate>
		<dc:creator>charlee</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[devilspie]]></category>
		<category><![CDATA[gnome]]></category>

		<guid isPermaLink="false">http://charlee.itbdns.com/tech/archive/131.html</guid>
		<description><![CDATA[<!-- begin Pukiwiki generated code--><p>我们知道，在KDE中可以通过窗口管理器方便地将窗口设置为总在最前、设置出现在所有工作区等，
但是Ubuntu 6.06的Gnome中无法做到这一点。Gnome所用的窗口管理器MetaCity认为这些不是窗口管理器的任务，
因此没有实现这些功能。好在Gnome的一名开发者为我们开发了 <a href="http://www.burtonini.com/blog/computers/devilspie">Devil's Pie</a>
这个程序，它能够根据预先设定的动作自动控制Gnome中的窗口。</p>
<!-- end Pukiwiki generated code--><span id="more-111"></span><!-- begin Pukiwiki generated code--><div class="contents">
<a id="contents_2"></a>
<ul class="list1" style="padding-left:16px;margin-left:16px"><li><a href="#content_2_0">  原理</a></li>
<li><a href="#content_2_1">  安装</a>
<ul class="list2" style="padding-left:16px;margin-left:16px"><li><a href="#content_2_2">  关于版本</a></li></ul></li>
<li><a href="#content_2_3">  入门</a></li>
<li><a href="#content_2_4">  命令参考</a>
<ul class="list2" style="padding-left:16px;margin-left:16px"><li><a href="#content_2_5">  流程控制</a>
<ul class="list3" style="padding-left:16px;margin-left:16px"><li><a href="#content_2_6">  if </a></li>
<li><a href="#content_2_7">  begin </a></li></ul></li>
<li><a href="#content_2_8">  逻辑运算</a>
<ul class="list3" style="padding-left:16px;margin-left:16px"><li><a href="#content_2_9">  and </a></li>
<li><a href="#content_2_10">  or </a></li>
<li><a href="#content_2_11">  not </a></li></ul></li>
<li><a href="#content_2_12">  字符串测试</a>
<ul class="list3" style="padding-left:16px;margin-left:16px"><li><a href="#content_2_13">  is </a></li>
<li><a href="#content_2_14">  contains </a></li>
<li><a href="#content_2_15">  matches </a></li></ul></li>
<li><a href="#content_2_16">  窗口变量</a>
<ul class="list3" style="padding-left:16px;margin-left:16px"><li><a href="#content_2_17">  window_name </a></li>
<li><a href="#content_2_18">  window_role </a></li>
<li><a href="#content_2_19">  application_name </a></li></ul></li>
<li><a href="#content_2_20">  动作</a>
<ul class="list3" style="padding-left:16px;margin-left:16px"><li><a href="#content_2_21">  debug </a></li>
<li><a href="#content_2_22">  print </a></li>
<li><a href="#content_2_23">  geometry </a></li>
<li><a href="#content_2_24">  fullscreen </a></li>
<li><a href="#content_2_25">  focus </a></li>
<li><a href="#content_2_26">  center </a></li>
<li><a href="#content_2_27">  maximize </a></li>
<li><a href="#content_2_28">  maximize_vertically </a></li>
<li><a href="#content_2_29">  maximize_horizontally </a></li>
<li><a href="#content_2_30">  minimize </a></li>
<li><a href="#content_2_31">  shade </a></li>
<li><a href="#content_2_32">  unshade </a></li>
<li><a href="#content_2_33">  close </a></li>
<li><a href="#content_2_34">  pin </a></li>
<li><a href="#content_2_35">  unpin </a></li>
<li><a href="#content_2_36">  set_workspace </a></li>
<li><a href="#content_2_37">  skip_pager </a></li>
<li><a href="#content_2_38">  skip_tasklist </a></li>
<li><a href="#content_2_39">  above </a></li>
<li><a href="#content_2_40">  below </a></li>
<li><a href="#content_2_41">  undecorate </a></li>
<li><a href="#content_2_42">  wintype </a></li></ul></li></ul></li>
<li><a href="#content_2_43">  FAQ </a>
<ul class="list2" style="padding-left:16px;margin-left:16px"><li><a href="#content_2_44">  为什么我的脚本不起作用？</a></li>
<li><a href="#content_2_45">  如何确定一个窗口的 window_name、application_name、window_role？</a></li>
<li><a href="#content_2_46">  为什么我的配置文件中，第二条以后的命令都不能执行？</a></li>
<li><a href="#content_2_47">  如何在 vim 中使用语法高亮显示？</a></li>
<li><a href="#content_2_48">  如何终止正在执行中的 Devil's Pie？</a></li></ul></li>
<li><a href="#content_2_49">  参考</a></li></ul>
</div>

<hr class="full_hr" />
<h2 id="content_2_0">原理</h2>
<p>Devil's Pie启动之后会监视新窗口的建立，如果新建的窗口满足指定的条件则按照预定的动作设置该窗口的属性。
例如，如果设置“标题为GVIM的窗口最大化”这样的条件，那么gvim启动时就会被 Devil's Pie 检测到并被最大话。</p>
<p>Devil's Pie的配置文件为 /etc/devilspie 和 ~/.devilspie/*.ds。每当有窗口启动时，Devil's Pie会针对此窗口
执行所有的配置文件，遇到匹配的条件则对此窗口执行相应的动作。</p>

<h2 id="content_2_1">安装</h2>
<p>Ubuntu 6.06 下安装很简单：</p>
<pre>$ sudo apt-get install devilspie</pre>
<p>若需要从源代码编译，可以从<a href="http://www.burtonini.com/blog/computers/devilspie">官方主页</a>下载最新版。</p>

<h3 id="content_2_2">关于版本</h3>
<p>Ubuntu 6.06 自带的版本是 0.16，以下教程都以该版本为准。0.12之前的版本使用 XML 配置文件，
而0.13之后的版本使用一种类似于 LISP 的语言―――― <strong>S-expression</strong>作为配置文件，
其扩展名为 .ds。</p>
<p>最新版本是 0.17（2006/09/22时的情况），如果你想使用最新版，可以自己编译。</p>

<h2 id="content_2_3">入门</h2>
<p>假设我们要让 Firefox 在 2 号桌面启动。
我们在自己的主目录下建立 .devilspie 目录，并创建一个名为 firefox.ds 的文件。</p>
<pre>$ cd ~
$ mkdir .devilspie
$ gedit .devilspie/firefox.ds</pre>
<p>然后输入以下的内容并保存，注意大小写。</p>
<pre>(if 
  (contains (window_name) &quot;Mozilla Firefox&quot;)
  (set_workspace 2)
)</pre>
<p>然后从终端中输入以下命令：</p>
<pre>$ devilspie</pre>
<p>之后启动 Firefox，你会发现 Firefox 被移动到了2号工作区。</p>
<p>（如果不能正常工作，请参考 [[FAQ篇&gt;#faq]]。）</p>
<p>我们当然不能每次都手动启动 Devil's Pie，因此要将其加入到自动启动中。选择
主菜单中的<strong>系统-&gt;首选项-&gt;会话</strong>，然后选择<strong>启动程序</strong>拦，单击<strong>添加</strong>，
输入启动命令为<strong>devilspie</strong>，确定。下次登录时系统会自动启动 Devil's Pie 了。</p>

<h2 id="content_2_4">命令参考</h2>

<h3 id="content_2_5">流程控制</h3>

<h4 id="content_2_6">if  <a class="anchor_super" id="if" href="?#if" title="if"></a></h4>
<p>条件判断命令，相当于 C语言的 if 语句。</p>
<p><strong>格式</strong></p>
<pre>(if a b)        - 如果满足条件 a，则执行b。
(if a b c)      - 如果满足条件 a，则执行b，否则执行c。</pre>
<p><strong>使用例</strong></p>
<pre>(if (contains (window_name) &quot;Firefox&quot;) (set_workspace 2))
如果窗口名匹配字符串&quot;Firefox&quot;，则将该窗口移动到2号工作区。</pre>

<h4 id="content_2_7">begin  <a class="anchor_super" id="begin" href="?#begin" title="begin"></a></h4>
<p>连续执行一连串的动作，相当于C语言的程序块。</p>
<p><strong>格式</strong></p>
<pre>(begin a b c ...)    - 连续执行 a、b、c……</pre>
<p><strong>使用例</strong></p>
<pre>(if (contains (window_name) &quot;Firefox&quot;) (begin (set_workspace 2) (maximize)))
如果窗口名匹配字符串&quot;Firefox&quot;，则将该窗口移动到2号工作区，然后将其最大化。</pre>

<h3 id="content_2_8">逻辑运算</h3>

<h4 id="content_2_9">and  <a class="anchor_super" id="and" href="?#and" title="and"></a></h4>
<p>当两个条件均为真时返回真；只要有一个条件为假，则返回假。相当于 C 语言的 &amp;&amp; 运算符。</p>
<p><strong>格式</strong></p>
<pre>(and a b)      - 如果条件 a 和 b 均为真，则全体的值为真</pre>

<h4 id="content_2_10">or  <a class="anchor_super" id="or" href="?#or" title="or"></a></h4>
<p>当两个条件有一个为真，则返回真，两个均为假时返回假。相当于 C 语言的 || 运算符。</p>
<p><strong>格式</strong></p>
<pre>(or a b)      - 只要条件 a 和 b 有一个为真，则全体的值为真 </pre>

<h4 id="content_2_11">not  <a class="anchor_super" id="not" href="?#not" title="not"></a></h4>
<p>返回与给定条件相反的真假值，相当于 C 语言的 ! 运算符。</p>
<p><strong>格式</strong></p>
<pre>(not a)      - 若 a 为真，则返回假；若 a 为假，则返回真</pre>

<h3 id="content_2_12">字符串测试</h3>

<h4 id="content_2_13">is  <a class="anchor_super" id="is" href="?#is" title="is"></a></h4>
<p>当给定两个字符串完全相等时返回真，否则返回假。相当于 C 语言的 strcmp 函数。</p>
<p><strong>格式</strong></p>
<pre>(is &quot;foo&quot; &quot;foo&quot;)      - 返回真
(is &quot;foo&quot; &quot;bar&quot;)      - 返回假</pre>

<h4 id="content_2_14">contains  <a class="anchor_super" id="contains" href="?#contains" title="contains"></a></h4>
<p>给定两个字符串，若前者包含后者（即后者是前者的子字符串），则返回真，否则返回假。</p>
<p><strong>格式</strong></p>
<pre>(contains haystack needle)   - 若 haystack 包含 needle 则返回真</pre>
<p><strong>使用例</strong></p>
<pre>(if (contains (window_name) &quot;Firefox&quot;) (set_workspace 2))
如果窗口名称包含字符串 &quot;Firefox&quot; 则将窗口移动到2号工作区。</pre>

<h4 id="content_2_15">matches  <a class="anchor_super" id="matches" href="?#matches" title="matches"></a></h4>
<p>给定一个字符串和一个正规表达式，如果字符串匹配正规表达式则返回真，否则返回假。</p>
<p><strong>格式</strong></p>
<pre>(matches str pattern)      - 若 str 匹配 pattern 则返回真</pre>
<p><strong>使用例</strong></p>
<pre>(if (matches (window_name) &quot;Firefox$&quot;) (set_workspace 2))
当窗口名称的末尾是 &quot;Firefox&quot; 时将其移动到2号工作区。
(matches “foobar” “[o]{2}b”) - 真
(matches “foobar” “[0-9]+”) - 假</pre>

<h3 id="content_2_16">窗口变量</h3>
<p>窗口变量返回对象窗口的某种属性。</p>

<h4 id="content_2_17">window_name  <a class="anchor_super" id="window_name" href="?#window_name" title="window_name"></a></h4>
<p>返回窗口名称，即窗口标题栏上显示的文字。</p>
<p><strong>格式</strong></p>
<pre>(window_name)</pre>

<h4 id="content_2_18">window_role  <a class="anchor_super" id="window_role" href="?#window_role" title="window_role"></a></h4>
<p>返回窗口角色名，该属性由窗口内部的 WM_WINDOW_ROLE 变量定义。</p>
<p><strong>格式</strong></p>
<pre>(window_role)</pre>

<h4 id="content_2_19">application_name  <a class="anchor_super" id="application_name" href="?#application_name" title="application_name"></a></h4>
<p>返回应用程序名。</p>
<p><strong>格式</strong></p>
<pre>(application_name)</pre>

<h3 id="content_2_20">动作</h3>
<p>指定针对对象窗口进行的操作，大部分为修改窗口属性。</p>

<h4 id="content_2_21">debug  <a class="anchor_super" id="debug" href="?#debug" title="debug"></a></h4>
<p>输出调试信息，包括配置文件的读取、执行的窗口动作等。相当于命令行选项 -d。</p>
<p><strong>格式</strong></p>
<pre>(debug)</pre>

<h4 id="content_2_22">print  <a class="anchor_super" id="print" href="?#print" title="print"></a></h4>
<p>输出指定的字符串，一般用作调试。</p>
<p><strong>格式</strong></p>
<pre>(print text)</pre>
<p><strong>使用例</strong></p>
<pre>(print (application_name))
输出对象窗口的应用程序名称。</pre>

<h4 id="content_2_23">geometry  <a class="anchor_super" id="geometry" href="?#geometry" title="geometry"></a></h4>
<p>设置窗口位置。给定的字符串必须是一个合法的位置指定字符串。该字符串的格式如下：</p>
<pre>[=][&lt;width&gt;{xX}&lt;height&gt;][{+-}&lt;xoffset&gt;{+-}&lt;yoffset&gt;]</pre>
<p>详细说明可参考 man XParseGeometry 文档。</p>
<p><strong>格式</strong></p>
<pre>(geometry geo)     - 用字符串 geo 设置窗口位置。</pre>
<p><strong>应用例</strong></p>
<pre>(geometry &quot;400×300+0-22&quot;)
(geometry &quot;640×480&quot;)
(geometry &quot;+10+10&quot;)</pre>

<h4 id="content_2_24">fullscreen  <a class="anchor_super" id="fullscreen" href="?#fullscreen" title="fullscreen"></a></h4>
<p>设置窗口为全屏显示。</p>
<p><strong>格式</strong></p>
<pre>(fullscreen)</pre>

<h4 id="content_2_25">focus  <a class="anchor_super" id="focus" href="?#focus" title="focus"></a></h4>
<p>设置对象窗口为活动窗口。</p>
<p><strong>格式</strong></p>
<pre>(focus)</pre>

<h4 id="content_2_26">center  <a class="anchor_super" id="center" href="?#center" title="center"></a></h4>
<p>将对象窗口移动到屏幕正中央。</p>
<p><strong>格式</strong></p>
<pre>(center)</pre>

<h4 id="content_2_27">maximize  <a class="anchor_super" id="maximize" href="?#maximize" title="maximize"></a></h4>
<p>将对象窗口最大化。</p>
<p><strong>格式</strong></p>
<pre>(maximize)</pre>

<h4 id="content_2_28">maximize_vertically  <a class="anchor_super" id="maximize_vertically" href="?#maximize_vertically" title="maximize_vertically"></a></h4>
<pre>将对象窗口在垂直方向上最大化。</pre>
<p><strong>格式</strong></p>
<pre>(maximize_vertically)</pre>

<h4 id="content_2_29">maximize_horizontally  <a class="anchor_super" id="maximize_horizontally" href="?#maximize_horizontally" title="maximize_horizontally"></a></h4>
<pre>将对象窗口在水平方向上最大化。</pre>
<p><strong>格式</strong></p>
<pre>(maximize_horizontally)</pre>

<h4 id="content_2_30">minimize  <a class="anchor_super" id="minimize" href="?#minimize" title="minimize"></a></h4>
<p>将对象窗口最小化。</p>
<p><strong>格式</strong></p>
<pre>(minimize)</pre>

<h4 id="content_2_31">shade  <a class="anchor_super" id="shade" href="?#shade" title="shade"></a></h4>
<p><strong>格式</strong></p>
<pre>(shade)</pre>

<h4 id="content_2_32">unshade  <a class="anchor_super" id="unshade" href="?#unshade" title="unshade"></a></h4>
<p><strong>格式</strong></p>
<pre>(unshade)</pre>

<h4 id="content_2_33">close  <a class="anchor_super" id="close" href="?#close" title="close"></a></h4>
<p>关闭对象窗口。</p>
<p><strong>格式</strong></p>
<pre>(close)</pre>

<h4 id="content_2_34">pin  <a class="anchor_super" id="pin" href="?#pin" title="pin"></a></h4>
<p>将对象窗口固定在所有的工作区上。</p>
<p><strong>格式</strong></p>
<pre>(pin)</pre>

<h4 id="content_2_35">unpin  <a class="anchor_super" id="unpin" href="?#unpin" title="unpin"></a></h4>
<p>解除对象窗口的 pin 状态。</p>

<h4 id="content_2_36">set_workspace  <a class="anchor_super" id="set_workspace" href="?#set_workspace" title="set_workspace"></a></h4>
<p>将窗口移动到指定的工作区上。</p>
<p><strong>格式</strong></p>
<pre>(set_workspace num)</pre>
<p><strong>使用例</strong></p>
<pre>(set_workspace 1)</pre>

<h4 id="content_2_37">skip_pager  <a class="anchor_super" id="skip_pager" href="?#skip_pager" title="skip_pager"></a></h4>
<p><strong>格式</strong></p>
<pre>(skip_pager)</pre>

<h4 id="content_2_38">skip_tasklist  <a class="anchor_super" id="skip_tasklist" href="?#skip_tasklist" title="skip_tasklist"></a></h4>
<p><strong>格式</strong></p>
<pre>(skip_tasklist)</pre>

<h4 id="content_2_39">above  <a class="anchor_super" id="above" href="?#above" title="above"></a></h4>
<p>使对象窗口总在最前。</p>
<p><strong>格式</strong></p>
<pre>(above)</pre>

<h4 id="content_2_40">below  <a class="anchor_super" id="below" href="?#below" title="below"></a></h4>
<p>使对象窗口总在最底层。</p>
<p><strong>格式</strong></p>
<pre>(below)</pre>

<h4 id="content_2_41">undecorate  <a class="anchor_super" id="undecorate" href="?#undecorate" title="undecorate"></a></h4>
<p>删除对象窗口上的所有窗口修饰。</p>
<p><strong>格式</strong></p>
<pre>(undecorate)</pre>

<h4 id="content_2_42">wintype  <a class="anchor_super" id="wintype" href="?#wintype" title="wintype"></a></h4>
<p>设置窗口类型。窗口类型可以是以下字符串：&quot;normal&quot;, &quot;dialog&quot;, &quot;menu&quot;, &quot;toolbar&quot;, &quot;splashscreen&quot;, &quot;utility&quot;, &quot;dock&quot;, &quot;desktop&quot;。</p>
<p><strong>格式</strong></p>
<pre>(wintype type)</pre>
<p><strong>使用例</strong></p>
<pre>(wintype &quot;normal&quot;)</pre>

<h2 id="content_2_43">FAQ  <a class="anchor_super" id="faq" href="?#faq" title="faq"></a></h2>

<h3 id="content_2_44">为什么我的脚本不起作用？</h3>
<p>很有可能你的 window_name、application_name 等匹配字符串设置不正确。
首先确定对象窗口的正确的 window_name、application_name 之后再修改配置文件。</p>

<h3 id="content_2_45">如何确定一个窗口的 window_name、application_name、window_role？</h3>
<p>最简单的方法就是使用 print 动作输出 window_name 等变量。在 .devilspie 目录下建立
window_name.ds、application_name.ds、window_role.ds 三个文件，内容分别如下：</p>
<p><strong>window_name.ds</strong></p>
<pre>(print (window_name))</pre>
<p><strong>application_name.ds</strong></p>
<pre>(print (application_name)))</pre>
<p><strong>window_role.ds</strong></p>
<pre>(print (window_role))</pre>
<p>然后从命令行运行 Devil's Pie，再打开对象窗口，查看终端的输出结果。</p>

<h3 id="content_2_46">为什么我的配置文件中，第二条以后的命令都不能执行？</h3>
<p>这是 Devil's Pie 的一个bug，每一个 .ds 文件只有第一个命令（第一对括号内的内容）才能被执行。
因此，你无法把所有配置都写到一个文件中，而只能为每一条配置建立一个单独的配置文件。</p>

<h3 id="content_2_47">如何在 vim 中使用语法高亮显示？</h3>
<p>Devil's Pie 的配置文件语法与 LISP 相同，因此你可以在 vim 中使用下面的命令来设置语法高亮。</p>
<pre>:set syntax=lisp</pre>

<h3 id="content_2_48">如何终止正在执行中的 Devil's Pie？</h3>
<pre>$ killall devilspie</pre>

<h2 id="content_2_49">参考</h2>
<p>本文参考了以下网站，在此表示感谢。</p>
<ul class="list1" style="padding-left:16px;margin-left:16px"><li><a href="http://wiki.foosel.net/linux/devilspie">linux:devilspie</a></li>
<li><a href="http://live.gnome.org/DevilsPie">DevilsPie - GNOME Live!</a></li></ul>
<!-- end Pukiwiki generated code-->
]]></description>
			<content:encoded><![CDATA[<!-- begin Pukiwiki generated code--><p>我们知道，在KDE中可以通过窗口管理器方便地将窗口设置为总在最前、设置出现在所有工作区等，
但是Ubuntu 6.06的Gnome中无法做到这一点。Gnome所用的窗口管理器MetaCity认为这些不是窗口管理器的任务，
因此没有实现这些功能。好在Gnome的一名开发者为我们开发了 <a href="http://www.burtonini.com/blog/computers/devilspie">Devil's Pie</a>
这个程序，它能够根据预先设定的动作自动控制Gnome中的窗口。</p>
<!-- end Pukiwiki generated code--><span id="more-111"></span><!-- begin Pukiwiki generated code--><div class="contents">
<a id="contents_4"></a>
<ul class="list1" style="padding-left:16px;margin-left:16px"><li><a href="#content_4_0">  原理</a></li>
<li><a href="#content_4_1">  安装</a>
<ul class="list2" style="padding-left:16px;margin-left:16px"><li><a href="#content_4_2">  关于版本</a></li></ul></li>
<li><a href="#content_4_3">  入门</a></li>
<li><a href="#content_4_4">  命令参考</a>
<ul class="list2" style="padding-left:16px;margin-left:16px"><li><a href="#content_4_5">  流程控制</a>
<ul class="list3" style="padding-left:16px;margin-left:16px"><li><a href="#content_4_6">  if </a></li>
<li><a href="#content_4_7">  begin </a></li></ul></li>
<li><a href="#content_4_8">  逻辑运算</a>
<ul class="list3" style="padding-left:16px;margin-left:16px"><li><a href="#content_4_9">  and </a></li>
<li><a href="#content_4_10">  or </a></li>
<li><a href="#content_4_11">  not </a></li></ul></li>
<li><a href="#content_4_12">  字符串测试</a>
<ul class="list3" style="padding-left:16px;margin-left:16px"><li><a href="#content_4_13">  is </a></li>
<li><a href="#content_4_14">  contains </a></li>
<li><a href="#content_4_15">  matches </a></li></ul></li>
<li><a href="#content_4_16">  窗口变量</a>
<ul class="list3" style="padding-left:16px;margin-left:16px"><li><a href="#content_4_17">  window_name </a></li>
<li><a href="#content_4_18">  window_role </a></li>
<li><a href="#content_4_19">  application_name </a></li></ul></li>
<li><a href="#content_4_20">  动作</a>
<ul class="list3" style="padding-left:16px;margin-left:16px"><li><a href="#content_4_21">  debug </a></li>
<li><a href="#content_4_22">  print </a></li>
<li><a href="#content_4_23">  geometry </a></li>
<li><a href="#content_4_24">  fullscreen </a></li>
<li><a href="#content_4_25">  focus </a></li>
<li><a href="#content_4_26">  center </a></li>
<li><a href="#content_4_27">  maximize </a></li>
<li><a href="#content_4_28">  maximize_vertically </a></li>
<li><a href="#content_4_29">  maximize_horizontally </a></li>
<li><a href="#content_4_30">  minimize </a></li>
<li><a href="#content_4_31">  shade </a></li>
<li><a href="#content_4_32">  unshade </a></li>
<li><a href="#content_4_33">  close </a></li>
<li><a href="#content_4_34">  pin </a></li>
<li><a href="#content_4_35">  unpin </a></li>
<li><a href="#content_4_36">  set_workspace </a></li>
<li><a href="#content_4_37">  skip_pager </a></li>
<li><a href="#content_4_38">  skip_tasklist </a></li>
<li><a href="#content_4_39">  above </a></li>
<li><a href="#content_4_40">  below </a></li>
<li><a href="#content_4_41">  undecorate </a></li>
<li><a href="#content_4_42">  wintype </a></li></ul></li></ul></li>
<li><a href="#content_4_43">  FAQ </a>
<ul class="list2" style="padding-left:16px;margin-left:16px"><li><a href="#content_4_44">  为什么我的脚本不起作用？</a></li>
<li><a href="#content_4_45">  如何确定一个窗口的 window_name、application_name、window_role？</a></li>
<li><a href="#content_4_46">  为什么我的配置文件中，第二条以后的命令都不能执行？</a></li>
<li><a href="#content_4_47">  如何在 vim 中使用语法高亮显示？</a></li>
<li><a href="#content_4_48">  如何终止正在执行中的 Devil's Pie？</a></li></ul></li>
<li><a href="#content_4_49">  参考</a></li></ul>
</div>

<hr class="full_hr" />
<h2 id="content_4_0">原理</h2>
<p>Devil's Pie启动之后会监视新窗口的建立，如果新建的窗口满足指定的条件则按照预定的动作设置该窗口的属性。
例如，如果设置“标题为GVIM的窗口最大化”这样的条件，那么gvim启动时就会被 Devil's Pie 检测到并被最大话。</p>
<p>Devil's Pie的配置文件为 /etc/devilspie 和 ~/.devilspie/*.ds。每当有窗口启动时，Devil's Pie会针对此窗口
执行所有的配置文件，遇到匹配的条件则对此窗口执行相应的动作。</p>

<h2 id="content_4_1">安装</h2>
<p>Ubuntu 6.06 下安装很简单：</p>
<pre>$ sudo apt-get install devilspie</pre>
<p>若需要从源代码编译，可以从<a href="http://www.burtonini.com/blog/computers/devilspie">官方主页</a>下载最新版。</p>

<h3 id="content_4_2">关于版本</h3>
<p>Ubuntu 6.06 自带的版本是 0.16，以下教程都以该版本为准。0.12之前的版本使用 XML 配置文件，
而0.13之后的版本使用一种类似于 LISP 的语言―――― <strong>S-expression</strong>作为配置文件，
其扩展名为 .ds。</p>
<p>最新版本是 0.17（2006/09/22时的情况），如果你想使用最新版，可以自己编译。</p>

<h2 id="content_4_3">入门</h2>
<p>假设我们要让 Firefox 在 2 号桌面启动。
我们在自己的主目录下建立 .devilspie 目录，并创建一个名为 firefox.ds 的文件。</p>
<pre>$ cd ~
$ mkdir .devilspie
$ gedit .devilspie/firefox.ds</pre>
<p>然后输入以下的内容并保存，注意大小写。</p>
<pre>(if 
  (contains (window_name) &quot;Mozilla Firefox&quot;)
  (set_workspace 2)
)</pre>
<p>然后从终端中输入以下命令：</p>
<pre>$ devilspie</pre>
<p>之后启动 Firefox，你会发现 Firefox 被移动到了2号工作区。</p>
<p>（如果不能正常工作，请参考 [[FAQ篇&gt;#faq]]。）</p>
<p>我们当然不能每次都手动启动 Devil's Pie，因此要将其加入到自动启动中。选择
主菜单中的<strong>系统-&gt;首选项-&gt;会话</strong>，然后选择<strong>启动程序</strong>拦，单击<strong>添加</strong>，
输入启动命令为<strong>devilspie</strong>，确定。下次登录时系统会自动启动 Devil's Pie 了。</p>

<h2 id="content_4_4">命令参考</h2>

<h3 id="content_4_5">流程控制</h3>

<h4 id="content_4_6">if  <a class="anchor_super" id="if" href="?#if" title="if"></a></h4>
<p>条件判断命令，相当于 C语言的 if 语句。</p>
<p><strong>格式</strong></p>
<pre>(if a b)        - 如果满足条件 a，则执行b。
(if a b c)      - 如果满足条件 a，则执行b，否则执行c。</pre>
<p><strong>使用例</strong></p>
<pre>(if (contains (window_name) &quot;Firefox&quot;) (set_workspace 2))
如果窗口名匹配字符串&quot;Firefox&quot;，则将该窗口移动到2号工作区。</pre>

<h4 id="content_4_7">begin  <a class="anchor_super" id="begin" href="?#begin" title="begin"></a></h4>
<p>连续执行一连串的动作，相当于C语言的程序块。</p>
<p><strong>格式</strong></p>
<pre>(begin a b c ...)    - 连续执行 a、b、c……</pre>
<p><strong>使用例</strong></p>
<pre>(if (contains (window_name) &quot;Firefox&quot;) (begin (set_workspace 2) (maximize)))
如果窗口名匹配字符串&quot;Firefox&quot;，则将该窗口移动到2号工作区，然后将其最大化。</pre>

<h3 id="content_4_8">逻辑运算</h3>

<h4 id="content_4_9">and  <a class="anchor_super" id="and" href="?#and" title="and"></a></h4>
<p>当两个条件均为真时返回真；只要有一个条件为假，则返回假。相当于 C 语言的 &amp;&amp; 运算符。</p>
<p><strong>格式</strong></p>
<pre>(and a b)      - 如果条件 a 和 b 均为真，则全体的值为真</pre>

<h4 id="content_4_10">or  <a class="anchor_super" id="or" href="?#or" title="or"></a></h4>
<p>当两个条件有一个为真，则返回真，两个均为假时返回假。相当于 C 语言的 || 运算符。</p>
<p><strong>格式</strong></p>
<pre>(or a b)      - 只要条件 a 和 b 有一个为真，则全体的值为真 </pre>

<h4 id="content_4_11">not  <a class="anchor_super" id="not" href="?#not" title="not"></a></h4>
<p>返回与给定条件相反的真假值，相当于 C 语言的 ! 运算符。</p>
<p><strong>格式</strong></p>
<pre>(not a)      - 若 a 为真，则返回假；若 a 为假，则返回真</pre>

<h3 id="content_4_12">字符串测试</h3>

<h4 id="content_4_13">is  <a class="anchor_super" id="is" href="?#is" title="is"></a></h4>
<p>当给定两个字符串完全相等时返回真，否则返回假。相当于 C 语言的 strcmp 函数。</p>
<p><strong>格式</strong></p>
<pre>(is &quot;foo&quot; &quot;foo&quot;)      - 返回真
(is &quot;foo&quot; &quot;bar&quot;)      - 返回假</pre>

<h4 id="content_4_14">contains  <a class="anchor_super" id="contains" href="?#contains" title="contains"></a></h4>
<p>给定两个字符串，若前者包含后者（即后者是前者的子字符串），则返回真，否则返回假。</p>
<p><strong>格式</strong></p>
<pre>(contains haystack needle)   - 若 haystack 包含 needle 则返回真</pre>
<p><strong>使用例</strong></p>
<pre>(if (contains (window_name) &quot;Firefox&quot;) (set_workspace 2))
如果窗口名称包含字符串 &quot;Firefox&quot; 则将窗口移动到2号工作区。</pre>

<h4 id="content_4_15">matches  <a class="anchor_super" id="matches" href="?#matches" title="matches"></a></h4>
<p>给定一个字符串和一个正规表达式，如果字符串匹配正规表达式则返回真，否则返回假。</p>
<p><strong>格式</strong></p>
<pre>(matches str pattern)      - 若 str 匹配 pattern 则返回真</pre>
<p><strong>使用例</strong></p>
<pre>(if (matches (window_name) &quot;Firefox$&quot;) (set_workspace 2))
当窗口名称的末尾是 &quot;Firefox&quot; 时将其移动到2号工作区。
(matches “foobar” “[o]{2}b”) - 真
(matches “foobar” “[0-9]+”) - 假</pre>

<h3 id="content_4_16">窗口变量</h3>
<p>窗口变量返回对象窗口的某种属性。</p>

<h4 id="content_4_17">window_name  <a class="anchor_super" id="window_name" href="?#window_name" title="window_name"></a></h4>
<p>返回窗口名称，即窗口标题栏上显示的文字。</p>
<p><strong>格式</strong></p>
<pre>(window_name)</pre>

<h4 id="content_4_18">window_role  <a class="anchor_super" id="window_role" href="?#window_role" title="window_role"></a></h4>
<p>返回窗口角色名，该属性由窗口内部的 WM_WINDOW_ROLE 变量定义。</p>
<p><strong>格式</strong></p>
<pre>(window_role)</pre>

<h4 id="content_4_19">application_name  <a class="anchor_super" id="application_name" href="?#application_name" title="application_name"></a></h4>
<p>返回应用程序名。</p>
<p><strong>格式</strong></p>
<pre>(application_name)</pre>

<h3 id="content_4_20">动作</h3>
<p>指定针对对象窗口进行的操作，大部分为修改窗口属性。</p>

<h4 id="content_4_21">debug  <a class="anchor_super" id="debug" href="?#debug" title="debug"></a></h4>
<p>输出调试信息，包括配置文件的读取、执行的窗口动作等。相当于命令行选项 -d。</p>
<p><strong>格式</strong></p>
<pre>(debug)</pre>

<h4 id="content_4_22">print  <a class="anchor_super" id="print" href="?#print" title="print"></a></h4>
<p>输出指定的字符串，一般用作调试。</p>
<p><strong>格式</strong></p>
<pre>(print text)</pre>
<p><strong>使用例</strong></p>
<pre>(print (application_name))
输出对象窗口的应用程序名称。</pre>

<h4 id="content_4_23">geometry  <a class="anchor_super" id="geometry" href="?#geometry" title="geometry"></a></h4>
<p>设置窗口位置。给定的字符串必须是一个合法的位置指定字符串。该字符串的格式如下：</p>
<pre>[=][&lt;width&gt;{xX}&lt;height&gt;][{+-}&lt;xoffset&gt;{+-}&lt;yoffset&gt;]</pre>
<p>详细说明可参考 man XParseGeometry 文档。</p>
<p><strong>格式</strong></p>
<pre>(geometry geo)     - 用字符串 geo 设置窗口位置。</pre>
<p><strong>应用例</strong></p>
<pre>(geometry &quot;400×300+0-22&quot;)
(geometry &quot;640×480&quot;)
(geometry &quot;+10+10&quot;)</pre>

<h4 id="content_4_24">fullscreen  <a class="anchor_super" id="fullscreen" href="?#fullscreen" title="fullscreen"></a></h4>
<p>设置窗口为全屏显示。</p>
<p><strong>格式</strong></p>
<pre>(fullscreen)</pre>

<h4 id="content_4_25">focus  <a class="anchor_super" id="focus" href="?#focus" title="focus"></a></h4>
<p>设置对象窗口为活动窗口。</p>
<p><strong>格式</strong></p>
<pre>(focus)</pre>

<h4 id="content_4_26">center  <a class="anchor_super" id="center" href="?#center" title="center"></a></h4>
<p>将对象窗口移动到屏幕正中央。</p>
<p><strong>格式</strong></p>
<pre>(center)</pre>

<h4 id="content_4_27">maximize  <a class="anchor_super" id="maximize" href="?#maximize" title="maximize"></a></h4>
<p>将对象窗口最大化。</p>
<p><strong>格式</strong></p>
<pre>(maximize)</pre>

<h4 id="content_4_28">maximize_vertically  <a class="anchor_super" id="maximize_vertically" href="?#maximize_vertically" title="maximize_vertically"></a></h4>
<pre>将对象窗口在垂直方向上最大化。</pre>
<p><strong>格式</strong></p>
<pre>(maximize_vertically)</pre>

<h4 id="content_4_29">maximize_horizontally  <a class="anchor_super" id="maximize_horizontally" href="?#maximize_horizontally" title="maximize_horizontally"></a></h4>
<pre>将对象窗口在水平方向上最大化。</pre>
<p><strong>格式</strong></p>
<pre>(maximize_horizontally)</pre>

<h4 id="content_4_30">minimize  <a class="anchor_super" id="minimize" href="?#minimize" title="minimize"></a></h4>
<p>将对象窗口最小化。</p>
<p><strong>格式</strong></p>
<pre>(minimize)</pre>

<h4 id="content_4_31">shade  <a class="anchor_super" id="shade" href="?#shade" title="shade"></a></h4>
<p><strong>格式</strong></p>
<pre>(shade)</pre>

<h4 id="content_4_32">unshade  <a class="anchor_super" id="unshade" href="?#unshade" title="unshade"></a></h4>
<p><strong>格式</strong></p>
<pre>(unshade)</pre>

<h4 id="content_4_33">close  <a class="anchor_super" id="close" href="?#close" title="close"></a></h4>
<p>关闭对象窗口。</p>
<p><strong>格式</strong></p>
<pre>(close)</pre>

<h4 id="content_4_34">pin  <a class="anchor_super" id="pin" href="?#pin" title="pin"></a></h4>
<p>将对象窗口固定在所有的工作区上。</p>
<p><strong>格式</strong></p>
<pre>(pin)</pre>

<h4 id="content_4_35">unpin  <a class="anchor_super" id="unpin" href="?#unpin" title="unpin"></a></h4>
<p>解除对象窗口的 pin 状态。</p>

<h4 id="content_4_36">set_workspace  <a class="anchor_super" id="set_workspace" href="?#set_workspace" title="set_workspace"></a></h4>
<p>将窗口移动到指定的工作区上。</p>
<p><strong>格式</strong></p>
<pre>(set_workspace num)</pre>
<p><strong>使用例</strong></p>
<pre>(set_workspace 1)</pre>

<h4 id="content_4_37">skip_pager  <a class="anchor_super" id="skip_pager" href="?#skip_pager" title="skip_pager"></a></h4>
<p><strong>格式</strong></p>
<pre>(skip_pager)</pre>

<h4 id="content_4_38">skip_tasklist  <a class="anchor_super" id="skip_tasklist" href="?#skip_tasklist" title="skip_tasklist"></a></h4>
<p><strong>格式</strong></p>
<pre>(skip_tasklist)</pre>

<h4 id="content_4_39">above  <a class="anchor_super" id="above" href="?#above" title="above"></a></h4>
<p>使对象窗口总在最前。</p>
<p><strong>格式</strong></p>
<pre>(above)</pre>

<h4 id="content_4_40">below  <a class="anchor_super" id="below" href="?#below" title="below"></a></h4>
<p>使对象窗口总在最底层。</p>
<p><strong>格式</strong></p>
<pre>(below)</pre>

<h4 id="content_4_41">undecorate  <a class="anchor_super" id="undecorate" href="?#undecorate" title="undecorate"></a></h4>
<p>删除对象窗口上的所有窗口修饰。</p>
<p><strong>格式</strong></p>
<pre>(undecorate)</pre>

<h4 id="content_4_42">wintype  <a class="anchor_super" id="wintype" href="?#wintype" title="wintype"></a></h4>
<p>设置窗口类型。窗口类型可以是以下字符串：&quot;normal&quot;, &quot;dialog&quot;, &quot;menu&quot;, &quot;toolbar&quot;, &quot;splashscreen&quot;, &quot;utility&quot;, &quot;dock&quot;, &quot;desktop&quot;。</p>
<p><strong>格式</strong></p>
<pre>(wintype type)</pre>
<p><strong>使用例</strong></p>
<pre>(wintype &quot;normal&quot;)</pre>

<h2 id="content_4_43">FAQ  <a class="anchor_super" id="faq" href="?#faq" title="faq"></a></h2>

<h3 id="content_4_44">为什么我的脚本不起作用？</h3>
<p>很有可能你的 window_name、application_name 等匹配字符串设置不正确。
首先确定对象窗口的正确的 window_name、application_name 之后再修改配置文件。</p>

<h3 id="content_4_45">如何确定一个窗口的 window_name、application_name、window_role？</h3>
<p>最简单的方法就是使用 print 动作输出 window_name 等变量。在 .devilspie 目录下建立
window_name.ds、application_name.ds、window_role.ds 三个文件，内容分别如下：</p>
<p><strong>window_name.ds</strong></p>
<pre>(print (window_name))</pre>
<p><strong>application_name.ds</strong></p>
<pre>(print (application_name)))</pre>
<p><strong>window_role.ds</strong></p>
<pre>(print (window_role))</pre>
<p>然后从命令行运行 Devil's Pie，再打开对象窗口，查看终端的输出结果。</p>

<h3 id="content_4_46">为什么我的配置文件中，第二条以后的命令都不能执行？</h3>
<p>这是 Devil's Pie 的一个bug，每一个 .ds 文件只有第一个命令（第一对括号内的内容）才能被执行。
因此，你无法把所有配置都写到一个文件中，而只能为每一条配置建立一个单独的配置文件。</p>

<h3 id="content_4_47">如何在 vim 中使用语法高亮显示？</h3>
<p>Devil's Pie 的配置文件语法与 LISP 相同，因此你可以在 vim 中使用下面的命令来设置语法高亮。</p>
<pre>:set syntax=lisp</pre>

<h3 id="content_4_48">如何终止正在执行中的 Devil's Pie？</h3>
<pre>$ killall devilspie</pre>

<h2 id="content_4_49">参考</h2>
<p>本文参考了以下网站，在此表示感谢。</p>
<ul class="list1" style="padding-left:16px;margin-left:16px"><li><a href="http://wiki.foosel.net/linux/devilspie">linux:devilspie</a></li>
<li><a href="http://live.gnome.org/DevilsPie">DevilsPie - GNOME Live!</a></li></ul>
<!-- end Pukiwiki generated code-->
]]></content:encoded>
			<wfw:commentRss>http://tech.idv2.com/2006/09/22/use-devilspie-to-automatic-your-gnome/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
