# Gtk and root window

**URL:** <https://rubytalk.org/t/gtk-and-root-window/25026>\
**Category:** ruby-talk\
**Created:** [18 February 2006 19:37 UTC](https://rubytalk.org/t/gtk-and-root-window/25026 "2006-02-18T19:37:51Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![\_Eustaquio\_Rangel\_de](https://avatars.discourse-cdn.com/v4/letter/_/c4cdca/32.png) [@\_Eustaquio\_Rangel\_de](https://rubytalk.org/u/_Eustaquio_Rangel_de)\
**Post date:** [18 February 2006 19:37 UTC](https://rubytalk.org/t/gtk-and-root-window/25026/1 "2006-02-18T19:37:51Z")

</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! 🙂

> **···**
>
> ----------------------------  
> Eustáquio "TaQ" Rangel  
> [eustaquiorangel@yahoo.com](mailto:eustaquiorangel@yahoo.com)  
> [http://beam.to/taq](http://beam.to/taq)  
> Usuário GNU/Linux no. 224050

---

<div class="post-metadata">

**Author:** ![Detlef\_Reichl](https://avatars.discourse-cdn.com/v4/letter/d/439d5e/32.png) [@Detlef\_Reichl](https://rubytalk.org/u/Detlef_Reichl)\
**Post date:** [18 February 2006 19:55 UTC](https://rubytalk.org/t/gtk-and-root-window/25026/2 "2006-02-18T19:55:14Z")

</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! 🙂

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

> **···**
>
> Am Sonntag, den 19.02.2006, 04:37 +0900 schrieb Eustaquio Rangel de Oliveira J:
> 
> > ----------------------------  
> > Eustáquio "TaQ" Rangel  
> > eustaquiorangel@yahoo.com  
> > [The easiest way to create, record and stream live video - Beings](http://beam.to/taq)  
> > Usuário GNU/Linux no. 224050

---

<div class="post-metadata">

**Author:** ![\_Eustaquio\_Rangel\_de](https://avatars.discourse-cdn.com/v4/letter/_/c4cdca/32.png) [@\_Eustaquio\_Rangel\_de](https://rubytalk.org/u/_Eustaquio_Rangel_de)\
**Post date:** [18 February 2006 20:19 UTC](https://rubytalk.org/t/gtk-and-root-window/25026/3 "2006-02-18T20:19:50Z")

</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!

> **···**
>
> ----------------------------  
> Eustáquio "TaQ" Rangel  
> eustaquiorangel@yahoo.com
> 
> > **[The easiest way to create, record and stream live video - Beings](https://beings.com)**
> >
> > Professional live streaming for marketers. Create, record and stream high-quality live video without being an expert.
> 
> Usuário GNU/Linux no. 224050

---

<div class="post-metadata">

**Author:** ![\_Eustaquio\_Rangel\_de](https://avatars.discourse-cdn.com/v4/letter/_/c4cdca/32.png) [@\_Eustaquio\_Rangel\_de](https://rubytalk.org/u/_Eustaquio_Rangel_de)\
**Post date:** [18 February 2006 22:03 UTC](https://rubytalk.org/t/gtk-and-root-window/25026/4 "2006-02-18T22:03:24Z")

</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!

> **···**
>
> ----------------------------  
> Eustáquio "TaQ" Rangel  
> eustaquiorangel@yahoo.com
> 
> > **[The easiest way to create, record and stream live video - Beings](https://beings.com)**
> >
> > Professional live streaming for marketers. Create, record and stream high-quality live video without being an expert.
> 
> Usuário GNU/Linux no. 224050

---

<div class="post-metadata">

**Author:** ![Detlef\_Reichl](https://avatars.discourse-cdn.com/v4/letter/d/439d5e/32.png) [@Detlef\_Reichl](https://rubytalk.org/u/Detlef_Reichl)\
**Post date:** [18 February 2006 21:26 UTC](https://rubytalk.org/t/gtk-and-root-window/25026/5 "2006-02-18T21:26:23Z")

</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. 🙂

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

> **···**
>
> Am Sonntag, den 19.02.2006, 05:19 +0900 schrieb Eustaquio Rangel de Oliveira J:
> 
> > Thanks again!
> > 
> > ----------------------------  
> > Eustáquio "TaQ" Rangel  
> > eustaquiorangel@yahoo.com  
> > [The easiest way to create, record and stream live video - Beings](http://beam.to/taq)  
> > Usuário GNU/Linux no. 224050

---

<div class="post-metadata">

**Author:** ![\_Eustaquio\_Rangel\_de](https://avatars.discourse-cdn.com/v4/letter/_/c4cdca/32.png) [@\_Eustaquio\_Rangel\_de](https://rubytalk.org/u/_Eustaquio_Rangel_de)\
**Post date:** [18 February 2006 21:38 UTC](https://rubytalk.org/t/gtk-and-root-window/25026/6 "2006-02-18T21:38:47Z")

</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,

> **···**
>
> ----------------------------  
> Eustáquio "TaQ" Rangel  
> eustaquiorangel@yahoo.com
> 
> > **[The easiest way to create, record and stream live video - Beings](https://beings.com)**
> >
> > Professional live streaming for marketers. Create, record and stream high-quality live video without being an expert.
> 
> Usuário GNU/Linux no. 224050
