summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2021-03-03 20:37:02 -0500
committerJesse Luehrs <doy@tozt.net>2021-03-03 20:37:02 -0500
commit0730a4af3b5f6167d441afbaeea415b206f9c8be (patch)
tree8db8e6f549af1e305d7f9b30a97d942f69c7fe49
parent0411b4b9948aaae795d732ba56698e0e399c6560 (diff)
downloadconf-0730a4af3b5f6167d441afbaeea415b206f9c8be.tar.gz
conf-0730a4af3b5f6167d441afbaeea415b206f9c8be.zip
add get operations for backlight and volume
-rwxr-xr-xbin/hornet/backlight27
-rwxr-xr-xbin/hornet/volume67
2 files changed, 67 insertions, 27 deletions
diff --git a/bin/hornet/backlight b/bin/hornet/backlight
index b98d1bd..314e874 100755
--- a/bin/hornet/backlight
+++ b/bin/hornet/backlight
@@ -3,17 +3,6 @@ use strict;
use warnings;
use 5.014;
-my $inc;
-if ($ARGV[0] eq 'inc') {
- $inc = 1;
-}
-elsif ($ARGV[0] eq 'dec') {
- $inc = -1;
-}
-else {
- die "unknown arg '$ARGV[0]'";
-}
-
my @levels = (
1,
2,
@@ -35,6 +24,22 @@ for my $i (0..$#levels) {
$idx = $i;
last if $level >= $current;
}
+
+my $inc;
+if ($ARGV[0] eq 'inc') {
+ $inc = 1;
+}
+elsif ($ARGV[0] eq 'dec') {
+ $inc = -1;
+}
+elsif ($ARGV[0] eq 'get') {
+ say $idx * 10;
+ exit;
+}
+else {
+ die "unknown arg '$ARGV[0]'";
+}
+
my $new_idx = $idx + $inc;
if ($new_idx >= 0 && $new_idx <= $#levels) {
my $new_level = $levels[$new_idx] * 0.1;
diff --git a/bin/hornet/volume b/bin/hornet/volume
index 42c0b8e..56f5209 100755
--- a/bin/hornet/volume
+++ b/bin/hornet/volume
@@ -1,17 +1,52 @@
-#!/bin/sh
-set -eu
-set -o pipefail
+#!/usr/bin/env perl
+use strict;
+use warnings;
+use 5.014;
-case $1 in
- up)
- pactl set-sink-mute 3 0
- pactl set-sink-volume 3 +5%
- ;;
- down)
- pactl set-sink-mute 3 0
- pactl set-sink-volume 3 -5%
- ;;
- mute)
- pactl set-sink-mute 3 toggle
- ;;
-esac
+chomp(my $sink=`pacmd stat | grep 'Default sink name' | sed 's/^Default sink name: //'`);
+
+sub get {
+ my $volume;
+
+ for (split "\n", `pacmd list-sinks`) {
+ chomp;
+ next unless /name: <\Q$sink\E>/../^$/;
+ if (/^\s+volume: .* ([0-9]+)% /) {
+ if (!defined($volume)) {
+ $volume = $1;
+ }
+ }
+ elsif (/^\s+muted: yes/) {
+ $volume = 'mute';
+ last;
+ }
+ }
+
+ $volume
+}
+
+if ($ARGV[0] eq 'get') {
+ say get;
+}
+elsif ($ARGV[0] eq 'up') {
+ my $get = get;
+ system("pactl set-sink-mute $sink 0");
+ if ($get eq 'mute') {
+ exit;
+ }
+ elsif ($get <= 95) {
+ system("pactl set-sink-volume $sink +5%");
+ }
+ elsif ($get < 100) {
+ system("pactl set-sink-volume $sink 100%");
+ }
+}
+elsif ($ARGV[0] eq 'down') {
+ system("pactl set-sink-volume $sink -5%");
+}
+elsif ($ARGV[0] eq 'mute') {
+ system("pactl set-sink-mute $sink toggle")
+}
+else {
+ die "unknown command '$ARGV[0]'";
+}