Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to print hotkeys' descriptions to stdout #248

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 7 additions & 2 deletions doc/sxhkd.1
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
.\" Title: sxhkd
.\" Author: [see the "Author" section]
.\" Generator: DocBook XSL Stylesheets vsnapshot <http://docbook.sf.net/>
.\" Date: 08/02/2020
.\" Date: 09/03/2021
.\" Manual: Sxhkd Manual
.\" Source: Sxhkd 0.6.2
.\" Language: English
.\"
.TH "SXHKD" "1" "08/02/2020" "Sxhkd 0\&.6\&.2" "Sxhkd Manual"
.TH "SXHKD" "1" "09/03/2021" "Sxhkd 0\&.6\&.2" "Sxhkd Manual"
.\" -----------------------------------------------------------------
.\" * Define some portability stuff
.\" -----------------------------------------------------------------
Expand Down Expand Up @@ -78,6 +78,11 @@ Output status information to the given FIFO\&.
.RS 4
Name of the keysym used for aborting chord chains\&.
.RE
.PP
\fB\-p\fR
.RS 4
Print hotkeys and associated commands read from config files to stdout\&.
.RE
.SH "BEHAVIOR"
.sp
\fBsxhkd\fR is a daemon that listens to keyboard events and execute commands\&.
Expand Down
3 changes: 3 additions & 0 deletions doc/sxhkd.1.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ Options
*-a* _ABORT_KEYSYM_::
Name of the keysym used for aborting chord chains.

*-p*::
Print hotkeys and associated commands read from config files to stdout.


Behavior
--------
Expand Down
2 changes: 1 addition & 1 deletion src/parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -2687,7 +2687,7 @@ bool parse_chain(char *string, chain_t *chain)
return false;
}
add_chord(chain, c);
if (status_fifo != NULL) {
if (status_fifo != NULL || print_hotkeys_mode) {
snprintf(c->repr, sizeof(c->repr), "%s", chord);
}
keysym = XCB_NO_SYMBOL;
Expand Down
33 changes: 31 additions & 2 deletions src/sxhkd.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ int mapping_count;
int timeout;

hotkey_t *hotkeys_head, *hotkeys_tail;
bool running, grabbed, toggle_grab, reload, bell, chained, locked;
bool running, grabbed, toggle_grab, reload, bell, chained, locked, print_hotkeys_mode;
xcb_keysym_t abort_keysym;
chord_t *abort_chord;

Expand All @@ -72,7 +72,7 @@ int main(int argc, char *argv[])
redir_fd = -1;
abort_keysym = ESCAPE_KEYSYM;

while ((opt = getopt(argc, argv, "hvm:t:c:r:s:a:")) != -1) {
while ((opt = getopt(argc, argv, "hvpm:t:c:r:s:a:")) != -1) {
switch (opt) {
case 'v':
printf("%s\n", VERSION);
Expand Down Expand Up @@ -105,6 +105,9 @@ int main(int argc, char *argv[])
warn("Invalid keysym name: %s.\n", optarg);
}
break;
case 'p':
print_hotkeys_mode = 1;
break;
}
}

Expand Down Expand Up @@ -144,6 +147,12 @@ int main(int argc, char *argv[])
load_config(config_file);
for (int i = 0; i < num_extra_confs; i++)
load_config(extra_confs[i]);

if (print_hotkeys_mode) {
print_hotkeys(hotkeys_head, hotkeys_tail);
exit(0);
}

grab();

xcb_generic_event_t *evt;
Expand Down Expand Up @@ -354,3 +363,23 @@ void put_status(char c, const char *s)
fprintf(status_fifo, "%c%s\n", c, s);
fflush(status_fifo);
}

void print_chain(chain_t *chain)
{
chord_t *c = chain->head;
printf("%s", c->repr);
while (c != chain->tail) {
c = c->next;
printf(" ; %s", c->repr);
}
printf(" | ");
}

void print_hotkeys(hotkey_t *head, hotkey_t *tail)
{
hotkey_t *h;
for (h = head; h != tail; h = h->next) {
print_chain(h->chain);
printf("%s\n", h->command);
}
}
4 changes: 3 additions & 1 deletion src/sxhkd.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ extern int mapping_count;
extern int timeout;

extern hotkey_t *hotkeys_head, *hotkeys_tail;
extern bool running, grabbed, toggle_grab, reload, bell, chained, locked;
extern bool running, grabbed, toggle_grab, reload, bell, chained, locked, print_hotkeys_mode;
extern xcb_keysym_t abort_keysym;
extern chord_t *abort_chord;

Expand All @@ -74,5 +74,7 @@ void reload_cmd(void);
void toggle_grab_cmd(void);
void hold(int sig);
void put_status(char c, const char *s);
void print_chord(chord_t *chord);
void print_hotkeys(hotkey_t *head, hotkey_t *tail);

#endif