+static void
+gtk_entry_move_adjustments (GtkEntry *entry)
+{
+ PangoContext *context;
+ PangoFontMetrics *metrics;
+ gint x, layout_x, border_x, border_y;
+ gint char_width;
+ GtkAdjustment *adjustment;
+
+ adjustment = g_object_get_qdata (G_OBJECT (entry), quark_cursor_hadjustment);
+ if (!adjustment)
+ return;
+
+ /* Cursor position, layout offset, border width, and widget allocation */
+ gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &x, NULL);
+ get_layout_position (entry, &layout_x, NULL);
+ _gtk_entry_get_borders (entry, &border_x, &border_y);
+ x += entry->widget.allocation.x + layout_x + border_x;
+
+ /* Approximate width of a char, so user can see what is ahead/behind */
+ context = gtk_widget_get_pango_context (GTK_WIDGET (entry));
+ metrics = pango_context_get_metrics (context,
+ entry->widget.style->font_desc,
+ pango_context_get_language (context));
+ char_width = pango_font_metrics_get_approximate_char_width (metrics) / PANGO_SCALE;
+
+ /* Scroll it */
+ gtk_adjustment_clamp_page (adjustment,
+ x - (char_width + 1), /* one char + one pixel before */
+ x + (char_width + 2)); /* one char + cursor + one pixel after */
+}
+