How to access GtkNotebook tabs widget size?

while working on QEMU’s GTK UI, I’ve come across a seemingly insurmountable issue.
It uses the GtkNotebook to display the different visual connections (vGPU, serial console, EFI console) and has a menu toggle to show the Notebook tabs widget.
So far so good.
To implement proportional guest scaling via gtk_window_set_geometry_hints min_aspect and max_aspect I need to know the sizes of all the widgets in the window.
The _GtkNotebok does have a *tabs_widget but that’s private.
As far as I can tell the GtkNotebook API doesn’t provide a function to access it:
How would I get at that to call gtk_widget_get_allocated_height on it?
I’d much rather have the height of the tabs widget as a number and add that to the new display resolution than move to gtk_widget_get_allocated_height(GTK_WIDGET(notebook)) since the information needs to be available before gtk_window_set_geometry_hints and gtk_widget_set_size_request.
Retrieving the height of the notebook will not yield the correct result yet as the rescale of the contained display widget has not even been requested yet.


First, avoid gtk_widget_get_allocated_height, it doesn’t take CSS margins in account.
In Gtk4 you should use gtk_widget_get_height instead.

Regarding the tabs header size, you could use gtk_widget_translate_coordinates, with the visible page as src_widget, the GtkNotebook as dest_widget, and src_x=src_y=0.
That will give you the position of the top-left corner of the page relatively to the notebook, so dest_y will actually be the tabs header heigth.

thank you very much @gwillems !!

I did manage to solve it on my own eventually, though differently:

int tabs_h = gtk_widget_get_allocated_height(notebook) - gtk_widget_get_allocated_height(gtk_notebook_get_nth_page(notebook, gtk_notebook_get_current_page(notebook)));

this is simply height(notebook) - height(page in notebook)

though I’ll have to use gtk_widget_get_height() like you said, rookie mistake.

So using the relative coordinates basically, this?

gtk_widget_translate_coordinates(notebook, gtk_notebook_get_nth_page(notebook, gtk_notebook_get_current_page(notebook)), 0.0, 0.0, NULL, &tabs_h);

also, gtk_widget_get_height() appears to be new (GTK4), the qemu source ( specifies GTK 3.22.0 as the minimum version and I am in no place to touch that.

ah, yes, should work too :slight_smile:

Something like that, yes.

Yes indeed, sorry, I though you used Gtk4 because a link in the 1st post pointed to the gtk4 documentation…

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.