From 3d73cf25541a5ea3dceb864a15f8ad4f654615da Mon Sep 17 00:00:00 2001 From: Dave Davenport Date: Fri, 23 Dec 2022 22:11:22 +0100 Subject: [PATCH] [Textbox] Cursor goes over, not under. allow cursor outline. --- doc/rofi-theme.5 | 6 +++++ doc/rofi-theme.5.markdown | 3 +++ source/widgets/textbox.c | 51 ++++++++++++++++++++++++--------------- 3 files changed, 41 insertions(+), 19 deletions(-) diff --git a/doc/rofi-theme.5 b/doc/rofi-theme.5 index 293304c5..f70aa560 100644 --- a/doc/rofi-theme.5 +++ b/doc/rofi-theme.5 @@ -1537,6 +1537,12 @@ The text appears to the right of the tab stop position (other alignments are not .IP \(bu 2 \fBcursor-color\fP: The color used to draw the cursor. .IP \(bu 2 +\fBcursor-outline\fP: Enable a border (outline) around the cursor. (Boolean) +.IP \(bu 2 +\fBcursor-outline-width\fP: The width of the border around the cursor. (Double) +.IP \(bu 2 +\fBcursor-outline-color\fP: The color to use for the cursor outline. (Color) +.IP \(bu 2 \fBtext-outline\fP: Enable a border (outline) around the text. (Boolean) .IP \(bu 2 \fBtext-outline-width\fP: The width of the border around the text. (Double) diff --git a/doc/rofi-theme.5.markdown b/doc/rofi-theme.5.markdown index 354d77cf..24388f58 100644 --- a/doc/rofi-theme.5.markdown +++ b/doc/rofi-theme.5.markdown @@ -951,6 +951,9 @@ The following properties are currently supported: The text appears to the right of the tab stop position (other alignments are not supported yet). * **cursor-width**: The width of the cursor. * **cursor-color**: The color used to draw the cursor. +* **cursor-outline**: Enable a border (outline) around the cursor. (Boolean) +* **cursor-outline-width**: The width of the border around the cursor. (Double) +* **cursor-outline-color**: The color to use for the cursor outline. (Color) * **text-outline**: Enable a border (outline) around the text. (Boolean) * **text-outline-width**: The width of the border around the text. (Double) * **text-outline-color**: The color to use for the text outline. (Color) diff --git a/source/widgets/textbox.c b/source/widgets/textbox.c index 90e8cc53..5e45a0d5 100644 --- a/source/widgets/textbox.c +++ b/source/widgets/textbox.c @@ -518,6 +518,28 @@ static void textbox_draw(widget *wid, cairo_t *draw) { } } + // draw the text + cairo_save(draw); + cairo_reset_clip(draw); + + gboolean show_outline = + rofi_theme_get_boolean(WIDGET(tb), "text-outline", FALSE); + if (tb->show_placeholder) { + rofi_theme_get_color(WIDGET(tb), "placeholder-color", draw); + show_outline = FALSE; + } + pango_cairo_show_layout(draw, tb->layout); + + if (show_outline) { + rofi_theme_get_color(WIDGET(tb), "text-outline-color", draw); + double width = rofi_theme_get_double(WIDGET(tb), "text-outline-width", 0.5); + pango_cairo_layout_path(draw, tb->layout); + cairo_set_line_width(draw, width); + cairo_stroke(draw); + } + + cairo_restore(draw); + // draw the cursor if (tb->flags & TB_EDITABLE) { // We want to place the cursor based on the text shown. @@ -544,28 +566,19 @@ static void textbox_draw(widget *wid, cairo_t *draw) { rofi_theme_get_color(WIDGET(tb), "cursor-color", draw); cairo_rectangle(draw, x + cursor_x, y + cursor_y, cursor_pixel_width, cursor_height); - cairo_fill(draw); + if (rofi_theme_get_boolean(WIDGET(tb), "cursor-outline", FALSE)) { + cairo_fill_preserve(draw); + rofi_theme_get_color(WIDGET(tb), "cursor-outline-color", draw); + double width = + rofi_theme_get_double(WIDGET(tb), "cursor-outline-width", 0.5); + cairo_set_line_width(draw, width); + cairo_stroke(draw); + } else { + cairo_fill(draw); + } cairo_restore(draw); } } - - // draw the text - cairo_save(draw); - cairo_reset_clip(draw); - if (tb->show_placeholder) { - rofi_theme_get_color(WIDGET(tb), "placeholder-color", draw); - } - pango_cairo_show_layout(draw, tb->layout); - - if (rofi_theme_get_boolean(WIDGET(tb), "text-outline", FALSE)) { - rofi_theme_get_color(WIDGET(tb), "text-outline-color", draw); - double width = rofi_theme_get_double(WIDGET(tb), "text-outline-width", 0.5); - pango_cairo_layout_path(draw, tb->layout); - cairo_set_line_width(draw, width); - cairo_stroke(draw); - } - - cairo_restore(draw); } // cursor handling for edit mode