开发者

How can I use the FilterFunction passed to Gdk.Window.AddFilter?

I need to intercept several events before they are delivered to the widget's standard handlers, so I've done this already:

//Inside the definition of my custom widget
protected override void OnRealized()
{
    base.OnRealized();
    this.GdkWindow.AddFilter(PreFilterMessage);
    ...
}

So, later I define the PreFilterMessage 开发者_运维知识库method:

public Gdk.FilterReturn PreFilterMessage(IntPtr xEvent, Gdk.Event evnt)
{
    Console.WriteLine(evnt.Type);
    ...
}

But the thing is that when I test it, whatever message gets to the window (KeyEvent, ButtonEvent, etc.) it always prints "Nothing", so I'm only getting empty events every time. Somewhere I read that the real information gets through the xEvent parameter, but that's just an IntPtr, so I don't know how to get the information I need (event type, pointer coordinates, etc.) from it.

Can anyone tell me how to do this? Thanks in advance.


Per the docs on the gtk.org website, the GdkEvent received in the filter func is unpopulated. The purpose of this AddFilter mechanism is to allow the user to intercept X events before the gdk event processing starts up. We do not bind any of the X data structures in Gtk#, so you would need to manually marshal that data from the IntPtr using System.Runtime.InteropServices Marshal.

So, unless that sounds familiar as far as what you are trying to accomplish, you may want to consider other alternatives.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