5 ms·
Is it really that much better than this: #include <X11/Xlib.h> #include <stdlib.h> int GetKeyCode(Display* d, char* s) { return XKeysymToKeyco
by qsort 1y ago
Is it really that much better than this:
#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 &");
}
}
}
- netrap 1y agoI think this is more readable than with macros, but it might be a preference.
- qsort 1y agoIt's also 50 bytes longer than the original. More LOC only because my Vim formats on save. 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.
- deleted 1y ago[deleted]
- l-albertovich 1y agoJust for fun I reformatted it minimally in the conservative way I write code that is intended to be easy to read and understand to improve the odds of future contributors (or future me) introducing a bug in it due to misunderstanding it. 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/984fff0825ff8feb6b390ac16847055f https://gist.github.com/leonardo-albertovich/984fff0825ff8fe...
- teo_zero 1y agoSorry but you didn't just reformatted it, you added new variables and return statements that were not in the original code (and even introduced bugs like row 41). 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 "=".
- l-albertovich 1y agoOh no, I accidentally duplicated a function call while quickly rewriting the code for fun, what a terrible sin! (as a side note, I didn't even compile the code but I after quick check I don't see any notes on the man page that suggest that the accidental spurious repeated call could cause a problem) 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.
- teo_zero 1y agoIt was not my intention to make you sad or angry. I assure you that I have nothing against who uses a different coding style than mine. But consider that, just like you, I too have the right to tell the world what my preference is. Should I have softened my post with more "IMHO", "I feel", "my taste"? Probably, and I apologize. Please don't stop participating in social media just because a halfwit like me hasn't agree with you once!