textview: Match cursor blink behavior of GtkText
This makes the conditions in cursor_blinks() more similar to what GtkText does, and fixes adds the same notify handler for has-focus, so we start blinking when requires. Crucially, we also no longer try to blink when unmapped, which should fix a epiphany crash. Fixes: #6515
This commit is contained in:
@@ -830,6 +830,17 @@ add_move_binding (GtkWidgetClass *widget_class,
|
||||
"(iib)", step, count, TRUE);
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_text_view_notify (GObject *object,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
if (pspec->name == I_("has-focus"))
|
||||
gtk_text_view_check_cursor_blink (GTK_TEXT_VIEW (object));
|
||||
|
||||
if (G_OBJECT_CLASS (gtk_text_view_parent_class)->notify)
|
||||
G_OBJECT_CLASS (gtk_text_view_parent_class)->notify (object, pspec);
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_text_view_class_init (GtkTextViewClass *klass)
|
||||
{
|
||||
@@ -842,6 +853,7 @@ gtk_text_view_class_init (GtkTextViewClass *klass)
|
||||
gobject_class->get_property = gtk_text_view_get_property;
|
||||
gobject_class->finalize = gtk_text_view_finalize;
|
||||
gobject_class->dispose = gtk_text_view_dispose;
|
||||
gobject_class->notify = gtk_text_view_notify;
|
||||
|
||||
widget_class->realize = gtk_text_view_realize;
|
||||
widget_class->unrealize = gtk_text_view_unrealize;
|
||||
@@ -6069,28 +6081,35 @@ gtk_text_view_remove (GtkTextView *text_view,
|
||||
static gboolean
|
||||
cursor_blinks (GtkTextView *text_view)
|
||||
{
|
||||
GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (text_view));
|
||||
gboolean blink;
|
||||
GtkRoot *root = gtk_widget_get_root (GTK_WIDGET (text_view));
|
||||
|
||||
#ifdef DEBUG_VALIDATION_AND_SCROLLING
|
||||
return FALSE;
|
||||
#endif
|
||||
|
||||
g_object_get (settings, "gtk-cursor-blink", &blink, NULL);
|
||||
|
||||
if (!blink)
|
||||
return FALSE;
|
||||
|
||||
if (text_view->priv->editable)
|
||||
if (gtk_widget_get_mapped (GTK_WIDGET (text_view)) &&
|
||||
gtk_window_is_active (GTK_WINDOW (root)) &&
|
||||
gtk_widget_has_focus (GTK_WIDGET (text_view)))
|
||||
{
|
||||
GtkTextMark *insert;
|
||||
GtkTextIter iter;
|
||||
GtkSettings *settings = gtk_widget_get_settings (GTK_WIDGET (text_view));
|
||||
gboolean blink;
|
||||
|
||||
insert = gtk_text_buffer_get_insert (get_buffer (text_view));
|
||||
gtk_text_buffer_get_iter_at_mark (get_buffer (text_view), &iter, insert);
|
||||
g_object_get (settings, "gtk-cursor-blink", &blink, NULL);
|
||||
|
||||
if (gtk_text_iter_editable (&iter, text_view->priv->editable))
|
||||
return blink;
|
||||
if (!blink)
|
||||
return FALSE;
|
||||
|
||||
if (text_view->priv->editable)
|
||||
{
|
||||
GtkTextMark *insert;
|
||||
GtkTextIter iter;
|
||||
|
||||
insert = gtk_text_buffer_get_insert (get_buffer (text_view));
|
||||
gtk_text_buffer_get_iter_at_mark (get_buffer (text_view), &iter, insert);
|
||||
|
||||
if (gtk_text_iter_editable (&iter, text_view->priv->editable))
|
||||
return blink;
|
||||
}
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
|
||||
Reference in New Issue
Block a user