127 static void leavenotify(XEvent *e); |
127 static void leavenotify(XEvent *e); |
128 static void mappingnotify(XEvent *e); |
128 static void mappingnotify(XEvent *e); |
129 static void maprequest(XEvent *e); |
129 static void maprequest(XEvent *e); |
130 static void propertynotify(XEvent *e); |
130 static void propertynotify(XEvent *e); |
131 static void unmapnotify(XEvent *e); |
131 static void unmapnotify(XEvent *e); |
132 static void grabkeys(void); |
|
133 static unsigned int idxoftag(const char *tag); |
132 static unsigned int idxoftag(const char *tag); |
134 static void floating(void); /* default floating layout */ |
133 static void floating(void); /* default floating layout */ |
135 static void applyrules(Client *c); |
134 static void applyrules(Client *c); |
136 static void compileregs(void); |
135 static void compileregs(void); |
137 static void focusnext(const char *arg); |
136 static void focusnext(const char *arg); |
1068 static void |
1067 static void |
1069 keypress(XEvent *e) { |
1068 keypress(XEvent *e) { |
1070 KEYS |
1069 KEYS |
1071 unsigned int len = sizeof keys / sizeof keys[0]; |
1070 unsigned int len = sizeof keys / sizeof keys[0]; |
1072 unsigned int i; |
1071 unsigned int i; |
|
1072 KeyCode code; |
1073 KeySym keysym; |
1073 KeySym keysym; |
1074 XKeyEvent *ev = &e->xkey; |
1074 XKeyEvent *ev; |
1075 |
1075 |
|
1076 if(!e) { /* grabkeys */ |
|
1077 XUngrabKey(dpy, AnyKey, AnyModifier, root); |
|
1078 for(i = 0; i < len; i++) { |
|
1079 code = XKeysymToKeycode(dpy, keys[i].keysym); |
|
1080 XGrabKey(dpy, code, keys[i].mod, root, True, |
|
1081 GrabModeAsync, GrabModeAsync); |
|
1082 XGrabKey(dpy, code, keys[i].mod | LockMask, root, True, |
|
1083 GrabModeAsync, GrabModeAsync); |
|
1084 XGrabKey(dpy, code, keys[i].mod | numlockmask, root, True, |
|
1085 GrabModeAsync, GrabModeAsync); |
|
1086 XGrabKey(dpy, code, keys[i].mod | numlockmask | LockMask, root, True, |
|
1087 GrabModeAsync, GrabModeAsync); |
|
1088 } |
|
1089 return; |
|
1090 } |
|
1091 ev = &e->xkey; |
1076 keysym = XKeycodeToKeysym(dpy, (KeyCode)ev->keycode, 0); |
1092 keysym = XKeycodeToKeysym(dpy, (KeyCode)ev->keycode, 0); |
1077 for(i = 0; i < len; i++) |
1093 for(i = 0; i < len; i++) |
1078 if(keysym == keys[i].keysym |
1094 if(keysym == keys[i].keysym |
1079 && CLEANMASK(keys[i].mod) == CLEANMASK(ev->state)) |
1095 && CLEANMASK(keys[i].mod) == CLEANMASK(ev->state)) |
1080 { |
1096 { |
1097 mappingnotify(XEvent *e) { |
1113 mappingnotify(XEvent *e) { |
1098 XMappingEvent *ev = &e->xmapping; |
1114 XMappingEvent *ev = &e->xmapping; |
1099 |
1115 |
1100 XRefreshKeyboardMapping(ev); |
1116 XRefreshKeyboardMapping(ev); |
1101 if(ev->request == MappingKeyboard) |
1117 if(ev->request == MappingKeyboard) |
1102 grabkeys(); |
1118 keypress(NULL); |
1103 } |
1119 } |
1104 |
1120 |
1105 static void |
1121 static void |
1106 maprequest(XEvent *e) { |
1122 maprequest(XEvent *e) { |
1107 static XWindowAttributes wa; |
1123 static XWindowAttributes wa; |
1148 Client *c; |
1164 Client *c; |
1149 XUnmapEvent *ev = &e->xunmap; |
1165 XUnmapEvent *ev = &e->xunmap; |
1150 |
1166 |
1151 if((c = getclient(ev->window))) |
1167 if((c = getclient(ev->window))) |
1152 unmanage(c); |
1168 unmanage(c); |
1153 } |
|
1154 |
|
1155 static void |
|
1156 grabkeys(void) { |
|
1157 KEYS |
|
1158 unsigned int len = sizeof keys / sizeof keys[0]; |
|
1159 unsigned int i; |
|
1160 KeyCode code; |
|
1161 |
|
1162 XUngrabKey(dpy, AnyKey, AnyModifier, root); |
|
1163 for(i = 0; i < len; i++) { |
|
1164 code = XKeysymToKeycode(dpy, keys[i].keysym); |
|
1165 XGrabKey(dpy, code, keys[i].mod, root, True, |
|
1166 GrabModeAsync, GrabModeAsync); |
|
1167 XGrabKey(dpy, code, keys[i].mod | LockMask, root, True, |
|
1168 GrabModeAsync, GrabModeAsync); |
|
1169 XGrabKey(dpy, code, keys[i].mod | numlockmask, root, True, |
|
1170 GrabModeAsync, GrabModeAsync); |
|
1171 XGrabKey(dpy, code, keys[i].mod | numlockmask | LockMask, root, True, |
|
1172 GrabModeAsync, GrabModeAsync); |
|
1173 } |
|
1174 } |
1169 } |
1175 |
1170 |
1176 static unsigned int |
1171 static unsigned int |
1177 idxoftag(const char *tag) { |
1172 idxoftag(const char *tag) { |
1178 unsigned int i; |
1173 unsigned int i; |
1544 wa.event_mask = SubstructureRedirectMask | SubstructureNotifyMask |
1539 wa.event_mask = SubstructureRedirectMask | SubstructureNotifyMask |
1545 | EnterWindowMask | LeaveWindowMask | StructureNotifyMask; |
1540 | EnterWindowMask | LeaveWindowMask | StructureNotifyMask; |
1546 wa.cursor = cursor[CurNormal]; |
1541 wa.cursor = cursor[CurNormal]; |
1547 XChangeWindowAttributes(dpy, root, CWEventMask | CWCursor, &wa); |
1542 XChangeWindowAttributes(dpy, root, CWEventMask | CWCursor, &wa); |
1548 XSelectInput(dpy, root, wa.event_mask); |
1543 XSelectInput(dpy, root, wa.event_mask); |
1549 grabkeys(); |
1544 keypress(NULL); /* grabkeys */ |
1550 compileregs(); |
1545 compileregs(); |
1551 for(ntags = 0; tags[ntags]; ntags++); |
1546 for(ntags = 0; tags[ntags]; ntags++); |
1552 seltags = emallocz(sizeof(Bool) * ntags); |
1547 seltags = emallocz(sizeof(Bool) * ntags); |
1553 seltags[0] = True; |
1548 seltags[0] = True; |
1554 /* geometry */ |
1549 /* geometry */ |