我在GNU/Linux下使用的桌面环境工具组合(5)

;; Increase sound volume
(bind-keys global-keymap
    "Super-]" `(progn
   (volume-up-by-ratio volume-adjust-ratio-step)
   (display-close-message (concat "Volume L:" (get-volume-percentage-str current-left-volume) " R:" (get-volume-percentage-str current-right-volume)) alert-msg-short-time alert-msg-attrib)))

;; Decrease sound volume
(bind-keys global-keymap
    "Super-[" `(progn
   (volume-down-by-ratio volume-adjust-ratio-step)
   (display-close-message (concat "Volume L:" (get-volume-percentage-str current-left-volume) " R:" (get-volume-percentage-str current-right-volume)) alert-msg-short-time alert-msg-attrib)))

;; Toggle sound mute and unmute
(bind-keys global-keymap
    "Super-\\" `(toggle-volume-mute))

以上代码中还用到了自己编写的脚本get_volume.sh用于获取系统当前音量,具体如下:

#!/bin/bash

amixer cget $DEFAULT_SOUND | gawk '{if(match($0, /values=([[:digit:]]+,[[:digit:]]+)/, res) != 0) print res[1];}'

4. 关闭与激活屏幕保护程序:看电影的时候就不要启动屏保了,所以需要这样的功能。绑定的快捷键为Win+p。相关配置如下。

;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; xscreensaver related variables and functions
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(setq xscreensaver-enabled t)

(defun enable-xscreensaver ()
  "Enable xscreensaver"
  (interactive)
  (system "exec /usr/bin/xscreensaver -no-splash &")
  (setq xscreensaver-enabled t))

(defun disable-xscreensaver ()
  "Disable xscreensaver"
  (interactive)
  (system "exec /usr/bin/xscreensaver-command -exit &")
  (setq xscreensaver-enabled nil))

(defun toggle-xscreensaver-activation ()
  "Activate/deactivate xscreensaver"
  (interactive)
  (if xscreensaver-enabled
      (disable-xscreensaver)
    (enable-xscreensaver)))

(bind-keys global-keymap
    "Super-p" `(progn
   (toggle-xscreensaver-activation)
   (if xscreensaver-enabled
      (display-close-message "Screensaver enabled!" alert-msg-short-time alert-msg-attrib)
    (display-close-message "Screensaver disabled!" alert-msg-short-time alert-msg-attrib))))

5. 关闭与激活触控板按钮(仅对笔记本电脑有效),快捷键为Win+z。相关配置如下:

;; ;;;;;;;;;;;;;;;;;;;;
;; Touchpad operation
;; ;;;;;;;;;;;;;;;;;;;;
(setq tapbutton-enabled t)
;; Toggle tap button function of the touchpad
(bind-keys global-keymap
    "Super-z" `(progn
   (system "toggle_tapbutton.sh &")
   (setq tapbutton-enabled (not tapbutton-enabled))
   (if tapbutton-enabled
      (display-close-message "Tap button enabled!" alert-msg-short-time alert-msg-attrib)
    (display-close-message "Tap button disabled!" alert-msg-short-time alert-msg-attrib))))

其中调用了自己编写的脚本程序toggle_tapbutton.sh与enable_tapbutton.sh,其内容分别为:

#!/bin/bash

script_name="toggle_tapbutton.sh"
script_usage=$(cat <<EOF
$script_name
EOF
)
script_function=$(cat <<EOF
This script is used to disable/enable the finger tap function of Synaptics touchpad.
EOF
)
script_doc=$(cat <<EOF
-h    Display this help.
EOF
)
script_examples=$(cat <<EOF
EOF
)
state_prefix="==="
warning_prefix="***"
error_prefix="!!!"

function display_help() {
    if [ -n "$script_usage" ]; then
    echo -e "Usage: $script_usage"
    fi
   
    if [ -n "$script_function" ]; then
    echo -e "$script_function"
    fi
   
    if [ -n "$script_doc" ] ; then
    echo -e "\n$script_doc"
    fi
   
    if [ -n "$script_examples" ]; then
    echo -e "\nExamples"
    echo -e "$script_examples"
    fi
}

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/15885.html