summaryrefslogtreecommitdiffstatshomepage
path: root/xkbcat.c
diff options
context:
space:
mode:
authorGravatar Antti K2014-07-29 23:48:53 +0200
committerGravatar Antti K2014-07-30 01:11:09 +0200
commitcf2bbd108919e0c11cfe135b594817a06501a685 (patch)
treeeacb2574596aac7c8a835ee15e89de7074ac8de7 /xkbcat.c
parent0d0a616515e78a542189ac90ba028401a6d569c8 (diff)
downloadxkbcat-cf2bbd108919e0c11cfe135b594817a06501a685.tar.gz
xkbcat-cf2bbd108919e0c11cfe135b594817a06501a685.zip
Small clarifications
Improved comments. Moved declaration of `printKeyPress` further down to decrease cognitive load.
Diffstat (limited to 'xkbcat.c')
-rw-r--r--xkbcat.c12
1 files changed, 6 insertions, 6 deletions
diff --git a/xkbcat.c b/xkbcat.c
index 5b55b3b..4afab90 100644
--- a/xkbcat.c
+++ b/xkbcat.c
@@ -17,8 +17,6 @@ static inline bool keyState(KbBuffer b, int key) {
return b[key/8] & (1<<(key%8));
}
-void printKeyPress(Display * disp, int code, bool down, bool printKeyUps);
-
int printUsage() {
printf("\
USAGE: xkbcat [-display <display>] [-delay <nanosec>] [-up]\n\
@@ -29,13 +27,15 @@ USAGE: xkbcat [-display <display>] [-delay <nanosec>] [-up]\n\
exit(0);
}
+void printKeyPress(Display * disp, int code, bool down, bool printKeyUps);
+
int main(int argc, char * argv[]) {
const char * hostname = DEFAULT_DISPLAY;
int delay = DEFAULT_DELAY;
bool printKeyUps = DEFAULT_PRINT_UP;
- // Get args
+ // Get arguments
for (int i = 1; i < argc; i++) {
if (!strcmp(argv[i], "-help")) printUsage();
else if (!strcmp(argv[i], "-display")) hostname = argv[++i];
@@ -44,7 +44,7 @@ int main(int argc, char * argv[]) {
else printUsage();
}
- // Setup Xwindows
+ // Set up X
Display * disp = XOpenDisplay(hostname);
if (NULL == disp) {
fprintf(stderr, "Cannot open X display: %s\n", hostname);
@@ -58,6 +58,7 @@ int main(int argc, char * argv[]) {
* keys = &keyBuffer2;
XQueryKeymap(disp, *oldKeys); // Initial fetch
+ // Timespec for time to sleep for
struct timespec sleepTime = { .tv_nsec = delay };
while (1) { // Forever
@@ -82,8 +83,7 @@ int main(int argc, char * argv[]) {
}
// Since `XKeysymToString` returns a string of unknown length that shouldn't be
-// modified, it makes more sense to just `printf` the thing in-place without
-// copying it anywhere. It's not needed anywhere else anyway.
+// modified, so it makes more sense to just `printf` it in-place.
void printKeyPress(Display * disp, int code, bool down, bool printKeyUps) {
KeySym s = XkbKeycodeToKeysym(disp, code, 0, 0); if (NoSymbol == s) return;