summaryrefslogtreecommitdiff
path: root/gtk/gtkstylecontext.c
diff options
context:
space:
mode:
authorTimm Bäder <mail@baedert.org>2018-05-04 20:20:09 +0200
committerTimm Bäder <mail@baedert.org>2018-05-05 07:25:10 +0200
commite379ea617ace37faf23977e3387b40ba0fe06b1b (patch)
treeecfe336931aae56a44b1d191a3460782e69fc091 /gtk/gtkstylecontext.c
parentf44959fa59e4f2d91e7460f5b21ac1a2be04273f (diff)
downloadgtk+-e379ea617ace37faf23977e3387b40ba0fe06b1b.tar.gz
stylecontext: Draw arrow-less insertion cursors as color nodes
This lets us avoid an often used cairo node.
Diffstat (limited to 'gtk/gtkstylecontext.c')
-rw-r--r--gtk/gtkstylecontext.c38
1 files changed, 31 insertions, 7 deletions
diff --git a/gtk/gtkstylecontext.c b/gtk/gtkstylecontext.c
index c26ab4136e..d01602cc82 100644
--- a/gtk/gtkstylecontext.c
+++ b/gtk/gtkstylecontext.c
@@ -1787,15 +1787,39 @@ snapshot_insertion_cursor (GtkSnapshot *snapshot,
PangoDirection direction,
gboolean draw_arrow)
{
- graphene_rect_t bounds;
- cairo_t *cr;
-
- get_insertion_cursor_bounds (height, direction, draw_arrow, &bounds);
- cr = gtk_snapshot_append_cairo (snapshot, &bounds);
+ if (draw_arrow)
+ {
+ cairo_t *cr;
+ graphene_rect_t bounds;
+
+ get_insertion_cursor_bounds (height, direction, draw_arrow, &bounds);
+ cr = gtk_snapshot_append_cairo (snapshot, &bounds);
+
+ draw_insertion_cursor (context, cr, 0, 0, height, is_primary, direction, draw_arrow);
- draw_insertion_cursor (context, cr, 0, 0, height, is_primary, direction, draw_arrow);
+ cairo_destroy (cr);
+ }
+ else
+ {
+ GdkRGBA primary_color;
+ GdkRGBA secondary_color;
+ int stem_width;
+ int offset;
- cairo_destroy (cr);
+ _gtk_style_context_get_cursor_color (context, &primary_color, &secondary_color);
+
+ stem_width = height * CURSOR_ASPECT_RATIO + 1;
+
+ /* put (stem_width % 2) on the proper side of the cursor */
+ if (direction == PANGO_DIRECTION_LTR)
+ offset = stem_width / 2;
+ else
+ offset = stem_width - stem_width / 2;
+
+ gtk_snapshot_append_color (snapshot,
+ is_primary ? &primary_color : &secondary_color,
+ &GRAPHENE_RECT_INIT (- offset, 0, stem_width, height));
+ }
}
/**