Skip to content

Commit

Permalink
[script|dmenu] Add option to make row permanent.
Browse files Browse the repository at this point in the history
fixes: #1952
  • Loading branch information
DaveDavenport committed Feb 28, 2024
1 parent f2c0f75 commit afc65ac
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 25 deletions.
47 changes: 22 additions & 25 deletions Examples/test_script_mode.sh
Original file line number Diff line number Diff line change
@@ -1,32 +1,29 @@
#!/usr/bin/env bash

if [ "$*" = "quit" ]
then
exit 0
if [ "$*" = "quit" ]; then
exit 0
fi

if [ "$@" ]
then
# Override the previously set prompt.
echo -en "\x00prompt\x1fChange prompt\n"
for a in {1..10}
do
echo "$a"
done
echo "quit"
if [ "$@" ]; then
# Override the previously set prompt.
echo -en "\x00prompt\x1fChange prompt\n"
for a in {1..10}; do
echo "$a"
done
echo "quit"
else
echo -en "\x00prompt\x1ftesting\n"
echo -en "\0urgent\x1f0,2\n"
echo -en "\0active\x1f1\n"
echo -en "\0markup-rows\x1ftrue\n"
echo -en "\0message\x1fSpecial <b>bold</b>message\n"
echo -en "\x00prompt\x1ftesting\n"
echo -en "\0urgent\x1f0,2\n"
echo -en "\0active\x1f1\n"
echo -en "\0markup-rows\x1ftrue\n"
echo -en "\0message\x1fSpecial <b>bold</b>message\n"

echo -en "aap\0icon\x1ffolder\n"
echo -en "blob\0icon\x1ffolder\x1fdisplay\x1fblub\n"
echo "noot"
echo "mies"
echo -en "-------------\0nonselectable\x1ftrue\n"
echo "testing"
echo "<b>Bold</b>"
echo "quit"
echo -en "aap\0icon\x1ffolder\n"
echo -en "blob\0icon\x1ffolder\x1fdisplay\x1fblub\n"
echo "noot"
echo "mies"
echo -en "-------------\0nonselectable\x1ftrue\x1fpermanent\x1ftrue\n"
echo "testing"
echo "<b>Bold</b>"
echo "quit"
fi
2 changes: 2 additions & 0 deletions doc/rofi-script.5
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,8 @@ The following options are supported:
.IP \(bu 2
\fBnonselectable\fP: If true the row cannot activated.
.IP \(bu 2
\fBpermantent\fP: If true the row always shows, independent of filter.

This comment has been minimized.

Copy link
@Nickwiz

Nickwiz Mar 16, 2024

Believe this is meant to say permanent and not permantent

.IP \(bu 2
\fBinfo\fP: Info that, on selection, gets placed in the \fB\fCROFI_INFO\fR
environment variable. This entry does not get searched for filtering.
.IP \(bu 2
Expand Down
2 changes: 2 additions & 0 deletions doc/rofi-script.5.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ The following options are supported:

- **nonselectable**: If true the row cannot activated.

- **permantent**: If true the row always shows, independent of filter.

- **info**: Info that, on selection, gets placed in the `ROFI_INFO`
environment variable. This entry does not get searched for filtering.

Expand Down
3 changes: 3 additions & 0 deletions include/modes/dmenuscriptshared.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ typedef struct {
/** non-selectable */
gboolean nonselectable;

/** permanent */
gboolean permanent;

/** urgent */
gboolean urgent;
/** active */
Expand Down
6 changes: 6 additions & 0 deletions source/modes/dmenu.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ static void read_add_block(DmenuModePrivateData *pd, Block **block, char *data,
(*block)->values[(*block)->length].meta = NULL;
(*block)->values[(*block)->length].info = NULL;
(*block)->values[(*block)->length].nonselectable = FALSE;
(*block)->values[(*block)->length].permanent = FALSE;
char *end = data;
while (end < data + len && *end != '\0') {
end++;
Expand Down Expand Up @@ -668,6 +669,11 @@ static int dmenu_token_match(const Mode *sw, rofi_int_matcher **tokens,

/** Strip out the markup when matching. */
char *esc = NULL;
if (rmpd->cmd_list[index].permanent == TRUE) {
// Always match
return 1;
}

if (rmpd->do_markup) {
pango_parse_markup(rmpd->cmd_list[index].entry, -1, 0, NULL, &esc, NULL,
NULL);
Expand Down
10 changes: 10 additions & 0 deletions source/modes/script.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ void dmenuscript_parse_entry_extras(G_GNUC_UNUSED Mode *sw,
} else if (strcasecmp(key, "nonselectable") == 0) {
entry->nonselectable = g_ascii_strcasecmp(value, "true") == 0;
g_free(value);
} else if (strcasecmp(key, "permanent") == 0) {
entry->permanent = g_ascii_strcasecmp(value, "true") == 0;
g_free(value);
} else if (strcasecmp(key, "urgent") == 0) {
entry->urgent = g_ascii_strcasecmp(value, "true") == 0;
g_free(value);
Expand Down Expand Up @@ -252,6 +255,7 @@ static DmenuScriptEntry *execute_executor(Mode *sw, char *arg,
retv[(*length)].icon_fetch_uid = 0;
retv[(*length)].icon_fetch_size = 0;
retv[(*length)].nonselectable = FALSE;
retv[(*length)].permanent = FALSE;
if (buf_length > 0 && (read_length > (ssize_t)buf_length)) {
dmenuscript_parse_entry_extras(sw, &(retv[(*length)]),
buffer + buf_length,
Expand Down Expand Up @@ -454,6 +458,12 @@ static int script_token_match(const Mode *sw, rofi_int_matcher **tokens,
ScriptModePrivateData *rmpd = sw->private_data;
/** Strip out the markup when matching. */
char *esc = NULL;

if (rmpd->cmd_list[index].permanent == TRUE) {
// Always match
return 1;
}

if (rmpd->do_markup) {
pango_parse_markup(rmpd->cmd_list[index].entry, -1, 0, NULL, &esc, NULL,
NULL);
Expand Down

0 comments on commit afc65ac

Please sign in to comment.