我正在尝试使用 GTK+ 3.x 获得一个透明窗口。AFAIK 下面的代码应该可以工作,但我的窗口永远不会触发“draw”信号。可能是什么原因?
我的代码:
using Gtk;
public class WallpaperWindow : Object {
private Window window;
public static int main (string[] args) {
Gtk.init (ref args);
new WallpaperWindow();
Gtk.main();
return 0;
}
public WallpaperWindow() {
// Initialize window
this.window = new Window();
this.window.resize(200, 200);
this.window.set_decorated(false);
this.window.set_border_width(8);
// Enable transparency
var screen = this.window.get_screen();
var visual = screen.get_rgba_visual();
if(visual != null && screen.is_composited()) {
message("Composition is enabled, enabling transparency");
this.window.set_visual(visual);
} else {
warning("Composition is not enabled, cannot enable transparency");
}
this.window.draw.connect(on_window_draw);
// Run!
this.window.show_all();
}
// NEVER CALLED
private bool on_window_draw(Cairo.Context cr) {
warning("on_window_draw");
cr.set_source_rgba(0.0, 0.0, 0.0, 0.0);
cr.set_operator(Cairo.Operator.SOURCE);
cr.paint();
cr.set_operator(Cairo.Operator.OVER);
return true;
}
}