# Gtk and root window

**URL:** <https://www.ruby-forum.com/t/gtk-and-root-window/53969>\
**Category:** Ruby\
**Created:** [February 18, 2006, 8:39pm UTC](https://www.ruby-forum.com/t/gtk-and-root-window/53969 "2006-02-18T20:39:43Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![taq](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/7c8e57/32.png) [@taq](https://www.ruby-forum.com/u/taq)\
**Post date:** [February 18, 2006, 8:39pm UTC](https://www.ruby-forum.com/t/gtk-and-root-window/53969/1 "2006-02-18T20:39:43Z")

</div>

Hi!  
Is there a way to draw something on the root window  
using Gtk/Gdk? For example, draw a filled rectangle  
there with some info labels.  
Thanks! 🙂

---

<div class="post-metadata">

**Author:** ![taq](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/7c8e57/32.png) [@taq](https://www.ruby-forum.com/u/taq)\
**Post date:** [February 18, 2006, 8:57pm UTC](https://www.ruby-forum.com/t/gtk-and-root-window/53969/2 "2006-02-18T20:57:53Z")

</div>

Am Sonntag, den 19.02.2006, 04:37 +0900 schrieb Eustaquio Rangel de  
Oliveira J:

> Hi!  
> Is there a way to draw something on the root window  
> using Gtk/Gdk? For example, draw a filled rectangle  
> there with some info labels.  
> Thanks! 🙂

Hi,

with

Gdk::Window.default\_root\_window

you get the root window, which you can use with all Gdk drawing  
functions.

But if you run GNOME the main window is completely covered by a nautilus  
window. On this window you can’t draw afaik cause it is owned by an  
other process.

Cheers  
detlef

---

<div class="post-metadata">

**Author:** ![taq](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/7c8e57/32.png) [@taq](https://www.ruby-forum.com/u/taq)\
**Post date:** [February 18, 2006, 9:22pm UTC](https://www.ruby-forum.com/t/gtk-and-root-window/53969/3 "2006-02-18T21:22:06Z")

</div>

> Hi,

Hi, thanks for your quick answer!

> with  
> Gdk::Window.default\_root\_window  
> you get the root window, which you can use with all  
> Gdk drawing  
> functions.

I’m kind of new on this Ruby graphics thing, I’m  
searching for some examples but I’m not finding some  
very clear.  
Could you please show me how to draw a rectangle on  
the screen (on root window or even on a gtk window)?  
If I have a starting point will be easier to go on and  
not bore you more with this kind of thing. 🙂

Thanks again!

---

<div class="post-metadata">

**Author:** ![taq](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/7c8e57/32.png) [@taq](https://www.ruby-forum.com/u/taq)\
**Post date:** [February 18, 2006, 10:28pm UTC](https://www.ruby-forum.com/t/gtk-and-root-window/53969/4 "2006-02-18T22:28:48Z")

</div>

Am Sonntag, den 19.02.2006, 05:19 +0900 schrieb Eustaquio Rangel de  
Oliveira J:

> I’m kind of new on this Ruby graphics thing, I’m  
> searching for some examples but I’m not finding some  
> very clear.  
> Could you please show me how to draw a rectangle on  
> the screen (on root window or even on a gtk window)?  
> If I have a starting point will be easier to go on and  
> not bore you more with this kind of thing. 🙂

require ‘gtk2’

Gtk.init

win = Gdk::Window.default\_root\_window

gc = Gdk::GC.new win  
win.draw\_rectangle gc, true, 100, 100, 300, 400

Gtk.main

Hi,

i don’t think that you will get much of it, if you don’t understand how  
X drawing works.

To get into the drawing concepts of Gdk the “X lib programming manual”  
is the best starting point, even if it is quite hard. I don’t know of a  
better tutorial.

Cheers  
detlef

---

<div class="post-metadata">

**Author:** ![taq](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/7c8e57/32.png) [@taq](https://www.ruby-forum.com/u/taq)\
**Post date:** [February 18, 2006, 11:05pm UTC](https://www.ruby-forum.com/t/gtk-and-root-window/53969/5 "2006-02-18T23:05:22Z")

</div>

Hi.

> But if you run GNOME the main window is completely  
> covered by a nautilus  
> window. On this window you can’t draw afaik cause it  
> is owned by an  
> other process.

Argh. XFCE4 also does not allow to draw on the root  
window, that’s why my initial tests were not working.  
When I run your code and saw nothing there, I closed  
XFCE and started Fluxbox and all worked fine.  
The root window is owned by xfdesktop. Seems that I’ll  
need to find another way to do that. 🙂

Thanks again for that tip!

---

<div class="post-metadata">

**Author:** ![taq](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/7c8e57/32.png) [@taq](https://www.ruby-forum.com/u/taq)\
**Post date:** [February 18, 2006, 10:41pm UTC](https://www.ruby-forum.com/t/gtk-and-root-window/53969/6 "2006-02-18T22:41:07Z")

</div>

Hi!

> require ‘gtk2’  
> Gtk.init  
> win = Gdk::Window.default\_root\_window  
> gc = Gdk::GC.new win  
> win.draw\_rectangle gc, true, 100, 100, 300, 400  
> Gtk.main

Thank you so much! I’ll run the code here. 🙂

> i don’t think that you will get much of it, if you  
> don’t understand how  
> X drawing works.  
> To get into the drawing concepts of Gdk the “X lib  
> programming manual”  
> is the best starting point, even if it is quite  
> hard. I don’t know of a  
> better tutorial.

Searching for it now. Thanks again, I’ll take a look!

Best regards,
