Pregunta

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!

¿Fue útil?

Solución

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;
});
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top