0

I've been trying for the last hour to make this work. The idea es Dock is a class whose base is Gtk::Window, and upon the signal_draw() being emited, the given context should be painted by CairoMM to be transparent.. Instead I see a black window. Here goes the code:

Dock::Dock() : Gtk::Window()
{
    set_decorated(false);
    set_default_size(200,200);  
    set_app_paintable(true);
    signal_draw().connect(sigc::mem_fun(*this,&Dock::dibujar));

}

bool Dock::dibujar(const Cairo::RefPtr<Cairo::Context>& contexto)
{

    contexto->set_source_rgba(1.0,1.0,1.0,0.0);
    contexto->set_operator(Cairo::OPERATOR_SOURCE);
    contexto->paint();
    return false;
}

Shouldn't it be enough to make the window transparent?

Debianita
  • 108
  • 1
  • 8

1 Answers1

0

Your draw handler doesn't have access to the information about what else should be painted on the window, so your paint() call paints a transparent layer above what is, I guess by default, a black background.

Luckily there is a method to achieve what you want: Gtk::Widget::set_opacity()

ptomato
  • 56,175
  • 13
  • 112
  • 165
  • 1
    But that way if I use it on a parent widget, child widgets won't be able to have different (greater) opacity, right? is there any way to have children widgets with different alpha levels? – Debianita Oct 21 '15 at 22:06
  • You mean you want to just have a window with normal widgets in it, but you can see the desktop background through it? – ptomato Oct 22 '15 at 05:01
  • Indeed, that's pretty much it – Debianita Oct 22 '15 at 22:28
  • Try [this](http://stackoverflow.com/a/30129690/172999). It seems to be very similar to what you are already doing. Perhaps you need the `gdk_cairo_create()` step which I believe translates into [`Gdk::Window::create_cairo_context()`](https://developer.gnome.org/gtkmm/stable/classGdk_1_1Window.html#abb9195d68d992dce25ef2cd84589d273) – ptomato Oct 23 '15 at 03:39