It works.  Thanks. But I found another problem. The vala will make a copy
of GdkEventKey everytime, when I access a field of struct GdkEventKey. I
think it is not efficient. How to avoid it? Is it a bug in vala?

I have some code like:

uint keyval  = e.keyval; // e is Gdk.EventKey;
uint state = e.state;

I found it be translated to some code like:

355     gboolean result = FALSE;
356     GdkEventKey _tmp0_;
357     guint _tmp1_;
358     guint keyval;
359     GdkEventKey _tmp2_;
360     GdkModifierType _tmp3_;
361     guint state;
362     guint _tmp4_;
363     guint _tmp5_;
364     guint _tmp6_ = 0U;
365     gboolean _tmp7_ = FALSE;
366     self = (Switcher*) base;
367     g_return_val_if_fail (e != NULL, FALSE);
368     _tmp0_ = *e;                     // !!!!!!!!!!!! EventKey is copied
369     _tmp1_ = _tmp0_.keyval;
370     keyval = _tmp1_;
371     _tmp2_ = *e;                    // !!!!!!!!!!!! EventKey is copied
again
372     _tmp3_ = _tmp2_.state;



2011/11/26 Tal Hadad <tal...@hotmail.com>

>
> Gdk.Event* real_e = (Gdk.Event*)(&e);
> It's tested.
>
> Gdk.Event* is an unowned Gdk.Event, only different is syntax:
> (Gdk.Event)instance = (Gdk.Event*)->instance
>
> Tal
>
> Date: Fri, 25 Nov 2011 23:48:59 -0500
> From: shawn.p.hu...@gmail.com
> To: vala-list@gnome.org
> Subject: [Vala] How to cast Gdk.EventKey to Gdk.Event ?
> How to cast Gdk.EventKey to Gdk.Event in vala?
>
> some code like, but it does not compile.
>
> 100     public override bool key_release_event(Gdk.EventKey e) {
> 101         if (m_primary_modifier !=
> KeybindingManager.keyval_to_modifier(e.keyval))
> 102             return true;
> 103
> 104         if
> (KeybindingManager.primary_modifier_still_pressed((Gdk.Event)e))
> 105             return true;
> 106
> 107         hide();
> 108         return true;
> 109     }
>
> Thanks,
>
> _______________________________________________
> vala-list mailing list
> vala-list@gnome.org
> http://mail.gnome.org/mailman/listinfo/vala-list
>
>
> _______________________________________________
> vala-list mailing list
> vala-list@gnome.org
> http://mail.gnome.org/mailman/listinfo/vala-list
>
>
_______________________________________________
vala-list mailing list
vala-list@gnome.org
http://mail.gnome.org/mailman/listinfo/vala-list

Reply via email to