From 6b0cd451fb12bb2eda88bd54511011e2184445a8 Mon Sep 17 00:00:00 2001 From: Stephan Witt Date: Sun, 20 Feb 2022 13:06:28 +0100 Subject: [PATCH] #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(+) diff --git a/src/frontends/qt/GuiApplication.cpp b/src/frontends/qt/GuiApplication.cpp index b44f2c56b2..c15f2d7738 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 9f154c6155..0d2e41adae 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 2c78bd2d8c..4278564a45 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"]; +} -- 2.39.5