diff options
author | Dave Davenport <qball@blame.services> | 2022-09-18 20:28:38 +0200 |
---|---|---|
committer | Dave Davenport <qball@blame.services> | 2022-09-18 20:28:38 +0200 |
commit | 5ae8fa5a3f691a0753d7f612ae2b07add7881d4d (patch) | |
tree | 97fe0d301bab3f9ce91366ed859a0e9deb9eb88b | |
parent | 0b72ff2a74da242f39697f2a51f5c3f4544c0268 (diff) |
[Keyb] Add a -list-keybindings command.
-rw-r--r-- | doc/rofi.1 | 7 | ||||
-rw-r--r-- | doc/rofi.1.markdown | 5 | ||||
-rw-r--r-- | include/keyb.h | 1 | ||||
-rw-r--r-- | source/keyb.c | 44 | ||||
-rw-r--r-- | source/rofi.c | 8 |
5 files changed, 57 insertions, 8 deletions
@@ -221,6 +221,13 @@ Dump the current active theme, in rasi format, to stdout and exit. Try to parse the file and return 0 when successful, non-zero when failed. .PP +\fB\fC-list-keybindings\fR + +.PP +List all known keybindings without trying to parse them. This can be used to +look for duplicate bindings. + +.PP \fB\fC-threads\fR \fInum\fP .PP diff --git a/doc/rofi.1.markdown b/doc/rofi.1.markdown index e73c98e5..ac2dbc02 100644 --- a/doc/rofi.1.markdown +++ b/doc/rofi.1.markdown @@ -143,6 +143,11 @@ Dump the current active theme, in rasi format, to stdout and exit. Try to parse the file and return 0 when successful, non-zero when failed. +`-list-keybindings` + +List all known keybindings without trying to parse them. This can be used to +look for duplicate bindings. + `-threads` *num* Specify the number of threads **rofi** should use: diff --git a/include/keyb.h b/include/keyb.h index 12418c4c..b2d3b323 100644 --- a/include/keyb.h +++ b/include/keyb.h @@ -186,6 +186,7 @@ gboolean parse_keys_abe(NkBindings *bindings); */ void setup_abe(void); +void abe_list_all_bindings(gboolean is_term); /** * @param name Don't have the name. * diff --git a/source/keyb.c b/source/keyb.c index 16a5c595..a3eac3d1 100644 --- a/source/keyb.c +++ b/source/keyb.c @@ -24,11 +24,11 @@ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * */ +#include "rofi.h" +#include "xrmoptions.h" #include <glib.h> #include <string.h> #include "nkutils-bindings.h" -#include "rofi.h" -#include "xrmoptions.h" typedef struct { guint id; @@ -372,6 +372,24 @@ static const gchar *mouse_default_bindings[] = { [MOUSE_DCLICK_UP] = "!MouseDPrimary", }; +void abe_list_all_bindings(gboolean is_term ) { + + int length = 0; + for (gsize i = 0; i < G_N_ELEMENTS(rofi_bindings); ++i) { + ActionBindingEntry *b = &rofi_bindings[i]; + int sl = strlen(b->name); + length = MAX(length, sl); + } + for (gsize i = 0; i < G_N_ELEMENTS(rofi_bindings); ++i) { + ActionBindingEntry *b = &rofi_bindings[i]; + if (is_term) { + printf("%s%*s%s - %s\n", color_bold,length, b->name, color_reset,b->binding); + } else { + printf("%*s - %s\n", length, b->name, b->binding); + } + } +} + void setup_abe(void) { for (gsize i = 0; i < G_N_ELEMENTS(rofi_bindings); ++i) { ActionBindingEntry *b = &rofi_bindings[i]; @@ -421,12 +439,22 @@ gboolean parse_keys_abe(NkBindings *bindings) { if (!nk_bindings_add_binding(bindings, b->scope, entry, binding_check_action, binding_trigger_action, GUINT_TO_POINTER(b->id), NULL, &error)) { - char *str = g_markup_printf_escaped( - "Failed to set binding <i>%s</i> for: <i>%s (%s)</i>:\n\t<span " - "size=\"smaller\" style=\"italic\">%s</span>\n", - b->binding, b->comment, b->name, error->message); - g_string_append(error_msg, str); - g_free(str); + if ( error->code == NK_BINDINGS_ERROR_ALREADY_REGISTERED && error->domain == NK_BINDINGS_ERROR){ + char *str = g_markup_printf_escaped( + "Failed to set binding <i>%s</i> for: <i>%s (%s)</i>:\n\t<span " + "size=\"smaller\" style=\"italic\">Binding `%s` is already bound.\n" + "\tExecute <b>rofi -list-keybindings</b> to get the current list of configured bindings.</span>\n", + b->binding, b->comment, b->name, entry); + g_string_append(error_msg, str); + g_free(str); + } else { + char *str = g_markup_printf_escaped( + "Failed to set binding <i>%s</i> for: <i>%s (%s)</i>:\n\t<span " + "size=\"smaller\" style=\"italic\">%s</span>\n", + b->binding, b->comment, b->name, error->message); + g_string_append(error_msg, str); + g_free(str); + } g_clear_error(&error); } } diff --git a/source/rofi.c b/source/rofi.c index fd318ad2..0bf4be81 100644 --- a/source/rofi.c +++ b/source/rofi.c @@ -327,6 +327,9 @@ static void print_main_application_options(int is_term) { print_help_msg("-dump-theme", "", "Dump the current theme in rasi format and exit.", NULL, is_term); + print_help_msg("-list-keybindings", "", + "Print a list of current keybindings and exit.", NULL, + is_term); } static void help(G_GNUC_UNUSED int argc, char **argv) { int is_term = isatty(fileno(stdout)); @@ -1094,6 +1097,11 @@ int main(int argc, char *argv[]) { cleanup(); return EXIT_SUCCESS; } + if (find_arg("-list-keybindings") >= 0) { + int is_term = isatty(fileno(stdout)); + abe_list_all_bindings(is_term); + return EXIT_SUCCESS; + } unsigned int interval = 1; if (find_arg_uint("-record-screenshots", &interval)) { |