mirror of
https://github.com/davatorium/rofi.git
synced 2025-02-03 15:34:54 -05:00
Add markup flag for dmenu.
This commit is contained in:
parent
023bb23bcf
commit
5cc695e186
6 changed files with 21 additions and 35 deletions
|
@ -139,5 +139,6 @@ Settings config = {
|
|||
/** Separator style: dash/solid */
|
||||
.separator_style = "dash",
|
||||
/** Hide scrollbar */
|
||||
.hide_scrollbar = FALSE,
|
||||
.hide_scrollbar = FALSE,
|
||||
.markup_rows = FALSE,
|
||||
};
|
||||
|
|
|
@ -236,6 +236,8 @@ typedef struct _Settings
|
|||
char *separator_style;
|
||||
/** hide scrollbar */
|
||||
unsigned int hide_scrollbar;
|
||||
/** show markup in elements. */
|
||||
unsigned int markup_rows;
|
||||
} Settings;
|
||||
|
||||
/** Global Settings structure. */
|
||||
|
|
|
@ -239,6 +239,4 @@ void textbox_delete ( textbox *tb, int pos, int dlen );
|
|||
|
||||
void textbox_moveresize ( textbox *tb, int x, int y, int w, int h );
|
||||
int textbox_get_estimated_char_height ( void );
|
||||
|
||||
void textbox_text_markup ( textbox *tb, const char *text );
|
||||
#endif //ROFI_TEXTBOX_H
|
||||
|
|
|
@ -909,9 +909,13 @@ static void menu_resize ( MenuState *state )
|
|||
|
||||
int y_offset = state->top_offset;
|
||||
int x_offset = config.padding;
|
||||
int rstate = 0;
|
||||
if ( config.markup_rows ) {
|
||||
rstate = TB_MARKUP;
|
||||
}
|
||||
// Add newly added boxes.
|
||||
for ( unsigned int i = last_length; i < state->max_elements; i++ ) {
|
||||
state->boxes[i] = textbox_create ( main_window, &vinfo, map, 0, x_offset, y_offset,
|
||||
state->boxes[i] = textbox_create ( main_window, &vinfo, map, rstate, x_offset, y_offset,
|
||||
state->element_width, element_height, NORMAL, "" );
|
||||
}
|
||||
scrollbar_resize ( state->scrollbar, -1, ( state->max_rows ) * ( element_height ) - config.line_margin );
|
||||
|
@ -1028,8 +1032,12 @@ MenuReturn menu ( Switcher *sw, char **input, char *prompt, unsigned int *select
|
|||
int y_offset = state.top_offset;
|
||||
int x_offset = config.padding;
|
||||
|
||||
int rstate = 0;
|
||||
if ( config.markup_rows ) {
|
||||
rstate = TB_MARKUP;
|
||||
}
|
||||
for ( unsigned int i = 0; i < state.max_elements; i++ ) {
|
||||
state.boxes[i] = textbox_create ( main_window, &vinfo, map, 0, x_offset, y_offset,
|
||||
state.boxes[i] = textbox_create ( main_window, &vinfo, map, rstate, x_offset, y_offset,
|
||||
state.element_width, element_height, NORMAL, "" );
|
||||
}
|
||||
if ( !config.hide_scrollbar ) {
|
||||
|
|
|
@ -80,7 +80,6 @@ textbox* textbox_create ( Window parent, XVisualInfo *vinfo, Colormap map, Textb
|
|||
|
||||
tb->layout = pango_layout_new ( p_context );
|
||||
|
||||
tb->markup = FALSE;
|
||||
tb->changed = FALSE;
|
||||
|
||||
unsigned int cp;
|
||||
|
@ -111,11 +110,8 @@ textbox* textbox_create ( Window parent, XVisualInfo *vinfo, Colormap map, Textb
|
|||
|
||||
if ( ( flags & TB_MARKUP ) == TB_MARKUP ) {
|
||||
pango_layout_set_wrap ( tb->layout, PANGO_WRAP_WORD_CHAR );
|
||||
textbox_text_markup ( tb, text ? text : "" );
|
||||
}
|
||||
else{
|
||||
textbox_text ( tb, text ? text : "" );
|
||||
}
|
||||
textbox_text ( tb, text ? text : "" );
|
||||
textbox_cursor_end ( tb );
|
||||
|
||||
// auto height/width modes get handled here
|
||||
|
@ -173,32 +169,12 @@ void textbox_text ( textbox *tb, const char *text )
|
|||
tb->text = g_strdup ( "Invalid UTF-8 string." );
|
||||
}
|
||||
}
|
||||
pango_layout_set_text ( tb->layout, tb->text, strlen ( tb->text ) );
|
||||
if ( tb->flags & TB_AUTOWIDTH ) {
|
||||
textbox_moveresize ( tb, tb->x, tb->y, tb->w, tb->h );
|
||||
}
|
||||
|
||||
tb->cursor = MAX ( 0, MIN ( ( int ) strlen ( text ), tb->cursor ) );
|
||||
}
|
||||
// set the default text to display
|
||||
void textbox_text_markup ( textbox *tb, const char *text )
|
||||
{
|
||||
g_free ( tb->text );
|
||||
const gchar *last_pointer = NULL;
|
||||
if ( g_utf8_validate ( text, -1, &last_pointer ) ) {
|
||||
tb->text = g_strdup ( text );
|
||||
if ( tb->flags & TB_MARKUP ) {
|
||||
pango_layout_set_markup ( tb->layout, tb->text, strlen ( tb->text ) );
|
||||
}
|
||||
else {
|
||||
if ( last_pointer != NULL ) {
|
||||
// Copy string up to invalid character.
|
||||
tb->text = g_strndup ( text, ( last_pointer - text ) );
|
||||
}
|
||||
else {
|
||||
tb->text = g_strdup ( "Invalid UTF-8 string." );
|
||||
}
|
||||
pango_layout_set_text ( tb->layout, tb->text, strlen ( tb->text ) );
|
||||
}
|
||||
tb->markup = TRUE;
|
||||
pango_layout_set_markup ( tb->layout, tb->text, strlen ( tb->text ) );
|
||||
if ( tb->flags & TB_AUTOWIDTH ) {
|
||||
textbox_moveresize ( tb, tb->x, tb->y, tb->w, tb->h );
|
||||
}
|
||||
|
@ -301,7 +277,7 @@ void textbox_draw ( textbox *tb )
|
|||
int cursor_width = MAX ( 2, font_height / 10 );
|
||||
|
||||
if ( tb->changed ) {
|
||||
if ( tb->markup ) {
|
||||
if ( tb->flags & TB_MARKUP ) {
|
||||
pango_layout_set_markup ( tb->layout, text, text_len );
|
||||
}
|
||||
else{
|
||||
|
|
|
@ -128,7 +128,8 @@ static XrmOption xrmOptions[] = {
|
|||
{ xrm_Number, "line-margin", { .num = &config.line_margin }, NULL },
|
||||
{ xrm_String, "filter", { .str = &config.filter }, NULL },
|
||||
{ xrm_String, "separator-style", { .str = &config.separator_style }, NULL },
|
||||
{ xrm_Boolean, "hide-scrollbar", { .num = &config.hide_scrollbar }, NULL }
|
||||
{ xrm_Boolean, "hide-scrollbar", { .num = &config.hide_scrollbar }, NULL },
|
||||
{ xrm_Boolean, "markup-rows", { .num = &config.markup_rows }, NULL }
|
||||
};
|
||||
|
||||
// Dynamic options.
|
||||
|
|
Loading…
Add table
Reference in a new issue