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

[WIP] Feature/combi format string #1123

Draft
wants to merge 7 commits into
base: next
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions source/dialogs/combi.c
Original file line number Diff line number Diff line change
Expand Up @@ -236,9 +236,6 @@ static int combi_mode_match ( const Mode *sw, rofi_int_matcher **tokens, unsigne
static char * combi_mgrv ( const Mode *sw, unsigned int selected_line, int *state, GList **attr_list, int get_entry )
{
CombiModePrivateData *pd = mode_get_private_data ( sw );
if (config.markup_combi) {
*state |= MARKUP;
}
if ( !get_entry ) {
for ( unsigned i = 0; i < pd->num_switchers; i++ ) {
if ( selected_line >= pd->starts[i] && selected_line < ( pd->starts[i] + pd->lengths[i] ) ) {
Expand All @@ -253,17 +250,32 @@ static char * combi_mgrv ( const Mode *sw, unsigned int selected_line, int *stat
char * retv;
char * str = retv = mode_get_display_value ( pd->switchers[i].mode, selected_line - pd->starts[i], state, attr_list, TRUE );
const char *dname = mode_get_display_name ( pd->switchers[i].mode );
char *format_str = g_strdup( config.combi_display_format );
if ( !config.combi_hide_mode_prefix ) {
if ( !(*state & MARKUP) && config.markup_combi ) {
// Mode does not use markup, but we want to, so escape output
char * tmp_str = g_markup_escape_text( str, -1 );
g_free(str);
str = tmp_str;
*state |= MARKUP;
}
if ( (*state & MARKUP) && !config.markup_combi ) {
// Mode does use markup, but we did not want to, so escape pattern string
char * tmp_str = g_markup_escape_text( format_str, -1 );
g_free(format_str);
format_str = tmp_str;
}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should take care of the escaping.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To avoid confusion, wouldn't it be better to remove the markup_combi option and always do markup (and convert element that is not markup).

So the combi_display_format option is always a markup string. (don't think this is unreasonable, and how drun-display-format works)

Copy link
Author

@jchtt jchtt May 13, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done! For now, I always enabled markup, without checking if there was a custom combi_display_format set, I hope this is OK (the same as drun, that also enables markup by default).

If you think the other two options are OK, I‘ll try to put some documentation in the man page.

char *dname_markup = g_markup_escape_text ( dname, -1 );
char *opt_linebreak = g_strdup(pd->switchers[i].print_newline ? "\n" : config.combi_no_linebreak_str);
retv = helper_string_replace_if_exists( config.combi_display_format,
retv = helper_string_replace_if_exists( format_str,
"{mode}", dname_markup,
"{linebreak}", opt_linebreak,
"{element}", str,
NULL );
g_free ( str );
g_free ( dname_markup );
g_free ( opt_linebreak );
g_free ( format_str );
}

if ( attr_list != NULL ) {
Expand Down
4 changes: 2 additions & 2 deletions test/run_combi_mode_format.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ rofi -show combi -combi-modi "window,drun" -eh 2 \
-drun-display-format "[<span weight='light' size='small'><i>({generic})</i></span>]"$'\n'"{name}" \
-combi-display-format "[<span weight='light' size='small'><i>[{mode}]</i></span>]{linebreak}{element}" \
-combi-no-linebreak-str " " \
-markup-combi 1 \
-combi-no-linebreak-modi "drun"
-combi-no-linebreak-modi "drun" \
-markup-combi 1