Why does CSD windows accept transparency while SSD windows don't? and how to get it working with SSD windows?

I am making a panel using gtkmm3. I want to make the panel window transparent. I tried using CSS, which always works, but this time when I set window{background: transparent;} it becomes black. While all other apps become transparent if I put the same CSS in Gtk Inspector. After more investigation, I found that CSD windows accept transparency (they have an alpha channel) while SSD windows or windows with set_decorated(false); don’t have an alpha channel. Why is that behaviour? And how can I get the undecorated window transparent?

Hi! If I recall correctly, in GTK3 you have to request alpha-enabled visuals explicitly:

bool
enable_alpha_visual (Gtk::Window& window)
{
  Glib::RefPtr<Gdk::Screen> screen = Gdk::Screen::get_default();
  if (!screen)
    return false;
//if (!screen->is_composited())
//  return false;
  Glib::RefPtr<Gdk::Visual> rgba_visual = screen->get_rgba_visual();
  if (!rgba_visual)
    return false;

  window.set_visual(rgba_visual);

  return true;
}

That is done by GTK automatically for CSD windows.

See also: gtk - How do I make a gtkwindow background transparent on Linux? - Stack Overflow

1 Like

Actually, I’ve seen this example many times on StackOverflow and GitHub, but for some reason, gtkmm does not have set_visual method for widgets, it might be binding issue I’m not sure. Anyway I resorted to using the C API directly, so this line worked for me:
gtk_widget_set_visual(GTK_WIDGET(window.gobj()) , window.get_screen()->get_rgba_visual()->gobj());

1 Like

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