mirror of
https://github.com/davatorium/rofi.git
synced 2024-11-25 13:55:34 -05:00
[Textbox] Add a 'get_cursor_x_pos' function.
This commit is contained in:
parent
3d3af82b54
commit
62ebb863ed
2 changed files with 24 additions and 4 deletions
|
@ -76,6 +76,8 @@ typedef struct {
|
||||||
double yalign;
|
double yalign;
|
||||||
double xalign;
|
double xalign;
|
||||||
|
|
||||||
|
int cursor_x_pos;
|
||||||
|
|
||||||
TBFontConfig *tbfc;
|
TBFontConfig *tbfc;
|
||||||
|
|
||||||
PangoEllipsizeMode emode;
|
PangoEllipsizeMode emode;
|
||||||
|
@ -335,5 +337,12 @@ void textbox_cursor_end(textbox *tb);
|
||||||
* Set the ellipsizing mode used on the string.
|
* Set the ellipsizing mode used on the string.
|
||||||
*/
|
*/
|
||||||
void textbox_set_ellipsize(textbox *tb, PangoEllipsizeMode mode);
|
void textbox_set_ellipsize(textbox *tb, PangoEllipsizeMode mode);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param tb Handle to the textbox
|
||||||
|
*
|
||||||
|
* @returns the position of the cursor (0 if no cursor).
|
||||||
|
*/
|
||||||
|
int textbox_get_cursor_x_pos(const textbox *tb);
|
||||||
/**@}*/
|
/**@}*/
|
||||||
#endif // ROFI_TEXTBOX_H
|
#endif // ROFI_TEXTBOX_H
|
||||||
|
|
|
@ -525,7 +525,7 @@ static void textbox_draw(widget *wid, cairo_t *draw) {
|
||||||
|
|
||||||
// draw the cursor
|
// draw the cursor
|
||||||
rofi_theme_get_color(WIDGET(tb), "text-color", draw);
|
rofi_theme_get_color(WIDGET(tb), "text-color", draw);
|
||||||
if (tb->flags & TB_EDITABLE && tb->blink) {
|
if (tb->flags & TB_EDITABLE) {
|
||||||
// We want to place the cursor based on the text shown.
|
// We want to place the cursor based on the text shown.
|
||||||
const char *text = pango_layout_get_text(tb->layout);
|
const char *text = pango_layout_get_text(tb->layout);
|
||||||
// Clamp the position, should not be needed, but we are paranoid.
|
// Clamp the position, should not be needed, but we are paranoid.
|
||||||
|
@ -538,9 +538,14 @@ static void textbox_draw(widget *wid, cairo_t *draw) {
|
||||||
int cursor_y = pos.y / PANGO_SCALE;
|
int cursor_y = pos.y / PANGO_SCALE;
|
||||||
int cursor_height = pos.height / PANGO_SCALE;
|
int cursor_height = pos.height / PANGO_SCALE;
|
||||||
int cursor_width = 2;
|
int cursor_width = 2;
|
||||||
cairo_rectangle(draw, x + cursor_x, y + cursor_y, cursor_width,
|
if ((x + cursor_x) != tb->cursor_x_pos) {
|
||||||
cursor_height);
|
tb->cursor_x_pos = x + cursor_x;
|
||||||
cairo_fill(draw);
|
}
|
||||||
|
if (tb->blink) {
|
||||||
|
cairo_rectangle(draw, x + cursor_x, y + cursor_y, cursor_width,
|
||||||
|
cursor_height);
|
||||||
|
cairo_fill(draw);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -993,3 +998,9 @@ void textbox_set_ellipsize(textbox *tb, PangoEllipsizeMode mode) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
int textbox_get_cursor_x_pos(const textbox *tb) {
|
||||||
|
if (tb == NULL) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return tb->cursor_x_pos;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue