summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Davenport <qball@gmpclient.org>2017-03-14 17:02:03 +0100
committerDave Davenport <qball@gmpclient.org>2017-03-14 17:02:03 +0100
commitd52c80d76f6a6dc829e7b0d847d4e2bbf6f76367 (patch)
treec9fc8cd5c2b0f3cae44c7293ff6fbb155e92001e
parent479f515181c32935cdf79b7b3b09ef29160019f4 (diff)
[Textbox] Remove unneeded calls to pango_layout_get_pixel_size.
This was 21% of the widget update time.
-rw-r--r--source/theme.c2
-rw-r--r--source/widgets/textbox.c28
2 files changed, 13 insertions, 17 deletions
diff --git a/source/theme.c b/source/theme.c
index 122fa6a4..c57778c4 100644
--- a/source/theme.c
+++ b/source/theme.c
@@ -305,7 +305,7 @@ void rofi_theme_widget_add_properties ( ThemeWidget *widget, GHashTable *table )
* Public API
*/
-static ThemeWidget *rofi_theme_find_single ( ThemeWidget *widget, const char *name )
+static inline ThemeWidget *rofi_theme_find_single ( ThemeWidget *widget, const char *name )
{
for ( unsigned int j = 0; j < widget->num_widgets; j++ ) {
if ( g_strcmp0 ( widget->widgets[j]->name, name ) == 0 ) {
diff --git a/source/widgets/textbox.c b/source/widgets/textbox.c
index 7e3648ca..347cb7ca 100644
--- a/source/widgets/textbox.c
+++ b/source/widgets/textbox.c
@@ -332,29 +332,14 @@ static void textbox_draw ( widget *wid, cairo_t *draw )
{
textbox *tb = (textbox *) wid;
unsigned int offset = ( tb->flags & TB_INDICATOR ) ? DOT_OFFSET : 0;
- int font_height = textbox_get_font_height ( tb );
int cursor_x = 0;
int cursor_y = 0;
- int cursor_height = font_height;
if ( tb->changed ) {
__textbox_update_pango_text ( tb );
}
- 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 );
- // Clamp the position, should not be needed, but we are paranoid.
- int cursor_offset = MIN ( tb->cursor, g_utf8_strlen ( text, -1 ) );
- PangoRectangle pos;
- // convert to byte location.
- char *offset = g_utf8_offset_to_pointer ( text, cursor_offset );
- pango_layout_get_cursor_pos ( tb->layout, offset - text, &pos, NULL );
- cursor_x = pos.x / PANGO_SCALE;
- cursor_y = pos.y / PANGO_SCALE;
- cursor_height = pos.height / PANGO_SCALE;
- }
// Skip the side MARGIN on the X axis.
int x = widget_padding_get_left ( WIDGET ( tb ) ) + offset;
@@ -379,7 +364,18 @@ static void textbox_draw ( widget *wid, cairo_t *draw )
rofi_theme_get_color ( WIDGET ( tb ), "text", draw );
// draw the cursor
if ( tb->flags & TB_EDITABLE && tb->blink ) {
- int cursor_width = 2; //MAX ( 2, font_height / 10 );
+ // We want to place the cursor based on the text shown.
+ const char *text = pango_layout_get_text ( tb->layout );
+ // Clamp the position, should not be needed, but we are paranoid.
+ int cursor_offset = MIN ( tb->cursor, g_utf8_strlen ( text, -1 ) );
+ PangoRectangle pos;
+ // convert to byte location.
+ char *offset = g_utf8_offset_to_pointer ( text, cursor_offset );
+ pango_layout_get_cursor_pos ( tb->layout, offset - text, &pos, NULL );
+ cursor_x = pos.x / PANGO_SCALE;
+ cursor_y = pos.y / PANGO_SCALE;
+ int cursor_height = pos.height / PANGO_SCALE;
+ int cursor_width = 2;
cairo_rectangle ( draw, x + cursor_x, y + cursor_y, cursor_width, cursor_height );
cairo_fill ( draw );
}