mirror of https://github.com/davatorium/rofi.git
Remove the extra layer each textbox keeps for drawing its text. (#553)
This commit is contained in:
parent
7fd5365b1c
commit
42a1eba275
|
@ -33,10 +33,6 @@ typedef struct
|
||||||
int markup;
|
int markup;
|
||||||
int changed;
|
int changed;
|
||||||
|
|
||||||
cairo_surface_t *main_surface;
|
|
||||||
cairo_t *main_draw;
|
|
||||||
|
|
||||||
int update;
|
|
||||||
int blink;
|
int blink;
|
||||||
guint blink_timeout;
|
guint blink_timeout;
|
||||||
|
|
||||||
|
|
|
@ -72,7 +72,6 @@ static gboolean textbox_blink ( gpointer data )
|
||||||
textbox *tb = (textbox *) data;
|
textbox *tb = (textbox *) data;
|
||||||
if ( tb->blink < 2 ) {
|
if ( tb->blink < 2 ) {
|
||||||
tb->blink = !tb->blink;
|
tb->blink = !tb->blink;
|
||||||
tb->update = TRUE;
|
|
||||||
widget_queue_redraw ( WIDGET ( tb ) );
|
widget_queue_redraw ( WIDGET ( tb ) );
|
||||||
rofi_view_queue_redraw ( );
|
rofi_view_queue_redraw ( );
|
||||||
}
|
}
|
||||||
|
@ -116,8 +115,6 @@ textbox* textbox_create ( const char *name, TextboxFlags flags, TextBoxFontType
|
||||||
|
|
||||||
tb->changed = FALSE;
|
tb->changed = FALSE;
|
||||||
|
|
||||||
tb->main_surface = cairo_image_surface_create ( CAIRO_FORMAT_ARGB32, tb->widget.w, tb->widget.h );
|
|
||||||
tb->main_draw = cairo_create ( tb->main_surface );
|
|
||||||
tb->layout = pango_layout_new ( p_context );
|
tb->layout = pango_layout_new ( p_context );
|
||||||
textbox_font ( tb, tbft );
|
textbox_font ( tb, tbft );
|
||||||
|
|
||||||
|
@ -192,7 +189,6 @@ void textbox_font ( textbox *tb, TextBoxFontType tbft )
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if ( tb->tbft != tbft || tb->widget.state == NULL ) {
|
if ( tb->tbft != tbft || tb->widget.state == NULL ) {
|
||||||
tb->update = TRUE;
|
|
||||||
widget_queue_redraw ( WIDGET ( tb ) );
|
widget_queue_redraw ( WIDGET ( tb ) );
|
||||||
}
|
}
|
||||||
tb->tbft = tbft;
|
tb->tbft = tbft;
|
||||||
|
@ -238,7 +234,6 @@ void textbox_set_pango_attributes ( textbox *tb, PangoAttrList *list )
|
||||||
// set the default text to display
|
// set the default text to display
|
||||||
void textbox_text ( textbox *tb, const char *text )
|
void textbox_text ( textbox *tb, const char *text )
|
||||||
{
|
{
|
||||||
tb->update = TRUE;
|
|
||||||
g_free ( tb->text );
|
g_free ( tb->text );
|
||||||
const gchar *last_pointer = NULL;
|
const gchar *last_pointer = NULL;
|
||||||
|
|
||||||
|
@ -302,7 +297,6 @@ void textbox_moveresize ( textbox *tb, int x, int y, int w, int h )
|
||||||
|
|
||||||
// We always want to update this
|
// We always want to update this
|
||||||
pango_layout_set_width ( tb->layout, PANGO_SCALE * ( tb->widget.w - widget_padding_get_padding_width ( WIDGET ( tb ) ) - offset ) );
|
pango_layout_set_width ( tb->layout, PANGO_SCALE * ( tb->widget.w - widget_padding_get_padding_width ( WIDGET ( tb ) ) - offset ) );
|
||||||
tb->update = TRUE;
|
|
||||||
widget_queue_redraw ( WIDGET ( tb ) );
|
widget_queue_redraw ( WIDGET ( tb ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -319,33 +313,14 @@ static void textbox_free ( widget *wid )
|
||||||
if ( tb->layout != NULL ) {
|
if ( tb->layout != NULL ) {
|
||||||
g_object_unref ( tb->layout );
|
g_object_unref ( tb->layout );
|
||||||
}
|
}
|
||||||
if ( tb->main_draw ) {
|
|
||||||
cairo_destroy ( tb->main_draw );
|
|
||||||
tb->main_draw = NULL;
|
|
||||||
}
|
|
||||||
if ( tb->main_surface ) {
|
|
||||||
cairo_surface_destroy ( tb->main_surface );
|
|
||||||
tb->main_surface = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
g_slice_free ( textbox, tb );
|
g_slice_free ( textbox, tb );
|
||||||
}
|
}
|
||||||
|
|
||||||
static void texbox_update ( textbox *tb )
|
static void textbox_draw ( widget *wid, cairo_t *draw )
|
||||||
{
|
{
|
||||||
if ( tb->update ) {
|
textbox *tb = (textbox *) wid;
|
||||||
unsigned int offset = ( tb->flags & TB_INDICATOR ) ? DOT_OFFSET : 0;
|
unsigned int offset = ( tb->flags & TB_INDICATOR ) ? DOT_OFFSET : 0;
|
||||||
if ( tb->main_surface ) {
|
|
||||||
cairo_destroy ( tb->main_draw );
|
|
||||||
cairo_surface_destroy ( tb->main_surface );
|
|
||||||
tb->main_draw = NULL;
|
|
||||||
tb->main_surface = NULL;
|
|
||||||
}
|
|
||||||
tb->main_surface = cairo_image_surface_create ( CAIRO_FORMAT_ARGB32, tb->widget.w, tb->widget.h );
|
|
||||||
tb->main_draw = cairo_create ( tb->main_surface );
|
|
||||||
cairo_set_operator ( tb->main_draw, CAIRO_OPERATOR_OVER );
|
|
||||||
|
|
||||||
pango_cairo_update_layout ( tb->main_draw, tb->layout );
|
|
||||||
int font_height = textbox_get_font_height ( tb );
|
int font_height = textbox_get_font_height ( tb );
|
||||||
|
|
||||||
int cursor_x = 0;
|
int cursor_x = 0;
|
||||||
|
@ -387,46 +362,32 @@ static void texbox_update ( textbox *tb )
|
||||||
}
|
}
|
||||||
y = widget_padding_get_top ( WIDGET ( tb ) ) + ( pango_font_metrics_get_ascent ( tb->metrics ) - pango_layout_get_baseline ( tb->layout ) ) / PANGO_SCALE;
|
y = widget_padding_get_top ( WIDGET ( tb ) ) + ( pango_font_metrics_get_ascent ( tb->metrics ) - pango_layout_get_baseline ( tb->layout ) ) / PANGO_SCALE;
|
||||||
|
|
||||||
rofi_theme_get_color ( WIDGET ( tb ), "foreground", tb->main_draw );
|
rofi_theme_get_color ( WIDGET ( tb ), "foreground", draw );
|
||||||
// Text
|
// Text
|
||||||
rofi_theme_get_color ( WIDGET ( tb ), "text", tb->main_draw );
|
rofi_theme_get_color ( WIDGET ( tb ), "text", draw );
|
||||||
// draw the cursor
|
// draw the cursor
|
||||||
if ( tb->flags & TB_EDITABLE && tb->blink ) {
|
if ( tb->flags & TB_EDITABLE && tb->blink ) {
|
||||||
cairo_rectangle ( tb->main_draw, x + cursor_x, y + cursor_y, cursor_width, cursor_height );
|
cairo_rectangle ( draw, x + cursor_x, y + cursor_y, cursor_width, cursor_height );
|
||||||
cairo_fill ( tb->main_draw );
|
cairo_fill ( draw );
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set ARGB
|
// Set ARGB
|
||||||
// We need to set over, otherwise subpixel hinting wont work.
|
// We need to set over, otherwise subpixel hinting wont work.
|
||||||
//cairo_set_operator ( tb->main_draw, CAIRO_OPERATOR_OVER );
|
cairo_set_operator ( draw, CAIRO_OPERATOR_OVER );
|
||||||
cairo_move_to ( tb->main_draw, x, y );
|
cairo_move_to ( draw, x, y );
|
||||||
pango_cairo_show_layout ( tb->main_draw, tb->layout );
|
pango_cairo_show_layout ( draw, tb->layout );
|
||||||
|
|
||||||
if ( ( tb->flags & TB_INDICATOR ) == TB_INDICATOR && ( tb->tbft & ( SELECTED ) ) ) {
|
if ( ( tb->flags & TB_INDICATOR ) == TB_INDICATOR && ( tb->tbft & ( SELECTED ) ) ) {
|
||||||
cairo_arc ( tb->main_draw, DOT_OFFSET / 2.0, tb->widget.h / 2.0, 2.0, 0, 2.0 * M_PI );
|
cairo_arc ( draw, DOT_OFFSET / 2.0, tb->widget.h / 2.0, 2.0, 0, 2.0 * M_PI );
|
||||||
cairo_fill ( tb->main_draw );
|
|
||||||
}
|
|
||||||
|
|
||||||
tb->update = FALSE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
static void textbox_draw ( widget *wid, cairo_t *draw )
|
|
||||||
{
|
|
||||||
textbox *tb = (textbox *) wid;
|
|
||||||
texbox_update ( tb );
|
|
||||||
|
|
||||||
/* Write buffer */
|
|
||||||
cairo_set_source_surface ( draw, tb->main_surface, 0, 0 );
|
|
||||||
cairo_rectangle ( draw, 0, 0, tb->widget.w, tb->widget.h );
|
|
||||||
cairo_fill ( draw );
|
cairo_fill ( draw );
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// cursor handling for edit mode
|
// cursor handling for edit mode
|
||||||
void textbox_cursor ( textbox *tb, int pos )
|
void textbox_cursor ( textbox *tb, int pos )
|
||||||
{
|
{
|
||||||
int length = ( tb->text == NULL ) ? 0 : g_utf8_strlen ( tb->text, -1 );
|
int length = ( tb->text == NULL ) ? 0 : g_utf8_strlen ( tb->text, -1 );
|
||||||
tb->cursor = MAX ( 0, MIN ( length, pos ) );
|
tb->cursor = MAX ( 0, MIN ( length, pos ) );
|
||||||
tb->update = TRUE;
|
|
||||||
// Stop blink!
|
// Stop blink!
|
||||||
tb->blink = 3;
|
tb->blink = 3;
|
||||||
widget_queue_redraw ( WIDGET ( tb ) );
|
widget_queue_redraw ( WIDGET ( tb ) );
|
||||||
|
@ -519,12 +480,10 @@ static void textbox_cursor_end ( textbox *tb )
|
||||||
{
|
{
|
||||||
if ( tb->text == NULL ) {
|
if ( tb->text == NULL ) {
|
||||||
tb->cursor = 0;
|
tb->cursor = 0;
|
||||||
tb->update = TRUE;
|
|
||||||
widget_queue_redraw ( WIDGET ( tb ) );
|
widget_queue_redraw ( WIDGET ( tb ) );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
tb->cursor = ( int ) g_utf8_strlen ( tb->text, -1 );
|
tb->cursor = ( int ) g_utf8_strlen ( tb->text, -1 );
|
||||||
tb->update = TRUE;
|
|
||||||
widget_queue_redraw ( WIDGET ( tb ) );
|
widget_queue_redraw ( WIDGET ( tb ) );
|
||||||
// Stop blink!
|
// Stop blink!
|
||||||
tb->blink = 2;
|
tb->blink = 2;
|
||||||
|
@ -549,7 +508,6 @@ void textbox_insert ( textbox *tb, const int char_pos, const char *str, const in
|
||||||
// Stop blink!
|
// Stop blink!
|
||||||
tb->blink = 2;
|
tb->blink = 2;
|
||||||
tb->changed = TRUE;
|
tb->changed = TRUE;
|
||||||
tb->update = TRUE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// remove text
|
// remove text
|
||||||
|
@ -578,7 +536,6 @@ void textbox_delete ( textbox *tb, int pos, int dlen )
|
||||||
// Stop blink!
|
// Stop blink!
|
||||||
tb->blink = 2;
|
tb->blink = 2;
|
||||||
tb->changed = TRUE;
|
tb->changed = TRUE;
|
||||||
tb->update = TRUE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue