[LyX/master] #9287 query Standard User Defaults on mac and adjust cursor flash time accordingly

Stephan Witt switt at lyx.org
Sun Feb 20 12:29:17 UTC 2022


commit 6b0cd451fb12bb2eda88bd54511011e2184445a8
Author: Stephan Witt <switt at lyx.org>
Date:   Sun Feb 20 13:06:28 2022 +0100

    #9287 query Standard User Defaults on mac and adjust cursor flash time accordingly
---
 src/frontends/qt/GuiApplication.cpp |   14 ++++++++++++++
 src/support/AppleSupport.h          |    6 ++++++
 src/support/AppleSupport.m          |   16 ++++++++++++++++
 3 files changed, 36 insertions(+), 0 deletions(-)

diff --git a/src/frontends/qt/GuiApplication.cpp b/src/frontends/qt/GuiApplication.cpp
index b44f2c5..c15f2d7 100644
--- a/src/frontends/qt/GuiApplication.cpp
+++ b/src/frontends/qt/GuiApplication.cpp
@@ -197,6 +197,20 @@ frontend::Application * createApplication(int & argc, char * argv[])
 #endif
 
 
+#if defined(Q_OS_MAC)
+	int const cursor_time_on = NSTextInsertionPointBlinkPeriodOn();
+	int const cursor_time_off = NSTextInsertionPointBlinkPeriodOff();
+	if (cursor_time_on > 0 && cursor_time_off > 0) {
+		QApplication::setCursorFlashTime(cursor_time_on + cursor_time_off);
+	} else if (cursor_time_on <= 0 && cursor_time_off > 0) {
+		// Off is set and On is undefined of zero
+		QApplication::setCursorFlashTime(0);
+	} else if (cursor_time_off <= 0 && cursor_time_on > 0) {
+		// On is set and Off is undefined of zero
+		QApplication::setCursorFlashTime(0);
+	}
+#endif
+
 // Setup high DPI handling. This is a bit complicated, but will be default in Qt6.
 // macOS does it by itself.
 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) && !defined(Q_OS_MAC)
diff --git a/src/support/AppleSupport.h b/src/support/AppleSupport.h
index 9f154c6..0d2e41a 100644
--- a/src/support/AppleSupport.h
+++ b/src/support/AppleSupport.h
@@ -20,6 +20,12 @@ extern "C" {
 
 	// query the system preferences for users tabbing preference
 	bool appleUserTabbingPreferenceAlways();
+
+	// Query the Standard User Defaults for float values of
+	// NSTextInsertionPointBlinkPeriodOn resp. NSTextInsertionPointBlinkPeriodOff
+	// and return the integer part of it - return -1 in case of unset value
+	int NSTextInsertionPointBlinkPeriodOn();
+	int NSTextInsertionPointBlinkPeriodOff();
 #ifdef __cplusplus
 }
 #endif
diff --git a/src/support/AppleSupport.m b/src/support/AppleSupport.m
index 2c78bd2..4278564 100644
--- a/src/support/AppleSupport.m
+++ b/src/support/AppleSupport.m
@@ -49,3 +49,19 @@ bool appleUserTabbingPreferenceAlways() {
 	return false;
 #endif
 }
+
+
+int NSTextInsertionPointBlinkPeriodOn() {
+	NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
+
+	return [prefs objectForKey:@"NSTextInsertionPointBlinkPeriodOn"] == nil ?
+		-1 : [prefs floatForKey:@"NSTextInsertionPointBlinkPeriodOn"];
+}
+
+
+int NSTextInsertionPointBlinkPeriodOff() {
+	NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
+
+	return [prefs objectForKey:@"NSTextInsertionPointBlinkPeriodOff"] == nil ?
+			-1 : [prefs floatForKey:@"NSTextInsertionPointBlinkPeriodOff"];
+}


More information about the lyx-cvs mailing list