# Any idea on implementing Gdk::Window#add\_filter?

**URL:** <https://www.ruby-forum.com/t/any-idea-on-implementing-gdk-window-add-filter/121102>\
**Category:** Ruby-Gnome 2\
**Created:** [November 23, 2007, 7:15pm UTC](https://www.ruby-forum.com/t/any-idea-on-implementing-gdk-window-add-filter/121102 "2007-11-23T19:15:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sam](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/5f9b8f/32.png) [@sam](https://www.ruby-forum.com/u/sam)\
**Post date:** [November 23, 2007, 7:15pm UTC](https://www.ruby-forum.com/t/any-idea-on-implementing-gdk-window-add-filter/121102/1 "2007-11-23T19:15:26Z")

</div>

Hi Sirs,

To implement an OSD we’ll need to intercept key event (ex. multimedia  
volume control key) and that will need the method Gdk::Window#add\_filter  
but it’s missing in current ruby-gnome2 implementation.

Any idea to implement it ?

---

<div class="post-metadata">

**Author:** ![sam](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/5f9b8f/32.png) [@sam](https://www.ruby-forum.com/u/sam)\
**Post date:** [November 23, 2007, 7:25pm UTC](https://www.ruby-forum.com/t/any-idea-on-implementing-gdk-window-add-filter/121102/2 "2007-11-23T19:25:36Z")

</div>

Sam,

Might this work for you?

Gtk.key\_snooper\_install { |widget, event| … }

It lets you process keystrokes before the application gets them  
normally. If the return value is true GTK will stop processing the  
event.

-Ian

---

<div class="post-metadata">

**Author:** ![sam](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/5f9b8f/32.png) [@sam](https://www.ruby-forum.com/u/sam)\
**Post date:** [November 23, 2007, 11:17pm UTC](https://www.ruby-forum.com/t/any-idea-on-implementing-gdk-window-add-filter/121102/3 "2007-11-23T23:17:44Z")

</div>

Quoth Ian McIntosh [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid), on 2007-11-23 15:24:59 -0300:

> > To implement an OSD we’ll need to intercept key event (ex. multimedia  
> > volume control key) and that will need the method Gdk::Window#add\_filter  
> > but it’s missing in current ruby-gnome2 implementation.  
> > […]  
> > Might this work for you?
> 
> Gtk.key\_snooper\_install { |widget, event| … }

To forestall further confusion, I don’t think that’s what he meant.  
key\_snooper\_install only works for events that are already being  
delivered to GDK. From the GDK documentation:

void gdk\_window\_add\_filter(GdkWindow \*window,  
GdkFilterFunc function,  
gpointer data);

Adds an event filter to window, allowing you to intercept events  
before they reach GDK. This is a low-level operation and makes it  
easy to break GDK and/or GTK+, so you have to know what you’re  
doing. Pass NULL for window to get all events for all windows,  
instead of events for a specific window.

I expect they want to grab certain keys globally and feed them to  
a background process; that’s usually how “media keys” programs work,  
at least on X.

(I don’t know the answer to the original question, unfortunately. It  
looks like you’d have to add a Gdk::XEvent type too, though, and such.)

> -Ian

—\> Drake W.
