It is necessary to verify that the window is non-zero here, otherwise the following logic will cause a crash.
Fixes https://gitlab.gnome.org/GNOME/gtk/-/issues/5091