Any idea on implementing Gdk::Window#add_filter?

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 ?

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

Quoth Ian McIntosh [email protected], 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.