Global hotkeys in Mono

2019-07-20 07:03发布

问题:

I'm trying to implement global hotkeys in Mono and X11. Unfortunately the application uses System.Windows.Forms, so I can't use the GDK# event filter proposed in this question.

Using XGrabKey works, but I've got a problem with the event loop. When closing the application, the thread handling the X11 event loop still hangs in XNextEvent. Is there a way around that? I'd rather not resort to polling with XPending. Can I somehow cancel XNextEvent or send a dummy event?

I'm calling XGrabKey on the root window, so unfortunately I don't get any events like DestroyNotify or UnmapNotify.

回答1:

Use XSendEvent to send an XClientMessageEvent. Create your own atom and set the Atom member of the event, so that other apps that might be watching for XClientMessageEvent on the root window are not affected.

In your event loop, check for this atom, and exit if you get it.



标签: c# linux mono x11