From 15d889fa0ea9f89881b969a4f615337d27d5d82c Mon Sep 17 00:00:00 2001 From: William Carroll Date: Mon, 23 Dec 2019 12:19:59 +0000 Subject: 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. --- configs/shared/.emacs.d/wpc/pulse-audio.el | 62 +++++++++++++++++++++++------- 1 file changed, 49 insertions(+), 13 deletions(-) (limited to 'configs/shared/.emacs.d/wpc') 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 @@ -6,10 +6,19 @@ ;;; 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*" + 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*" + 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*" + 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*" + 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 "") #'pulse-audio/toggle-mute) (exwm-input-set-key - (kbd "") #'pulse-audio/lower-volume) + (kbd "") #'pulse-audio/decrease-volume) (exwm-input-set-key - (kbd "") #'pulse-audio/raise-volume) + (kbd "") #'pulse-audio/increase-volume) (exwm-input-set-key (kbd "") #'pulse-audio/toggle-microphone)) -- cgit 1.4.1