godotengine / godot-proposals

Godot Improvement Proposals (GIPs)
MIT License
1.11k stars 69 forks source link

Implement caret blink idle timeout #10165

Open alvinhochun opened 1 month ago

alvinhochun commented 1 month ago

Describe the project you are working on

N/A

Describe the problem or limitation you are having in your project

The script editor for example continuously blinks the caret even when nothing is happening, which causes unnecessary redraw and uses more power. It also does not match the native caret behaviour on Windows, which has a default timeout of 5000ms (configurable in registry).

Describe the feature / enhancement and how it helps to overcome the problem or limitation

The caret of LineEdit/TextEdit should stop blinking after a certain idle timeout, instead show a solid non-blinking line (or whatever caret shape applicable). This should prevent the editor having to redraw the window constantly.

It can either be an editor/project setting or simply follow the native behaviour.

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

The timeout on Windows can be read from the registry key HKEY_CURRENT_USER\Control Panel\Desktop, using the CaretTimeout DWORD value. LineEdit/TextEdit can keep track of the last idle time, to disable the blinking after the timeout and resume blinking after the user moved the caret or performed any input.

If this enhancement will not be used often, can it be worked around with a few lines of script?

Not really.

Is there a reason why this should be core and not an add-on in the asset library?

It should apply to the Godot Editor itself.

KoBeWi commented 1 month ago

You can unfocus the window and the caret disappears.

Calinou commented 1 month ago

This seems to be the case on Firefox 127 on Linux as well, although the timer is around 10 seconds there since the caret blinks slower. The timer resets whenever the caret moves or the text changes, but it does not reset if you move the mouse or make other inputs on Firefox (such as clicking on its menus).

Qt apps in KDE don't seem to have any caret blink timeout though.

The timeout on Windows can be read from the registry key HKEY_CURRENT_USER\Control Panel\Desktop, using the CaretTimeout DWORD value.

We currently don't use registry/OS-provided values for caret thickness and blinking, so I wouldn't do that for caret timeout either. If we start doing it for something, we should do it consistently for all caret behavior on all platforms where it's supported. Users also need to be able to opt out of this behavior for games which may be going for a specific look.

Also, I would only apply this timeout when running in low processor mode as it's not relevant for games that are redrawing constantly.

Edit: I have a WIP implementation: https://github.com/Calinou/godot/tree/lineedit-textedit-disable-caret-blink-inactive