about summary refs log tree commit diff
path: root/configs/shared
diff options
context:
space:
mode:
authorWilliam Carroll <wpcarro@gmail.com>2019-12-23T12·19+0000
committerWilliam Carroll <wpcarro@gmail.com>2020-01-06T15·25+0000
commit15d889fa0ea9f89881b969a4f615337d27d5d82c (patch)
tree641cc180202b6b295c073a806fb6943b89fb0582 /configs/shared
parent7ec4dca723d8f217d1a85d7669a1e3c4f9842cd4 (diff)
Prefer start-process to shell-command for pulse-audio module
Continuing the series of easy-win commits that increase the speed of commands
that I was previously using `shell-command` to run by using `start-process`
instead.
Diffstat (limited to 'configs/shared')
-rw-r--r--configs/shared/.emacs.d/wpc/pulse-audio.el62
1 files changed, 49 insertions, 13 deletions
diff --git a/configs/shared/.emacs.d/wpc/pulse-audio.el b/configs/shared/.emacs.d/wpc/pulse-audio.el
index 2a8418439c5d..87e0c7c5ed30 100644
--- a/configs/shared/.emacs.d/wpc/pulse-audio.el
+++ b/configs/shared/.emacs.d/wpc/pulse-audio.el
@@ -7,9 +7,18 @@
 ;;; Code:
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; Dependencies
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+(require 'string)
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;; Constants
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
+(defconst pulse-audio/step-size 5
+  "The size by which to increase or decrease the volume.")
+
 (defconst pulse-audio/install-kbds? t
   "When t, install keybindings defined herein.")
 
@@ -17,38 +26,65 @@
 ;; Library
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
+(defun pulse-audio/message (x)
+  "Output X to *Messages*."
+  (message (string/format "[pulse-audio.el] %s" x)))
+
 (defun pulse-audio/toggle-mute ()
   "Mute the default sink."
   (interactive)
-  (shell-command "pactl set-sink-mute @DEFAULT_SINK@ toggle")
-  (message (string/format "[pulse-audio.el] Mute toggled.")))
+  (start-process
+   "*pactl<pulse-audio/toggle-mute>*"
+   nil
+   "pactl"
+   "set-sink-mute"
+   "@DEFAULT_SINK@"
+   "toggle")
+  (pulse-audio/message "Mute toggled."))
 
 (defun pulse-audio/toggle-microphone ()
   "Mute the default sink."
   (interactive)
-  (shell-command "pactl set-source-mute @DEFAULT_SOURCE@ toggle")
-  (message (string/format "[pulse-audio.el] Microphone toggled.")))
+  (start-process
+   "*pactl<pulse-audio/toggle-mute>*"
+   nil
+   "pactl"
+   "set-source-mute"
+   "@DEFAULT_SOURCE@"
+   "toggle")
+  (pulse-audio/message "Microphone toggled."))
 
-(defun pulse-audio/lower-volume ()
+(defun pulse-audio/decrease-volume ()
   "Low the volume output of the default sink."
   (interactive)
-  (shell-command "pactl set-sink-volume @DEFAULT_SINK@ -10%")
-  (message (string/format "[pulse-audio.el] Volume lowered.")))
+  (start-process
+   "*pactl<pulse-audio/toggle-mute>*"
+   nil
+   "pactl"
+   "set-sink-volume"
+   "@DEFAULT_SINK@"
+   (string/format "-%s%%" pulse-audio/step-size))
+  (pulse-audio/message "Volume decreased."))
 
-(defun pulse-audio/raise-volume ()
+(defun pulse-audio/increase-volume ()
   "Raise the volume output of the default sink."
   (interactive)
-  (shell-command "pactl set-sink-volume @DEFAULT_SINK@ +10%")
-  (message (string/format "[pulse-audio.el] Volume raised.")))
-
+  (start-process
+   "*pactl<pulse-audio/toggle-mute>*"
+   nil
+   "pactl"
+   "set-sink-volume"
+   "@DEFAULT_SINK@"
+   (string/format "+%s%%" pulse-audio/step-size))
+  (pulse-audio/message "Volume increased."))
 
 (when pulse-audio/install-kbds?
   (exwm-input-set-key
    (kbd "<XF86AudioMute>") #'pulse-audio/toggle-mute)
   (exwm-input-set-key
-   (kbd "<XF86AudioLowerVolume>") #'pulse-audio/lower-volume)
+   (kbd "<XF86AudioLowerVolume>") #'pulse-audio/decrease-volume)
   (exwm-input-set-key
-   (kbd "<XF86AudioRaiseVolume>") #'pulse-audio/raise-volume)
+   (kbd "<XF86AudioRaiseVolume>") #'pulse-audio/increase-volume)
   (exwm-input-set-key
    (kbd "<XF86AudioMicMute>") #'pulse-audio/toggle-microphone))