Selections publish the system PRIMARY selection; middle-click, Shift+Insert and Paste Selection read it, and never fall back to CLIPBOARD. Ctrl+V pastes a clipboard PNG as a private file path and falls back to text, while Ctrl+Shift+V and Paste stay text-only. Copy as HTML offers plain text and escaped HTML through Kryon's MIME clipboard, and Kryon's image clipboard replaces the local GTK reader. Alt-click and Ctrl-click open web links, OSC 8 hyperlinks and e-mail addresses through kryon/open_uri in standalone and embedded windows, with a pointer cursor over links. The right-click menu matches xfce4-terminal 1.1.4: link and e-mail actions, Open Tab/Terminal/File Manager Here, Copy, Copy as HTML, Paste, Paste Selection, Show Menubar/Fullscreen/Read-Only check rows, Send Signal and Zoom submenus, Save Contents and Preferences. Right-click keeps the selection and copies nothing until a copy action is chosen. make install also installs the Xfce TerminalEmulator helper. Terminal starts in HOME unless told otherwise, so the helper passes --working-directory=. for the folder Exo starts it in, and runs launch commands with -x because Exo splits them into words. Thunar's Open Terminal Here and exo-open now open the selected folder. Terminal builds against Kryon's package-qualified widget imports now that the Widgets facade and *_props modules are gone, and the lock moves to the Kryon commit with the PRIMARY API and to the matching Ziran toolchain. CI installs the GTK, X11 and xcb development files, ImageMagick, tesseract and exo-utils the build and the new window tests need. The application context-menu test follows the new menu by label. The link test focuses the window and Shift+right-clicks while the child tracks the mouse; the selection test uses a window tall enough to reach Copy and gives each menu copy a fresh CLIPBOARD owner; the rendered-menu test reads 2x captures and waits for the submenu; the Thunar test launches the real Terminal through Exo.
143 lines
5.8 KiB
Python
143 lines
5.8 KiB
Python
"""Rendered xfce4-terminal 1.1.4 context-menu reference on private Xvfb."""
|
|
import os
|
|
from pathlib import Path
|
|
from difflib import SequenceMatcher
|
|
import re
|
|
import shlex
|
|
import shutil
|
|
import subprocess
|
|
import sys
|
|
import tempfile
|
|
import time
|
|
|
|
sys.dont_write_bytecode = True
|
|
from standalone_window_test import close_window
|
|
|
|
|
|
REFERENCE = (
|
|
'open tab', 'open terminal', 'open file manager here',
|
|
'copy', 'copy as html', 'paste', 'paste selection',
|
|
'show menubar', 'fullscreen', 'read-only', 'send signal', 'zoom',
|
|
'save contents', 'preferences',
|
|
)
|
|
|
|
|
|
def wait(predicate, message, seconds=8):
|
|
deadline = time.monotonic() + seconds
|
|
while time.monotonic() < deadline:
|
|
value = predicate()
|
|
if value:
|
|
return value
|
|
time.sleep(.06)
|
|
raise AssertionError(message)
|
|
|
|
|
|
def normalized(text):
|
|
return re.sub(r'[^a-z0-9+.-]+', ' ', text.lower()).strip()
|
|
|
|
|
|
def in_order(text, phrases):
|
|
rows = tuple(filter(None, text.splitlines()))
|
|
at = 0
|
|
for phrase in phrases:
|
|
for index in range(at, len(rows)):
|
|
if phrase in rows[index] or SequenceMatcher(None, phrase, rows[index]).ratio() >= .72:
|
|
at = index + 1
|
|
break
|
|
else:
|
|
return False
|
|
return True
|
|
|
|
|
|
def screenshot_text(window, env, root):
|
|
image = root / 'context-menu.png'
|
|
subprocess.run(['import', '-window', window, '-resize', '200%', str(image)], env=env,
|
|
check=True, timeout=5, stdout=subprocess.DEVNULL,
|
|
stderr=subprocess.DEVNULL)
|
|
result = subprocess.run(['tesseract', str(image), 'stdout', '--psm', '4'],
|
|
env=env, check=True, timeout=8, text=True,
|
|
capture_output=True)
|
|
return '\n'.join(normalized(line) for line in result.stdout.splitlines())
|
|
|
|
|
|
def main():
|
|
assert os.environ.get('TERMINAL_PRIVATE_XVFB') == '1'
|
|
assert os.environ['DISPLAY'].startswith(':')
|
|
assert os.environ.get('HARMONY_DESKTOP_RECOVERY') == '0'
|
|
for program in ('xdotool', 'import', 'tesseract'):
|
|
assert shutil.which(program), f'{program} is required for the rendered menu comparison'
|
|
binary = str(Path(sys.argv[1]).resolve())
|
|
Path('build/ziran').mkdir(parents=True, exist_ok=True)
|
|
with tempfile.TemporaryDirectory(prefix='terminal-context-menu-', dir='build/ziran') as directory:
|
|
root = Path(directory).resolve()
|
|
shell = root / 'shell'
|
|
shell.write_text('#!/bin/sh\nexec /bin/sh -c "$2"\n')
|
|
shell.chmod(0o700)
|
|
child = root / 'child.py'
|
|
ready = root / 'ready'
|
|
child.write_text(
|
|
'import os,sys,tty\n'
|
|
'tty.setraw(0)\n'
|
|
'open(sys.argv[1],"wb").close()\n'
|
|
'while os.read(0,1024): pass\n')
|
|
env = dict(os.environ, XDG_CONFIG_HOME=str(root / 'config'),
|
|
XDG_STATE_HOME=str(root / 'state'), SDL_VIDEODRIVER='x11',
|
|
LP_NUM_THREADS='1', OMP_NUM_THREADS='1')
|
|
|
|
def xdo(*args):
|
|
return subprocess.run(['xdotool', *map(str, args)], env=env, text=True,
|
|
capture_output=True, check=True, timeout=5).stdout.strip()
|
|
|
|
with (root / 'window.log').open('w') as log:
|
|
command = 'python3 ' + shlex.quote(str(child)) + ' ' + shlex.quote(str(ready))
|
|
app = subprocess.Popen([
|
|
binary, '--hide-menubar', '--hide-toolbar', '--geometry', '80x34',
|
|
'--shell', str(shell), '-e', command,
|
|
], env=env, stdout=log, stderr=log)
|
|
try:
|
|
def find_window():
|
|
found = subprocess.run(
|
|
['xdotool', 'search', '--onlyvisible', '--pid', str(app.pid)],
|
|
env=env, capture_output=True, text=True)
|
|
lines = found.stdout.splitlines()
|
|
return lines[-1] if found.returncode == 0 and lines and ready.exists() else None
|
|
|
|
window = wait(find_window, 'Terminal context-menu fixture did not open')
|
|
assert int(xdo('getwindowpid', window)) == app.pid
|
|
xdo('windowfocus', '--sync', window)
|
|
time.sleep(.3)
|
|
xdo('mousemove', '--window', window, 60, 100)
|
|
xdo('mousedown', '3'); time.sleep(.15); xdo('mouseup', '3')
|
|
|
|
# Each capture is read until the expected rows appear, so a frame
|
|
# taken before the menu or submenu is painted is not judged.
|
|
def rendered(phrases):
|
|
def read():
|
|
text = screenshot_text(window, env, root)
|
|
return text if in_order(text, phrases) else None
|
|
return read
|
|
|
|
text = wait(rendered(REFERENCE), 'Context menu was not rendered')
|
|
assert in_order(text, REFERENCE), repr(text)
|
|
assert 'open link' not in text and 'compose email' not in text
|
|
|
|
# The reference Zoom row is 335 units below the panel top and
|
|
# is 26 units tall. Hovering it must render the three reference
|
|
# submenu actions and their accelerator labels.
|
|
xdo('mousemove', '--window', window, 120, 448)
|
|
zoom = wait(rendered(('zoom in', 'zoom out', 'normal size')),
|
|
'Zoom submenu was not rendered')
|
|
assert in_order(zoom, ('zoom in', 'zoom out', 'normal size')), zoom
|
|
assert zoom.count('ctrl') >= 3, zoom
|
|
close_window(window, app.pid, env)
|
|
assert app.wait(timeout=5) == 0
|
|
finally:
|
|
if app.poll() is None:
|
|
app.terminate()
|
|
app.wait(timeout=5)
|
|
print('Terminal rendered context menu and Zoom submenu match the captured xfce4-terminal 1.1.4 reference')
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|