diff options
| author | 2024-10-27 04:31:23 +0000 | |
|---|---|---|
| committer | 2024-10-27 22:53:15 +0000 | |
| commit | b0dbffedcb91236259774e991223698b0fb114a0 (patch) | |
| tree | 27becb99dc66faac563aadc0da401448da49a013 | |
| parent | b07d54a12e7d42228093d0da7365617defd042e6 (diff) | |
Use wpctl if relevant
Also update copyright and terms
| -rw-r--r-- | PKGBUILD | 3 | ||||
| -rw-r--r-- | README.md | 26 | ||||
| -rwxr-xr-x | swob.sh | 41 |
3 files changed, 54 insertions, 16 deletions
@@ -4,8 +4,9 @@ pkgrel=1 pkgdesc='Volume and brightness controls for wayland, using wob' arch=(any) # limited only by dependencies depends=(sh coreutils sed wob alsa-utils brightnessctl) +optdepends=('wireplumber: for pipewire support') url='https://github.com/el-remph/swob' -license=(FSFULLRWD) +license=(GPL-3.0-or-later) provides=(swob) source=("git+$url") b2sums=(SKIP) @@ -5,7 +5,7 @@ This is a simple/stupid helper script and config files to provide volume and brightness controls under Wayland using [wob]. Sway is *not* mandatory (the helper script doesn't depend on sway or any wlroots features); the name is simply because sway was the first compositor I configured this for. Other -compositor configurations are available; see [Installation](#installation). +compositor configurations are available; see [§Installation](#installation). [wob]: https://github.com/francma/wob @@ -23,7 +23,9 @@ Dependencies - POSIX sh, sed and mkfifo(1); non-POSIX mktemp(1) (all pretty universally available) - [wob] -- [amixer (from alsa-utils)](https://www.alsa-project.org) +- For volume, at least one of: + - For ALSA, [amixer (from alsa-utils)](https://www.alsa-project.org) + - For Pipewire, [wireplumber and wpctl](https://pipewire.pages.freedesktop.org/wireplumber) - [brightnessctl](https://github.com/Hummer12007/brightnessctl) Installation @@ -52,10 +54,18 @@ Copying Copyright © 2024 The Remph <lhr@disroot.org> -These files are free software; the Remph gives unlimited permission to copy -and/or distribute them, with or without modification, as long as this notice -is preserved. +This program is free software: you can redistribute it and/or modify it +under the terms of the GNU General Public License as published by the Free +Software Foundation, either version 3 of the License, or (at your option) +any later version. -This software is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY, to the extent permitted by law; without even the -implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +This program is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +more details. + +A copy of the full GPL can be found at <https://www.gnu.org/licenses/GPL>. + +As an additional permission under GNU GPL version 3 section 7, the section 4 +requirement to distribute a copy of the GPL along with the work is waived, +provided that the above notices are distributed intact instead. @@ -1,6 +1,6 @@ #!/bin/sh # SPDX-FileCopyrightText: 2023-2024 The Remph <lhr@disroot.org> -# SPDX-License-Identifier: FSFULLRWD +# SPDX-License-Identifier: GPL-3.0-or-later wobfifo=${XDG_RUNTIME_DIR:-${TMPDIR:-/tmp}}/wob wobini= @@ -53,10 +53,30 @@ start_wob() { ) & } -do_cmd_get_percent() { - case $1 in - volume|vol) - amixer sset Master "$2" | sed -E ' +# This doesn't make me happy +have_pipewire() ( + set +fu + test -n "$SWOB_WPCTL" && return 0 + + # could guess at /run/user/`id -u`, but let's not jump the gun here + rundir=${PIPEWIRE_RUNTIME_DIR:-$XDG_RUNTIME_DIR} + test -z "$rundir" && return 1 + set -- "$rundir"/pipewire* + exec test $# -gt 1 -o -e "$1" +) + +set_vol() { + if have_pipewire; then + case $1 in + toggle) to_set=mute ;; + *) to_set='volume -l 1.0' ;; + esac + wpctl set-$to_set @DEFAULT_AUDIO_SINK@ "$1" + wpctl get-volume @DEFAULT_AUDIO_SINK@ | sed -E \ + -e 's/^Volume: ([0-9]+)\.([0-9][0-9])/\1\2/' \ + -e 's/\[MUTED\]/mute/' + else + amixer sset Master "$1" | sed -E ' # Extract percentage, keep original line for later h s/.*\[([0-9]+)%\].*/\1/ @@ -74,8 +94,15 @@ x } # else g -s/$/ volume/ -' ;; +s/$/ volume/' + fi +} + +do_cmd_get_percent() { + case $1 in + volume|vol) + set_vol "$2" + ;; brightness|brt) brightnessctl -m set "$2" | sed -En 's/(.*[^0-9])?([0-9]+)%.*/\2 brightness/p' ;; |
