Updated mwm.c.

This commit is contained in:
Luis Lavaire 2024-11-14 13:18:04 -06:00
parent 1e11c98aad
commit 5e4007b9d1

34
mwm.c
View file

@ -1,17 +1,37 @@
#include <X11/Xlib.h> #include <X11/Xlib.h>
#include <stdlib.h>
#define stok(s) XKeysymToKeycode(d, XStringToKeysym(s)) #define stk(s) XKeysymToKeycode(d, XStringToKeysym(s))
#define on(k, a) if (e.xkey.keycode == stok(k)) { a; continue; } #define K(k, x) if (e.xkey.keycode == stk(k)) { x; }
#define grab(k, m) XGrabKey (d, stok(k), m, r, 1, 1, 1) #define E(_, x) if (e.type == _) { x; }
#define gks(...) const char *l[] = { __VA_ARGS__ }; \
for (size_t i = 0; i < sizeof(l) / sizeof(*l); ++i) \
XGrabKey (d, stk(l[i]), Mod4Mask, r, 1, 1, 1);
int main (int argc, char **argv) { int main () {
Display *d = XOpenDisplay(0); Window r = DefaultRootWindow(d); XEvent e; Display *d = XOpenDisplay(0); Window r = DefaultRootWindow(d); XEvent e;
XSelectInput (d, r, SubstructureRedirectMask); XSelectInput (d, r, SubstructureRedirectMask);
// grab keys here. gks ("q", "n", "l", "space", "Return", "Right", "Left", "Up", "Down");
while (!XNextEvent (d, &e)) { while (!XNextEvent (d, &e)) {
if (e.type == KeyPress) ; E (KeyPress,
// define actions here. K("n", XCirculateSubwindowsUp(d, r); XSetInputFocus(d, e.xkey.window, 2, 0))
K("q", XKillClient(d, e.xkey.subwindow))
K("l", system("rotK &"))
K("space", system("chromium &"))
K("Return", system("xterm &"))
K("Right", system("vol 5%+ &"))
K("Left", system("vol 5%- &"))
K("Up", system("bri +100 &"))
K("Down", system("bri -100 &")))
E (MapRequest,
XMapWindow(d, e.xmaprequest.window);
XSetInputFocus(d, e.xmaprequest.window, 2, 0))
E (ConfigureRequest,
XMoveResizeWindow (d, e.xconfigure.window, 0, 0, e.xconfigure.width, e.xconfigure.height);
XMoveResizeWindow (d, e.xconfigure.window, 0, 0, 1920, 1080))
} }
} }