Drawing on the X root window

2020-04-02 09:13发布

I'd like to be able to draw on the root window in Linux. I.e. make an OSD.

I'm using Gnome.

Code samples or links to them would be appreciated.

标签: linux x11
2条回答
We Are One
2楼-- · 2020-04-02 10:03
use X11::Protocol;

my $x = X11::Protocol->new();
my $desktop;

my ($root,undef,@kids)=$x->QueryTree($x->{'root'});
printf "%10x:\tRoot\n", $root;
foreach (@kids){
my $gdkw = Gtk2::Gdk::Window->foreign_new($_);
printf ("%10x:\tDesktop\n",$gdkw->get_xid),$desktop=$gdkw,last if $gdkw->get_type_hint eq 'desktop';
}
$desktop=Gtk2::Gdk::Window->foreign_new($root) if ! $desktop;
#------------------------------------------

I can find desktop, verified by xwininfo. But, I lost the code which can draw desktop, seems used "set_back_pixmap".

Now cairo can draw on any windows very simply, just use

$cr = Gtk2::Gdk::Cairo::Context->create ($drawable);

But, this does not work on desktop. Perhaps due to kernel update? Or I messed up now on Ubuntu 10.04-3.

查看更多
Lonely孤独者°
3楼-- · 2020-04-02 10:06

It is possible, but you will not see anything in GNOME. Nautilus, GNOME's file manager, opens its own window on top of root X window to display icons. Because of that the root X window is fully covered... so there is no point in drawing on it.

If you want to make OSD, either you should use a library like XOSD, or open your own X window and make it translucent. In fact, XOSD's source code should be a good example of how to do this.

Whole library seems to be implemented in one file: xosd.c.

查看更多
登录 后发表回答