What does "Broken accounting of active state"

I’m getting these warnings (gtk 4.16.3) not always, just sometimes on opening a popover by means of a right click:

(process:1770709): Gtk-WARNING **: 14:59:35.896: Broken accounting of active state for widget 0x63967cf64380(GtkBox)
(process:1770709): Gtk-WARNING **: 14:59:35.896: Broken accounting of active state for widget 0x63967c3dd030(GtkPopoverContent)
(process:1770709): Gtk-WARNING **: 14:59:35.896: Broken accounting of active state for widget 0x63967cf64070(GtkPopover)
(process:1770709): Gtk-WARNING **: 14:59:35.896: Broken accounting of active state for widget 0x63967a62c020(GtkBox)
(process:1770709): Gtk-WARNING **: 14:59:35.896: Broken accounting of active state for widget 0x639679a31c60(GtkBox)
(process:1770709): Gtk-WARNING **: 14:59:35.896: Broken accounting of active state for widget 0x639679934f90(GtkListItemWidget)

Any clues on what these warnings mean?

1 Like

I think the warnings might be internal to GTK4, and not specific to your code.

Also, these warnings are normally emitted only on development builds of GTK4, and not on release builds.

Refer https://gitlab.gnome.org/GNOME/gtk/-/issues/4563 for more details.

It seems that what triggers this warning is the following.

Say you invoke the popover with button press at position (x,y). The popover is assigned to a parent such that the popover window will fill the space between (x1,y1) and (x2,y2).

The warnings will appear If and only if x1<x<x2 and y1<y<y2.

In other words, gtk4 “accounting” assumes that the button press position is associated with the popover parent widget, which is not necessarily true.

As you can see from position popover at x,y, you cannot position the popover anywhere (say the x,y click position), but must be associated to a parent widget’s position.

How about if you force the pointer away from the (x1,y1,x2,y2) rectangle before the popup() call?

With X11 this can be done with XWarpPointer(). Does it work?

Yeah, it works. The following code will send the pointer to the right edge of the main window, but only for X11. Maybe the warning does not occur with Wayland or Win32?

#ifdef GDK_WINDOWING_X11
      GdkDisplay *displayGdk = gdk_display_get_default();
      Display *display = gdk_x11_display_get_xdisplay(displayGdk);
      GtkNative *native = gtk_widget_get_native(MainWidget);
      GdkSurface *surface = gtk_native_get_surface(native);
      Window src_w = gdk_x11_surface_get_xid (surface);
      unsigned int src_width = gtk_widget_get_width(MainWidget);
      int i = round(x);
      XWarpPointer(display, src_w, None, 0, 0, 0, 0, src_width-i, 0);        
#endif
      gtk_popover_popup(GTK_POPOVER(popover));

After reviewing details pointed to by Sid, if the gesture callback is triggered by “pressed”, then, if you do not release the button and decide to move the cursor across the (x1,y1,x2,y2) rectangle, you will get the warnings. So to avoid the warnings, set the callback to the “released” signal.

AFAICT, the warning bug only applies to popovers that are triggered by a click which does not occur over the popover’s parent widget. This especially important when the popover applies to a selection model, since in this case the code has to decide where to assign the parent of the popover, with respect to the current selected items.

1 Like

I have similar issue but with GtkPopoverMenu.

in my case, it happened when I open context menu without moving focus to widget. Looks like GTK bug. Fedora 41