Add native notifications with OSD-style banners and a Control Center module
glassMxrph now owns org.freedesktop.Notifications. Banners drop out of the bar like the OSD; Control Center stacks history per app like macOS Notification Center. Do Not Disturb lives in the shell and falls back to SwayNC while another daemon holds the bus name. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
d7f0498ba0
commit
395de70b26
17 files changed
+1132
-13
No files matched your search
@@ -0,0 +1,77 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Real Wayland notification test on a private session bus (the user's daemon is untouched).
|
||||
Run inside one: dbus-run-session -- python3 tests/notifications_runtime.py [screenshot-dir]"""
|
||||
import json,os,subprocess,sys,tempfile,time
|
||||
from pathlib import Path
|
||||
ROOT=Path(__file__).resolve().parents[1]
|
||||
BASE=['quickshell','ipc','--path',str(ROOT/'quickshell'),'call']
|
||||
SHOTS=Path(sys.argv[1]) if len(sys.argv)>1 else None
|
||||
def ipc(target,method,*args):
|
||||
r=subprocess.run(BASE+[target,method,*map(str,args)],capture_output=True,text=True)
|
||||
out=r.stdout.strip()
|
||||
if r.returncode or not out:return None
|
||||
try:return json.loads(out)
|
||||
except ValueError:return out
|
||||
def status():return ipc('notifications','status') or {}
|
||||
def wait(check,label,timeout=15):
|
||||
end=time.monotonic()+timeout
|
||||
while time.monotonic()<end:
|
||||
try:
|
||||
if check():return
|
||||
except (TypeError,KeyError,ValueError):pass
|
||||
time.sleep(.08)
|
||||
raise AssertionError(label+': '+json.dumps(status()))
|
||||
def notify(*args):subprocess.run(['notify-send',*args],check=True,timeout=5)
|
||||
def shot(name):
|
||||
if SHOTS:
|
||||
time.sleep(.6);SHOTS.mkdir(parents=True,exist_ok=True)
|
||||
focused=next(m['name'] for m in json.loads(subprocess.check_output(['hyprctl','monitors','-j'],text=True)) if m['focused'])
|
||||
subprocess.run(['grim','-o',focused,str(SHOTS/(name+'.png'))],check=False)
|
||||
if 'DBUS_SESSION_BUS_ADDRESS' not in os.environ or ipc('shell','status'):raise SystemExit('Run in a private dbus-run-session with no instance from this path.')
|
||||
log=ROOT/'.cache/notifications-runtime.log';log.parent.mkdir(exist_ok=True)
|
||||
with tempfile.TemporaryDirectory(prefix='glassmxrph-notifications-') as tmp:
|
||||
cfg=Path(tmp)/'config/glassMxrph/config.json';cfg.parent.mkdir(parents=True)
|
||||
cfg.write_text(json.dumps({'schemaVersion':3,'dock':{'enabled':False},'notifications':{'timeout':4000}}))
|
||||
env=dict(os.environ,XDG_CONFIG_HOME=tmp+'/config',XDG_STATE_HOME=tmp+'/state',XDG_CACHE_HOME=tmp+'/cache',QT_NO_XDG_DESKTOP_PORTAL='1')
|
||||
with log.open('w') as output:
|
||||
shell=subprocess.Popen([str(ROOT/'scripts/glassmxrph'),'run'],env=env,stdout=output,stderr=subprocess.STDOUT)
|
||||
try:
|
||||
wait(lambda:ipc('shell','status')['ready'],'ready')
|
||||
wait(lambda:status()['active'] and status()['owner']=='shell','shell owns the notification bus')
|
||||
notify('-a','Mail','-i','mail-unread','New message','Lunch at <b>noon</b>? The usual place.')
|
||||
wait(lambda:status()['count']==1 and status()['popups']==1,'banner shown')
|
||||
shot('1-banner')
|
||||
notify('-a','Chat','Ada','Did you see the build?')
|
||||
notify('-a','Chat','Grace','Ship it 🚀')
|
||||
notify('-a','Chat','Linus','One more thing…')
|
||||
notify('-u','critical','-a','Battery','Battery low','5% remaining')
|
||||
wait(lambda:status()['count']==5,'history keeps everything')
|
||||
wait(lambda:status()['popups']==3,'banner stack capped at maxPopups')
|
||||
shot('2-stack')
|
||||
# Non-critical banners time out into history; the critical one stays.
|
||||
wait(lambda:status()['popups']==1,'banners expire',timeout=10)
|
||||
assert status()['count']==5
|
||||
groups={g['app']:g['count'] for g in status()['groups']}
|
||||
assert groups=={'Mail':1,'Chat':3,'Battery':1},groups
|
||||
ipc('controlcenter','open')
|
||||
wait(lambda:ipc('controlcenter','status')['opened'],'control center opens')
|
||||
wait(lambda:status()['popups']==0,'opening Control Center clears banners')
|
||||
shot('3-controlcenter')
|
||||
ipc('controlcenter','close')
|
||||
assert ipc('notifications','setDnd','true')
|
||||
wait(lambda:status()['dnd'],'dnd on')
|
||||
notify('-a','Mail','Quiet','Should not pop up')
|
||||
wait(lambda:status()['count']==6,'dnd still records')
|
||||
time.sleep(.5);assert status()['popups']==0,'dnd suppresses banners'
|
||||
notify('-u','critical','-a','Alarm','Wake up','Critical breaks through')
|
||||
wait(lambda:status()['popups']==1,'critical alerts break through dnd')
|
||||
ipc('notifications','setDnd','false');ipc('notifications','dismiss')
|
||||
wait(lambda:status()['popups']==0 and status()['count']==7,'dismiss hides banners but keeps history')
|
||||
ipc('notifications','clear')
|
||||
wait(lambda:status()['count']==0,'clear empties history')
|
||||
wait(lambda:json.loads(cfg.read_text())['notifications']['doNotDisturb'] is False,'dnd persisted')
|
||||
print('Notification server, banners, stacking, expiry, DND, Control Center grouping and clearing passed.')
|
||||
finally:
|
||||
shell.terminate()
|
||||
try:shell.wait(5)
|
||||
except subprocess.TimeoutExpired:shell.kill()
|
||||
Reference in new issue
Block a user