Global hotkeys in Mono

2019-07-20 06:54发布

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.

标签: c# linux mono x11
1条回答
兄弟一词,经得起流年.
2楼-- · 2019-07-20 07:34

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.

查看更多
登录 后发表回答