;; Display batter information by calling acpi
(defun display-batter-info ()
"Display batter information by calling acpi"
(interactive)
(let* ((res-stream (make-string-output-stream))
(proc (make-process res-stream))
(res-str))
(call-process proc nil "acpi" "-i" "-b")
(setq res-str (get-output-stream-string res-stream))
(display-message res-str alert-msg-attrib)))
(bind-keys global-keymap
"Super-b" `(display-batter-info))
8. 添加窗口hook(before-add-window-hook)对符合匹配条件的窗口赋以特殊属性,如令其不显示在窗口循环列表中、自启动后保持最大化、指定窗口初始大小、将窗口固定显示在桌面某个位置等。需要用到正则表达式模块rep.regexp匹配字符串,以及sawfish.wm.commands.groups和sawfish.wm.frames模块获取窗口属性。相关配置如下:
(require 'rep.regexp)
(require 'sawfish.wm.commands.groups)
(require 'sawfish.wm.frames)
(defun get-wm-window-type (win)
"Get the _NET_WM_WINDOW_TYPE property of a window"
(interactive)
(aref (nth 2 (get-x-property win '_NET_WM_WINDOW_TYPE)) 0))
(defun get-wm-property (win prop)
"Get the x window property of a window"
(interactive)
(nth 2 (get-x-property win prop)))
;; Set LibreOffice Impress window property
;; Remove window frame of LibreOffice Impress window when it is in fullscreen
;; presentation.
(add-hook 'before-add-window-hook
(lambda (w)
(if (and (string-match "^soffice" (get-wm-property w 'WM_CLASS)) (= (get-wm-window-type w) '_NET_WM_WINDOW_TYPE_NORMAL))
(set-window-type w 'unframed)))
t)
;; Set FreeRDP window property
(add-hook 'before-add-window-hook
(lambda (w)
(if (string-match "^FreeRDP" (get-wm-property w 'WM_NAME))
(progn
(set-window-type w 'unframed))))
t)
;; Set xclock window property
(add-hook 'before-add-window-hook
(lambda (w)
(if (string-match "^xclock$" (get-wm-property w 'WM_NAME))
(progn
(mark-window-as-dock w)
(window-put w 'task-list-skip t)
(set-window-type w 'unframed))))
t)
;; Set Audacious window property
(add-hook 'before-add-window-hook
(lambda (w)
(if (string-match "[aA]udacious" (get-wm-property w 'WM_NAME))
(progn
(mark-window-as-desktop w)
(window-put w 'task-list-skip t))))
t)
;; Set Workrave window property
(add-hook 'before-add-window-hook
(lambda (w)
(if (and (string-match "[wW]orkrave" (get-wm-property w 'WM_CLASS)) (string-match "[wW]orkrave" (get-wm-property w 'WM_NAME)))
(progn
(mark-window-as-dock w)
(window-put w 'task-list-skip t))))
t)
;; Set full-window online video window property (played in Iceweasel)
(add-hook 'before-add-window-hook
(lambda (w)
(if (string-match "plugin-container" (get-wm-property w 'WM_NAME))
(progn
(maximize-window-fullscreen w)))))
;; Set Wesnoth full-window property
(add-hook 'before-add-window-hook
(lambda (w)
(if (string-match "The Battle for Wesnoth" (get-wm-property w 'WM_NAME))
(progn
(set-window-type w 'unframed)
(move-window-to w 1280 0)))))
总结
由本文介绍可以看出,通过将GNU/Linux下不同的工具组合起来,如startx、Sawfish、xmodmap、amixer等,便可以实现节省系统资源、高效、方便的桌面操作环境。