Replacing gtk_window_set_type_hint in gtk4

Hello,
Rewriting the xffm application from gtk3 to gtk4.
Currently the xffm+ app serves the purpose of a file manager dialog to the lightweight panned window manager i3. As such, it should open by default in floating mode.
With gtk3 this is done easily with gtk_window_set_type_hint(window, GDK_WINDOW_TYPE_HINT_DIALOG);
But this function is no longer in gtk4. I suppose this is no longer an option as it is X11 specific and gtk4 is targeting a more general approach (just my guess).

Is there any easy replacement function call that will do the same?

In the meantime, if anyone needs a workaround, the following code works for me with X11. I have no idea if it will work with Wayland.

    void showWindow(GtkWindow *mainWindow_){
        GtkWidget *widget = GTK_WIDGET(mainWindow_);
        gtk_widget_realize(widget);

        GtkNative *native = gtk_widget_get_native(widget);
        GdkSurface *surface = gtk_native_get_surface(native);
        Window w = gdk_x11_surface_get_xid (surface);

        GdkDisplay *displayGdk = gdk_display_get_default();
        Atom atom = gdk_x11_get_xatom_by_name_for_display (displayGdk, "_NET_WM_WINDOW_TYPE_DIALOG");
        Atom atom0 = gdk_x11_get_xatom_by_name_for_display (displayGdk, "_NET_WM_WINDOW_TYPE");
        Display *display = gdk_x11_display_get_xdisplay(displayGdk);
        XChangeProperty (display, w,
		      atom0, XA_ATOM, 
          32, PropModeReplace,
		      (guchar *)&atom, 1);
        gtk_window_present (mainWindow_);
    }

That is correct: the windowing system integration for GTK4 (and the foreseeable future) is modelled on Wayland, which is actually easier to translate to other windowing systems than X11; a lot of code in GTK2 and GTK3 amounted to re-implementing X11 concepts on Windows and macOS, with various degrees of success.

It depends on what you consider “easy”; the replacement is to call Xlibs API on the window’s native identifier.

It won’t; you must check that the windowing system backend currently running is X11, as the documentation for X11 integration explains:

Wayland does not have type hints: windows are windows. If the compositor has different behaviours, it needs to expose a specific interface so that toolkits and/or applications can use it.

Thank you for your answer. I believe that gtk development is headed in the right direction.

Maybe this approach will one day also allow gtk apps to work with the windowing system that runs on Android (I have no idea what this is).

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