by qsort · 1y ago · 0 comments
#include <X11/Xlib.h>
#include <stdlib.h>
int GetKeyCode(Display* d, char* s)
{
return XKeysymToKeycode(d, XStringToKeysym(s));
}
int main()
{
Display* d = XOpenDisplay(0);
Window r = DefaultRootWindow(d);
XSelectInput(d, r, SubstructureRedirectMask);
XGrabKey(d, GetKeyCode(d, "n"), Mod4Mask, r, 1, 1, 1);
XGrabKey(d, GetKeyCode(d, "q"), Mod4Mask, r, 1, 1, 1);
XGrabKey(d, GetKeyCode(d, "e"), Mod4Mask, r, 1, 1, 1);
XEvent e;
while (!XNextEvent(d, &e)) {
switch (e.type) {
case ConfigureRequest:
XMoveResizeWindow(d, e.xconfigure.window, 0, 0, e.xconfigure.width, e.xconfigure.height);
break;
case MapRequest:
XMapWindow(d, e.xmaprequest.window);
break;
case KeyPress:
if (e.xkey.keycode == GetKeyCode(d, "n")) {
XCirculateSubwindowsUp(d, r);
XSetInputFocus(d, e.xkey.window, 2, 0);
}
if (e.xkey.keycode == GetKeyCode(d, "q"))
XKillClient(d, e.xkey.subwindow);
if (e.xkey.keycode == GetKeyCode(d, "e"))
system("dmenu_run &");
}
}
}It's painfully verbose but I think it's worth it considering that we're in 2025 and we're not limited to one character variable names.
https://gist.github.com/leonardo-albertovich/984fff0825ff8fe...
As of short variable names, I'd argue that they are actually more readable than long ones when they're the iterator of a loop:
while... XNextEvent(... &e)
What else can "e" stand for in the body of this loop?Longer lifetimes and not-as-obvious scopes do deserve longer names.
Finally, I strongly dislike this kind of reversed conditions:
if (const == var)
To paraphrase your own words, we're in 2025 and we should not be limited by our fear of forgetting one "=".I understand that you might not like that style but I think you're comming a bit too strong on this, especially considering how carefully I worded my message in terms of not hurting any feeling and being clear about this being MY preference.
I guess I shouldn't probably even answer but it saddens me and makes me a bit angry to get a reminder of why I don't usually participate in social media.
Please don't stop participating in social media just because a halfwit like me hasn't agree with you once!
Whenever somebody comes up with some big brain idea with macros, ORMs, DSLs, 180 IQ templates, language extensions that even Haskell nerds would say are too much, there's a good chance that the grugbrained version is just as readable, just as concise without going against the language.
I'm this close to go completely nuts with this industry and commit to full butlerian jihad against anybody who goes higher in abstraction than ANSI C.