terminal/src/renderer/inc/CursorOptions.h
Leonard Hecker 4fbcd65e1a
Fix multiple cursor invalidation issues (#17181)
There were multiple bugs:
* GDI engine only paints whatever has been invalidated.
  This means we need to not just invalidate the old cursor rect
  but also the new one, or else movements may not be visible.
* The composition should be drawn at the cursor position even if
  the cursor is invisible, but inside the renderer viewport.
* Conceptually, scrolling the viewport moves the relative cursor
  position even if the cursor is invisible.
* An invisible cursor is not the same as one that's outside the
  viewport. It's more like a cursor that's not turned on.

To resolve the first issue we simply need to call `InvalidateCursor`
again. To do so, it was abstracted into `_invalidateCurrentCursor()`.

The next 2 issues are resolved by un-`optional`-izing `CursorOptions`.
After all, even an invisible or an out-of-bounds cursor still has a
coordinate and it may still be scrolled into view.
Instead, it has the new `inViewport` property as a replacement.
This allows for instance the IME composition code in the renderer
to use the cursor coordinate while the cursor is invisible.

The last issue is fixed by simply changing the `.isOn` logic.

Closes #17150

## Validation Steps Performed
* In conhost with the GDI renderer:
  `printf "\e[2 q"; sleep 2; printf "\e[A"; sleep 2; printf "\e[B"`
  Cursor moves up after 2s and then down again after 2s. 
* Hide the cursor (`"\e[?25l"`) and use a CJK IME.
  Words can still be written and deleted correctly. 
* Turning the cursor back on (`"\e[?25h"`) works 
* Scrolling shows/hides the cursor 
2024-05-02 18:33:25 -05:00

63 lines
1.9 KiB
C++

/*++
Copyright (c) Microsoft Corporation
Licensed under the MIT license.
Module Name:
- CursorOptions.h
Abstract:
- A collection of state about the cursor that a render engine might need to display the cursor correctly.
Author(s):
- Mike Griese, 03-Jun-2020
--*/
#pragma once
#include "../../buffer/out/LineRendition.hpp"
#include "../../inc/conattrs.hpp"
namespace Microsoft::Console::Render
{
struct CursorOptions
{
// Character cell in the grid to draw at
// This is relative to the top of the viewport, not the buffer
til::point coordCursor;
// Left offset of the viewport, which may alter the horizontal position
til::CoordType viewportLeft;
// Line rendition of the current row, which can affect the cursor width
LineRendition lineRendition;
// For an underscore type _ cursor, how tall it should be as a % of cell height
ULONG ulCursorHeightPercent;
// For a vertical bar type | cursor, how many pixels wide it should be per ease of access preferences
ULONG cursorPixelWidth;
// Whether to draw the cursor 2 cells wide (+X from the coordinate given)
bool fIsDoubleWidth;
// Chooses a special cursor type like a full box, a vertical bar, etc.
CursorType cursorType;
// Specifies to use the color below instead of the default color
bool fUseColor;
// Color to use for drawing instead of the default
COLORREF cursorColor;
// The other kind of on/off state for the cursor, because VtEngine needs it to handle \x1b[?25l/h.
bool isVisible;
// Is the cursor currently visually visible?
// If the cursor has blinked off, this is false.
// if the cursor has blinked on, this is true.
bool isOn;
// Is the cursor within the viewport of the renderer?
bool inViewport;
};
}