Flat review improvements.

This commit is contained in:
Storm Dragon committed 2026-10-21 11:49:25 -04:00
1 parent ce5f196956
commit 4643f8e47f
14 files changed
+1291 -35

No files matched your search

+95
View File
@@ -0,0 +1,95 @@
// Copyright (c) 2026 Storm Dragon
// Authors: Storm Dragon, Angus Kola
// SPDX-License-Identifier: GPL-3.0-or-later
#include <gtk/gtk.h>
#include <stdio.h>
#include <string.h>
static gboolean armed;
static unsigned childQueries;
static gboolean slowRanges;
static gint largestRange;
static void (*originalRangeExtents)(AtkText *, gint, gint, AtkCoordType, AtkTextRectangle *);
static void range_extents(AtkText *text, gint start, gint end, AtkCoordType coordinates, AtkTextRectangle *rectangle) {
if (slowRanges) {
largestRange = MAX(largestRange, end - start);
if (end - start > 128) g_usleep(1200000);
}
originalRangeExtents(text, start, end, coordinates, rectangle);
}
static gint count_children(AtkObject *object) {
(void)object;
if (armed) {
childQueries++;
// The initial cache already reports this label as a leaf. A redundant
// property query models the temporarily unresponsive live cell.
g_usleep(1200000);
}
return 0;
}
static gboolean command_ready(GIOChannel *channel, GIOCondition condition, gpointer label) {
if (condition & G_IO_HUP) {
gtk_main_quit();
return FALSE;
}
gchar *line = NULL;
if (g_io_channel_read_line(channel, &line, NULL, NULL, NULL) != G_IO_STATUS_NORMAL)
return TRUE;
if (g_str_has_prefix(line, "arm")) {
armed = TRUE;
puts("armed");
} else if (g_str_has_prefix(line, "count")) {
printf("count %u\n", childQueries);
} else if (g_str_has_prefix(line, "measure")) {
slowRanges = TRUE;
puts("measuring");
} else if (g_str_has_prefix(line, "largest")) {
printf("largest %d\n", largestRange);
} else if (g_str_has_prefix(line, "change")) {
armed = FALSE;
gtk_label_set_text(GTK_LABEL(label), "Changed review text");
puts("changed");
}
g_free(line);
fflush(stdout);
return TRUE;
}
int main(int argc, char **argv) {
gboolean boundsMode = argc > 1 && strcmp(argv[1], "bounds") == 0;
gtk_init(&argc, &argv);
GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window), "Review cache probe");
gtk_window_set_default_size(GTK_WINDOW(window), 300, 100);
g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);
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');
gtk_label_set_text(GTK_LABEL(label), content);
g_free(content);
gtk_label_set_xalign(GTK_LABEL(label), 0);
AtkObject *accessible = gtk_widget_get_accessible(label);
atk_object_set_name(accessible, "Long review label");
originalRangeExtents = ATK_TEXT_GET_IFACE(accessible)->get_range_extents;
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);
gtk_container_add(GTK_CONTAINER(scroller), label);
gtk_container_add(GTK_CONTAINER(window), scroller);
} else {
gtk_container_add(GTK_CONTAINER(window), label);
}
GIOChannel *input = g_io_channel_unix_new(0);
g_io_add_watch(input, G_IO_IN | G_IO_HUP, command_ready, label);
gtk_widget_show_all(window);
gtk_main();
g_io_channel_unref(input);
return 0;
}