Some updates

- scripts:
  - volumecontrol: use Wireplumber's lua API
  - mangamenu: fix recursive call

- sway, river:
  - update syntax for the new volumecontrol script
  - input keyboard layout now is set in startwl script

- system: ditch pulsemixer, replaced by pavucontrol-qt

- notification: add microphone icons
This commit is contained in:
Hoang Nguyen 2022-03-06 15:44:00 +07:00
parent 3be104b697
commit a8f3d0ed23
No known key found for this signature in database
GPG key ID: 813CF484F4993419
14 changed files with 178 additions and 90 deletions

View file

@ -30,7 +30,7 @@ ansible-playbook -v -i hosts dotfiles.yml --tags 'never,all'
- [ ] ~~[wayout](https://git.sr.ht/~proycon/wayout)~~
- [x] [fuzzel](https://codeberg.org/dnkl/fuzzel) / [rofi-wayland](https://github.com/lbonn/rofi)
- [ ] GTK/Icons/Cursor theme, Sarasa font bootstraping
- [ ] Use Wireplumber lua API for 'volumncontrol' script instead of [pulsemixer](https://github.com/GeorgeFilipkin/pulsemixer)
- [x] Use Wireplumber lua API for 'volumncontrol' script instead of [pulsemixer](https://github.com/GeorgeFilipkin/pulsemixer)
- [ ] Neovim:
- [ ] vim.api.nvim{_buf}_set_keymap -> vim.keymap.set (wait for 0.7.0 release)
- [ ] OneDark theme
@ -41,6 +41,7 @@ ansible-playbook -v -i hosts dotfiles.yml --tags 'never,all'
- [ ] Rewrite River's init file in lua
- [ ] [eww](https://github.com/elkowar/eww)
- [ ] [swhkd](https://github.com/waycrate/swhkd) (maybe?)
- [ ] [senpai](https://git.sr.ht/~taiite/senpai)
## 📓 Notes

View file

@ -23,6 +23,8 @@ ui_opacity: 0.96
# RedHat recommends 0077 for a secure server
# 0027 is a good in-between for desktop usage (0022 is the default)
umask: '0027'
# The Lua VM used for all written scripts
lua_binary: /usr/bin/lua5.4
# Font ────────────────────────────────────────────────────────────────────────
cjk_font: Sarasa Mono J

View file

@ -25,9 +25,9 @@
font-noto-emoji, gdb, git-email, git-lfs, gpg, grim, buku, drill,
gnupg-doc, jq, iproute2, gst-plugins-pipewire, sops, imagemagick,
libarchive-tools, libffi-dev, qalc, love, bombadillo, mupdf-tools,
man-pages-posix, man-pages, mecurial, meson, mpc, mpd, mpdris2,
man-pages-posix, man-pages, meson, mpc, mpd, mpdris2, pavucontrol-qt,
mpv, mpv-mpris, ncmpcpp, neovim, npm, yarn, pandoc, k9s, rustscan,
py3-pynvim, newsboat, ngrep, nmap, nushell, p7zip, packer, rsync,
py3-pynvim, newsboat, ngrep, nmap, nushell, packer, rsync,
pcmanfm-qt, pinentry-qt, podman, pipewire, sway, swappy, sshfs,
pipewire-pulse, playerctl, qimgv, qt5ct, pipewire-tools, kubectl,
py3-virtualenv, py3-setuptools, ripgrep, senpai, shellcheck, castero,
@ -37,7 +37,7 @@
xdg-desktop-portal-wlr, xdg-desktop-portal-gtk, xdg-user-dirs,
xwayland, zathura, zathura-cb, zathura-ps, zoxide, openssh-doc,
zathura-pdf-mupdf, openssh-client-default, btop, zellij, gallery-dl,
alacritty, unifont, python3-dev, py3-requests, py3-proxmoxer,
alacritty, unifont, python3-dev, py3-proxmoxer,
rofi-calc, rofi-wayland, rofi-file-browser-extended, rofi-emoji,
automake, autoconf, libtool, mbuffer, onefetch, flawfinder
state: present

View file

@ -46,17 +46,4 @@
creates: ~/.config/fish/completions/zellij.fish
when: zellij_check.rc == 0
register: zellij_completion_generated
# https://github.com/zellij-org/zellij/issues/1030
- name: zellij | Inject zellij session completion snippet
blockinfile:
path: ~/.config/fish/completions/zellij.fish
insertbefore: BOF
mode: 0644
block: |
function __fish_complete_sessions
zellij list-sessions | sed "/No active zellij sessions found./d"
end
complete -c zellij -n "__fish_seen_subcommand_from attach" -f -a "(__fish_complete_sessions)" -d "Session"
when: zellij_completion_generated.rc == 0
when: multiplexer == 'zellij'

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

View file

@ -1,8 +1,5 @@
#!/bin/sh
export XKB_DEFAULT_LAYOUT="us,ru"
export XKB_DEFAULT_OPTIONS="grp:rctrl_rshift_toggle"
# Startup commands ─────────────────────────────────────────────────────────────
# Inform dbus about the environment
@ -213,9 +210,10 @@ do
riverctl map $mode None XF86Eject spawn 'eject -T'
# Control pulse audio volume
riverctl map $mode None XF86AudioRaiseVolume spawn '~/.local/libexec/wayland/volumecontrol increase'
riverctl map $mode None XF86AudioLowerVolume spawn '~/.local/libexec/wayland/volumecontrol decrease'
riverctl map $mode None XF86AudioMute spawn '~/.local/libexec/wayland/volumecontrol toggle'
riverctl map $mode None XF86AudioRaiseVolume spawn '~/.local/libexec/wayland/volumecontrol --increase'
riverctl map $mode None XF86AudioLowerVolume spawn '~/.local/libexec/wayland/volumecontrol --decrease'
riverctl map $mode None XF86AudioMute spawn '~/.local/libexec/wayland/volumecontrol --toggle'
riverctl map $mode None XF86AudioMicMute spawn '~/.local/libexec/wayland/volumecontrol --toggle-source'
# Control MPRIS aware media players with playerctl (https://github.com/altdesktop/playerctl)
riverctl map $mode None XF86AudioMedia spawn 'playerctl play-pause'
@ -244,8 +242,8 @@ riverctl attach-mode bottom
riverctl float-filter-add app-id 'float'
riverctl float-filter-add app-id 'popup'
riverctl float-filter-add app-id 'swappy'
riverctl float-filter-add app-id 'info.febvre.Komikku'
riverctl float-filter-add app-id 'pinentry-qt'
riverctl float-filter-add app-id 'pavucontrol-qt'
# Set app-ids of views which should use client side decorations
riverctl csd-filter-add app-id 'swappy'

View file

@ -25,7 +25,7 @@ if [ -n "$1" ]; then
*.rar) unrar x -ad "$1" ;;
*.rpm)
mkdir "$extract_dir"
cd "$extract_dir"
cd "$extract_dir" || exit
rpm2cpio "../$1" | cpio --quiet -id
cd .. ;;
*.7z) 7za x "$1" ;;
@ -35,7 +35,7 @@ if [ -n "$1" ]; then
cd "$extract_dir" && ar vx "../$1" >/dev/null
cd control && tar xzvf ../control.tar.gz
cd ../data && extract ../data.tar.*
cd .. && rm *.tar.* debian-binary
cd .. && rm -- *.tar.* debian-binary
cd .. ;;
*.zst) unzstd "$1" ;;
*) atool -X "$extract_dir" "$1" || echo "$1 cannot be extracted" ;;

View file

@ -52,6 +52,10 @@ export XDG_SESSION_DESKTOP=$1
export XDG_CURRENT_DESKTOP=$1
export XDG_CURRENT_SESSION=$1
# Set keyboard layout
export XKB_DEFAULT_LAYOUT="us,ru"
export XKB_DEFAULT_OPTIONS="grp:rctrl_rshift_toggle"
# catch crashes with core dump
ulimit -c unlimited

View file

@ -0,0 +1,66 @@
#!/usr/bin/wpexec
local argv = ...
-- Print help message if no argument is provided
if argv['action'] == nil then
print [[
Usage: wpexec volume.lua action=[value] step=[volume_step]
[value] can be either 'print_sink', 'print_source', 'toggle_sink', 'toggle_source', 'increase' or 'decrease'
[volume_step] is a float in range (0,1), only required if action is 'increase' or 'decrease']]
Core.quit()
return
end
local function findValue(tbl, value)
for _, v in ipairs(tbl) do
if v == value then
return value
end
end
return nil
end
local options = { 'print_sink', 'toggle_sink', 'increase', 'decrease', 'print_source', 'toggle_source' }
local action = assert(findValue(options, argv['action']), 'Invalid value of parameter "action".')
-- Load the necessary Wireplumber API modules
Core.require_api('default-nodes', 'mixer', function(...)
local default_nodes, mixer = ...
-- configure volumes to be printed in the cubic scale
-- this is also what the pulseaudio API shows
mixer.scale = 'cubic'
local id_source = default_nodes:call('get-default-node', 'Audio/Source')
local volume_source = mixer:call('get-volume', id_source)
local id_sink = default_nodes:call('get-default-node', 'Audio/Sink')
local volume_sink = mixer:call('get-volume', id_sink)
if action == 'toggle_source' then
mixer:call('set-volume', id_source, { mute = not volume_source.mute })
elseif action == 'print_source' then
print(string.format([[
Volume: %s
Mute: %s]], string.format('%.2f', volume_source.volume), volume_source.mute))
elseif action == 'toggle_sink' then
mixer:call('set-volume', id_sink, { mute = not volume_sink.mute })
elseif action == 'print_sink' then
print(string.format([[
Volume: %s
Mute: %s]], string.format('%.2f', volume_sink.volume), volume_sink.mute))
else
-- Too lazy to check for errors here
-- assert() and error() don't quit the process in the fallback function
local step = tonumber(argv['step'])
if action == 'increase' then
mixer:call('set-volume', id_sink, { volume = volume_sink.volume + step })
else
mixer:call('set-volume', id_sink, { volume = volume_sink.volume - step })
end
end
Core.quit()
end)

View file

@ -11,8 +11,8 @@ then
chapter=$(find "${mangadir}/${manga}" -type f -exec basename '{}' \; | ${menu2})
if [ -n "${chapter}" ]
then
zathura "${mangadir}/${manga}"/"${chapter}" &
zathura "${mangadir}/${manga}/${chapter}"
else
mangamenu "$1"
$0 "$1"
fi
fi

View file

@ -1,57 +1,92 @@
#!/bin/sh
#!{{ lua_binary }}
if command -v pulsemixer >/dev/null
then
_notify_volume() {
volume=$(pulsemixer --get-volume)
# 2 channels
left=$(echo "${volume}" | cut -d' ' -f1)
right=$(echo "${volume}" | cut -d' ' -f2)
-- Wireplumber doesn't expose much of the 'os' table so here is a wrapper script
notify-send -h string:x-canonical-private-synchronous:audio -h int:value:"${left}" -i "$HOME/.config/{{ notification }}/speaker.png" "Volume: L:${left}% / R:${right}%"
}
local argv = table.pack(...)
local wireplumber_script = os.getenv('HOME') .. '/.local/libexec/volume.lua'
local icon_dir = os.getenv('HOME') .. '/.config/{{ notification }}'
local volume_step = 0.05
case $1 in
increase)
pulsemixer --change-volume +5 && _notify_volume
;;
decrease)
pulsemixer --change-volume -5 && _notify_volume
;;
toggle)
pulsemixer --toggle-mute
status=$(pulsemixer --get-mute)
if [ "${status}" -eq 1 ] || [ "${status}" = "true" ]
then
notify-send -i "$HOME/.config/{{ notification }}/mute.png" "Sound muted"
else
notify-send -i "$HOME/.config/{{ notification }}/speaker.png" "Sound unmuted"
fi ;;
*)
;;
esac
local function print_help()
io.stdout:write(string.format([[
Usage: volumecontrol [--help|--increase|--decrease|--toggle-source|--toggle]
--increase : Increase volume of default sink by %s
--decrease : Decrease volume of default sink by %s
--toggle : Toggle mute state of default sink
--toggle-source: Toggle mute state of default source
]], volume_step, volume_step))
end
if #argv == 0 then
print_help()
return
end
local action = argv[1]:match('%-%-(.+)')
local options = { 'toggle', 'toggle-source', 'increase', 'decrease' }
local function findValue(tbl, value)
for _, v in pairs(tbl) do
if v == value then
return true
end
end
return false
end
if not findValue(options, action) then
print_help()
return
end
local function read_output(command)
-- No buffering to get all output at once
io.stdout:setvbuf('no')
local file = assert(io.popen(command, 'r'))
file:flush() -- receive all the output immediately (in case the output is big)
local output = file:read('a')
file:close()
return output
end
if action == 'toggle-source' then
os.execute('wpexec ' .. wireplumber_script .. ' action=toggle_source')
local status = read_output('wpexec ' .. wireplumber_script .. ' action=print_source')
local volume = tonumber(status:match('Volume:%s+([^%a]+)')) * 100
local mute = status:match('Mute:%s+(%a+)')
if mute == 'true' then
local icon = icon_dir .. '/microphone_mute.png'
os.execute('notify-send -i ' .. icon .. ' "Microphone muted" "Volume: ' .. tostring(volume) .. '%"')
else
local icon = icon_dir .. '/microphone.png'
os.execute('notify-send -i ' .. icon .. ' "Microphone unmuted" "Volume: ' .. tostring(volume) .. '%"')
end
elseif action == 'toggle' then
os.execute('wpexec ' .. wireplumber_script .. ' action=toggle_sink')
local status = read_output('wpexec ' .. wireplumber_script .. ' action=print_sink')
local volume = tonumber(status:match('Volume:%s+([^%a]+)')) * 100
local mute = status:match('Mute:%s+(%a+)')
if mute == 'true' then
local icon = icon_dir .. '/mute.png'
os.execute('notify-send -i ' .. icon .. ' "Sound muted" "Volume: ' .. tostring(volume) .. '%"')
else
local icon = icon_dir .. '/speaker.png'
os.execute('notify-send -i ' .. icon .. ' "Sound unmuted" "Volume: ' .. tostring(volume) .. '%"')
end
else
_notify_volume() {
volume=$(amixer get Master | sed -nre 's/.*\\[(.*%)\\].*/\\1/p')
notify-send -h string:x-canonical-private-synchronous:audio -h int:value:"${volume}" -i "$HOME/.config/{{ notification }}/speaker.png" "Volume: ${volume}"
}
os.execute('wpexec ' .. wireplumber_script .. ' action=' .. action .. ' step=' .. volume_step)
case $1 in
increase)
amixer set Master 5+ && _notify_volume
;;
decrease)
amixer set Master 5- && _notify_volume
;;
toggle)
amixer set Master toggle
if amixer get Master | grep "off"
then
notify-send -i "$HOME/.config/{{ notification }}/mute.png" "Sound muted"
else
notify-send -i "$HOME/.config/{{ notification }}/speaker.png" "Sound unmuted"
fi ;;
*)
;;
esac
fi
local status = read_output('wpexec ' .. wireplumber_script .. ' action=print_sink')
local volume = tonumber(status:match('Volume:%s+([^%a]+)')) * 100
local icon = icon_dir .. '/speaker.png'
os.execute(string.format([[
notify-send -h string:x-canonical-private-synchronous:audio -h int:value:%s -i %s "Volume: %s%%"
]], tostring(volume), icon, tostring(volume)))
end

