LinuxTOY 是一个致力于提供 Linux 相关资讯的专题站点。如果您发现了好用好玩的 Linux 东东并愿意发扬自由、分享的精神,可以点击顶部导航 Contact 按钮进行投稿。

Related entries

窗口管理器 Openbox 入门指南 (3)

说明:本系列文章仍在撰写中,尚未最终完成,请大家暂时不要转载。待完成后,我会出一个 PDF 版本,方便大家阅读。

目录表

设定键盘和鼠标绑定

配置文件

Openbox 默认的键盘和鼠标绑定文件位于:

/etc/xdg/openbox/rc.xml

同样复制一份到 .config/openbox/:

cp /etc/xdg/openbox/rc.xml ~/.config/openbox/

键盘绑定

Openbox 的键盘绑定使用 <keyboard> 标签,形如下面的内容:

<keyboard>
...
</keyboard>

要定义一个具体的键盘绑定,我们需要使用 <keybind> 标签。该标签具有 key 属性,其作用是指定快捷键。常用的修饰键如下:

  • S - Shift
  • C - Ctrl
  • A - Alt
  • W - Win (即 Windows 徽标键)

例如,假设我要为最大化窗口指定快捷键为 Alt-F6,那么,可以定义如下:


<keyboard>
 <keybind key="A-F6">
  <action name="MaximizeFull" />
 </keybind>
 ...
</keyboard>

又如,我想为 URxvt 指定启动快捷键 Win-u,可作下面的定义:


<keybind key="W-u">
 <action name="Execute">
  <command>urxvt</command>
 </action>
</keybind>

其实,Openbox 已经默认定义了很多键盘绑定,如切换活动桌面、提升窗口等等,具体内容都可以在上面的 rc.xml 文件中找到。

至于在我们前面的菜单创建过程中、键盘绑定中、以及后面的鼠标绑定中所用的 Action,可以通过下面的地址参考:

http://icculus.org/openbox/index.php/Help:Actions

鼠标绑定

鼠标绑定使用 <mouse> 标签定义。具体如下:

<mouse>
...
</mouse>

与键盘绑定不同的是,鼠标绑定会要求你首先设置情景,也就是触发鼠标绑定的对象,即 <context> 标签。常用的 Context 如下表所示:

名称 说明
Frame 除桌面外的任何窗口
Client 应用程序窗口,不含窗口边框
Desktop 桌面
Root 与 Desktop 相似,通常用于 Root 菜单
Titlebar 窗口标题栏
Top, Bottom, Left, Right 窗口的上、下、左、右四边
TLCorner, TRCorner, BLCorner, BRCorner 窗口的四角
Icon 窗口图标
Iconify 最小化按钮
Maximize 最大化按钮
Close 关闭按钮
AllDesktops 所有桌面按钮
Shade 折叠按钮
MoveResize 移动并调整窗口大小

扩展上面的例子:


<mouse>
 <context name="Titlebar">
 ...
 </context>
</mouse>

Titlebar 说明这是针对标题栏的鼠标操作。

然后,即可使用 <mousebind> 标签进行具体的鼠标绑定。该标签具有 button 和 action 属性:

  • button:该属性指定使用哪一个鼠标按钮来触发鼠标绑定,如左键、右键、滚轮等。
    Left 鼠标左键
    Right 鼠标右键
    Middle 鼠标中键
    UP 向上滚
    Down 向下滚
  • action:用来指定一个鼠标触发的事件,如按下、单击、双击等。一些常见的 Action 事件如下表所示:
    Press 按下
    Click 单击
    DoubleClick 双击
    Release 释放
    Drag 拖曳

例如,当我们双击一个窗口时让其最大化,可以作如下定义:


<mouse>
 <context name="Titlebar">
  <mousebind button="Left" action="DoubleClick">
   <action name="ToggleMaximizeFull"/>
  </mousebind>
 </context>
</mouse>

[待续]

署名 • 注明出处 • 非商业性使用

12 Comments

  1. 1 wanzigunzi Commented @ 2008-08-01 9:40 amReply to this comment

    一早起来就看到这篇,高兴…

  2. 2 kevin Commented @ 2008-08-01 9:44 amReply to this comment

    good good

  3. 3 Aspirin Commented @ 2008-08-01 9:52 amReply to this comment

    Toy真勤劳,呵呵

  4. 4 MK Commented @ 2008-08-01 10:02 amReply to this comment

    纯支持~ob有图形设置没有。。总有懒人。。比如我。。。

  5. 5 suxixb Commented @ 2008-08-01 10:16 amReply to this comment

    期待 pdf 版。。

  6. 6 fox Commented @ 2008-08-01 11:14 amReply to this comment

    似乎color代码没有关闭

  7. 7 wanzigunzi Commented @ 2008-08-01 11:22 amReply to this comment

    恩,在konqueror上这篇文章和评论全是红色

  8. 8 Toy Commented @ 2008-08-01 11:32 amReply to this comment

    @fox, wanzigunzi: 确实忘了关 code 标签,谢谢。

  9. 9 somebody(莫多) Commented @ 2008-08-01 12:46 pmReply to this comment

    不错不错。有了Toy的文章,我们就可以懒一下了。拿toy的配置文件来修改就ok了。

  10. 10 希罗 Commented @ 2008-08-01 9:15 pmReply to this comment

    我来分享个技巧吧!
    把下面的代码覆盖调部分 ~/.pypanelrc
    里时钟部分(有一部分我保留了原文,应该很好找的)
    如有需要我贴全!

    作用是,把鼠标移动到pypanel里显示时钟的地方,通过鼠标滚轮调解音量!
    我自己想到的,用了好久了!算是原创,在这里分享吧!
    让更多的人了解到Linux的个人之处!

    #——————————–
    def clockButtonEvent(pp, button):
    #——————————–
    “”" Button event handler for the panel’s clock object “”"

    if button == 1:
    os.system(”xclock &”)
    elif button == 2:
    pass
    elif button == 3:
    pp.toggleHidden()
    #mouse wheel control volume [mod by Loading(http://ycf.name)]
    elif button == 4:
    os.system(”amixer -q set PCM 2+ unmute”)
    elif button == 5:
    os.system(”amixer -q set PCM 2- unmute”)

  11. 11 Toy Commented @ 2008-08-02 8:53 amReply to this comment

    @希罗

    感谢分享,很实用。

  12. 12 cagewang Commented @ 2008-08-03 9:30 pmReply to this comment

    @希罗

    感谢分享!!呵呵..正好用的上!