Initial commit of the Quickshell desktop suite: bar, dock, launcher, settings, Control Center, dashboard, OSD, lock screen, desktop widgets, plugin host with the vendored Noctalia/Omarchy compatibility layer, helpers, packaging, tests and phase documentation. Includes the optimization work so far: usage widgets and dashboard gauges no longer animate continuously, desktop widgets pause while covered, system controls stop flickering on background polls, dock app matching uses an indexed catalog, and workspace ghosts are created only for occupied slots. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
138 lines
5.0 KiB
Python
138 lines
5.0 KiB
Python
#!/usr/bin/env python3
|
|
"""EasyEffects 10-band equalizer bridge. Prints one JSON status object.
|
|
|
|
status installed/running/bypass plus the saved equalizer
|
|
apply GAINS NAME save gains (JSON list of 10 dB values) and load them as the
|
|
"glassmxrph_eq" output preset, starting the service if needed
|
|
bypass on|off global EasyEffects bypass
|
|
"""
|
|
import json, os, re, shutil, subprocess, sys, time
|
|
from pathlib import Path
|
|
|
|
PRESET = 'glassmxrph_eq'
|
|
FREQUENCIES = [32, 63, 125, 250, 500, 1000, 2000, 4000, 8000, 16000]
|
|
STATE = Path(os.environ.get('XDG_STATE_HOME') or Path.home() / '.local/state') / 'glassMxrph/equalizer.json'
|
|
|
|
|
|
def binary():
|
|
return os.environ.get('GLASSMXRPH_EASYEFFECTS') or shutil.which('easyeffects')
|
|
|
|
|
|
def run(*args, timeout=4):
|
|
try:
|
|
return subprocess.run([binary(), *args], capture_output=True, text=True, timeout=timeout)
|
|
except (OSError, subprocess.TimeoutExpired):
|
|
return None
|
|
|
|
|
|
def version():
|
|
p = run('--version')
|
|
m = re.search(r'(\d+)\.(\d+)', (p.stdout + p.stderr) if p else '')
|
|
return (int(m.group(1)), int(m.group(2))) if m else (8, 0)
|
|
|
|
|
|
def running():
|
|
# Nix wraps the binary as .easyeffects-wrapped; match the executable name only.
|
|
for proc in Path('/proc').glob('[0-9]*'):
|
|
try:
|
|
argv0 = (proc / 'cmdline').read_bytes().split(b'\0', 1)[0].decode(errors='ignore')
|
|
except OSError:
|
|
continue
|
|
if re.fullmatch(r'\.?easyeffects(-wrapped)?', os.path.basename(argv0)):
|
|
return True
|
|
return False
|
|
|
|
|
|
def load_state():
|
|
try:
|
|
data = json.loads(STATE.read_text())
|
|
bands = [max(-12.0, min(12.0, float(v))) for v in data['bands']][:10]
|
|
if len(bands) == 10:
|
|
return dict(bands=bands, preset=str(data.get('preset', 'Custom')))
|
|
except (OSError, ValueError, KeyError, TypeError):
|
|
pass
|
|
return dict(bands=[0.0] * 10, preset='Flat')
|
|
|
|
|
|
def preset_dir():
|
|
# EasyEffects 8 keeps presets under XDG data; 7.x used XDG config.
|
|
if version() >= (8, 0):
|
|
return Path(os.environ.get('XDG_DATA_HOME') or Path.home() / '.local/share') / 'easyeffects/output'
|
|
return Path(os.environ.get('XDG_CONFIG_HOME') or Path.home() / '.config') / 'easyeffects/output'
|
|
|
|
|
|
def write_preset(bands):
|
|
band = lambda f, g: dict(frequency=f, gain=g, mode='Bell', mute=False, q=1.41, solo=False, width=1.0, slope='x1')
|
|
channel = {f'band{i}': band(f, bands[i]) for i, f in enumerate(FREQUENCIES)}
|
|
preset = {'output': {'blocklist': [], 'plugins_order': ['equalizer'], 'equalizer': {
|
|
'bypass': False, 'input-gain': 0.0, 'output-gain': 0.0, 'left': channel, 'right': channel,
|
|
'mode': 'IIR', 'num-bands': len(FREQUENCIES), 'split-channels': False}}}
|
|
directory = preset_dir()
|
|
directory.mkdir(parents=True, exist_ok=True)
|
|
tmp = directory / f'.{PRESET}.json.tmp'
|
|
tmp.write_text(json.dumps(preset, indent=4))
|
|
tmp.replace(directory / f'{PRESET}.json')
|
|
|
|
|
|
def ensure_service():
|
|
if running():
|
|
return True
|
|
# Service mode keeps it in the background; loading a preset without a running
|
|
# instance would open the full window instead.
|
|
flag = '--service-mode' if version() >= (8, 0) else '--gapplication-service'
|
|
try:
|
|
subprocess.Popen([binary(), flag, '-w'], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, start_new_session=True)
|
|
except OSError:
|
|
return False
|
|
for _ in range(30):
|
|
if running():
|
|
time.sleep(0.6)
|
|
return True
|
|
time.sleep(0.1)
|
|
return False
|
|
|
|
|
|
def bypassed():
|
|
if not running():
|
|
return False
|
|
p = run('-b', '3')
|
|
text = (p.stdout if p else '').strip().lower()
|
|
return text in ('1', 'true', 'on', 'enabled')
|
|
|
|
|
|
def status(error=''):
|
|
installed = bool(binary())
|
|
state = load_state()
|
|
alive = installed and running()
|
|
return dict(installed=installed, running=alive, bypass=installed and alive and bypassed(), bands=state['bands'],
|
|
preset=state['preset'], frequencies=FREQUENCIES, error=error)
|
|
|
|
|
|
def main():
|
|
command = sys.argv[1] if len(sys.argv) > 1 else 'status'
|
|
error = ''
|
|
if command == 'apply' and binary():
|
|
try:
|
|
bands = [max(-12.0, min(12.0, float(v))) for v in json.loads(sys.argv[2])][:10]
|
|
if len(bands) != 10:
|
|
raise ValueError('expected 10 bands')
|
|
STATE.parent.mkdir(parents=True, exist_ok=True)
|
|
STATE.write_text(json.dumps(dict(bands=bands, preset=sys.argv[3] if len(sys.argv) > 3 else 'Custom')))
|
|
write_preset(bands)
|
|
if not ensure_service():
|
|
error = 'EasyEffects did not start'
|
|
elif not (p := run('-l', PRESET)) or p.returncode != 0:
|
|
error = 'EasyEffects rejected the preset'
|
|
except (ValueError, IndexError, OSError) as e:
|
|
error = str(e)
|
|
elif command == 'bypass' and binary():
|
|
if running():
|
|
run('-b', '1' if (sys.argv[2:] or ['on'])[0] == 'on' else '2')
|
|
else:
|
|
error = 'EasyEffects is not running'
|
|
print(json.dumps(status(error)))
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|