Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions showcase/panel/panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -1125,6 +1125,7 @@
const scroll = $('pane-' + tab).closest('.body').scrollTop;
head();
const pane = $(`pane-${tab}`);
if (!Object.hasOwn(PANES, tab)) tab = 'home'; // show() only sets page names; this keeps PANES[tab] one of them
const same = render.tab === tab; render.tab = tab;
const before = new Set([...pane.querySelectorAll('[data-anim]')].filter(shown).map((n) => n.dataset.anim));
// A page with a list fits it to the room left and pages it; any other page scrolls.
Expand Down
44 changes: 32 additions & 12 deletions showcase/tauri/src-tauri/hands-linux/roamies-hands
Original file line number Diff line number Diff line change
Expand Up @@ -884,16 +884,37 @@ def atspi_ui(win):
# ---------------------------------------------------------------- OCR


def temp_png():
"""A new .png file only this user can read, for grim or convert to write over. mkstemp makes it, so no other
program can take the name between choosing it and writing it (mktemp's race)."""
fd, path = tempfile.mkstemp(suffix=".png")
os.close(fd)
return path


def drop(path):
try:
os.unlink(path)
except OSError:
pass


def wrote(r, path):
"""The command succeeded and left a picture (an empty file is what mkstemp made)."""
return r.returncode == 0 and os.path.exists(path) and os.path.getsize(path) > 0


def capture_png(win=None, screen=False, cursor=False):
tmp = tempfile.mktemp(suffix=".png")
tmp = temp_png()
cmd = ["grim"]
if cursor:
cmd.append("-c")
if not screen and win:
x, y, w, h = win["bounds"]
cmd += ["-g", f"{x},{y} {w}x{h}"]
r = sh(cmd + [tmp])
if r.returncode != 0 or not os.path.exists(tmp):
if not wrote(r, tmp):
drop(tmp)
return None
return tmp

Expand Down Expand Up @@ -936,11 +957,12 @@ def browser_sidebar(win):
return []
x, y, w, h = win["bounds"]
sw = min(380, w)
tmp = tempfile.mktemp(suffix=".png")
tmp = temp_png()
r = sh(["grim", "-g", f"{x},{y} {sw}x{h}", tmp])
if r.returncode != 0 or not os.path.exists(tmp):
if not wrote(r, tmp):
drop(tmp)
return []
big = tempfile.mktemp(suffix=".png")
big = temp_png()
try:
sh(["convert", tmp, "-resize", "200%", big])
scale = scale_for(win["bounds"]) * 2
Expand Down Expand Up @@ -972,7 +994,7 @@ def ocr_ui(win):
words = tsv_words(png, win["bounds"][:2], scale)
if len(words) < 4:
# Dark themes and thin terminal fonts read better inverted; try once more.
alt = tempfile.mktemp(suffix=".png")
alt = temp_png()
try:
sh(["convert", png, "-colorspace", "Gray", "-negate", "-normalize", alt])
more = tsv_words(alt, win["bounds"][:2], scale)
Expand Down Expand Up @@ -1753,14 +1775,11 @@ TYPE_TEST_TEXT = ("Hello, World! This is a long typing test: 1234567890.\n\n"
def cmd_selftest_type():
"""Type the same long string into a Wayland terminal and an XWayland terminal, then compare the files."""
results = []
work = tempfile.mkdtemp(prefix="roamies-type-") # private to this user, unlike a fixed name in /tmp
for label, x11 in (("wayland", False), ("xwayland", True)):
title = "TypeSelf" + label
target = f"/tmp/roamies-type-{label}.txt"
try:
os.unlink(target)
except Exception:
pass
args = ["kitty", "--title", title, "sh", "-c", f"cat > {target}"]
target = os.path.join(work, f"{label}.txt")
args = ["kitty", "--title", title, "sh", "-c", 'cat > "$0"', target]
if x11:
args = ["env", "-u", "WAYLAND_DISPLAY"] + args
subprocess.Popen(["setsid"] + args, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
Expand All @@ -1785,6 +1804,7 @@ def cmd_selftest_type():
except Exception:
got = ""
results.append({"where": label, "ok": got == TYPE_TEST_TEXT, "expected": TYPE_TEST_TEXT, "got": got[:800]})
shutil.rmtree(work, ignore_errors=True)
out({"ok": all(r.get("ok") for r in results), "text": TYPE_TEST_TEXT, "results": results})


Expand Down
Loading