ui: a press anywhere in the window closes the time-window popover
The window control is a GtkMenuButton whose popover autohides -- which works for as long as
GTK holds the popover's grab, and the grab is what can go missing: a window manager moving
it, the nested popover the unit dropdown opens taking it, and every headless run, where
there is no manager to hand one out at all. After that a click anywhere else in the window
leaves the bubble up, which is the "sometimes it is awkward to close" report.
`on_window_popover_press()` states the rule outright instead of relying on the grab: any
press that reaches the window's own surface closes it. That needs no hit test beyond the
button -- a popover is its own surface, so a click *inside* it never arrives here -- and the
button is left alone, because its own click is the toggle that closes it. The press gesture
is on the window in the capture phase, so a widget under the press (the plot's own gestures
among them) cannot hide it.
[windowpop] reads both halves, with autohide turned off for the probe -- the state a user
meets when the grab goes missing:
[windowpop] opened=1 visible=1 click_gestures=2
[windowpop] after a press elsewhere: active=0 (want 0)
[windowpop] after a press on the button: active=1 (want 1)
`click_gestures` is read as well as the handler, so "the rule works" and "the rule is
connected" are two facts rather than one.
This commit is contained in:
1 parent
47d49e75ff
commit
d34b97158e
5 files changed
+126
No files matched your search
@@ -2500,6 +2500,63 @@ void menus_probe_next(App& a, int step, guint delay_ms) {
|
||||
g_timeout_add(delay_ms, menus_probe_step, &a);
|
||||
}
|
||||
|
||||
/// `UDPSCOPE_PROBE_WINDOWPOP_MS`: the time-window popover, closed by a press elsewhere in the window.
|
||||
///
|
||||
/// Autohide is turned off for the probe, exactly as the menu probe does it: a popover dismisses itself
|
||||
/// when GTK holds its *grab*, and a bare `xvfb-run` has no window manager to hand one out -- so with
|
||||
/// autohide on the bubble would not stay up to be tested. Autohide off is the state a user meets when
|
||||
/// the grab goes missing, which is the report this guards: the press has to close it anyway. The second
|
||||
/// half presses the button itself, which must *not* close it (its own click toggles).
|
||||
gboolean windowpop_probe_step(gpointer user) {
|
||||
static int step = 0;
|
||||
App* a = static_cast<App*>(user);
|
||||
if (a->window == nullptr || a->window_button == nullptr) return G_SOURCE_REMOVE;
|
||||
const auto active = [a] {
|
||||
return gtk_menu_button_get_active(GTK_MENU_BUTTON(a->window_button)) ? 1 : 0;
|
||||
};
|
||||
if (step == 0) {
|
||||
GtkPopover* pop = gtk_menu_button_get_popover(GTK_MENU_BUTTON(a->window_button));
|
||||
if (pop != nullptr) gtk_popover_set_autohide(pop, FALSE);
|
||||
gtk_menu_button_popup(GTK_MENU_BUTTON(a->window_button));
|
||||
step = 1;
|
||||
g_timeout_add(300, windowpop_probe_step, a);
|
||||
return G_SOURCE_REMOVE;
|
||||
}
|
||||
// How many click gestures the window carries, so that "the handler works" and "the handler is
|
||||
// connected" are read as two facts rather than one.
|
||||
int clicks = 0;
|
||||
{
|
||||
GListModel* controllers = gtk_widget_observe_controllers(a->window);
|
||||
const guint n = controllers != nullptr ? g_list_model_get_n_items(controllers) : 0;
|
||||
for (guint i = 0; i < n; ++i) {
|
||||
GObject* item = G_OBJECT(g_list_model_get_item(controllers, i));
|
||||
if (item != nullptr) {
|
||||
if (GTK_IS_GESTURE_CLICK(item)) ++clicks;
|
||||
g_object_unref(item);
|
||||
}
|
||||
}
|
||||
if (controllers != nullptr) g_object_unref(controllers);
|
||||
}
|
||||
std::fprintf(stderr, "[windowpop] opened=%d visible=%d click_gestures=%d\n", active(),
|
||||
gtk_widget_is_visible(GTK_WIDGET(gtk_menu_button_get_popover(
|
||||
GTK_MENU_BUTTON(a->window_button))))
|
||||
? 1
|
||||
: 0,
|
||||
clicks);
|
||||
on_window_popover_press(nullptr, 0, 20.0, 200.0, a);
|
||||
std::fprintf(stderr, "[windowpop] after a press elsewhere: active=%d (want 0)\n", active());
|
||||
gtk_menu_button_popup(GTK_MENU_BUTTON(a->window_button));
|
||||
graphene_rect_t r = GRAPHENE_RECT_INIT(0, 0, 0, 0);
|
||||
if (gtk_widget_compute_bounds(a->window_button, a->window, &r)) {
|
||||
on_window_popover_press(nullptr, 0, r.origin.x + r.size.width / 2.0,
|
||||
r.origin.y + r.size.height / 2.0, a);
|
||||
}
|
||||
std::fprintf(stderr, "[windowpop] after a press on the button: active=%d (want 1)\n", active());
|
||||
gtk_menu_button_popdown(GTK_MENU_BUTTON(a->window_button));
|
||||
std::fflush(stderr);
|
||||
return G_SOURCE_REMOVE;
|
||||
}
|
||||
|
||||
gboolean menus_probe_step(gpointer user) {
|
||||
App* a = static_cast<App*>(user);
|
||||
if (a->window == nullptr) return G_SOURCE_REMOVE;
|
||||
|
||||
Reference in new issue
Block a user