During XGrabKey(board), discover which window had

2019-08-05 23:31发布

问题:

  1. A program has called XGrabKey() to make a hotkey.
  2. The user presses that key combination (while another window is focused).
  3. The program receives control to do something in response to the key combination. Meanwhile, the program has been temporarily focused (because of the effects of XGrabKey (see man XGrabKey, man XGrabKeyboard)).

I want the program to create a synthetic X event (a keypress or mouse click) to the originally focused window. In some cases this means I need to focus that window before sending it the event (Firefox ignores synthetic events when it is not focused), which means I need to know which window it is. How can I find out which window it is?

回答1:

Wait for the next FocusOut event, verify that the mode is set to NotifyUngrab, get the focus with XGetInputFocus(), and send away your synthetic events.



标签: x11