From 65c9c1173b2e2485ff3f5c00094ccaaeb8e1b834 Mon Sep 17 00:00:00 2001 From: Gabriel Ebner Date: Tue, 12 Jan 2021 13:32:09 +0100 Subject: [PATCH] Allow the user to disable cursor blinking. (#2170) This uses the same setting which is also used by the built-in text entry widget. --- src/gui/TextEditor.cpp | 25 +++++++++++++++++++------ src/gui/TextEditor.h | 1 + 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/gui/TextEditor.cpp b/src/gui/TextEditor.cpp index 797185a7..3b628d44 100644 --- a/src/gui/TextEditor.cpp +++ b/src/gui/TextEditor.cpp @@ -31,6 +31,7 @@ TextEditor::TextEditor(XojPageView* gui, GtkWidget* widget, Text* text, bool own gtk_text_buffer_place_cursor(this->buffer, &first); GtkSettings* settings = gtk_widget_get_settings(this->widget); + g_object_get(settings, "gtk-cursor-blink", &this->cursorBlink, nullptr); g_object_get(settings, "gtk-cursor-blink-time", &this->cursorBlinkTime, nullptr); g_object_get(settings, "gtk-cursor-blink-timeout", &this->cursorBlinkTimeout, nullptr); @@ -42,7 +43,11 @@ TextEditor::TextEditor(XojPageView* gui, GtkWidget* widget, Text* text, bool own g_signal_connect(this->imContext, "retrieve-surrounding", G_CALLBACK(iMRetrieveSurroundingCallback), this); g_signal_connect(this->imContext, "delete-surrounding", G_CALLBACK(imDeleteSurroundingCallback), this); - blinkCallback(this); + if (this->cursorBlink) { + blinkCallback(this); + } else { + this->cursorVisible = true; + } } TextEditor::~TextEditor() { @@ -523,11 +528,15 @@ void TextEditor::moveCursor(GtkMovementStep step, int count, bool extendSelectio gtk_widget_error_bell(this->widget); } - this->cursorVisible = false; - if (this->blinkTimeout) { - g_source_remove(this->blinkTimeout); + if (this->cursorBlink) { + this->cursorVisible = false; + if (this->blinkTimeout) { + g_source_remove(this->blinkTimeout); + } + blinkCallback(this); + } else { + repaintCursor(); } - blinkCallback(this); } void TextEditor::findPos(GtkTextIter* iter, double xPos, double yPos) { @@ -854,7 +863,11 @@ void TextEditor::resetImContext() { } } -void TextEditor::repaintCursor() { repaintEditor(); } +void TextEditor::repaintCursor() { + double x = this->text->getX(); + double y = this->text->getY(); + this->gui->repaintArea(x, y, x + this->text->getElementWidth(), y + this->text->getElementHeight()); +} #define CURSOR_ON_MULTIPLIER 2 #define CURSOR_OFF_MULTIPLIER 1 diff --git a/src/gui/TextEditor.h b/src/gui/TextEditor.h index cc205aca..6c4756f8 100644 --- a/src/gui/TextEditor.h +++ b/src/gui/TextEditor.h @@ -105,6 +105,7 @@ private: double markPosX = 0; double markPosY = 0; + bool cursorBlink = true; int cursorBlinkTime = 0; int cursorBlinkTimeout = 0; int blinkTimeout = 0; // handler id