I’m trying to receive the keys pressed in the Onboard application. I created a small test application in gtkmm (first application I wrote) based on the a gtk3 sample posted here:
here is my code that manage to open the Onboard application but does not receive the events (I did not post the main function that is minor):
#include "onboard.h"
#include <iostream>
static gboolean watch_out_channel(GIOChannel *channel, GIOCondition cond, gpointer *data)
{
if(cond==G_IO_HUP)
{
g_print("Unreference Channel\n");
g_io_channel_unref(channel);
return FALSE;
}
else
{
g_print("Channel reached\n");
if (g_io_channel_get_buffer_size(channel) > 0)
{
g_print("somethig to read\n");
}
gchar *string;
gchar buf[100];
gsize bytes_read;
}
return TRUE;
}
OnBoard::OnBoard() : m_button("Open Keyboard")
{
m_button.set_margin(10);
m_button.signal_clicked().connect(sigc::mem_fun(*this, &OnBoard::add_plug), nullptr);
set_child(m_button);
}
OnBoard::~OnBoard()
{
}
void OnBoard::add_plug()
{
g_print("Add Plug\n");
gboolean retval;
const gchar *argv[] = {"onboard", nullptr};
gint std_out=0;
GError *error=NULL;
GIOChannel *std_out_ch;
retval=g_spawn_async_with_pipes(NULL, argv, NULL, G_SPAWN_DO_NOT_REAP_CHILD|G_SPAWN_SEARCH_PATH, NULL, NULL, &child_pid, NULL, &std_out, NULL, &error);
if(retval)
{
//gtk_widget_set_sensitive(widget, FALSE);
std_out_ch=g_io_channel_unix_new(std_out);
g_io_add_watch(std_out_ch, G_IO_IN | G_IO_HUP, (GIOFunc)watch_out_channel, nullptr);
g_print("Channel Added\n");
}
else
{
g_print("Couldn't start plug. %s\n", error->message);
g_error_free(error);
}
}
The button appears, I click on it, the keyboard opens and then the watch_out_channel
function is reached with cond==G_IO_HUP
and from that point nothing happens. What an I missing in creating the io channel?
Thank you for your help