0

I need to receive a GTK+ focus in event on a Terminal (VTE), but the event returns EventFocus which holds Gtk.Window reference:

http://www.valadoc.org/gdk-3.0/Gdk.EventFocus.html

How can I get the Terminal from the Window reference? I cannot retype it, it looks like it is a container. But I am unable to find which method to call to get the Terminal.

  Terminal terminal = new Terminal();
  // ...
  terminal.focus_in_event.connect((event) =>
  {
    the_terminal = event.window; // DOES NOT WORK > invalid cast from `GdkX11Window' to `Terminal'
    return false;
  });

Thanks for pointing out I dont need it. Yeah, my real code is:

for (int i = 0; i < terminal.length; i++) {
  this.terminal[i].focus_in_event.connect((event) =>
  {
    GLib.stdout.printf("Focus event terminal %p\n", this.terminal[i]);
    return false;
  });
}

Unfortunately it always prints null :-(

Thanks!

ptomato
  • 56,175
  • 13
  • 112
  • 165
lzap
  • 16,417
  • 12
  • 71
  • 108

1 Answers1

2

I'm not sure there is an easy way to convert a Gdk.Window to a Gtk.Widget as not all widgets have an associated GDK window, necessarily. As I see it, there's no compelling reason to try to extract the terminal from the event. In the context of the callback, you can simply reference the outer variable terminal and Vala will lift it into the callback.

Terminal terminal = new Terminal();
// ...
terminal.focus_in_event.connect((event) =>
{
  terminal.queue_draw();
  return false;
});
apmasell
  • 7,033
  • 19
  • 28
  • Yeah, but my problem is I have a bunch (array) of Terminals, so I am connecting in a loop: foreach (Terminal t in terminals). And when I try to use "t" variable there, vala screams. I thought I can use closures, but apparently I cannot. – lzap Mar 24 '12 at 14:09