I have an application where I need to intercept keyboard LEFT / RIGHT key presses and translate them to SHIFT+TAB / TAB. I understand that Gdk::Window::add_filter()
or gdk_window_add_filter()
is my way forward.
So I installed a filter function by calling the above method and I am able to intercept the events right. However I am unable to translate the X event to an equivalent Gdk event.
001 GdkFilterReturn FilterInput(GdkXEvent *xevent,
002 GdkEvent *event,
003 gpointer data)
004 {
005 GdkFilterReturn eRet = GDK_FILTER_CONTINUE;
006
007 {
008 XEvent *pEvent = (XEvent*)xevent;
009
010 if (2
011 == pEvent->type)
012 {
013 if ((113
014 == pEvent->xkey.keycode)
015 || (114
016 == pEvent->xkey.keycode))
017 {
018 event->key.hardware_keycode = pEvent->xkey.keycode;
019 event->key.keyval = GDK_KEY_Tab;
020 event->key.length = 0;
021 event->key.time = pEvent->xkey.time;
022 event->key.type = GDK_KEY_PRESS;
023
024 if(113 == pEvent->xkey.keycode)
025 {
026 event->key.state |= GDK_SHIFT_MASK;
027 event->key.keyval = GDK_KEY_ISO_Left_Tab;
028 }
029
030 eRet = GDK_FILTER_TRANSLATE;
031 }
032 }
033 }
034
035 return eRet;
036 }
Above code always causes the application to crash when I do LEFT / RIGHT with the following warning.
Gdk-WARNING **: 13:16:43.246: Event with type 8 not holding a GdkDevice. It is most likely synthesized outside Gdk/GTK+
I did quite a bit of search to find examples on translating X events to Gdk events without any leads. Can someone tell me what is missing in my code or point me to some examples where filtering is done?