View file

@ -1,6 +1,5 @@
# remap
abbr x extract
abbr p pulsemixer
alias cp='cp -vir'
alias mv='mv -vi'
alias rm='rm -vr'

View file

@ -40,11 +40,6 @@ set $ws10 "10"
{% include 'by_host/' + ansible_hostname + '/config.j2' ignore missing %}
input type:keyboard {
xkb_layout us,ru
xkb_options grp:rctrl_rshift_toggle
}
#input * xkb_numlock enable
# Autostart ─────────────────────────────────────────────────────────────
@ -147,9 +142,10 @@ bindsym $mod+Mod1+c exec ~/.local/libexec/wayland/clipboard --clear
bindsym $mod+c exec ~/.local/libexec/wayland/clipboard --{{ launcher }}-clear | xargs swaymsg exec --
# Media keys
bindsym XF86AudioRaiseVolume exec ~/.local/libexec/wayland/volumecontrol increase
bindsym XF86AudioLowerVolume exec ~/.local/libexec/wayland/volumecontrol decrease
bindsym XF86AudioMute exec ~/.local/libexec/wayland/volumecontrol toggle
bindsym XF86AudioRaiseVolume exec ~/.local/libexec/wayland/volumecontrol --increase
bindsym XF86AudioLowerVolume exec ~/.local/libexec/wayland/volumecontrol --decrease
bindsym XF86AudioMute exec ~/.local/libexec/wayland/volumecontrol --toggle
bindsym XF86AudioMicMute exec ~/.local/libexec/wayland/volumecontrol --toggle-source
bindsym --locked XF86AudioPlay exec playerctl play-pause
bindsym --locked XF86AudioNext exec playerctl next
bindsym --locked XF86AudioPrev exec playerctl previous
@ -300,8 +296,8 @@ bindsym $mod+Shift+0 move container to workspace $ws10
# Window rules ─────────────────────────────────────────────────────────────
# Floating
for_window [app_id="info.febvre.Komikku"] floating enable
for_window [app_id="pinentry-qt"] floating enable
for_window [app_id="pavucontrol-qt"] floating enable
for_window [title="About Mozilla Firefox"] floating enable
for_window [title="Picture-in-Picture"] floating enable