summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Davenport <qball@blame.services>2022-08-28 21:47:05 +0200
committerDave Davenport <qball@blame.services>2022-08-28 21:47:05 +0200
commitfce721a1053ad6d861834e9f3a9c96c20bf1eb6d (patch)
treef7adfca82636c27526d231b9bc0ce6451327d552
parentcb6afae71ff376b87f992dbc573e790c496963ce (diff)
[Textbox] Add 'placeholder-markup' flag.
Fixes: #1690
-rw-r--r--doc/rofi-theme.52
-rw-r--r--doc/rofi-theme.5.markdown1
-rw-r--r--include/widgets/textbox.h2
-rw-r--r--source/widgets/textbox.c9
4 files changed, 11 insertions, 3 deletions
diff --git a/doc/rofi-theme.5 b/doc/rofi-theme.5
index f396a755..c0a229c5 100644
--- a/doc/rofi-theme.5
+++ b/doc/rofi-theme.5
@@ -1501,6 +1501,8 @@ This option is only available on the \fB\fCelement-text\fR widget.
.IP \(bu 2
\fBplaceholder\fP: Set the displayed text (String) when nothing is entered.
.IP \(bu 2
+\fBplaceholder-markup\fP: If true, placeholder text supports pango markup for stylizing.
+.IP \(bu 2
\fBplaceholder-color\fP: Color of the placeholder text.
.IP \(bu 2
\fBblink\fP: Enable/Disable blinking on an input textbox (Boolean).
diff --git a/doc/rofi-theme.5.markdown b/doc/rofi-theme.5.markdown
index a61a125f..bf0f3630 100644
--- a/doc/rofi-theme.5.markdown
+++ b/doc/rofi-theme.5.markdown
@@ -929,6 +929,7 @@ The following properties are currently supported:
* **width**: override the desired width for the textbox.
* **content**: Set the displayed text (String).
* **placeholder**: Set the displayed text (String) when nothing is entered.
+* **placeholder-markup**: If true, placeholder text supports pango markup for stylizing.
* **placeholder-color**: Color of the placeholder text.
* **blink**: Enable/Disable blinking on an input textbox (Boolean).
* **markup**: Force markup on, beware that only valid pango markup strings are shown.
diff --git a/include/widgets/textbox.h b/include/widgets/textbox.h
index b8b5ea20..7ec36ce1 100644
--- a/include/widgets/textbox.h
+++ b/include/widgets/textbox.h
@@ -63,7 +63,7 @@ typedef struct {
unsigned long flags;
short cursor;
char *text;
- const char *placeholder;
+ char *placeholder;
int show_placeholder;
PangoLayout *layout;
int tbft;
diff --git a/source/widgets/textbox.c b/source/widgets/textbox.c
index 00ab1ac1..80e4be09 100644
--- a/source/widgets/textbox.c
+++ b/source/widgets/textbox.c
@@ -227,7 +227,11 @@ textbox *textbox_create(widget *parent, WidgetType type, const char *name,
const char *placeholder =
rofi_theme_get_string(WIDGET(tb), "placeholder", NULL);
if (placeholder) {
- tb->placeholder = placeholder;
+ if (rofi_theme_get_boolean(WIDGET(tb), "placeholder-markup", FALSE)) {
+ tb->placeholder = g_strdup(placeholder);
+ } else {
+ tb->placeholder = g_markup_escape_text(placeholder, -1);
+ }
}
textbox_text(tb, txt ? txt : "");
textbox_cursor_end(tb);
@@ -310,7 +314,7 @@ static void __textbox_update_pango_text(textbox *tb) {
pango_layout_set_attributes(tb->layout, NULL);
if (tb->placeholder && (tb->text == NULL || tb->text[0] == 0)) {
tb->show_placeholder = TRUE;
- pango_layout_set_text(tb->layout, tb->placeholder, -1);
+ pango_layout_set_markup(tb->layout, tb->placeholder, -1);
return;
}
tb->show_placeholder = FALSE;
@@ -442,6 +446,7 @@ static void textbox_free(widget *wid) {
}
g_free(tb->text);
+ g_free(tb->placeholder);
if (tb->layout != NULL) {
g_object_unref(tb->layout);
}