#!/usr/bin/env python3 """Real Wayland Emoji Picker test on a private session bus. Copying is global on Wayland, so the user's clipboard is saved and restored. Run: dbus-run-session -- python3 tests/emoji_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 Key={'Return':0x01000004,'Right':0x01000014,'Down':0x01000015,'Escape':0x01000000} 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 snap():return ipc('launcherTest','snapshot') or {} def wait(check,label,timeout=10): end=time.monotonic()+timeout while time.monotonic()emoji') wait(lambda:snap()['results'][0]['id']=='emoji','emoji command listed') ipc('launcherTest','key',Key['Return']) wait(lambda:snap()['mode']=='emoji' and snap()['resultCount']==total,'command switches to the emoji grid') s=snap();assert s['opened'] and s['query']=='' and s['focused'],s assert (s['x'],s['y'],s['width'])==(before['x'],before['y'],before['width']),(before,s) assert s['results'][0]['id']=='😀' and s['results'][0]['title']=='grinning face',s['results'][0] time.sleep(.3);shot('1-emoji') # Six rows visible: the body stops growing past them. assert abs(s['height']-(60+6*52+42))<=2,s['height'] ipc('launcherTest','key',Key['Right']);ipc('launcherTest','key',Key['Down']) cols=snap()['selected']-1;assert cols>4,snap()['selected'] ipc('launcherTest','query','heart red') wait(lambda:snap()['results'][0]['title']=='red heart','search ranks names first') ipc('launcherTest','query','pizza') wait(lambda:[r['id'] for r in snap()['results']]==['🍕'],'search filters') shot('2-search') ipc('launcherTest','key',Key['Return']) wait(lambda:not snap()['opened'],'copying closes') wait(lambda:pasted()=='🍕','emoji copied') ipc('launcherTest','query','') ipc('launcher','emoji');wait(lambda:snap()['opened'] and snap()['mode']=='emoji','IPC opens the emoji picker') ipc('launcherTest','query','flag germany') wait(lambda:[r['id'] for r in snap()['results']]==['🇩🇪'],'keyword search') ipc('launcher','emoji');wait(lambda:not snap()['opened'],'IPC toggles it closed') ipc('launcher','open');wait(lambda:snap()['opened'] and snap()['mode']=='apps','launcher reopens in app mode') ipc('launcher','close') print('Emoji picker: >emoji switches in place, grid of six rows, search, copy, IPC toggle passed.') finally: shell.terminate() try:shell.wait(5) except subprocess.TimeoutExpired:shell.kill() if saved.returncode==0: restore=subprocess.Popen(['wl-copy'],stdin=subprocess.PIPE,stdout=subprocess.DEVNULL,stderr=subprocess.DEVNULL,start_new_session=True) restore.stdin.write(saved.stdout);restore.stdin.close()