Drawing on the X root window
Asked Answered
A

2

9

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.

Alright answered 19/12, 2009 at 23:22 Comment(0)
S
12

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.

Screwball answered 19/12, 2009 at 23:23 Comment(2)
Thank you, your answer was most helpful. I'd like to draw things other than just text, but this is a fine starting point.Alright
Here's some sample code: pastebin.com/f58970b0c And a tutorial: ldots.org/xosd-guide/using_libxosd.htmlAlright
S
1
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.

Seine answered 15/11, 2011 at 8:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.