How to hide app from taskbar in gtk4?

I need to show window without app button in taskbar, is it possible in gtk4?

You can only use platform-specific API, like gdk_x11_surface_set_skip_taskbar_hint(), which are still just hints—taskbars, if they exist, are entirely free to disregard the hint you set.

There is xfce4-screenshooter app which hides itself from taskbar, and looks like it does not use any platform-specifics (maybe it uses some xfce4 magic…), but it is old gtk2 app, trying to figure it out how it does it
this created window is without taskbar button:

Looks to me that it’s not hidden from the taskbar, it’s just drawing over the taskbar

My personal recommendation is to implement the screenshot functionality directly into the Xfce window manager/compositor, and then have xfce4-screenshooter call it. You can look at how gnome-screenshot talks to gnome-shell, for an example.

Moving to that design would also let you migrate to Wayland in the future.

After a bit of research, I can, probably, safely say there is no such thing as hiding app from taskbar in gtk (in the sense of cross-platform supported feature).
Notable commit:

But. For example in Gtk3 it is possible to create manual window using gdk_window_set_override_redirect, which will not be shown in taskbar, this approach uses xfce4-screenshooter for example.

Now question is how can I create such manual window under Gtk4? I have not figured out it yet, but it looks like I need to use gdk_surface_new_popup.

example for Gtk3:

#include <gtk/gtk.h>

static void
activate (GtkApplication* app,
          gpointer        user_data)
  GtkWidget *window;

  window = gtk_application_window_new (app);
  gtk_window_set_title (GTK_WINDOW (window), "Window");
  gtk_window_set_default_size (GTK_WINDOW (window), 200, 200);
  gtk_widget_realize (window);
  gdk_window_set_override_redirect (gtk_widget_get_window(window), TRUE);
  gtk_window_move (GTK_WINDOW (window), 100, 100);
  gtk_widget_show_all (window);

main (int    argc,
      char **argv)
  GtkApplication *app;
  int status;

  app = gtk_application_new ("org.gtk.example", G_APPLICATION_FLAGS_NONE);
  g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
  status = g_application_run (G_APPLICATION (app), argc, argv);
  g_object_unref (app);

  return status;

In GTK3 there is gtk_window_set_skip_taskbar_hint. As Emmanuele pointed out, In GTK4 you can use the backend-specific API.

If you confused by my last post let me explain in more detail.
gtk_window_set_skip_taskbar_hint - in Gtk3 was only implemented for X11, and no other backend supports it, whats why it was removed in linked commit. You can review source code all the implementations is empty except X11. Whats why I’m saying there is no cross-platform support, it will work only for X11.

As for Gtk4 - same there is only backend specific code for X11 and no other backends.

Anyway it is possible to create window which is not managed by window manager and it has cross-platform support. Window in that case will be fully controlled by app, but it will not have default features provided by window manager, like it will not have header, taskbar button, move, resize. In Gtk3 such window can be create by gdk_window_set_override_redirect. Now I’m trying to make such window with Gtk4, if anyone have example I will be happy to look at it, if not I will post later if I will be able to figure it out myself.

You can create an override-redirect window—also known as “popup”—by subclassing GtkWidget, and inside the GtkWidget.realize virtual function, you will have to create a GdkPopup surface using gdk_surface_new_popup(). There is no convenience API for making a popup GtkWindow, like in GTK3, because all popup windows are specialised widgets, and GtkWindow is already too complicated.

If you want, you can look at an implementation of a popup window by searching for GtkTooltipWindow in the GTK source repository.

1 Like

xfce4-screenshooter only works on X11 so what is or isn’t supported on non-X11 is rather moot

And as @ebassi said for X11 gdk_x11_surface_set_skip_taskbar_hint is available - no need for complex custom window shenanigans

xfce4-screenshooter is just random app which happen to have functionality I’m taking about in this thread, I’m not related to it in any way.
I’m planning to use Gtk as cross-platform framework, and taskbar_hint is not cross-platform, so no interest for me.
Learning internals of Gtk is fun, understanding its limit is useful.

No shenanigans involved, I’m using only 100% document public api :innocent:!

Is a custom gdk_surface toplevel also hidden from the taskbar?

@SeaDve No, gdk_surface_new_toplevel always creates regular window, gdk_surface_new_popup - creates popup, you can review code here:

Well really it creates windows full stop. A popup surface is for things like context menus.

Menus aren’t really “hidden from the taskbar” - they’re just not windows

but gdk_surface_new_popup requires parent, it can’t be created as separate surface, it can be only as child of toplevel surface, it means Gtk4 doesn’t allow creating separate override-redirect window (as Gtk3 allows).

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