Add new version of audio device controller
This commit is contained in:
parent
3630cc2bf5
commit
41a9604735
6 changed files with 91 additions and 2 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -1,8 +1,9 @@
|
||||||
# TOML Bombadil templating directory
|
# TOML Bombadil templating directory
|
||||||
.dots/
|
.dots/
|
||||||
|
|
||||||
# Python cache files
|
# Python files
|
||||||
**/__pycache__/
|
**/__pycache__/
|
||||||
|
**/venv/
|
||||||
|
|
||||||
# Program-specific cache files
|
# Program-specific cache files
|
||||||
nvim/lazy-lock.json
|
nvim/lazy-lock.json
|
||||||
|
|
10
rofi/audio.py
Executable file
10
rofi/audio.py
Executable file
|
@ -0,0 +1,10 @@
|
||||||
|
#!/home/mbradley/.config/rofi/venv/bin/python -OO
|
||||||
|
from sys import argv
|
||||||
|
|
||||||
|
from rofi_menu import run
|
||||||
|
|
||||||
|
from lib.pactl import create_menu, NodeType
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
run(create_menu(NodeType[argv[1]]))
|
|
@ -1,6 +1,6 @@
|
||||||
@theme "arthuredit"
|
@theme "arthuredit"
|
||||||
configuration {
|
configuration {
|
||||||
modi: "drun,calc,emoji:/usr/bin/rofimoji -a copy -f emojis math";
|
modi: "drun,calc,emoji:/usr/bin/rofimoji -a copy -f emojis math,sinks:/home/mbradley/.config/rofi/venv/bin/python -OO /home/mbradley/.config/rofi/audio.py SINK,sources:/home/mbradley/.config/rofi/venv/bin/python -OO /home/mbradley/.config/rofi/audio.py SOURCE";
|
||||||
icon-theme: "Papirus";
|
icon-theme: "Papirus";
|
||||||
show-icons: true;
|
show-icons: true;
|
||||||
run-command: "uwsm-app -- {cmd}";
|
run-command: "uwsm-app -- {cmd}";
|
||||||
|
|
0
rofi/lib/__init__.py
Normal file
0
rofi/lib/__init__.py
Normal file
77
rofi/lib/pactl.py
Normal file
77
rofi/lib/pactl.py
Normal file
|
@ -0,0 +1,77 @@
|
||||||
|
from enum import auto, StrEnum
|
||||||
|
from json import loads
|
||||||
|
from subprocess import run
|
||||||
|
from typing import TypedDict, cast
|
||||||
|
|
||||||
|
from rofi_menu import FLAG_STYLE_URGENT, Menu, ShellItem
|
||||||
|
|
||||||
|
|
||||||
|
class NodeType(StrEnum):
|
||||||
|
SINK = auto()
|
||||||
|
SOURCE = auto()
|
||||||
|
|
||||||
|
|
||||||
|
def _pactl(*args: str) -> str:
|
||||||
|
return run(["pactl", "--format=json", *args], capture_output=True).stdout.decode()
|
||||||
|
|
||||||
|
|
||||||
|
class Volume(TypedDict):
|
||||||
|
value: int
|
||||||
|
value_percent: str
|
||||||
|
db: str
|
||||||
|
class Latency(TypedDict):
|
||||||
|
actual: float
|
||||||
|
configured: float
|
||||||
|
class Port(TypedDict):
|
||||||
|
name: str
|
||||||
|
description: str
|
||||||
|
type: str
|
||||||
|
priority: int
|
||||||
|
availability_group: str
|
||||||
|
availability: str
|
||||||
|
class Node(TypedDict):
|
||||||
|
index: int
|
||||||
|
state: str
|
||||||
|
name: str
|
||||||
|
description: str
|
||||||
|
driver: str
|
||||||
|
sample_specification: str
|
||||||
|
channel_map: str
|
||||||
|
owner_module: int
|
||||||
|
mute: bool
|
||||||
|
volume: dict[str, Volume]
|
||||||
|
balance: float
|
||||||
|
base_volume: Volume
|
||||||
|
monitor_source: str
|
||||||
|
latency: Latency
|
||||||
|
flags: list[str]
|
||||||
|
properties: dict[str, str]
|
||||||
|
ports: list[Port]
|
||||||
|
active_port: str
|
||||||
|
formats: list[str]
|
||||||
|
|
||||||
|
|
||||||
|
def list_nodes(node_type: NodeType) -> list[Node]:
|
||||||
|
return cast(list[Node], loads(_pactl("list", f"{node_type}s")))
|
||||||
|
|
||||||
|
|
||||||
|
def get_default(node_type: NodeType) -> str:
|
||||||
|
return _pactl(f"get-default-{node_type}").strip()
|
||||||
|
|
||||||
|
|
||||||
|
def create_item(node_type: NodeType, node: Node, default: str) -> ShellItem:
|
||||||
|
return ShellItem(
|
||||||
|
node["description"],
|
||||||
|
f"pactl set-default-{node_type} {node["name"]}",
|
||||||
|
flags=FLAG_STYLE_URGENT if node["name"] == default else None,
|
||||||
|
show_output=True
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def create_menu(node_type: NodeType) -> Menu:
|
||||||
|
default = get_default(node_type)
|
||||||
|
return Menu(
|
||||||
|
prompt=f"Select {node_type}",
|
||||||
|
items=[create_item(node_type, node, default) for node in list_nodes(node_type)]
|
||||||
|
)
|
||||||
|
|
1
rofi/requirements.txt
Normal file
1
rofi/requirements.txt
Normal file
|
@ -0,0 +1 @@
|
||||||
|
rofi-menu==0.6
|
Loading…
Add table
Add a link
Reference in a new issue