mirror of
https://github.com/davatorium/rofi.git
synced 2024-11-25 13:55:34 -05:00
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
This commit is contained in:
parent
54aa148a5e
commit
23de9e9d2c
3 changed files with 55 additions and 11 deletions
|
@ -196,6 +196,25 @@ element-text {
|
|||
.fi
|
||||
.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:
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue