More flat review improvement.

This commit is contained in:
Storm Dragon committed 2026-10-21 20:56:18 -04:00
1 parent 50e32f24df
commit e88de5ee66
41 files changed
+2167 -73

No files matched your search

+69
View File
@@ -0,0 +1,69 @@
#!/usr/bin/env python3
"""Private GTK controls for current-line AT-SPI checks."""
import json
import sys
import gi
gi.require_version("Gtk", "3.0")
from gi.repository import GLib, Gtk
window = Gtk.Window(title="Current line fixture")
box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
window.add(box)
entry = Gtk.Entry()
entry.get_accessible().set_name("Entry")
textView = Gtk.TextView()
textView.get_accessible().set_name("Text")
password = Gtk.Entry()
password.set_visibility(False)
password.get_accessible().set_name("Password")
button = Gtk.Button(label="Example button")
controls = {"entry": entry, "text": textView, "password": password, "button": button}
for control in controls.values():
box.pack_start(control, True, True, 0)
window.show_all()
def command_ready(source, condition):
line = sys.stdin.readline()
if not line:
Gtk.main_quit()
return False
command = json.loads(line)
control = controls[command["control"]]
if command["action"] == "focus":
if isinstance(control, Gtk.Entry):
control.set_text(command["text"])
control.set_position(command["offset"])
elif isinstance(control, Gtk.TextView):
buffer = control.get_buffer()
buffer.set_text(command["text"])
buffer.place_cursor(buffer.get_iter_at_offset(command["offset"]))
window.present()
control.grab_focus()
def finish_focus():
if isinstance(control, Gtk.Entry):
control.set_position(command["offset"])
elif isinstance(control, Gtk.TextView):
buffer = control.get_buffer()
buffer.place_cursor(buffer.get_iter_at_offset(command["offset"]))
print("ready", flush=True)
return False
GLib.timeout_add(50, finish_focus)
return True
elif command["action"] == "caret":
if isinstance(control, Gtk.Entry):
offset = control.get_position()
else:
buffer = control.get_buffer()
offset = buffer.get_iter_at_mark(buffer.get_insert()).get_offset()
print(offset, flush=True)
print("ready", flush=True)
return True
GLib.io_add_watch(sys.stdin, GLib.IO_IN | GLib.IO_HUP, command_ready)
print("ready", flush=True)
Gtk.main()
+55 -3
View File
@@ -10,9 +10,22 @@ static gboolean armed;
static unsigned childQueries;
static gboolean slowRanges;
static gint largestRange;
static gboolean lineGeometryOnly;
static gboolean missingGlyph;
static GtkWidget *reviewScroller;
static AtkObject *brokenSubtree;
static gint (*originalChildCount)(AtkObject *);
static void (*originalRangeExtents)(AtkText *, gint, gint, AtkCoordType, AtkTextRectangle *);
static void range_extents(AtkText *text, gint start, gint end, AtkCoordType coordinates, AtkTextRectangle *rectangle) {
if (missingGlyph && start == 5 && end == 6) {
memset(rectangle, 0, sizeof(*rectangle));
return;
}
if (lineGeometryOnly && end - start == 1) {
memset(rectangle, 0, sizeof(*rectangle));
return;
}
if (slowRanges) {
largestRange = MAX(largestRange, end - start);
if (end - start > 128) g_usleep(1200000);
@@ -31,6 +44,11 @@ static gint count_children(AtkObject *object) {
return 0;
}
static gint subtree_child_count(AtkObject *object) {
if (object == brokenSubtree && armed) return -1;
return originalChildCount(object);
}
static gboolean command_ready(GIOChannel *channel, GIOCondition condition, gpointer label) {
if (condition & G_IO_HUP) {
gtk_main_quit();
@@ -49,6 +67,11 @@ static gboolean command_ready(GIOChannel *channel, GIOCondition condition, gpoin
puts("measuring");
} else if (g_str_has_prefix(line, "largest")) {
printf("largest %d\n", largestRange);
} else if (g_str_has_prefix(line, "scroll")) {
GtkAdjustment *adjustment = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(reviewScroller));
gtk_adjustment_set_value(adjustment, gtk_adjustment_get_upper(adjustment) * 0.75);
while (gtk_events_pending()) gtk_main_iteration();
puts("scrolled");
} else if (g_str_has_prefix(line, "change")) {
armed = FALSE;
gtk_label_set_text(GTK_LABEL(label), "Changed review text");
@@ -61,6 +84,13 @@ static gboolean command_ready(GIOChannel *channel, GIOCondition condition, gpoin
int main(int argc, char **argv) {
gboolean boundsMode = argc > 1 && strcmp(argv[1], "bounds") == 0;
gboolean clippedMode = argc > 1 && strcmp(argv[1], "clipped") == 0;
gboolean longMode = argc > 1 && strcmp(argv[1], "long") == 0;
gboolean linesMode = argc > 1 && strcmp(argv[1], "lines") == 0;
gboolean childrenMode = argc > 1 && strcmp(argv[1], "children") == 0;
gboolean glyphsMode = argc > 1 && strcmp(argv[1], "glyphs") == 0;
lineGeometryOnly = linesMode;
missingGlyph = glyphsMode;
gtk_init(&argc, &argv);
GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window), "Review cache probe");
@@ -69,9 +99,30 @@ int main(int argc, char **argv) {
GtkWidget *label = gtk_label_new("Cached review text");
// This fixture has one label. Replace its class vfunc before the bridge
// builds the initial cache, then arm the delay explicitly over stdin.
ATK_OBJECT_GET_CLASS(gtk_widget_get_accessible(label))->get_n_children = count_children;
if (boundsMode) {
gchar *content = g_strnfill(3424, 'x');
if (!childrenMode)
ATK_OBJECT_GET_CLASS(gtk_widget_get_accessible(label))->get_n_children = count_children;
if (childrenMode) {
GtkWidget *box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
GtkWidget *panel = gtk_event_box_new();
brokenSubtree = gtk_widget_get_accessible(panel);
atk_object_set_name(brokenSubtree, "Broken subtree");
originalChildCount = ATK_OBJECT_GET_CLASS(brokenSubtree)->get_n_children;
ATK_OBJECT_GET_CLASS(brokenSubtree)->get_n_children = subtree_child_count;
gtk_container_add(GTK_CONTAINER(panel), gtk_label_new("Subtree text"));
gtk_container_add(GTK_CONTAINER(box), label);
gtk_container_add(GTK_CONTAINER(box), panel);
gtk_container_add(GTK_CONTAINER(window), box);
} else if (boundsMode || clippedMode || longMode || linesMode || glyphsMode) {
gchar *content = g_strnfill(linesMode ? 101000 : longMode ? 100001 : clippedMode ? 2020 : 3424, 'x');
if (longMode) content[100000] = '\n';
if (linesMode) {
for (int row = 0; row < 1000; row++) content[row * 101 + 100] = '\n';
gtk_window_set_default_size(GTK_WINDOW(window), 1000, 100);
}
if (clippedMode) {
for (int row = 0; row < 20; row++) content[row * 101 + 100] = '\n';
gtk_window_set_default_size(GTK_WINDOW(window), 300, 450);
}
gtk_label_set_text(GTK_LABEL(label), content);
g_free(content);
gtk_label_set_xalign(GTK_LABEL(label), 0);
@@ -81,6 +132,7 @@ int main(int argc, char **argv) {
if (originalRangeExtents == NULL) g_error("fixture needs native GTK range extents");
ATK_TEXT_GET_IFACE(accessible)->get_range_extents = range_extents;
GtkWidget *scroller = gtk_scrolled_window_new(NULL, NULL);
reviewScroller = scroller;
gtk_container_add(GTK_CONTAINER(scroller), label);
gtk_container_add(GTK_CONTAINER(window), scroller);
} else {