add MappingNotify + utility function grab_input
This commit is contained in:
parent
5e10dc08a3
commit
279e7cbcfa
1 changed files with 25 additions and 7 deletions
32
wm.c
32
wm.c
|
@ -7,10 +7,19 @@
|
|||
#define MODMASK Mod1Mask
|
||||
#define MAX(a, b) ((a) > (b) ? (a) : (b))
|
||||
|
||||
static Window root;
|
||||
|
||||
static Display* dpy;
|
||||
static XWindowAttributes attr;
|
||||
static XButtonEvent start;
|
||||
|
||||
void grab_input(Window* root) {
|
||||
XGrabKey(dpy, XKeysymToKeycode(dpy, XStringToKeysym("1")), MODMASK, *root, True, GrabModeAsync, GrabModeAsync);
|
||||
XGrabKey(dpy, XKeysymToKeycode(dpy, XStringToKeysym("Q")), MODMASK, *root, True, GrabModeAsync, GrabModeAsync);
|
||||
XGrabButton(dpy, 1, MODMASK, *root, True, ButtonPressMask|ButtonReleaseMask|PointerMotionMask, GrabModeAsync, GrabModeAsync, None, None);
|
||||
XGrabButton(dpy, 3, MODMASK, *root, True, ButtonPressMask|ButtonReleaseMask|PointerMotionMask, GrabModeAsync, GrabModeAsync, None, None);
|
||||
}
|
||||
|
||||
void handle_event_keypress(XEvent *e) {
|
||||
if (e->xkey.subwindow != None) {
|
||||
KeySym keysym = XkbKeycodeToKeysym(dpy, e->xkey.keycode, 0, 0);
|
||||
|
@ -45,23 +54,32 @@ void handle_event_buttonrelease(XEvent *e) {
|
|||
start.subwindow = None;
|
||||
}
|
||||
|
||||
void handle_event_mappingnotify(XEvent *e) {
|
||||
XMappingEvent *ev = &e->xmapping;
|
||||
|
||||
if (ev->request == MappingKeyboard || ev->request == MappingModifier) {
|
||||
XRefreshKeyboardMapping(ev);
|
||||
grab_input(&root);
|
||||
}
|
||||
}
|
||||
|
||||
static void (*event_handlers[LASTEvent])(XEvent *e) = {
|
||||
[KeyPress] = handle_event_keypress,
|
||||
[ButtonPress] = handle_event_buttonpress,
|
||||
[ButtonRelease] = handle_event_buttonrelease,
|
||||
[MotionNotify] = handle_event_motionnotify
|
||||
[MotionNotify] = handle_event_motionnotify,
|
||||
|
||||
// Below are events that are not 100% needed but without them some programs may break!
|
||||
// TODO: MapRequest, ConfigureRequest
|
||||
[MappingNotify] = handle_event_mappingnotify
|
||||
};
|
||||
|
||||
int main() {
|
||||
if(!(dpy = XOpenDisplay(0x0))) return 1;
|
||||
|
||||
XEvent ev;
|
||||
|
||||
XGrabKey(dpy, XKeysymToKeycode(dpy, XStringToKeysym("F1")), MODMASK, DefaultRootWindow(dpy), True, GrabModeAsync, GrabModeAsync);
|
||||
XGrabKey(dpy, XKeysymToKeycode(dpy, XStringToKeysym("Q")), MODMASK, DefaultRootWindow(dpy), True, GrabModeAsync, GrabModeAsync);
|
||||
XGrabButton(dpy, 1, MODMASK, DefaultRootWindow(dpy), True, ButtonPressMask|ButtonReleaseMask|PointerMotionMask, GrabModeAsync, GrabModeAsync, None, None);
|
||||
XGrabButton(dpy, 3, MODMASK, DefaultRootWindow(dpy), True, ButtonPressMask|ButtonReleaseMask|PointerMotionMask, GrabModeAsync, GrabModeAsync, None, None);
|
||||
|
||||
root = DefaultRootWindow(dpy);
|
||||
grab_input(&root);
|
||||
start.subwindow = None;
|
||||
|
||||
for (;;) {
|
||||
|
|
Reference in a new issue