volume: replace amixer with pamixer
volume: use sink instead of channel
This commit is contained in:
parent
ab357d786b
commit
3345c46837
2 changed files with 50 additions and 25 deletions
|
|
@ -10,6 +10,7 @@ Blocks compatible with [i3blocks](https://github.com/vivien/i3blocks).
|
|||
* `df` for `du` block
|
||||
* `xdg-open` for `du` block
|
||||
* `playerctl` for `spotify` block
|
||||
* `pamixer` for `volume` block
|
||||
|
||||
## Installation
|
||||
|
||||
|
|
@ -101,7 +102,7 @@ markup=pango
|
|||
interval=3
|
||||
|
||||
[ip_eth0_ip6]
|
||||
command=/path/to/ip -iface=eth0 -version=ip4 -name=Bar
|
||||
command=/path/to/ip -iface=eth0 -version=ip6 -name=Bar
|
||||
format=json
|
||||
markup=pango
|
||||
interval=3
|
||||
|
|
@ -179,9 +180,11 @@ interval=3
|
|||
|
||||
Show volume.
|
||||
|
||||
Note: use `pamixer --list-sinks`
|
||||
|
||||
```
|
||||
[volume]
|
||||
command=/path/to/volume -channel=Master
|
||||
command=/path/to/volume -sinks="Default:alsa_output.pci-0000_00_1f.3.analog-stereo;Headset:bluez_output.00_1B_66_B6_87_05
|
||||
format=json
|
||||
markup=pango
|
||||
interval=1
|
||||
|
|
|
|||
|
|
@ -3,46 +3,68 @@ package main
|
|||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
r "gitnet.fr/deblan/i3-blocks-go/rendering"
|
||||
"os/exec"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
r "gitnet.fr/deblan/i3-blocks-go/rendering"
|
||||
)
|
||||
|
||||
func Volume(channel string) int {
|
||||
output, _ := exec.Command("amixer", "get", channel).Output()
|
||||
func Volume(id string) int {
|
||||
output, _ := exec.Command("pamixer", "--sink", id, "--get-volume").Output()
|
||||
|
||||
regex, _ := regexp.Compile(`\[(\d+)%\]`)
|
||||
data := regex.FindStringSubmatch(string(output))
|
||||
|
||||
volume, _ := strconv.Atoi(data[1])
|
||||
volume, _ := strconv.Atoi(strings.TrimSpace(string(output)))
|
||||
|
||||
return volume
|
||||
}
|
||||
|
||||
func main() {
|
||||
argChannel := flag.String("channel", "Master", "the channel")
|
||||
argSinks := flag.String("sinks", "", "list of sinks, eg: CUSTOM_NAME:SINK_VALUE;CUSTOM_NAME2:SINK_VALUE2")
|
||||
flag.Parse()
|
||||
|
||||
volume := Volume(*argChannel)
|
||||
sinks := strings.Split(*argSinks, ";")
|
||||
|
||||
var symbole string
|
||||
var items []string
|
||||
|
||||
if volume == 0 {
|
||||
symbole = "\uf026"
|
||||
} else if volume < 50 {
|
||||
symbole = "\uf027"
|
||||
} else {
|
||||
symbole = "\uf028"
|
||||
for _, sink := range sinks {
|
||||
info := strings.Split(sink, ":")
|
||||
|
||||
if len(info) != 2 {
|
||||
continue
|
||||
}
|
||||
|
||||
name := info[0]
|
||||
id := info[1]
|
||||
volume := Volume(id)
|
||||
|
||||
var symbole string
|
||||
|
||||
if volume == 0 {
|
||||
symbole = "\uf026"
|
||||
} else if volume < 50 {
|
||||
symbole = "\uf027"
|
||||
} else {
|
||||
symbole = "\uf028"
|
||||
}
|
||||
|
||||
label := r.TextWithPadding(
|
||||
name,
|
||||
r.FB{
|
||||
Foreground: r.Color("grey1"),
|
||||
Background: r.Color("black2"),
|
||||
},
|
||||
)
|
||||
|
||||
value := r.TextWithPadding(fmt.Sprintf("%d%% %s", volume, r.FontAwesome(symbole)), r.FB{
|
||||
Foreground: r.Color("grey1"),
|
||||
Background: r.Color("black1"),
|
||||
})
|
||||
|
||||
items = append(items, fmt.Sprintf("%s%s", label, value))
|
||||
}
|
||||
|
||||
value := r.TextWithPadding(fmt.Sprintf("%d%% %s", volume, r.FontAwesome(symbole)), r.FB{
|
||||
Foreground: r.Color("grey1"),
|
||||
Background: r.Color("black1"),
|
||||
})
|
||||
|
||||
options := r.NewBlockOptions()
|
||||
options.FullText = value
|
||||
options.FullText = strings.Join(items, "")
|
||||
block := r.Block("volume", options)
|
||||
|
||||
fmt.Println(block)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue