summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorvE5li <ve5li@tuta.io>2022-11-25 10:28:34 +0100
committerGitHub <noreply@github.com>2022-11-25 10:28:34 +0100
commit23de9e9d2c35af8cce72b060f6d2916cd6215a23 (patch)
tree623ca085f65b78787e885e12d7268f2fe1b5a20e
parent54aa148a5ece4027cabceec3f79df880e158376d (diff)
make cursor more customizable by adding cursor-width and cursor-color (#1753)
* make cursor more customizable by adding cursor-width and cursor-color to the theme * fix placeholder color * add doc entry * more documentation
-rw-r--r--doc/rofi-theme.523
-rw-r--r--doc/rofi-theme.5.markdown14
-rw-r--r--source/widgets/textbox.c29
3 files changed, 55 insertions, 11 deletions
diff --git a/doc/rofi-theme.5 b/doc/rofi-theme.5
index c0a229c5..1e1bdda5 100644
--- a/doc/rofi-theme.5
+++ b/doc/rofi-theme.5
@@ -197,6 +197,25 @@ element-text {
.RE
.PP
+We can also specify the color and width of the cursor. You could, for example,
+create a crimson block cursor like this:
+
+.PP
+.RS
+
+.nf
+entry {
+ cursor-color: rgb(220,20,60);
+ cursor-width: 8px;
+}
+
+.fi
+.RE
+
+.PP
+By default, the \fB\fCcursor-color\fR will be the same as the \fB\fCtext-color\fR\&. The \fB\fCcursor-width\fR will always default to 2 pixels.
+
+.PP
If you want to see the complete theme, including the modification you can run:
.PP
@@ -1513,6 +1532,10 @@ This option is only available on the \fB\fCelement-text\fR widget.
Set the location of tab stops by their distance from the beginning of the line.
Each distance should be greater than the previous one.
The text appears to the right of the tab stop position (other alignments are not supported yet).
+.IP \(bu 2
+\fBcursor-width\fP: The width of the cursor.
+.IP \(bu 2
+\fBcursor-color\fP: The color used to draw the cursor.
.RE
diff --git a/doc/rofi-theme.5.markdown b/doc/rofi-theme.5.markdown
index bf0f3630..bbb0a7cd 100644
--- a/doc/rofi-theme.5.markdown
+++ b/doc/rofi-theme.5.markdown
@@ -132,6 +132,18 @@ element-text {
└─────────────────────────────────────────────────────────────────────┘
```
+We can also specify the color and width of the cursor. You could, for example,
+create a crimson block cursor like this:
+
+```css
+entry {
+ cursor-color: rgb(220,20,60);
+ cursor-width: 8px;
+}
+```
+
+By default, the `cursor-color` will be the same as the `text-color`. The `cursor-width` will always default to 2 pixels.
+
If you want to see the complete theme, including the modification you can run:
```bash
@@ -937,6 +949,8 @@ The following properties are currently supported:
Set the location of tab stops by their distance from the beginning of the line.
Each distance should be greater than the previous one.
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.
### listview:
* **columns**: integer
diff --git a/source/widgets/textbox.c b/source/widgets/textbox.c
index e8f178ce..0501b432 100644
--- a/source/widgets/textbox.c
+++ b/source/widgets/textbox.c
@@ -484,12 +484,10 @@ static void textbox_draw(widget *wid, cairo_t *draw) {
// TODO check if this is still needed after flatning.
cairo_set_operator(draw, CAIRO_OPERATOR_OVER);
- cairo_set_source_rgb(draw, 0.0, 0.0, 0.0);
+ cairo_set_source_rgb ( draw, 0.0, 0.0, 0.0 );
+ // use text color as fallback for themes that don't specify the cursor color
rofi_theme_get_color(WIDGET(tb), "text-color", draw);
- if (tb->show_placeholder) {
- rofi_theme_get_color(WIDGET(tb), "placeholder-color", draw);
- }
// Set ARGB
// We need to set over, otherwise subpixel hinting wont work.
switch (pango_layout_get_alignment(tb->layout)) {
@@ -519,13 +517,8 @@ static void textbox_draw(widget *wid, cairo_t *draw) {
break;
}
}
- cairo_save(draw);
- cairo_reset_clip(draw);
- pango_cairo_show_layout(draw, tb->layout);
- cairo_restore(draw);
// draw the cursor
- rofi_theme_get_color(WIDGET(tb), "text-color", draw);
if (tb->flags & TB_EDITABLE) {
// We want to place the cursor based on the text shown.
const char *text = pango_layout_get_text(tb->layout);
@@ -538,16 +531,30 @@ static void textbox_draw(widget *wid, cairo_t *draw) {
int cursor_x = pos.x / PANGO_SCALE;
int cursor_y = pos.y / PANGO_SCALE;
int cursor_height = pos.height / PANGO_SCALE;
- int cursor_width = 2;
+ RofiDistance cursor_width = rofi_theme_get_distance(WIDGET(tb), "cursor-width", 2);
+ int cursor_pixel_width = distance_get_pixel(cursor_width, ROFI_ORIENTATION_HORIZONTAL);
if ((x + cursor_x) != tb->cursor_x_pos) {
tb->cursor_x_pos = x + cursor_x;
}
if (tb->blink) {
- cairo_rectangle(draw, x + cursor_x, y + cursor_y, cursor_width,
+ // save the state so we can restore the text color afterwards
+ cairo_save(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);
+ 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);
+ cairo_restore(draw);
}
// cursor handling for edit mode