4

I would like to develop a system-wide onscreen keyboard in Qt/QML. Injecting key-events via xlib works fine.

My problem now: If a keyboard-button is clicked, the window with the selected input field will lose the focus. In consequence, the key event will not be delivered to the previously selected input field.

So does anybody know how to prevent a QWidget from beeing activated/focussed by mouse-clicks? Every hint is welcome and a code examples would be great!

Thank you very much in advance, Frime

Frime
  • 261
  • 2
  • 6
  • You can watch FocusIn/FocusOut events and return the focus to the previous window by force. Alternatively, make your onscreen keyboard override-redirect and don't worry about focus at all (it will not work if you have "focus strictly under mouse" policy, but I think no on-screen keyboard can sensibly work with this policy). – n. m. could be an AI Mar 17 '15 at 11:25
  • Hi! Thanks for comment. How can i catch X11 FocusIn Events in Qt? Or do you mean QWidgets own FocusIn/Out Events? This will not work because the keyboard has to operate systemwide with any application - not only within its own application. – Frime Mar 17 '15 at 12:05
  • I mean X11 events. See [this](http://stackoverflow.com/questions/9041456/how-to-pass-x11-events-to-qdialog).You need to call `XSelectInput(dpy, root, FocusChangeMask)`. – n. m. could be an AI Mar 17 '15 at 12:25
  • Thank you very much again. Okay, now i can catch these "xcb_generic_event_t" events. With different response-types like "FocusIn" or "FocusOut". But they doesn't provide any reusable information about the previous focussed window... Or does i miss something? – Frime Mar 17 '15 at 15:02
  • You want to look at the FocusOut event that came before FocusIn. It should contain your previously focussed window. – n. m. could be an AI Mar 17 '15 at 15:23
  • What i already did is implementing / instgalling a QAbstractNativeEventfilter and the following Code: *display = XOpenDisplay(0); if(!display == 0) { XSetWindowAttributes attr; attr.override_redirect = true; XChangeWindowAttributes(display, engine.winId(), CWOverrideRedirect, &attr); XSelectInput(display, XDefaultRootWindow(display), EnterWindowMask | FocusChangeMask); but all events i receive are relative to my keyboard. So focusOut Event does not help .. – Frime Mar 18 '15 at 12:09
  • Sorry my mistake, `XSelectInput(dpy, root, FocusChangeMask)` doesn't help, you need to call `XSelectInput(dpy, w, FocusChangeMask)` on all top-level windows, and track top-level windows creation and destruction. This is not easy. The other way to achieve that is to watch the _NET_ACTIVE_WINDOW property of the root window. What about making your window override-redirect? You need to do that before you map it. Then your window won't get any focus on click. – n. m. could be an AI Mar 18 '15 at 22:48
  • Setting this flag after creation of the window instance had no effect.. What means "map it" ? I guess this is something done by the Qt Framework.. The question now is: How to intervene here. (Thanks a lot for your help, it's the first time i have to struggle directly with X11) – Frime Mar 19 '15 at 09:52
  • mapping a window actually shows it on screen which is a distinct operation from creating it. – n. m. could be an AI Mar 19 '15 at 13:47
  • I don't remember which Qt concepts correspond to "map" and "override redirect" – n. m. could be an AI Mar 19 '15 at 14:26
  • http://stackoverflow.com/questions/29209462/qt-x11-how-to-make-a-qwidget-override-redirect-calling-xchangewindowattribute – Frime Mar 23 '15 at 12:16

0 Answers0