3

Is there a way or a hack to create a GTK+3 transparent window without a composition manager in Linux? I want a GtkWindow invisible (zero alpha) with visible childs objects. I've triedgtk_widget_set_opacity(window, 0.0); and another things but it didn't work.

I'm using Arch Linux with OpenBox. Sorry for my english.

EDIT

I've created my window with GDK_WINDOW_TYPE_HINT_DESKTOP flag so my window will be always on desktop, and i think the way to do what i want is get desktop wallpaper and draw my window background with this image. It is possible to do this?

oldtechaa
  • 1,463
  • 1
  • 14
  • 26
vaati
  • 162
  • 2
  • 13
  • 3
    You may like [**How to make a gtkwindow background transparent on linux?**](http://stackoverflow.com/questions/16832581/how-to-make-a-gtkwindow-background-transparent-on-linux). – David C. Rankin May 03 '16 at 04:26
  • It doesn't work, the result is a black window. – vaati May 03 '16 at 04:39
  • That's the only downside to the rapid API changes to the GTK3.X library. You will just have to compare the code there to the current *new features* and *deprecated features* between whatever that version was for and the one you are using. There may also be desktop and window manager capability issues as well. (with Arch you are on the absolute latest released version ~ `gtk3 3.20.3-1` and the example was `3.10` if I recall correctly) – David C. Rankin May 03 '16 at 04:44
  • Without composition manager you can take advantage of XShape extension, eg. [gdk_window_shape_combine_region](https://developer.gnome.org/gdk3/stable/gdk3-Windows.html#gdk-window-shape-combine-region), but that way you can get only binary transparency - i.e. each pixel if either 100% opaque or transparent. – el.pescado - нет войне May 06 '16 at 13:02
  • BTW, it makes no sense for `GDK_WINDOW_TYPE_HINT_DESKTOP` windows to be transparent. It will be placed beneath all other windows... – el.pescado - нет войне May 06 '16 at 13:05
  • I will try ```gdk_window_shape_combine_region```, and i was thinking to myself, how does ```Conky``` and ```LXpanel``` transparency? I have both in my desktop and both are transparent even without a compmanager. – vaati May 06 '16 at 16:47

3 Answers3

1

You cannot make a window transparent without a compositing manager using the GtkWidget:opacity property.

The only way to make it transparent, on X11, is to read the contents of the root window at the coordinates of the window, and then use the contents as the background pattern for the window. This will not work if your window is stacked on top of other windows, but that's what you get if you don't use a compositing manager.

ebassi
  • 8,648
  • 27
  • 29
1

it worked well for me, with a compositing manager (xcompmgr or picom) and initializing window with

  GdkScreen *screen;
  GdkVisual *visual;

  gtk_widget_set_app_paintable(win, TRUE);
  screen = gdk_screen_get_default();
  visual = gdk_screen_get_rgba_visual(screen);

  if (visual != NULL && gdk_screen_is_composited(screen)) {
    gtk_widget_set_visual(win, visual);
  }
vrx
  • 11
  • 1
0

I do not know if this can help you

#include <cairo.h>
#include <gtk/gtk.h>

static void do_drawing(cairo_t *);


static void tran_setup(GtkWidget *win)
{
  GdkScreen *screen;
  GdkVisual *visual;

  gtk_widget_set_app_paintable(win, TRUE);
  screen = gdk_screen_get_default();
  visual = gdk_screen_get_rgba_visual(screen);

  if (visual != NULL && gdk_screen_is_composited(screen)) {
    gtk_widget_set_visual(win, visual);
  }
}

static gboolean on_draw_event(GtkWidget *widget, cairo_t *cr,
                  gpointer user_data)
{
  do_drawing(cr);

  return FALSE;
}

static void do_drawing(cairo_t *cr)
{
  cairo_set_source_rgba(cr, 0.2, 0.2, 0.2, 0.4);
  cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
  cairo_paint(cr);
}

int main (int argc, char *argv[])
{
  GtkWidget *window;
  GtkWidget *darea;

  gtk_init(&argc, &argv);

  window = gtk_window_new(GTK_WINDOW_TOPLEVEL);

  tran_setup(window);

  darea = gtk_drawing_area_new();
  gtk_container_add(GTK_CONTAINER (window), darea);

  g_signal_connect(G_OBJECT(darea), "draw",
           G_CALLBACK(on_draw_event), NULL);
  g_signal_connect(window, "destroy",
           G_CALLBACK(gtk_main_quit), NULL);

  gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
  gtk_window_set_default_size(GTK_WINDOW(window), 300, 250);
  gtk_window_set_title(GTK_WINDOW(window), "Transparent window");

  gtk_widget_show_all(window);

  gtk_main();

  return 0;
}
Sciamano
  • 21
  • 5
  • Thanks for the help but it didn't work, result is a black screen. – vaati May 07 '16 at 15:40
  • 3
    You should've mentioned that this code is from http://zetcode.com/gfx/cairo/root/ except if you're the author himself. Even then it'd be appropriate to mention the source. – Rok Dec 09 '17 at 20:09