[Gtk-sharp-list] How to increase Gdk.Window reference count ?

kmarecki marecki.krzysztof at gmail.com
Tue Dec 22 08:32:59 EST 2009


Hello,

I would like to emulate key pressed events for GtkEntry.
In plain C, code looks like this :

gtk_widget_grab_focus((GtkWidget*)entry);
GdkWindow *window=gtk_widget_get_window((GtkWidget*)entry);
g_object_ref((gpointer)window);

GdkEventKey* event=(GdkEventKey*)gdk_event_new(type);
event->window=window;
event->keyval=keyval;
event->send_event=TRUE;

gdk_event_put((GdkEvent*)event);
gdk_event_free((GdkEvent*)event);


(I've omitted for simplicity setting other GdkEventKey fields).
Invoking g_object_ref is necessary because gdk_event_put
calls g_object_unref.

For C#, I've translated above code to:

[StructLayout(LayoutKind.Sequential)]
public struct EventKeyStruct
{
    public EventType type;
    public IntPtr window;
    public SByte send_event;
   
    public uint time;
    public uint state;
    public uint keyval;
    public uint length;
    public string str;
    public ushort hardware_keycode;
    public SByte group;
    public uint is_modifier;
   
}

entry.GrabFocus();
Gdk.Window window=entry.GdkWindow;
EventKeyStruct native=new EventKeyStruct();
native.window=window.Handle;
native.keyval=keyval;
native.send_event=1;
           
//placeholder for invoking g_object_ref;

IntPtr ptr=GLib.Marshaller.StructureToPtrAlloc(native);

EventKey evnt=new EventKey(ptr);
EventHelper.Put(evnt);
EventHelper.Free(evnt);

GLib.Marshaller.Free(ptr);

Tried following (based on Banshee class GtkWorkarounds)

MethodInfo g_object_ref = typeof (GLib.Object).GetMethod ("g_object_ref",
                BindingFlags.NonPublic | BindingFlags.Static);

g_object_ref.Invoke(null, new object[] { window.Handle });

But it did not work out. There is no error except that my entry is
destroyed,
indicates that reference increasing was unsuccessful.

Thanks for any help on this.

Krzysztof Marecki

-- 
View this message in context: http://old.nabble.com/How-to-increase-Gdk.Window-reference-count---tp26887589p26887589.html
Sent from the Mono - Gtk# mailing list archive at Nabble.com.



More information about the Gtk-sharp-list mailing list