2019-10-09 13:13:56 +02:00
|
|
|
;;; pulse-audio.el --- Control audio with Elisp -*- lexical-binding: t -*-
|
|
|
|
;; Author: William Carroll <wpcarro@gmail.com>
|
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
;; Because everything in my configuration is turning into Elisp these days.
|
|
|
|
|
|
|
|
;;; Code:
|
|
|
|
|
2019-12-23 13:19:59 +01:00
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;; Dependencies
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
2019-12-23 18:31:42 +01:00
|
|
|
(require 'prelude)
|
2019-12-23 13:19:59 +01:00
|
|
|
(require 'string)
|
|
|
|
|
2019-10-09 13:13:56 +02:00
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;; Constants
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
2019-12-23 13:19:59 +01:00
|
|
|
(defconst pulse-audio/step-size 5
|
|
|
|
"The size by which to increase or decrease the volume.")
|
|
|
|
|
2019-10-09 13:13:56 +02:00
|
|
|
(defconst pulse-audio/install-kbds? t
|
|
|
|
"When t, install keybindings defined herein.")
|
|
|
|
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;; Library
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
2019-12-23 13:19:59 +01:00
|
|
|
(defun pulse-audio/message (x)
|
|
|
|
"Output X to *Messages*."
|
|
|
|
(message (string/format "[pulse-audio.el] %s" x)))
|
|
|
|
|
2019-10-09 13:13:56 +02:00
|
|
|
(defun pulse-audio/toggle-mute ()
|
|
|
|
"Mute the default sink."
|
|
|
|
(interactive)
|
2019-12-23 18:31:42 +01:00
|
|
|
(prelude/start-process
|
|
|
|
:name "pulse-audio/toggle-mute"
|
|
|
|
:command "pactl set-sink-mute @DEFAULT_SINK@ toggle")
|
2019-12-23 13:19:59 +01:00
|
|
|
(pulse-audio/message "Mute toggled."))
|
2019-10-09 13:13:56 +02:00
|
|
|
|
2019-12-23 11:56:38 +01:00
|
|
|
(defun pulse-audio/toggle-microphone ()
|
|
|
|
"Mute the default sink."
|
|
|
|
(interactive)
|
2019-12-23 18:31:42 +01:00
|
|
|
(prelude/start-process
|
|
|
|
:name "pulse-audio/toggle-microphone"
|
|
|
|
:command "pactl set-source-mute @DEFAULT_SOURCE@ toggle")
|
2019-12-23 13:19:59 +01:00
|
|
|
(pulse-audio/message "Microphone toggled."))
|
2019-12-23 11:56:38 +01:00
|
|
|
|
2019-12-23 13:19:59 +01:00
|
|
|
(defun pulse-audio/decrease-volume ()
|
2019-10-09 13:13:56 +02:00
|
|
|
"Low the volume output of the default sink."
|
|
|
|
(interactive)
|
2019-12-23 18:31:42 +01:00
|
|
|
(prelude/start-process
|
|
|
|
:name "pulse-audio/decrease-volume"
|
|
|
|
:command (string/format "pactl set-sink-volume @DEFAULT_SINK@ -%s%%"
|
|
|
|
pulse-audio/step-size))
|
2019-12-23 13:19:59 +01:00
|
|
|
(pulse-audio/message "Volume decreased."))
|
2019-10-09 13:13:56 +02:00
|
|
|
|
2019-12-23 13:19:59 +01:00
|
|
|
(defun pulse-audio/increase-volume ()
|
2019-10-09 13:13:56 +02:00
|
|
|
"Raise the volume output of the default sink."
|
|
|
|
(interactive)
|
2019-12-23 18:31:42 +01:00
|
|
|
(prelude/start-process
|
|
|
|
:name "pulse-audio/increase-volume"
|
|
|
|
:command (string/format "pactl set-sink-volume @DEFAULT_SINK@ +%s%%"
|
|
|
|
pulse-audio/step-size))
|
2019-12-23 13:19:59 +01:00
|
|
|
(pulse-audio/message "Volume increased."))
|
2019-10-09 13:13:56 +02:00
|
|
|
|
|
|
|
(when pulse-audio/install-kbds?
|
|
|
|
(exwm-input-set-key
|
|
|
|
(kbd "<XF86AudioMute>") #'pulse-audio/toggle-mute)
|
|
|
|
(exwm-input-set-key
|
2019-12-23 13:19:59 +01:00
|
|
|
(kbd "<XF86AudioLowerVolume>") #'pulse-audio/decrease-volume)
|
2019-10-09 13:13:56 +02:00
|
|
|
(exwm-input-set-key
|
2019-12-23 13:19:59 +01:00
|
|
|
(kbd "<XF86AudioRaiseVolume>") #'pulse-audio/increase-volume)
|
2019-12-23 11:56:38 +01:00
|
|
|
(exwm-input-set-key
|
|
|
|
(kbd "<XF86AudioMicMute>") #'pulse-audio/toggle-microphone))
|
2019-10-09 13:13:56 +02:00
|
|
|
|
|
|
|
(provide 'pulse-audio)
|
|
|
|
;;; pulse-audio.el ends here
|