1
0
Fork 0
mirror of https://github.com/davatorium/rofi.git synced 2024-11-25 13:55:34 -05:00

[View|Textbox] cleanups to drawing code

This commit is contained in:
Nikita Zlobin 2023-08-28 23:35:03 +05:00 committed by Dave Davenport
parent 9b2b52b13e
commit a53daa68c4
2 changed files with 27 additions and 36 deletions

View file

@ -1344,20 +1344,18 @@ void rofi_view_update(RofiViewState *state, gboolean qr) {
cairo_set_source_surface(d, CacheState.fake_bg, 0.0, 0.0); cairo_set_source_surface(d, CacheState.fake_bg, 0.0, 0.0);
} else { } else {
cairo_set_source_surface(d, CacheState.fake_bg, cairo_set_source_surface(d, CacheState.fake_bg,
-(double)(state->x - CacheState.mon.x), (double)(CacheState.mon.x - state->x),
-(double)(state->y - CacheState.mon.y)); (double)(CacheState.mon.y - state->y));
} }
cairo_paint(d);
cairo_set_operator(d, CAIRO_OPERATOR_OVER);
} else { } else {
// Paint the background transparent. // Paint the background transparent.
cairo_set_source_rgba(d, 0, 0, 0, 0.0); cairo_set_source_rgba(d, 0, 0, 0, 0.0);
cairo_paint(d);
} }
TICK_N("Background"); cairo_paint(d);
// Always paint as overlay over the background. // Always paint as overlay over the background.
cairo_set_operator(d, CAIRO_OPERATOR_OVER); cairo_set_operator(d, CAIRO_OPERATOR_OVER);
TICK_N("Background");
widget_draw(WIDGET(state->main_window), d); widget_draw(WIDGET(state->main_window), d);
#ifdef XCB_IMDKIT #ifdef XCB_IMDKIT

View file

@ -494,37 +494,29 @@ static void textbox_draw(widget *wid, cairo_t *draw) {
} }
y += top; y += top;
// TODO check if this is still needed after flatning. // Set ARGB
cairo_set_operator(draw, CAIRO_OPERATOR_OVER); // NOTE: cairo operator must be OVER at this moment,
// to not break subpixel text rendering.
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 // use text color as fallback for themes that don't specify the cursor color
rofi_theme_get_color(WIDGET(tb), "text-color", draw); rofi_theme_get_color(WIDGET(tb), "text-color", draw);
// Set ARGB { int rem =
// We need to set over, otherwise subpixel hinting wont work. MAX(0, tb->widget.w - widget_padding_get_padding_width(WIDGET(tb)) -
line_width - dot_offset);
switch (pango_layout_get_alignment(tb->layout)) { switch (pango_layout_get_alignment(tb->layout)) {
case PANGO_ALIGN_CENTER: { case PANGO_ALIGN_CENTER:
int rem = x = rem * (tb->xalign - 0.5);
MAX(0, tb->widget.w - widget_padding_get_padding_width(WIDGET(tb)) - break;
line_width - dot_offset); case PANGO_ALIGN_RIGHT:
x = (tb->xalign - 0.5) * rem + widget_padding_get_left(WIDGET(tb)); x = rem * (tb->xalign - 1.0);
break; break;
} default:
case PANGO_ALIGN_RIGHT: { x = rem * tb->xalign + dot_offset;
int rem =
MAX(0, tb->widget.w - widget_padding_get_padding_width(WIDGET(tb)) -
line_width - dot_offset);
x = -(1.0 - tb->xalign) * rem + widget_padding_get_left(WIDGET(tb));
break;
}
default: {
int rem =
MAX(0, tb->widget.w - widget_padding_get_padding_width(WIDGET(tb)) -
line_width - dot_offset);
x = tb->xalign * rem + widget_padding_get_left(WIDGET(tb));
x += dot_offset;
break; break;
} }
x += widget_padding_get_left(WIDGET(tb));
} }
// draw the cursor // draw the cursor
@ -574,11 +566,12 @@ static void textbox_draw(widget *wid, cairo_t *draw) {
cairo_rectangle(draw, x1, y1, x2 - x1, y2 - y1); cairo_rectangle(draw, x1, y1, x2 - x1, y2 - y1);
cairo_clip(draw); cairo_clip(draw);
gboolean show_outline = gboolean show_outline;
rofi_theme_get_boolean(WIDGET(tb), "text-outline", FALSE);
if (tb->show_placeholder) { if (tb->show_placeholder) {
rofi_theme_get_color(WIDGET(tb), "placeholder-color", draw); rofi_theme_get_color(WIDGET(tb), "placeholder-color", draw);
show_outline = FALSE; show_outline = FALSE;
} else {
show_outline = rofi_theme_get_boolean(WIDGET(tb), "text-outline", FALSE);
} }
cairo_move_to(draw, x, top); cairo_move_to(draw, x, top);
pango_cairo_show_layout(draw, tb->layout); pango_cairo_show_layout(draw, tb->layout);