diff --git a/docs/changelog.rst b/docs/changelog.rst index 7d913666c..e97498f15 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -66,6 +66,10 @@ To update |kitty|, :doc:`follow the instructions `. - macOS: Fix :opt:`sync_to_monitor` not working on Mojave. +- macOS: Use the system cursor blink interval by default + :opt:`cursor_blink_interval`. + + 0.13.3 [2019-01-19] ------------------------------ diff --git a/kitty/cocoa_window.m b/kitty/cocoa_window.m index 71c42edd1..5e9252ba5 100644 --- a/kitty/cocoa_window.m +++ b/kitty/cocoa_window.m @@ -427,6 +427,21 @@ cocoa_get_lang(PyObject UNUSED *self) { return Py_BuildValue("s", [locale UTF8String]); } +double +cocoa_cursor_blink_interval(void) { + NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; + double on_period_ms = [defaults doubleForKey:@"NSTextInsertionPointBlinkPeriodOn"]; + double off_period_ms = [defaults doubleForKey:@"NSTextInsertionPointBlinkPeriodOff"]; + double period_ms = [defaults doubleForKey:@"NSTextInsertionPointBlinkPeriod"]; + double max_value = 60 * 1000.0, ans = -1.0; + if (on_period_ms || off_period_ms) { + ans = on_period_ms + off_period_ms; + } else if (period_ms) { + ans = period_ms; + } + return ans > max_value ? 0.0 : ans; +} + void cocoa_set_hide_from_tasks(void) { [NSApp setActivationPolicy:NSApplicationActivationPolicyAccessory]; diff --git a/kitty/config_data.py b/kitty/config_data.py index 0d6638116..b833c0734 100644 --- a/kitty/config_data.py +++ b/kitty/config_data.py @@ -309,13 +309,15 @@ Choose the color of text under the cursor. If you want it rendered with the background color of the cell underneath instead, use the special keyword: background''')) o('cursor_shape', 'block', option_type=to_cursor_shape, long_text=_( 'The cursor shape can be one of (block, beam, underline)')) -o('cursor_blink_interval', 0.5, option_type=positive_float, long_text=_(''' +o('cursor_blink_interval', -1, option_type=float, long_text=_(''' The interval (in seconds) at which to blink the cursor. Set to zero to disable -blinking. Note that numbers smaller than :opt:`repaint_delay` will be limited -to :opt:`repaint_delay`. Stop blinking cursor after the specified number of -seconds of keyboard inactivity. Set to zero to never stop blinking. +blinking. Negative values mean use system default. Note that numbers smaller +than :opt:`repaint_delay` will be limited to :opt:`repaint_delay`. +''')) +o('cursor_stop_blinking_after', 15.0, option_type=positive_float, long_text=_(''' +Stop blinking cursor after the specified number of seconds of keyboard +inactivity. Set to zero to never stop blinking. ''')) -o('cursor_stop_blinking_after', 15.0, option_type=positive_float) # }}} diff --git a/kitty/glfw.c b/kitty/glfw.c index 2587e072b..fe3cea7fc 100644 --- a/kitty/glfw.c +++ b/kitty/glfw.c @@ -16,6 +16,7 @@ extern void cocoa_set_hide_from_tasks(void); extern void cocoa_set_titlebar_color(void *w, color_type color); extern bool cocoa_alt_option_key_pressed(unsigned long); extern size_t cocoa_get_workspace_ids(void *w, size_t *workspace_ids, size_t array_sz); +extern double cocoa_cursor_blink_interval(void); #if GLFW_KEY_LAST >= MAX_KEY_COUNT @@ -541,6 +542,13 @@ create_os_window(PyObject UNUSED *self, PyObject *args) { CC(standard, IBEAM); CC(click, HAND); CC(arrow, ARROW); #undef CC if (OPT(click_interval) < 0) OPT(click_interval) = glfwGetDoubleClickInterval(glfw_window); + if (OPT(cursor_blink_interval) < 0) { + OPT(cursor_blink_interval) = 0.5; +#ifdef __APPLE__ + double cbi = cocoa_cursor_blink_interval(); + if (cbi >= 0) OPT(cursor_blink_interval) = cbi / 2.0; +#endif + } is_first_window = false; } OSWindow *w = add_os_window();