Connecting to the "key-press-event" signal will again not work for all cases. There could be times when the cursor position is changed by a mouse click, a touch sensitive screen or even by the programme.
The best by of of being notified of a potential change of cursor position is to connect a notify signal to the "cursor-position" property of the GtkTextBuffer, so that when the property is updated we will get a call back.
Below is a rough section of code that should do this.
Code:
g_signal_connect (buffer, "notify::cursor-position",
G_CALLBACK (gtk_text_view_notify_cursor_position),
view);
/*callback method*/
void
gtk_text_view_notify_cursor_position(GtkTextBuffer *buffer, GParamSpec *pspec,gpointer user_data)
{
/*calculate cursor position using insert mark*/
....
}
E.