Unix/Arch Linux

Volume Mixer OSD for OpenBox (LXDE)

ForceCore 2021. 7. 27. 20:04

https://forcecore.tistory.com/1417  : 저번에 하긴 했었는데 python3가 끼어있다. 근데 perl보다 느리니까 ㅡㅡㅋ;; 그리고 OSD라고 하긴 tray notification이라 좀 못생겼다. 이번 것은 좀 더 OSD스럽다.

 

LXDE 볼륨 조절 OSD

github.com/maur1th/LXDE-VolumeControlOSD maur1th/LXDE-VolumeControlOSD Volume control and OSD for LXDE with pulseaudio and xfce4-notifyd (lubuntu 14.04 setup) - maur1th/LXDE-VolumeControlOSD github...

forcecore.tistory.com

https://blog.cykerway.com/posts/2010/08/19/volume-control-osd-for-openbox.html

 

Volume Control OSD for Openbox

I’ve looked up a lightweight volume control OSD for Openbox for over an hour. I want it simple, no-dependency and XF86Audio-keys-supported so it’s really hard to find. But finally I got this pretty tool, written in Bash. It’s a small script which can

blog.cykerway.com

AUR에서 libaosd 를 설치해야한다. 그러면 aosd_cat 명령어가 생겨서 화면에 글씨 띄우는 것이 있다.
libaosd 자체도 꽤 낡았는데 아직도 컴파일되고 잘 작동한다 ㄷㄷㄷㄷㄷㄷㄷㄷㄷ

사이트에 나온 스크립트는 perl로 포팅했다. 좀 낡아서... 무려 2010년 ㄷㄷㄷ
작동 안 하는 부분은 오로지 amixer 명령어가 좀 달라져서 어긋난 부분!

 

/usr/local/bin/mixer-osd 란 파일을 만들고 내용은 아래처럼 한다.

그리고 chmod +x /usr/local/bin/mixer-osd 하면 스크립트는 완성.

#!/usr/bin/perl
#============================================#
#   mixer-osd
#============================================#
use strict;

# Get on/off state of the sound.
# $1 = vol_change: string, one of 0+, N+, M-
# Returns array of string, which contains new volume info.
sub get_vol_state
{
    my $vol_change = shift;
    my $output = `amixer sset Master $vol_change`;
    # $output looks like this:
    # Simple mixer control 'Master',0
    # Capabilities: pvolume pswitch pswitch-joined
    # Playback channels: Front Left - Front Right
    # Limits: Playback 0 - 65536
    # Mono:
    # Front Left: Playback 30200 [46%] [on]
    # Front Right: Playback 30200 [46%] [on]
    $output =~ /Front Left:(.*)/;  # Match this line

    my $volume_line = $1;
    my @data = split(/\s+/, $volume_line);
    return @data;
}

sub voltoggle
{
    my @state = get_vol_state("toggle");
    return $state[4];
}

sub volup
{
    my @state = get_vol_state("5%+");
    return $state[3];
}

sub voldown
{
    my @state = get_vol_state("5%-");
    return $state[3];
}

###
### main
###

my $msg = "";
my $action = shift;  # Get one from argv

if ($action eq "volup")
{
    my $vol = volup();
    $msg = "VOLUME: $vol";
}
elsif ($action eq "voldown")
{
    my $vol = voldown();
    $msg = "VOLUME: $vol";
}
elsif ($action eq "toggle")
{
    my $vol = voltoggle();
    $msg = "VOLUME: $vol";
}
else
{
    print("Usage: mixer-osd { volup | voldown | toggle}\n");
}

system("killall aosd_cat &> /dev/null");
system("echo $msg |  aosd_cat -p 4 --fore-color=green --shadow-color=#006633 --font='Droid Sans Mono 32' --x-offset=-40 --y-offset=-0 --transparency=2 --fade-in=0 --fade-out=0 --fade-full=500");

이제 LXDE 단축키 편집을 통해 (GUI가 있다... OpenBox에는 없지만 LXDE만해도 단축키 편집 GUI 프로그램이 있다) mixer-osd volup / voldown toggle을 등록해주자.

 

2024-03-12: perl-x11-aosd 패키지를 설치해야 되고 amixer대신 pavucontrol 명령어 사용.

#!/usr/bin/perl
#============================================#
#   mixer-osd
#============================================#
use strict;

# Get on/off state of the sound.
# $1 = vol_change: string, one of 0+, N+, M-
# Returns current volume
sub get_vol_state
{
    my $vol_change = shift;
    my $cmd = "pactl set-sink-volume \@DEFAULT_SINK\@ $vol_change";
    system($cmd);

    my $output = `pactl get-sink-volume \@DEFAULT_SINK\@`;
    # $output looks like this:
    # Volume: front-left: 32729 /  50% / -18.09 dB,   front-right: 32729 /  50% / -18.09 dB
    #    balance 0.00
    $output =~ /front-left: .* ([0-9]+)%/;  # Match this line

    return $1;
}

sub voltoggle
{
    return get_vol_state("toggle");
}

sub volup
{
    return get_vol_state("+5%");
}

sub voldown
{
    return get_vol_state("-5%");
}

###
### main
###

my $msg = "";
my $action = shift;  # Get one from argv

if ($action eq "volup")
{
    my $vol = volup();
    $msg = "VOLUME: $vol";
}
elsif ($action eq "voldown")
{
    my $vol = voldown();
    $msg = "VOLUME: $vol";
}
elsif ($action eq "toggle")
{
    my $vol = voltoggle();
    $msg = "VOLUME: $vol";
}
else
{
    print("Usage: mixer-osd { volup | voldown | toggle}\n");
}

system("killall aosd_cat &> /dev/null");
system("echo $msg |  aosd_cat -p 4 --fore-color=green --shadow-color=#006633 --font='Droid Sans Mono 32' --x-offset=-40 --y-offset=-0 --transparency=2 --fade-in=0 --fade-out=0 --fade-full=500");