xaizek / d2if (License: GPLv2+) (since 2018-12-07)
Simple dzen2 input formatter, which is supposed to not waste CPU time for nothing and provides a number of builtin "widgets" for displaying system information.
Commit 53ad3fa5a5731deeb05f8725bf2d5c12fcc16260

Make Volume field pick up device change by PA/PW
Attach/detach card every time to be able to read volume of current
default device which changes when PulseAudio or PipeWire is in use.
It even applies to startup before PA/PW which then modify the device
resulting in volume not being displayed.
Author: xaizek
Author date (UTC): 2024-04-12 11:52
Committer name: xaizek
Committer date (UTC): 2024-04-12 11:52
Parent(s): 1ba6c2257f938aa1e82cd2492ca0a4516e45984c
Signing key: 99DC5E4DB05F6BE2
Tree: 61c9cd4ab6bf79424e74339177251af2bb17cd94
File Lines added Lines deleted
src/Volume.cpp 8 4
File src/Volume.cpp changed (mode: 100644) (index f796347..902f855)
... ... std::pair<bool, int> Volume::getVolumeLevel() const
58 58 if (snd_mixer_open(&raw_handle, 0) < 0) { if (snd_mixer_open(&raw_handle, 0) < 0) {
59 59 return {false, -1}; return {false, -1};
60 60 } }
61
62 if (snd_mixer_attach(raw_handle, cardName.c_str()) < 0) {
63 return {false, -1};
64 }
65 61 if (snd_mixer_selem_register(raw_handle, nullptr, nullptr) < 0) { if (snd_mixer_selem_register(raw_handle, nullptr, nullptr) < 0) {
66 62 return {false, -1}; return {false, -1};
67 63 } }
68 64 } }
69 65
66 if (snd_mixer_attach(raw_handle, cardName.c_str()) < 0) {
67 return {false, -1};
68 }
69
70 70 if (snd_mixer_load(raw_handle) < 0) { if (snd_mixer_load(raw_handle) < 0) {
71 71 return {false, -1}; return {false, -1};
72 72 } }
 
... ... std::pair<bool, int> Volume::getVolumeLevel() const
99 99
100 100 snd_mixer_free(raw_handle); snd_mixer_free(raw_handle);
101 101
102 if (snd_mixer_detach(raw_handle, cardName.c_str()) < 0) {
103 return {false, -1};
104 }
105
102 106 return {state, (100*(vol - min))/(max - min)}; return {state, (100*(vol - min))/(max - min)};
103 107 } }
Hints

Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://code.reversed.top/user/xaizek/d2if

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@code.reversed.top/user/xaizek/d2if

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a pull request:
... clone the repository ...
... make some changes and some commits ...
git push origin master