[StumpWM] Add MPD interactivity

This commit is contained in:
Lucien Cartier-Tilet 2021-11-07 02:30:23 +01:00
parent af4fbf625b
commit 1bce6d902d
Signed by: phundrak
GPG Key ID: BD7789E705CB8DCA

View File

@ -182,10 +182,10 @@ including a short description of what they are for:
#+name: loaded-modules #+name: loaded-modules
| Module Name | Why It Is Loaded | | Module Name | Why It Is Loaded |
|-----------------+------------------------------------------------------------| |-----------------+------------------------------------------------------------|
| alert-me | Creates notifications, can also create timed notifications |
| beckon | Bring the mouse cursor to the current window | | beckon | Bring the mouse cursor to the current window |
| end-session | Gracefully end programs when ending user session | | end-session | Gracefully end programs when ending user session |
| globalwindows | Navigate between windows from all workspaces | | globalwindows | Navigate between windows from all workspaces |
| mpd | Interact with MPD |
| stump-backlight | Native management of backlight in StumpWM | | stump-backlight | Native management of backlight in StumpWM |
| urgentwindows | Get urgent windows | | urgentwindows | Get urgent windows |
@ -198,16 +198,23 @@ including a short description of what they are for:
"\n") "\n")
#+end_src #+end_src
#+RESULTS[508e36f9747f1da901bbee63582416a8a6ba2c2f]: gen-load-modules #+RESULTS[0cbba236372280cb2eb6a1e277cda84938e15d46]: gen-load-modules
#+begin_src lisp #+begin_src lisp
(load-module "alert-me")
(load-module "beckon") (load-module "beckon")
(load-module "end-session") (load-module "end-session")
(load-module "globalwindows") (load-module "globalwindows")
(load-module "mpd")
(load-module "stump-backlight") (load-module "stump-backlight")
(load-module "urgentwindows") (load-module "urgentwindows")
#+end_src #+end_src
In order to be able to use MPD from StumpWM itself, well need to
connect to it.
#+begin_src lisp
(when *initializing*
(mpd-connect))
#+end_src
Finally, we can notify the user everything is ready. Finally, we can notify the user everything is ready.
#+begin_src lisp #+begin_src lisp
(setf *startup-message* "StumpWM is ready!") (setf *startup-message* "StumpWM is ready!")
@ -353,9 +360,9 @@ still set its color to Nord1, just in case.
#+end_src #+end_src
The timeout of the modeline indicates how often it refreshes in The timeout of the modeline indicates how often it refreshes in
seconds. I think one second is good. seconds. I think two seconds is good.
#+begin_src lisp #+begin_src lisp
(setf *mode-line-timeout* 1) (setf *mode-line-timeout* 2)
#+end_src #+end_src
Next we get to the content of the modeline. This format follows the Next we get to the content of the modeline. This format follows the
@ -380,8 +387,9 @@ Here are some modules that we will load for the modeline:
| Module Name | Why It Is Loaded | | Module Name | Why It Is Loaded |
|------------------+--------------------------------------------------| |------------------+--------------------------------------------------|
| battery-portable | Get information on the battery level of a laptop | | battery-portable | Get information on the battery level of a laptop |
| cpu | Get the CPU usage of the computer | | cpu | Get the CPU usage |
| mem | Get the memory usage of the computer | | mpd | Display MPDs status |
| mem | Get the memory usage |
| wifi | Display information about Wifi connectivity | | wifi | Display information about Wifi connectivity |
#+name: gen-load-modeline-modules #+name: gen-load-modeline-modules
@ -393,21 +401,25 @@ Here are some modules that we will load for the modeline:
"\n") "\n")
#+end_src #+end_src
#+RESULTS[125d7bbaa15ee28f0baf4cad59c4742ac372853b]: gen-load-modeline-modules #+RESULTS[22e9c907b8814e15dd2bc2a16aa98bb7cab0fd46]: gen-load-modeline-modules
#+begin_src lisp #+begin_src lisp
(load-module "battery-portable") (load-module "battery-portable")
(load-module "cpu") (load-module "cpu")
(load-module "mpd")
(load-module "mem") (load-module "mem")
(load-module "wifi") (load-module "wifi")
#+end_src #+end_src
Some variables need to be set so modules are displayed correctly.
#+begin_src lisp #+begin_src lisp
(setq cpu::*cpu-modeline-fmt* "%c" (setf cpu::*cpu-modeline-fmt* "%c"
mem::*mem-modeline-fmt* "%a %p" mem::*mem-modeline-fmt* "%a%p"
wifi:*wifi-modeline-fmt* "%e %P" wifi:*wifi-modeline-fmt* "%e %P"
wifi:*use-colors* nil wifi:*use-colors* nil
,*mode-line-highlight-template* "<~A>" mpd:*mpd-modeline-fmt* "%a - %t"
,*hidden-window-color* "^**") mpd:*mpd-status-fmt* "%a - %t"
,*mode-line-highlight-template* "«~A»"
,*hidden-window-color* "^**")
#+end_src #+end_src
We can indicate what to display in our modeline. Each formatter will We can indicate what to display in our modeline. Each formatter will
@ -420,9 +432,10 @@ the font I am using (see §[[#Theme-Fonts-28pc8141v5j0]]).
| ~%W~ | Display list of windows in the current group and head | | | ~%W~ | Display list of windows in the current group and head | |
| ~^>~ | Rest of the modeline will be aligned to the right | | | ~^>~ | Rest of the modeline will be aligned to the right | |
| ~mu-unread~ | Display number of unread emails | yes | | ~mu-unread~ | Display number of unread emails | yes |
| ~%m~ | Display current MPD song | |
| ~%I~ | Display Wifi status | | | ~%I~ | Display Wifi status | |
| ~%C~ | Display CPU status | | | ~%C~ | Display CPU usage | |
| ~%M~ | Display RAM status | | | ~%M~ | Display RAM usage | |
| ~%B~ | Display battery status | | | ~%B~ | Display battery status | |
| ~%d~ | Display date | | | ~%d~ | Display date | |
@ -437,8 +450,8 @@ the font I am using (see §[[#Theme-Fonts-28pc8141v5j0]]).
elements) elements)
#+end_src #+end_src
#+RESULTS[5d43e832fca88ddfffecd2a55d63bbb767e2e315]: modeline-format-gen #+RESULTS[54964dce177e8031e22761857d7d1a0bc960c6bd]: modeline-format-gen
: (("%g") ("%W") ("^>") ("mu-unread" . t) ("%I") ("%C") ("%M") ("%B") ("%d")) : (("%g") ("%W") ("^>") ("mu-unread" . t) ("%m") ("%I") ("%C") ("%M") ("%B") ("%d"))
#+begin_src lisp :noweb yes #+begin_src lisp :noweb yes
(defun generate-modeline (elements &optional not-invertedp) (defun generate-modeline (elements &optional not-invertedp)
@ -1289,25 +1302,32 @@ with Emacs buffers.
:END: :END:
My music is managed through MPD, and I often use ~mpc~ commands in order My music is managed through MPD, and I often use ~mpc~ commands in order
to interact with it without any GUI application. So, well see a lot to interact with it without any GUI application. So, well see a lot
of its usage here. of its usage here, and numerous commands used here come from the ~mpd~
minor mode loaded [[#Init-file-l3q4snd1u5j0][above]].
First, lets declare an interactive keymap in order to easily change First, lets declare an interactive keymap in order to easily change
several times in a row either the current song playing or the volume several times in a row either the current song playing or the volume
of MPD. of MPD.
#+name: inter-mpc #+name: inter-mpc
#+caption: Interactive keybinds for ~mpc~ #+caption: Interactive keybinds for ~mpc~
| Keychord | Function | | Keychord | Function |
|----------+--------------------| |----------+-----------------|
| ~c~ | ~exec mpc prev~ | | ~c~ | ~mpd-prev~ |
| ~t~ | ~exec mpc volume -2~ | | ~t~ | ~mpd-volume-down~ |
| ~s~ | ~exec mpc volume +2~ | | ~s~ | ~mpd-volume-up~ |
| ~r~ | ~exec mpc next~ | | ~r~ | ~mpd-next~ |
Cela donne le code suivant: This can be translated in CommonLisp as:
#+begin_src lisp #+begin_src lisp
<<interactive-gen(name="mpc-interactive", keys=inter-mpc)>> <<interactive-gen(name="mpc-interactive", keys=inter-mpc)>>
#+end_src #+end_src
We need to indicate also how much the volume is affected by
~mpd-volume-down~ and ~mpd-volume-up~.
#+begin_src lisp
(setf *mpd-volume-step* 2)
#+end_src
Another one will be defined for the general audio of my computer. And Another one will be defined for the general audio of my computer. And
I know it isnt technically media keybinds, but Ill add in keybinds I know it isnt technically media keybinds, but Ill add in keybinds
for my screens backlight. for my screens backlight.
@ -1326,21 +1346,56 @@ for my screens backlight.
#+end_src #+end_src
Then, lets declare a keymap for our media controls. Then, lets declare a keymap for our media controls.
#+name: mpd-add-map
#+caption: ~*my-mpd-add-map*~
| Keychord | Function |
|----------+---------------------------|
| ~a~ | ~mpd-search-and-add-artist~ |
| ~A~ | ~mpd-search-and-add-album~ |
| ~f~ | ~mpd-search-and-add-file~ |
| ~F~ | ~mpd-add-file~ |
| ~g~ | ~mpd-search-and-add-genre~ |
| ~t~ | ~mpd-search-and-add-title~ |
#+name: mpd-browse-map
#+caption: ~*my-mpd-browse-map*~
| Keychord | Function |
|----------+---------------------|
| ~a~ | ~mpd-browse-artists~ |
| ~A~ | ~mpd-browse-albums~ |
| ~g~ | ~mpd-browse-genres~ |
| ~p~ | ~mpd-browse-playlist~ |
| ~t~ | ~mpd-browse-tracks~ |
#+name: media-management #+name: media-management
#+caption: ~*my-media-keymap*~ #+caption: ~*my-media-keymap*~
| Keychord | Function | | Keychord | Function |
|----------+-----------------------------| |----------+-----------------------------|
| ~.~ | ~media-interactive~ | | ~.~ | ~media-interactive~ |
| ~a~ | ~'*my-mpd-add-map*~ |
| ~b~ | ~'*my-mpd-browse-map*~ |
| ~c~ | ~mpd-clear~ |
| ~m~ | ~mpc-interactive~ | | ~m~ | ~mpc-interactive~ |
| ~p~ | ~exec mpc prev~ | | ~p~ | ~mpd-prev~ |
| ~n~ | ~exec mpc next~ | | ~n~ | ~mpd-next~ |
| ~p~ | ~exec mpc toggle~ | | ~P~ | ~mpd-toggle-pause~ |
| ~s~ | ~exec mpc stop~ | | ~s~ | ~mpd-stop~ |
| ~u~ | ~mpd-update~ |
| ~N~ | ~term ncmpcpp -q~ | | ~N~ | ~term ncmpcpp -q~ |
| ~v~ | ~term ncmpcpp -qs visualizer~ | | ~v~ | ~term ncmpcpp -qs visualizer~ |
Lets translate this table in CommonLisp: Lets translate this table in CommonLisp:
#+begin_src lisp #+begin_src lisp
(defvar *my-mpd-add-map*
(let ((m (make-sparse-keymap)))
<<keybinds-gen(map="m", keybinds=mpd-add-map)>>
m))
(defvar *my-mpd-browse-map*
(let ((m (make-sparse-keymap)))
<<keybinds-gen(map="m", keybinds=mpd-browse-map)>>
m))
(defvar *my-media-keymap* (defvar *my-media-keymap*
(let ((m (make-sparse-keymap))) (let ((m (make-sparse-keymap)))
<<keybinds-gen(map="m", keybinds=media-management)>> <<keybinds-gen(map="m", keybinds=media-management)>>
@ -1356,10 +1411,10 @@ media-related, but Ill add keybinds for my screens backlight.
#+caption: Top-level media keys #+caption: Top-level media keys
| Keychord | Function | | Keychord | Function |
|-----------------------+--------------------------------------| |-----------------------+--------------------------------------|
| ~XF86AudioPlay~ | ~exec mpc play~ | | ~XF86AudioPlay~ | ~mpd-play~ |
| ~XF86AudioPause~ | ~exec mpc pause~ | | ~XF86AudioPause~ | ~exec mpc pause~ |
| ~XF86AudioPrev~ | ~exec mpc prev~ | | ~XF86AudioPrev~ | ~mpd-prev~ |
| ~XF86AudioNext~ | ~exec mpc next~ | | ~XF86AudioNext~ | ~mpd-next~ |
| ~XF86AudioRaiseVolume~ | ~exec amixer -q set Master 2%+ unmute~ | | ~XF86AudioRaiseVolume~ | ~exec amixer -q set Master 2%+ unmute~ |
| ~XF86AudioLowerVolume~ | ~exec amixer -q set Master 2%- unmute~ | | ~XF86AudioLowerVolume~ | ~exec amixer -q set Master 2%- unmute~ |
| ~XF86AudioMute~ | ~exec amixer -q set Master 1+ toggle~ | | ~XF86AudioMute~ | ~exec amixer -q set Master 1+ toggle~ |