Why is window coordinate offset required when using custom GtkHeaderBar in XFCE environment?

In a GTK3 window with a custom GtkHeaderBar in the XFCE environment, there is a need to shift the window coordinates for correct positioning. Why does this happen and how to correctly take such indents into account?

I use this code to create a custom window title:


GtkWidget *wnd = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_type_hint(GTK_WINDOW(wnd), GdkWindowTypeHint::GDK_WINDOW_TYPE_HINT_NORMAL);
GtkWidget *header = gtk_header_bar_new();
gtk_window_set_titlebar(GTK_WINDOW(wnd), header);

Then, in order to move the window to coordinates (0, 0), you have to use the offset (-62, -25)


gtk_window_move(GTK_WINDOW(wnd), -62, -25);

Some thoughts:
When using a custom headerbar, you’re window switches from using server-side window decorations to client-side ones. This means that the window borders, etc. are drawn by the app, not the desktop compositor.

AFAIK this also includes the window shadow. So, the area drawn by the app is larger, as it now also includes the shadow.

That would be my guess as to the reason.

Thanks for the answer! Is there a way to determine the size of the shadow?

I don’t think so.

If I know this right, the shadow is defined by the CSS stylesheet.

That aside, using gtk_window_move isn’t guaranteed to work anyway. Under Wayland-based compositors moving windows relative to the monitor isn’t possible for example, which is also why it was removed in GTK4.

This method seems to work:

int x, y;
GtkWidget *content = gtk_bin_get_child(GTK_BIN(main_window));
gtk_widget_translate_coordinates(content, main_window, 0, 0, &x, &y);