GLImageSink events

I need keyboard events from a GLImageSink window (on Ubuntu). I have a test pipeline similar to this :

auto source = gst_element_factory_make(“gltestsrc”, “source”);
auto sink = gst_element_factory_make(“glimagesink”, “sink”);
gst_video_overlay_handle_events(GST_VIDEO_OVERLAY(sink), true);

GMainLoop *loop = g_main_loop_new(g_main_context_get_thread_default(), FALSE);
GIOChannel *io_stdin = g_io_channel_unix_new(fileno (stdin));
g_io_add_watch(io_stdin, G_IO_IN, (GIOFunc) handle_keyboard, this);
gst_element_set_state(m_pipeline, GST_STATE_PLAYING);
g_main_loop_run(loop);

static gboolean handle_keyboard(GIOChannel *source, GIOCondition cond, Pipeline *ths)
{
    gchar buf[10];
    gsize count=0;
    GError *error;
    auto status = g_io_channel_read_chars(source, buf, 1, &count, &error);
    if (status != G_IO_STATUS_NORMAL)
        return TRUE;
    for (int i=0; i<count; i++)
    {
        int key = (int)(uint8_t)buf[i];
        std::cout << "Gstreamer " << count  << " key: " << key << std::endl;
    }
    return TRUE;
}

But key codes are only transmitted after pressing Enter-key. Also if the GLWindow has focus, no events are transmitted this way. I prefer to get the events from the window itself. How to do this?

This is not an answer, though you may find some way looking at source code of gst-play-1.0.

Thank you for link, but this only works when the terminal window has focus. When the glimagesink window has focus, it doesn’t work.