Merge branch 'cursor-aspect-ratio-for-3' into 'gtk-3-24'

Add a gtk-cursor-aspect-ratio setting

See merge request GNOME/gtk!2144
This commit is contained in:
Matthias Clasen 2020-06-23 21:14:58 +00:00
commit 40bbcfebcb
2 changed files with 22 additions and 6 deletions

View File

@ -148,6 +148,7 @@ enum {
PROP_CURSOR_BLINK_TIME, PROP_CURSOR_BLINK_TIME,
PROP_CURSOR_BLINK_TIMEOUT, PROP_CURSOR_BLINK_TIMEOUT,
PROP_SPLIT_CURSOR, PROP_SPLIT_CURSOR,
PROP_CURSOR_ASPECT_RATIO,
PROP_THEME_NAME, PROP_THEME_NAME,
PROP_ICON_THEME_NAME, PROP_ICON_THEME_NAME,
PROP_FALLBACK_ICON_THEME, PROP_FALLBACK_ICON_THEME,
@ -455,6 +456,15 @@ gtk_settings_class_init (GtkSettingsClass *class)
GTK_PARAM_READWRITE), GTK_PARAM_READWRITE),
NULL); NULL);
g_assert (result == PROP_SPLIT_CURSOR); g_assert (result == PROP_SPLIT_CURSOR);
result = settings_install_property_parser (class,
g_param_spec_float ("gtk-cursor-aspect-ratio",
P_("Cursor Aspect Ratio"),
P_("The aspect ratio of the text caret"),
0.0, 1.0, 0.04,
GTK_PARAM_READWRITE),
NULL);
g_assert (result == PROP_CURSOR_ASPECT_RATIO);
result = settings_install_property_parser (class, result = settings_install_property_parser (class,
g_param_spec_string ("gtk-theme-name", g_param_spec_string ("gtk-theme-name",
P_("Theme Name"), P_("Theme Name"),

View File

@ -2807,6 +2807,7 @@ draw_insertion_cursor (GtkStyleContext *context,
gdouble x, gdouble x,
gdouble y, gdouble y,
gdouble height, gdouble height,
float aspect_ratio,
gboolean is_primary, gboolean is_primary,
PangoDirection direction, PangoDirection direction,
gboolean draw_arrow) gboolean draw_arrow)
@ -2814,7 +2815,6 @@ draw_insertion_cursor (GtkStyleContext *context,
{ {
GdkRGBA primary_color; GdkRGBA primary_color;
GdkRGBA secondary_color; GdkRGBA secondary_color;
gfloat cursor_aspect_ratio;
gint stem_width; gint stem_width;
gint offset; gint offset;
@ -2828,11 +2828,7 @@ draw_insertion_cursor (GtkStyleContext *context,
* propagate the changes to gtktextview.c:text_window_invalidate_cursors(). * propagate the changes to gtktextview.c:text_window_invalidate_cursors().
*/ */
gtk_style_context_get_style (context, stem_width = height * aspect_ratio + 1;
"cursor-aspect-ratio", &cursor_aspect_ratio,
NULL);
stem_width = height * cursor_aspect_ratio + 1;
/* put (stem_width % 2) on the proper side of the cursor */ /* put (stem_width % 2) on the proper side of the cursor */
if (direction == PANGO_DIRECTION_LTR) if (direction == PANGO_DIRECTION_LTR)
@ -2902,6 +2898,7 @@ gtk_render_insertion_cursor (GtkStyleContext *context,
{ {
GtkStyleContextPrivate *priv; GtkStyleContextPrivate *priv;
gboolean split_cursor; gboolean split_cursor;
float aspect_ratio;
PangoRectangle strong_pos, weak_pos; PangoRectangle strong_pos, weak_pos;
PangoRectangle *cursor1, *cursor2; PangoRectangle *cursor1, *cursor2;
PangoDirection keymap_direction; PangoDirection keymap_direction;
@ -2916,6 +2913,7 @@ gtk_render_insertion_cursor (GtkStyleContext *context,
g_object_get (gtk_settings_get_for_screen (priv->screen), g_object_get (gtk_settings_get_for_screen (priv->screen),
"gtk-split-cursor", &split_cursor, "gtk-split-cursor", &split_cursor,
"gtk-cursor-aspect-ratio", &aspect_ratio,
NULL); NULL);
keymap_direction = gdk_keymap_get_direction (gdk_keymap_get_for_display (gdk_screen_get_display (priv->screen))); keymap_direction = gdk_keymap_get_direction (gdk_keymap_get_for_display (gdk_screen_get_display (priv->screen)));
@ -2947,6 +2945,7 @@ gtk_render_insertion_cursor (GtkStyleContext *context,
x + PANGO_PIXELS (cursor1->x), x + PANGO_PIXELS (cursor1->x),
y + PANGO_PIXELS (cursor1->y), y + PANGO_PIXELS (cursor1->y),
PANGO_PIXELS (cursor1->height), PANGO_PIXELS (cursor1->height),
aspect_ratio,
TRUE, TRUE,
direction, direction,
direction2 != PANGO_DIRECTION_NEUTRAL); direction2 != PANGO_DIRECTION_NEUTRAL);
@ -2958,6 +2957,7 @@ gtk_render_insertion_cursor (GtkStyleContext *context,
x + PANGO_PIXELS (cursor2->x), x + PANGO_PIXELS (cursor2->x),
y + PANGO_PIXELS (cursor2->y), y + PANGO_PIXELS (cursor2->y),
PANGO_PIXELS (cursor2->height), PANGO_PIXELS (cursor2->height),
aspect_ratio,
FALSE, FALSE,
direction2, direction2,
TRUE); TRUE);
@ -2990,6 +2990,7 @@ gtk_draw_insertion_cursor (GtkWidget *widget,
gboolean draw_arrow) gboolean draw_arrow)
{ {
GtkStyleContext *context; GtkStyleContext *context;
float aspect_ratio;
g_return_if_fail (GTK_IS_WIDGET (widget)); g_return_if_fail (GTK_IS_WIDGET (widget));
g_return_if_fail (cr != NULL); g_return_if_fail (cr != NULL);
@ -2998,8 +2999,13 @@ gtk_draw_insertion_cursor (GtkWidget *widget,
context = gtk_widget_get_style_context (widget); context = gtk_widget_get_style_context (widget);
g_object_get (gtk_settings_get_for_screen (context->priv->screen),
"gtk-cursor-aspect-ratio", &aspect_ratio,
NULL);
draw_insertion_cursor (context, cr, draw_insertion_cursor (context, cr,
location->x, location->y, location->height, location->x, location->y, location->height,
aspect_ratio,
is_primary, is_primary,
(direction == GTK_TEXT_DIR_RTL) ? PANGO_DIRECTION_RTL : PANGO_DIRECTION_LTR, (direction == GTK_TEXT_DIR_RTL) ? PANGO_DIRECTION_RTL : PANGO_DIRECTION_LTR,
draw_arrow); draw_arrow);