From 7dcc3f450ca23143c074a2c3e24eb9414ebc36fb Mon Sep 17 00:00:00 2001 From: Dave Davenport Date: Sun, 2 Feb 2020 14:21:29 +0100 Subject: [PATCH] Add option to make entry non-selectable in dmenu/script. Fixes: #1024 --- Examples/test_script_mode.sh | 1 + include/dialogs/dmenuscriptshared.h | 2 ++ source/dialogs/dmenu.c | 9 +++++++++ source/dialogs/script.c | 10 ++++++++-- 4 files changed, 20 insertions(+), 2 deletions(-) diff --git a/Examples/test_script_mode.sh b/Examples/test_script_mode.sh index d91f6a0f..95c8b49b 100755 --- a/Examples/test_script_mode.sh +++ b/Examples/test_script_mode.sh @@ -24,6 +24,7 @@ else echo -en "aap\0icon\x1ffolder\n" echo "noot" echo "mies" + echo -en "-------------\0nonselectable\x1ftrue\n" echo "testing" echo "Bold" echo "quit" diff --git a/include/dialogs/dmenuscriptshared.h b/include/dialogs/dmenuscriptshared.h index 12423869..a7f1f47a 100644 --- a/include/dialogs/dmenuscriptshared.h +++ b/include/dialogs/dmenuscriptshared.h @@ -11,6 +11,8 @@ typedef struct uint32_t icon_fetch_uid; /** Hidden meta keywords. */ char *meta; + /** non-selectable */ + gboolean nonselectable; } DmenuScriptEntry; /** * @param sw Unused diff --git a/source/dialogs/dmenu.c b/source/dialogs/dmenu.c index eeef4dba..459d2292 100644 --- a/source/dialogs/dmenu.c +++ b/source/dialogs/dmenu.c @@ -554,6 +554,10 @@ static void dmenu_finalize ( RofiViewState *state ) } } else if ( ( mretv & ( MENU_OK | MENU_QUICK_SWITCH ) ) && cmd_list[pd->selected_line].entry != NULL ) { + if ( cmd_list[pd->selected_line].nonselectable == TRUE ) { + g_free ( input ); + return; + } dmenu_print_results ( pd, input ); retv = TRUE; if ( ( mretv & MENU_QUICK_SWITCH ) ) { @@ -579,6 +583,11 @@ static void dmenu_finalize ( RofiViewState *state ) restart = FALSE; // Normal mode if ( ( mretv & MENU_OK ) && pd->selected_line != UINT32_MAX && cmd_list[pd->selected_line].entry != NULL ) { + // Check if entry is non-selectable. + if ( cmd_list[pd->selected_line].nonselectable == TRUE ) { + g_free ( input ); + return; + } if ( ( mretv & MENU_CUSTOM_ACTION ) && pd->multi_select ) { restart = TRUE; if ( pd->selected_list == NULL ) { diff --git a/source/dialogs/script.c b/source/dialogs/script.c index 254fab0b..4279f438 100644 --- a/source/dialogs/script.c +++ b/source/dialogs/script.c @@ -85,9 +85,12 @@ void dmenuscript_parse_entry_extras ( G_GNUC_UNUSED Mode *sw, DmenuScriptEntry * if ( strcasecmp ( buffer, "icon" ) == 0 ) { entry->icon_name = g_strdup ( value ); } - if ( strcasecmp ( buffer, "meta" ) == 0 ) { + else if ( strcasecmp ( buffer, "meta" ) == 0 ) { entry->meta = g_strdup ( value ); } + else if ( strcasecmp ( buffer, "nonselectable" ) == 0 ) { + entry->nonselectable = strcasecmp ( value, "true" ) == 0; + } } } @@ -244,7 +247,7 @@ static ModeMode script_mode_result ( Mode *sw, int mretv, char **input, unsigned unsigned int new_length = 0; if ( ( mretv & MENU_NEXT ) ) { - retv = NEXT_DIALOG; + retv = RELOAD_DIALOG;; } else if ( ( mretv & MENU_PREVIOUS ) ) { retv = PREVIOUS_DIALOG; @@ -253,6 +256,9 @@ static ModeMode script_mode_result ( Mode *sw, int mretv, char **input, unsigned retv = ( mretv & MENU_LOWER_MASK ); } else if ( ( mretv & MENU_OK ) && rmpd->cmd_list[selected_line].entry != NULL ) { + if ( rmpd->cmd_list[selected_line].nonselectable ) { + return FALSE; + } script_mode_reset_highlight ( sw ); new_list = execute_executor ( sw, rmpd->cmd_list[selected_line].entry, &new_length ); }