From 1b5bcaa9f4a73adf07a3a4eb3c37f4f91032a417 Mon Sep 17 00:00:00 2001 From: Dave Davenport Date: Mon, 30 May 2016 10:25:58 +0200 Subject: [PATCH] Issue #411: Show list of Keyboard bindings with rofi, from rofi. --- Makefile.am | 2 + config/config.c | 2 +- data/uncrustify.cfg | 2 +- include/dialogs/dialogs.h | 1 + include/dialogs/help-keys.h | 11 +++ include/textbox.h | 18 ++--- include/xrmoptions.h | 2 + source/dialogs/help-keys.c | 142 ++++++++++++++++++++++++++++++++++++ source/dialogs/window.c | 2 +- source/keyb.c | 105 +++++++++++++------------- source/rofi.c | 4 + source/xrmoptions.c | 68 +++++++++++++++++ 12 files changed, 295 insertions(+), 64 deletions(-) create mode 100644 include/dialogs/help-keys.h create mode 100644 source/dialogs/help-keys.c diff --git a/Makefile.am b/Makefile.am index 769bcc4d..4f7834ef 100644 --- a/Makefile.am +++ b/Makefile.am @@ -38,6 +38,7 @@ rofi_SOURCES=\ source/dialogs/combi.c\ source/dialogs/window.c\ source/dialogs/script.c\ + source/dialogs/help-keys.c\ include/xcb.h\ include/xcb-internal.h\ include/rofi.h\ @@ -64,6 +65,7 @@ rofi_SOURCES=\ include/dialogs/script.h\ include/dialogs/window.h\ include/dialogs/dialogs.h\ + include/dialogs/help-keys.h\ include/xkb.h\ include/xkb-internal.h diff --git a/config/config.c b/config/config.c index 4222ebb1..d20a2cb4 100644 --- a/config/config.c +++ b/config/config.c @@ -67,7 +67,7 @@ Settings config = { /** Command executed when running application in terminal */ .run_shell_command = "{terminal} -e {cmd}", /** Command executed on accep-entry-custom for window modus */ - .window_command = "xkill -id {window}", + .window_command = "xkill -id {window}", /** * Location of the window. * Enumeration indicating location or gravity of window. diff --git a/data/uncrustify.cfg b/data/uncrustify.cfg index 8fc2b96e..3e11e22f 100644 --- a/data/uncrustify.cfg +++ b/data/uncrustify.cfg @@ -1,7 +1,7 @@ # # My favorite format # -code_width = 140 +code_width = 240 nl_max = 2 ls_func_split_full = True indent_with_tabs = 0 # 1=indent to level only, 2=indent with tabs diff --git a/include/dialogs/dialogs.h b/include/dialogs/dialogs.h index 2690bc90..8f5d09b0 100644 --- a/include/dialogs/dialogs.h +++ b/include/dialogs/dialogs.h @@ -15,4 +15,5 @@ #include "dialogs/script.h" #include "dialogs/window.h" #include "dialogs/combi.h" +#include "dialogs/help-keys.h" #endif // ROFI_DIALOGS_DIALOGS_H diff --git a/include/dialogs/help-keys.h b/include/dialogs/help-keys.h new file mode 100644 index 00000000..c7934c55 --- /dev/null +++ b/include/dialogs/help-keys.h @@ -0,0 +1,11 @@ +#ifndef ROFI_DIALOG_HELPKEYS_H +#define ROFI_DIALOG_HELPKEYS_H + +/** + * @defgroup HELPKEYSMode KeysHelp + * @ingroup MODES + * @{ + */ +extern Mode help_keys_mode; +/*@}*/ +#endif // ROFI_DIALOG_HELPKEYS_H diff --git a/include/textbox.h b/include/textbox.h index afadd9e4..e08b88ed 100644 --- a/include/textbox.h +++ b/include/textbox.h @@ -39,15 +39,15 @@ typedef struct typedef enum { - TB_AUTOHEIGHT = 1 << 0, - TB_AUTOWIDTH = 1 << 1, - TB_LEFT = 1 << 16, - TB_RIGHT = 1 << 17, - TB_CENTER = 1 << 18, - TB_EDITABLE = 1 << 19, - TB_MARKUP = 1 << 20, - TB_WRAP = 1 << 21, - TB_PASSWORD = 1 << 22, + TB_AUTOHEIGHT = 1 << 0, + TB_AUTOWIDTH = 1 << 1, + TB_LEFT = 1 << 16, + TB_RIGHT = 1 << 17, + TB_CENTER = 1 << 18, + TB_EDITABLE = 1 << 19, + TB_MARKUP = 1 << 20, + TB_WRAP = 1 << 21, + TB_PASSWORD = 1 << 22, } TextboxFlags; typedef enum diff --git a/include/xrmoptions.h b/include/xrmoptions.h index e8967158..218015f7 100644 --- a/include/xrmoptions.h +++ b/include/xrmoptions.h @@ -142,5 +142,7 @@ void print_options ( void ); */ void print_help_msg ( const char *option, const char *type, const char*text, const char *def, int isatty ); +char ** config_parser_return_display_help ( unsigned int *length ); + /* @}*/ #endif diff --git a/source/dialogs/help-keys.c b/source/dialogs/help-keys.c new file mode 100644 index 00000000..6a633174 --- /dev/null +++ b/source/dialogs/help-keys.c @@ -0,0 +1,142 @@ +/** + * rofi + * + * MIT/X11 License + * Copyright 2013-2016 Qball Cow + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + */ +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "rofi.h" +#include "settings.h" +#include "helper.h" +#include "xrmoptions.h" +#include "dialogs/help-keys.h" +#include "textbox.h" + +typedef struct +{ + char **messages; + unsigned int messages_length; +} KeysHelpModePrivateData; + +static void get_apps ( KeysHelpModePrivateData *pd ) +{ + pd->messages = config_parser_return_display_help ( &( pd->messages_length ) ); +} + +static int help_keys_mode_init ( Mode *sw ) +{ + if ( mode_get_private_data ( sw ) == NULL ) { + KeysHelpModePrivateData *pd = g_malloc0 ( sizeof ( *pd ) ); + mode_set_private_data ( sw, (void *) pd ); + get_apps ( pd ); + } + return TRUE; +} + +static ModeMode help_keys_mode_result ( G_GNUC_UNUSED Mode *sw, + int mretv, + G_GNUC_UNUSED char **input, + G_GNUC_UNUSED unsigned int selected_line ) +{ + ModeMode retv = MODE_EXIT; + + if ( mretv & MENU_NEXT ) { + retv = NEXT_DIALOG; + } + else if ( mretv & MENU_PREVIOUS ) { + retv = PREVIOUS_DIALOG; + } + else if ( mretv & MENU_QUICK_SWITCH ) { + retv = ( mretv & MENU_LOWER_MASK ); + } + return retv; +} +static void help_keys_mode_destroy ( Mode *sw ) +{ + KeysHelpModePrivateData *rmpd = (KeysHelpModePrivateData *) mode_get_private_data ( sw ); + if ( rmpd != NULL ) { + g_strfreev ( rmpd->messages ); + g_free ( rmpd ); + mode_set_private_data ( sw, NULL ); + } +} + +static char *_get_display_value ( const Mode *sw, unsigned int selected_line, int *state, int get_entry ) +{ + KeysHelpModePrivateData *pd = (KeysHelpModePrivateData *) mode_get_private_data ( sw ); + *state |= MARKUP; + if ( !get_entry ) { + return NULL; + } + return g_strdup ( pd->messages[selected_line] ); +} +static int help_keys_token_match ( const Mode *data, + char **tokens, + int not_ascii, + int case_sensitive, + unsigned int index + ) +{ + KeysHelpModePrivateData *rmpd = (KeysHelpModePrivateData *) mode_get_private_data ( data ); + return token_match ( tokens, rmpd->messages[index], not_ascii, case_sensitive ); +} + +static unsigned int help_keys_mode_get_num_entries ( const Mode *sw ) +{ + const KeysHelpModePrivateData *pd = (const KeysHelpModePrivateData *) mode_get_private_data ( sw ); + return pd->messages_length; +} +static int help_keys_is_not_ascii ( const Mode *sw, unsigned int index ) +{ + const KeysHelpModePrivateData *pd = (const KeysHelpModePrivateData *) mode_get_private_data ( sw ); + return !g_str_is_ascii ( pd->messages[index] ); +} + +#include "mode-private.h" +Mode help_keys_mode = +{ + .name = "keys", + .cfg_name_key = "display-keys", + ._init = help_keys_mode_init, + ._get_num_entries = help_keys_mode_get_num_entries, + ._result = help_keys_mode_result, + ._destroy = help_keys_mode_destroy, + ._token_match = help_keys_token_match, + ._get_completion = NULL, + ._get_display_value = _get_display_value, + ._is_not_ascii = help_keys_is_not_ascii, + .private_data = NULL, + .free = NULL +}; diff --git a/source/dialogs/window.c b/source/dialogs/window.c index 5e5dd63e..f228cbf7 100644 --- a/source/dialogs/window.c +++ b/source/dialogs/window.c @@ -534,7 +534,7 @@ static inline int act_on_window ( xcb_window_t window ) int argc = 0; char window_str[100]; /* We are probably safe here */ - g_snprintf(window_str, sizeof window_str, "%d", window); + g_snprintf ( window_str, sizeof window_str, "%d", window ); helper_parse_setup ( config.window_command, &args, &argc, "{window}", window_str, NULL ); diff --git a/source/keyb.c b/source/keyb.c index c0e3bc5a..15380e44 100644 --- a/source/keyb.c +++ b/source/keyb.c @@ -24,6 +24,7 @@ typedef struct KeyBindingAction id; char *name; char *keybinding; + char *comment; } DefaultBinding; ActionBindingEntry abe[NUM_ABE]; @@ -33,57 +34,57 @@ ActionBindingEntry abe[NUM_ABE]; */ DefaultBinding bindings[NUM_ABE] = { - { .id = PASTE_PRIMARY, .name = "kb-primary-paste", .keybinding = "Control+Shift+v,Shift+Insert", }, - { .id = PASTE_SECONDARY, .name = "kb-secondary-paste", .keybinding = "Control+v,Insert", }, - { .id = CLEAR_LINE, .name = "kb-clear-line", .keybinding = "Control+u", }, - { .id = MOVE_FRONT, .name = "kb-move-front", .keybinding = "Control+a", }, - { .id = MOVE_END, .name = "kb-move-end", .keybinding = "Control+e", }, - { .id = MOVE_WORD_BACK, .name = "kb-move-word-back", .keybinding = "Alt+b", }, - { .id = MOVE_WORD_FORWARD, .name = "kb-move-word-forward", .keybinding = "Alt+f", }, - { .id = MOVE_CHAR_BACK, .name = "kb-move-char-back", .keybinding = "Left,Control+b" }, - { .id = MOVE_CHAR_FORWARD, .name = "kb-move-char-forward", .keybinding = "Right,Control+f" }, - { .id = REMOVE_WORD_BACK, .name = "kb-remove-word-back", .keybinding = "Control+Alt+h", }, - { .id = REMOVE_WORD_FORWARD, .name = "kb-remove-word-forward", .keybinding = "Control+Alt+d", }, - { .id = REMOVE_CHAR_FORWARD, .name = "kb-remove-char-forward", .keybinding = "Delete,Control+d", }, - { .id = REMOVE_CHAR_BACK, .name = "kb-remove-char-back", .keybinding = "BackSpace,Control+h", }, - { .id = ACCEPT_ENTRY, .name = "kb-accept-entry", .keybinding = "Control+j,Control+m,Return,KP_Enter", }, - { .id = ACCEPT_CUSTOM, .name = "kb-accept-custom", .keybinding = "Control+Return,Shift+Return", }, - { .id = MODE_NEXT, .name = "kb-mode-next", .keybinding = "Shift+Right,Control+Tab" }, - { .id = MODE_PREVIOUS, .name = "kb-mode-previous", .keybinding = "Shift+Left,Control+Shift+Tab" }, - { .id = TOGGLE_CASE_SENSITIVITY, .name = "kb-toggle-case-sensitivity", .keybinding = "grave,dead_grave" }, - { .id = DELETE_ENTRY, .name = "kb-delete-entry", .keybinding = "Shift+Delete" }, - { .id = ROW_LEFT, .name = "kb-row-left", .keybinding = "Control+Page_Up" }, - { .id = ROW_RIGHT, .name = "kb-row-right", .keybinding = "Control+Page_Down" }, - { .id = ROW_UP, .name = "kb-row-up", .keybinding = "Up,Control+p,Shift+Tab,Shift+ISO_Left_Tab" }, - { .id = ROW_DOWN, .name = "kb-row-down", .keybinding = "Down,Control+n" }, - { .id = ROW_TAB, .name = "kb-row-tab", .keybinding = "Tab" }, - { .id = PAGE_PREV, .name = "kb-page-prev", .keybinding = "Page_Up" }, - { .id = PAGE_NEXT, .name = "kb-page-next", .keybinding = "Page_Down" }, - { .id = ROW_FIRST, .name = "kb-row-first", .keybinding = "Home,KP_Home" }, - { .id = ROW_LAST, .name = "kb-row-last", .keybinding = "End,KP_End" }, - { .id = ROW_SELECT, .name = "kb-row-select", .keybinding = "Control+space" }, - { .id = CANCEL, .name = "kb-cancel", .keybinding = "Escape,Control+bracketleft" }, - { .id = CUSTOM_1, .name = "kb-custom-1", .keybinding = "Alt+1" }, - { .id = CUSTOM_2, .name = "kb-custom-2", .keybinding = "Alt+2" }, - { .id = CUSTOM_3, .name = "kb-custom-3", .keybinding = "Alt+3" }, - { .id = CUSTOM_4, .name = "kb-custom-4", .keybinding = "Alt+4" }, - { .id = CUSTOM_5, .name = "kb-custom-5", .keybinding = "Alt+5" }, - { .id = CUSTOM_6, .name = "kb-custom-6", .keybinding = "Alt+6" }, - { .id = CUSTOM_7, .name = "kb-custom-7", .keybinding = "Alt+7" }, - { .id = CUSTOM_8, .name = "kb-custom-8", .keybinding = "Alt+8" }, - { .id = CUSTOM_9, .name = "kb-custom-9", .keybinding = "Alt+9" }, - { .id = CUSTOM_10, .name = "kb-custom-10", .keybinding = "Alt+0" }, - { .id = CUSTOM_11, .name = "kb-custom-11", .keybinding = "Alt+Shift+1" }, - { .id = CUSTOM_12, .name = "kb-custom-12", .keybinding = "Alt+Shift+2" }, - { .id = CUSTOM_13, .name = "kb-custom-13", .keybinding = "Alt+Shift+3" }, - { .id = CUSTOM_14, .name = "kb-custom-14", .keybinding = "Alt+Shift+4" }, - { .id = CUSTOM_15, .name = "kb-custom-15", .keybinding = "Alt+Shift+5" }, - { .id = CUSTOM_16, .name = "kb-custom-16", .keybinding = "Alt+Shift+6" }, - { .id = CUSTOM_18, .name = "kb-custom-18", .keybinding = "Alt+Shift+8" }, - { .id = CUSTOM_17, .name = "kb-custom-17", .keybinding = "Alt+Shift+7" }, - { .id = CUSTOM_19, .name = "kb-custom-19", .keybinding = "Alt+Shift+9" }, - { .id = SCREENSHOT, .name = "kb-screenshot", .keybinding = "Alt+Shift+S" }, - { .id = TOGGLE_SORT, .name = "kb-toggle-sort", .keybinding = "Alt+grave" }, + { .id = PASTE_PRIMARY, .name = "kb-primary-paste", .keybinding = "Control+Shift+v,Shift+Insert", .comment = "Keybinding paste primary clipboard" }, + { .id = PASTE_SECONDARY, .name = "kb-secondary-paste", .keybinding = "Control+v,Insert", .comment = "Keybinding paste secondary clipboard" }, + { .id = CLEAR_LINE, .name = "kb-clear-line", .keybinding = "Control+u", .comment = "Keybinding clear input line" }, + { .id = MOVE_FRONT, .name = "kb-move-front", .keybinding = "Control+a", .comment = "Keybinding move cursor to front" }, + { .id = MOVE_END, .name = "kb-move-end", .keybinding = "Control+e", .comment = "Keybinding move cursor to end" }, + { .id = MOVE_WORD_BACK, .name = "kb-move-word-back", .keybinding = "Alt+b", .comment = "Keybinding move word back" }, + { .id = MOVE_WORD_FORWARD, .name = "kb-move-word-forward", .keybinding = "Alt+f", .comment = "Keybinding" }, + { .id = MOVE_CHAR_BACK, .name = "kb-move-char-back", .keybinding = "Left,Control+b", .comment = "Keybinding" }, + { .id = MOVE_CHAR_FORWARD, .name = "kb-move-char-forward", .keybinding = "Right,Control+f", .comment = "Keybinding" }, + { .id = REMOVE_WORD_BACK, .name = "kb-remove-word-back", .keybinding = "Control+Alt+h", .comment = "Keybinding" }, + { .id = REMOVE_WORD_FORWARD, .name = "kb-remove-word-forward", .keybinding = "Control+Alt+d", .comment = "Keybinding" }, + { .id = REMOVE_CHAR_FORWARD, .name = "kb-remove-char-forward", .keybinding = "Delete,Control+d", .comment = "Keybinding" }, + { .id = REMOVE_CHAR_BACK, .name = "kb-remove-char-back", .keybinding = "BackSpace,Control+h", .comment = "Keybinding" }, + { .id = ACCEPT_ENTRY, .name = "kb-accept-entry", .keybinding = "Control+j,Control+m,Return,KP_Enter", .comment = "Keybinding" }, + { .id = ACCEPT_CUSTOM, .name = "kb-accept-custom", .keybinding = "Control+Return,Shift+Return", .comment = "Keybinding" }, + { .id = MODE_NEXT, .name = "kb-mode-next", .keybinding = "Shift+Right,Control+Tab", .comment = "Keybinding" }, + { .id = MODE_PREVIOUS, .name = "kb-mode-previous", .keybinding = "Shift+Left,Control+Shift+Tab", .comment = "Keybinding" }, + { .id = TOGGLE_CASE_SENSITIVITY, .name = "kb-toggle-case-sensitivity", .keybinding = "grave,dead_grave", .comment = "Keybinding" }, + { .id = DELETE_ENTRY, .name = "kb-delete-entry", .keybinding = "Shift+Delete", .comment = "Keybinding" }, + { .id = ROW_LEFT, .name = "kb-row-left", .keybinding = "Control+Page_Up", .comment = "Keybinding" }, + { .id = ROW_RIGHT, .name = "kb-row-right", .keybinding = "Control+Page_Down", .comment = "Keybinding" }, + { .id = ROW_UP, .name = "kb-row-up", .keybinding = "Up,Control+p,Shift+Tab,Shift+ISO_Left_Tab", .comment = "Keybinding" }, + { .id = ROW_DOWN, .name = "kb-row-down", .keybinding = "Down,Control+n", .comment = "Keybinding" }, + { .id = ROW_TAB, .name = "kb-row-tab", .keybinding = "Tab", .comment = "Keybinding" }, + { .id = PAGE_PREV, .name = "kb-page-prev", .keybinding = "Page_Up", .comment = "Keybinding" }, + { .id = PAGE_NEXT, .name = "kb-page-next", .keybinding = "Page_Down", .comment = "Keybinding" }, + { .id = ROW_FIRST, .name = "kb-row-first", .keybinding = "Home,KP_Home", .comment = "Keybinding" }, + { .id = ROW_LAST, .name = "kb-row-last", .keybinding = "End,KP_End", .comment = "Keybinding" }, + { .id = ROW_SELECT, .name = "kb-row-select", .keybinding = "Control+space", .comment = "Keybinding" }, + { .id = CANCEL, .name = "kb-cancel", .keybinding = "Escape,Control+bracketleft", .comment = "Keybinding" }, + { .id = CUSTOM_1, .name = "kb-custom-1", .keybinding = "Alt+1", .comment = "Keybinding" }, + { .id = CUSTOM_2, .name = "kb-custom-2", .keybinding = "Alt+2", .comment = "Keybinding" }, + { .id = CUSTOM_3, .name = "kb-custom-3", .keybinding = "Alt+3", .comment = "Keybinding" }, + { .id = CUSTOM_4, .name = "kb-custom-4", .keybinding = "Alt+4", .comment = "Keybinding" }, + { .id = CUSTOM_5, .name = "kb-custom-5", .keybinding = "Alt+5", .comment = "Keybinding" }, + { .id = CUSTOM_6, .name = "kb-custom-6", .keybinding = "Alt+6", .comment = "Keybinding" }, + { .id = CUSTOM_7, .name = "kb-custom-7", .keybinding = "Alt+7", .comment = "Keybinding" }, + { .id = CUSTOM_8, .name = "kb-custom-8", .keybinding = "Alt+8", .comment = "Keybinding" }, + { .id = CUSTOM_9, .name = "kb-custom-9", .keybinding = "Alt+9", .comment = "Keybinding" }, + { .id = CUSTOM_10, .name = "kb-custom-10", .keybinding = "Alt+0", .comment = "Keybinding" }, + { .id = CUSTOM_11, .name = "kb-custom-11", .keybinding = "Alt+Shift+1", .comment = "Keybinding" }, + { .id = CUSTOM_12, .name = "kb-custom-12", .keybinding = "Alt+Shift+2", .comment = "Keybinding" }, + { .id = CUSTOM_13, .name = "kb-custom-13", .keybinding = "Alt+Shift+3", .comment = "Keybinding" }, + { .id = CUSTOM_14, .name = "kb-custom-14", .keybinding = "Alt+Shift+4", .comment = "Keybinding" }, + { .id = CUSTOM_15, .name = "kb-custom-15", .keybinding = "Alt+Shift+5", .comment = "Keybinding" }, + { .id = CUSTOM_16, .name = "kb-custom-16", .keybinding = "Alt+Shift+6", .comment = "Keybinding" }, + { .id = CUSTOM_18, .name = "kb-custom-18", .keybinding = "Alt+Shift+8", .comment = "Keybinding" }, + { .id = CUSTOM_17, .name = "kb-custom-17", .keybinding = "Alt+Shift+7", .comment = "Keybinding" }, + { .id = CUSTOM_19, .name = "kb-custom-19", .keybinding = "Alt+Shift+9", .comment = "Keybinding" }, + { .id = SCREENSHOT, .name = "kb-screenshot", .keybinding = "Alt+Shift+S", .comment = "Keybinding" }, + { .id = TOGGLE_SORT, .name = "kb-toggle-sort", .keybinding = "Alt+grave", .comment = "Keybinding" }, }; void setup_abe ( void ) @@ -96,7 +97,7 @@ void setup_abe ( void ) abe[id].num_bindings = 0; abe[id].kb = NULL; - config_parser_add_option ( xrm_String, abe[id].name, (void * *) &( abe[id].keystr ), "Keybinding" ); + config_parser_add_option ( xrm_String, abe[id].name, (void * *) &( abe[id].keystr ), bindings[iter].comment ); } } diff --git a/source/rofi.c b/source/rofi.c index 474deebb..4da1c6d3 100644 --- a/source/rofi.c +++ b/source/rofi.c @@ -334,6 +334,10 @@ static int add_mode ( const char * token ) modi[num_modi] = &ssh_mode; num_modi++; } + else if ( strcasecmp ( token, mode_get_name ( &help_keys_mode ) ) ) { + modi[num_modi] = &help_keys_mode; + num_modi++; + } // Run dialog else if ( strcasecmp ( token, "run" ) == 0 ) { modi[num_modi] = &run_mode; diff --git a/source/xrmoptions.c b/source/xrmoptions.c index 3119992e..63bf12c5 100644 --- a/source/xrmoptions.c +++ b/source/xrmoptions.c @@ -596,3 +596,71 @@ void config_parse_xresource_init ( void ) { XrmInitialize (); } + +static char * config_parser_return_display_help_entry ( XrmOption *option ) +{ + switch ( option->type ) + { + case xrm_Number: + return g_markup_printf_escaped ( " (%u) %s", + option->name, *( option->value.num ), option->comment ); + case xrm_SNumber: + return g_markup_printf_escaped ( " (%d) %s", + option->name, *( option->value.snum ), option->comment ); + case xrm_String: + return g_markup_printf_escaped ( "%s (%s) %s", + option->name, + ( *( option->value.str ) != NULL ) ? *( option->value.str ) : "null", + option->comment + ); + case xrm_Boolean: + return g_markup_printf_escaped ( "%s (%s) %s", + option->name, ( *( option->value.num ) == TRUE ) ? "true" : "false", option->comment ); + case xrm_Char: + if ( *( option->value.charc ) > 32 && *( option->value.charc ) < 127 ) { + return g_markup_printf_escaped ( "%s (%c) %s", + option->name, *( option->value.charc ), option->comment ); + } + else { + return g_markup_printf_escaped ( " (\\x%02X) %s", + option->name, *( option->value.charc ), option->comment ); + } + default: + break; + } + + return g_strdup ( "failed" ); +} + +char ** config_parser_return_display_help ( unsigned int *length ) +{ + unsigned int entries = sizeof ( xrmOptions ) / sizeof ( *xrmOptions ); + char **retv = NULL; + for ( unsigned int i = 0; i < entries; ++i ) { + if ( ( i + 1 ) < entries ) { + if ( xrmOptions[i].value.str == xrmOptions[i + 1].value.str ) { + continue; + } + } + if ( strncmp ( xrmOptions[i].name, "kb", 2 ) != 0 ) { + continue; + } + + retv = g_realloc ( retv, ( ( *length ) + 2 ) * sizeof ( char* ) ); + + retv[( *length )] = config_parser_return_display_help_entry ( &xrmOptions[i] ); + ( *length )++; + } + for ( unsigned int i = 0; i < num_extra_options; i++ ) { + if ( strncmp ( extra_options[i].name, "kb", 2 ) != 0 ) { + continue; + } + retv = g_realloc ( retv, ( ( *length ) + 2 ) * sizeof ( char* ) ); + retv[( *length )] = config_parser_return_display_help_entry ( &extra_options[i] ); + ( *length )++; + } + if ( ( *length ) > 0 ) { + retv[( *length )] = NULL; + } + return retv; +}