added the dump option

useful for debugging, if the dump option is set hkd prints the hotkey list
xkbcommon
Alessandro Mauri 4 years ago
parent 122ba9b44b
commit 699ddd057c
  1. 4
      hkd.1
  2. 44
      hkd.c

@ -6,6 +6,7 @@ hkd \- simple HotKey Daemon
.SH SYNOPSIS
.SY hkd
.OP \-v
.OP \-d
.OP \-c file
.YS
@ -23,6 +24,9 @@ correctly.
.IP \-v
verbose, prints debug information and the internal pressed key buffer upon
change acting as a crude keylogger :^)
.IP \-d
dump, used for debugging, it prints the whole hotkey list along with the
information about the hotkeys (matching type, keys and associated command).
.IP "\-c file"
override default configuration file location, instead using the specified
.I file

44
hkd.c

@ -235,7 +235,7 @@ char *ext_config_file = NULL;
/* Flags */
int vflag = 0;
int dead = 0; // exit flag
int dump = 0;
/* key buffer operations */
int key_buffer_add (struct key_buffer*, unsigned short);
int key_buffer_remove (struct key_buffer*, unsigned short);
@ -251,6 +251,7 @@ void remove_lock (void);
void die (const char *, ...);
int prepare_epoll (int *, int, int);
unsigned short key_to_code (char *);
const char * code_to_name (unsigned int);
/* hotkey list operations */
void hotkey_list_add (struct hotkey_list_e *, struct key_buffer *, char *, int);
void hotkey_list_destroy (struct hotkey_list_e *);
@ -288,7 +289,7 @@ int main (int argc, char *argv[])
sigaction(SIGINT, &action, NULL);
/* Parse command line arguments */
while ((opc = getopt(argc, argv, "vc:")) != -1) {
while ((opc = getopt(argc, argv, "vc:d")) != -1) {
switch (opc) {
case 'v':
vflag = 1;
@ -298,6 +299,10 @@ int main (int argc, char *argv[])
if (!ext_config_file)
die("malloc in main():");
strcpy(ext_config_file, optarg);
break;
case 'd':
dump = 1;
break;
break;
}
}
@ -305,6 +310,20 @@ int main (int argc, char *argv[])
/* Parse config file */
parse_config_file();
/* If a dump is requested print the hotkey list then exit */
if (dump) {
printf("DUMPING HOTKEY LIST\n\n");
for (struct hotkey_list_e *tmp = hotkey_list; tmp; tmp = tmp->next) {
printf("Hotkey\n");
printf("\tKeys: ");
for (unsigned int i = 0; i < tmp->kb.size; i++)
printf("%s ", code_to_name(tmp->kb.buf[i]));
printf("\n\tMatching: %s\n", tmp->fuzzy ? "fuzzy" : "ordered");
printf("\tCommand: %s\n\n", tmp->command);
}
exit(EXIT_SUCCESS);
}
/* Load descriptors */
update_descriptors_list(&fds, &fd_num);
@ -375,17 +394,9 @@ int main (int argc, char *argv[])
continue;
if (vflag) {
int ci;
printf("Pressed keys: ");
for (unsigned int i = 0; i < pb.size; i++) {
ci = i;
while (pb.buf[i] != key_conversion_table[ci + 1].value) {
if (ci >= array_size_const(key_conversion_table) - 2)
break;
ci++;
}
printf("%s ", key_conversion_table[ci + 1].name);
}
for (unsigned int i = 0; i < pb.size; i++)
printf("%s ", code_to_name(pb.buf[i]));
putchar('\n');
}
@ -914,3 +925,12 @@ void die(const char *fmt, ...)
va_end(ap);
exit(errno ? errno : 1);
}
const char * code_to_name (unsigned int code)
{
for (int i = 0; i < array_size_const(key_conversion_table); i++) {
if (key_conversion_table[i].value == code)
return key_conversion_table[i].name;
}
return "Key not recognized";
}

Loading…
Cancel
Save