Compare commits
2 Commits
213db3cee5
...
d6b8e129d7
Author | SHA1 | Date | |
---|---|---|---|
d6b8e129d7 | |||
8ad875b311 |
8
hkd.1
8
hkd.1
@ -7,6 +7,7 @@ hkd \- simple HotKey Daemon
|
||||
.SY hkd
|
||||
.OP \-v
|
||||
.OP \-d
|
||||
.OP \-h
|
||||
.OP \-c file
|
||||
.YS
|
||||
|
||||
@ -27,6 +28,8 @@ 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 \-h
|
||||
prints help message and exits
|
||||
.IP "\-c file"
|
||||
override default configuration file location, instead using the specified
|
||||
.I file
|
||||
@ -77,6 +80,11 @@ Key names are always capitalized and do not differenciate between upper or
|
||||
lower case, as such hotkeys that require a capitalized letter need to include
|
||||
RIGHTSHIFT or LEFTSHIFT in the keys section.
|
||||
Keys are intended as a list of comma separated strings.
|
||||
.PP
|
||||
hkd can live reload the configuration file by signaling it with
|
||||
.I SIGUSR1
|
||||
for example with the command "$ pkill -USR1 -x hkd", for easier use one could add
|
||||
an hotkey to execute that command.
|
||||
|
||||
.SH EXAMPLES
|
||||
This is a valid config file example
|
||||
|
58
hkd.c
58
hkd.c
@ -249,6 +249,7 @@ void parse_config_file (void);
|
||||
void update_descriptors_list (int **, int *);
|
||||
void remove_lock (void);
|
||||
void die (const char *, ...);
|
||||
void usage (void);
|
||||
int prepare_epoll (int *, int, int);
|
||||
unsigned short key_to_code (char *);
|
||||
const char * code_to_name (unsigned int);
|
||||
@ -270,26 +271,8 @@ int main (int argc, char *argv[])
|
||||
struct input_event event;
|
||||
struct key_buffer pb = {{0}, 0}; // Pressed keys buffer
|
||||
|
||||
/* Check if hkd is already running */
|
||||
lock_file_descriptor = open(LOCK_FILE, O_RDWR | O_CREAT, 0600);
|
||||
if (lock_file_descriptor < 0)
|
||||
die("Can't open lock file:");
|
||||
fl.l_start = 0;
|
||||
fl.l_len = 0;
|
||||
fl.l_type = F_WRLCK;
|
||||
fl.l_whence = SEEK_SET;
|
||||
if (fcntl(lock_file_descriptor, F_SETLK, &fl) < 0)
|
||||
die("hkd is already running");
|
||||
atexit(remove_lock);
|
||||
|
||||
/* Handle SIGINT */
|
||||
dead = 0;
|
||||
memset(&action, 0, sizeof(action));
|
||||
action.sa_handler = int_handler;
|
||||
sigaction(SIGINT, &action, NULL);
|
||||
|
||||
/* Parse command line arguments */
|
||||
while ((opc = getopt(argc, argv, "vc:d")) != -1) {
|
||||
while ((opc = getopt(argc, argv, "vc:dh")) != -1) {
|
||||
switch (opc) {
|
||||
case 'v':
|
||||
vflag = 1;
|
||||
@ -303,13 +286,35 @@ int main (int argc, char *argv[])
|
||||
case 'd':
|
||||
dump = 1;
|
||||
break;
|
||||
case 'h':
|
||||
usage();
|
||||
break;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Handle SIGINT */
|
||||
dead = 0;
|
||||
memset(&action, 0, sizeof(action));
|
||||
action.sa_handler = int_handler;
|
||||
sigaction(SIGINT, &action, NULL);
|
||||
sigaction(SIGUSR1, &action, NULL);
|
||||
|
||||
/* Parse config file */
|
||||
parse_config_file();
|
||||
|
||||
/* Check if hkd is already running */
|
||||
lock_file_descriptor = open(LOCK_FILE, O_RDWR | O_CREAT, 0600);
|
||||
if (lock_file_descriptor < 0)
|
||||
die("Can't open lock file:");
|
||||
fl.l_start = 0;
|
||||
fl.l_len = 0;
|
||||
fl.l_type = F_WRLCK;
|
||||
fl.l_whence = SEEK_SET;
|
||||
if (fcntl(lock_file_descriptor, F_SETLK, &fl) < 0)
|
||||
die("hkd is already running");
|
||||
atexit(remove_lock);
|
||||
|
||||
/* If a dump is requested print the hotkey list then exit */
|
||||
if (dump) {
|
||||
printf("DUMPING HOTKEY LIST\n\n");
|
||||
@ -475,6 +480,9 @@ void int_handler (int signum)
|
||||
printf(yellow("Received interrupt signal, exiting gracefully...\n"));
|
||||
dead = 1;
|
||||
break;
|
||||
case SIGUSR1:
|
||||
parse_config_file();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -721,6 +729,8 @@ void parse_config_file (void)
|
||||
if (!fd)
|
||||
die("Could not open any config files, check the log for more details");
|
||||
}
|
||||
|
||||
hotkey_list_destroy(hotkey_list);
|
||||
while (exit_state >= 0) {
|
||||
int tmp = 0;
|
||||
memset(block, 0, BLOCK_SIZE + 1);
|
||||
@ -947,3 +957,13 @@ const char * code_to_name (unsigned int code)
|
||||
}
|
||||
return "Key not recognized";
|
||||
}
|
||||
|
||||
void usage (void)
|
||||
{
|
||||
puts("Usage: hkd [-vdh] [-c file]\n"
|
||||
"\t-v verbose, prints all the key presses and debug information\n"
|
||||
"\t-d dump, dumps the hotkey list and exits\n"
|
||||
"\t-h prints this help message\n"
|
||||
"\t-f file uses the specified file as config\n");
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user