Terminal uses system default for number of rows scrolled at a t… (#3575)

The terminal will use the system setting to determine the number of lines to scroll at a time.
This can be overridden by adding rowsToScroll to app global settings file.
terminal will use the system setting if the app setting is 0, or not specified. No restart is needed to reflect setting changes in system or the settings file.

The default was hardcoded to 4 in the code with a todo comment. 1 works better on precision touchpads, where 4 scrolls too fast.

Co-authored-by: Hannes Nel <hannesne@microsoft.com>
This commit is contained in:
Hannes Nel 2020-01-07 06:39:02 +13:00 committed by Michael Niksa
parent d711d731d7
commit a60ed52064
12 changed files with 68 additions and 6 deletions

View file

@ -10,6 +10,7 @@ Properties listed below affect the entire window, regardless of the profile sett
| `defaultProfile` | _Required_ | String | PowerShell guid | Sets the default profile. Opens by typing <kbd>Ctrl</kbd> + <kbd>T</kbd> or by clicking the '+' icon. The guid of the desired default profile is used as the value. |
| `initialCols` | _Required_ | Integer | `120` | The number of columns displayed in the window upon first load. |
| `initialRows` | _Required_ | Integer | `30` | The number of rows displayed in the window upon first load. |
| `rowsToScroll` | Optional | Integer | `system` | The number of rows to scroll at a time with the mouse wheel. This will override the system setting if the value is not zero or "system". |
| `requestedTheme` | _Required_ | String | `system` | Sets the theme of the application. Possible values: `"light"`, `"dark"`, `"system"` |
| `showTerminalTitleInTitlebar` | _Required_ | Boolean | `true` | When set to `true`, titlebar displays the title of the selected tab. When set to `false`, titlebar displays "Windows Terminal". |
| `showTabsInTitlebar` | Optional | Boolean | `true` | When set to `true`, the tabs are moved into the titlebar and the titlebar disappears. When set to `false`, the titlebar sits above the tabs. |

View file

@ -284,6 +284,13 @@
"minimum": 1,
"type": "integer"
},
"rowsToScroll": {
"default": "system",
"description": "The number of rows to scroll at a time with the mouse wheel. This will override the system setting if the value is not zero or 'system'.",
"maximum": 999,
"minimum": 0,
"type": "integer"
},
"keybindings": {
"description": "Properties are specific to each custom key binding.",
"items": {

View file

@ -433,7 +433,8 @@ namespace TerminalAppLocalTests
"globals": {
"alwaysShowTabs": true,
"initialCols" : 120,
"initialRows" : 30
"initialRows" : 30,
"rowsToScroll" : 4,
}
})" };
const std::string settings1String{ R"(
@ -441,7 +442,8 @@ namespace TerminalAppLocalTests
"globals": {
"showTabsInTitlebar": false,
"initialCols" : 240,
"initialRows" : 60
"initialRows" : 60,
"rowsToScroll" : 8
}
})" };
const auto settings0Json = VerifyParseSucceeded(settings0String);
@ -453,12 +455,14 @@ namespace TerminalAppLocalTests
VERIFY_ARE_EQUAL(true, settings._globals._alwaysShowTabs);
VERIFY_ARE_EQUAL(120, settings._globals._initialCols);
VERIFY_ARE_EQUAL(30, settings._globals._initialRows);
VERIFY_ARE_EQUAL(4, settings._globals._rowsToScroll);
VERIFY_ARE_EQUAL(true, settings._globals._showTabsInTitlebar);
settings.LayerJson(settings1Json);
VERIFY_ARE_EQUAL(true, settings._globals._alwaysShowTabs);
VERIFY_ARE_EQUAL(240, settings._globals._initialCols);
VERIFY_ARE_EQUAL(60, settings._globals._initialRows);
VERIFY_ARE_EQUAL(8, settings._globals._rowsToScroll);
VERIFY_ARE_EQUAL(false, settings._globals._showTabsInTitlebar);
}

View file

@ -21,6 +21,7 @@ static constexpr std::string_view DefaultProfileKey{ "defaultProfile" };
static constexpr std::string_view AlwaysShowTabsKey{ "alwaysShowTabs" };
static constexpr std::string_view InitialRowsKey{ "initialRows" };
static constexpr std::string_view InitialColsKey{ "initialCols" };
static constexpr std::string_view RowsToScrollKey{ "rowsToScroll" };
static constexpr std::string_view InitialPositionKey{ "initialPosition" };
static constexpr std::string_view ShowTitleInTitlebarKey{ "showTerminalTitleInTitlebar" };
static constexpr std::string_view RequestedThemeKey{ "requestedTheme" };
@ -41,6 +42,7 @@ GlobalAppSettings::GlobalAppSettings() :
_alwaysShowTabs{ true },
_initialRows{ DEFAULT_ROWS },
_initialCols{ DEFAULT_COLS },
_rowsToScroll{ DEFAULT_ROWSTOSCROLL },
_initialX{},
_initialY{},
_showTitleInTitlebar{ true },
@ -175,6 +177,7 @@ void GlobalAppSettings::ApplyToSettings(TerminalSettings& settings) const noexce
settings.KeyBindings(GetKeybindings());
settings.InitialRows(_initialRows);
settings.InitialCols(_initialCols);
settings.RowsToScroll(_rowsToScroll);
settings.WordDelimiters(_wordDelimiters);
settings.CopyOnSelect(_copyOnSelect);
@ -193,6 +196,7 @@ Json::Value GlobalAppSettings::ToJson() const
jsonObject[JsonKey(DefaultProfileKey)] = winrt::to_string(Utils::GuidToString(_defaultProfile));
jsonObject[JsonKey(InitialRowsKey)] = _initialRows;
jsonObject[JsonKey(InitialColsKey)] = _initialCols;
jsonObject[JsonKey(RowsToScrollKey)] = _rowsToScroll;
jsonObject[JsonKey(InitialPositionKey)] = _SerializeInitialPosition(_initialX, _initialY);
jsonObject[JsonKey(AlwaysShowTabsKey)] = _alwaysShowTabs;
jsonObject[JsonKey(ShowTitleInTitlebarKey)] = _showTitleInTitlebar;
@ -239,6 +243,18 @@ void GlobalAppSettings::LayerJson(const Json::Value& json)
{
_initialCols = initialCols.asInt();
}
if (auto rowsToScroll{ json[JsonKey(RowsToScrollKey)] })
{
//if it's not an int we fall back to setting it to 0, which implies using the system setting. This will be the case if it's set to "system"
if (rowsToScroll.isInt())
{
_rowsToScroll = rowsToScroll.asInt();
}
else
{
_rowsToScroll = 0;
}
}
if (auto initialPosition{ json[JsonKey(InitialPositionKey)] })
{
_ParseInitialPosition(GetWstringFromJson(initialPosition), _initialX, _initialY);

View file

@ -85,6 +85,8 @@ private:
int32_t _initialRows;
int32_t _initialCols;
int32_t _rowsToScroll;
std::optional<int32_t> _initialX;
std::optional<int32_t> _initialY;

View file

@ -351,6 +351,9 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation
foregroundBrush.Color(ColorRefToColor(_settings.DefaultForeground()));
_tsfInputControl.Foreground(foregroundBrush);
_tsfInputControl.Margin(newMargin);
// set number of rows to scroll at a time
_rowsToScroll = _settings.RowsToScroll();
}
// Method Description:
@ -1151,13 +1154,10 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation
// However, for us, the signs are flipped.
const auto rowDelta = mouseDelta < 0 ? 1.0 : -1.0;
// TODO: Should we be getting some setting from the system
// for number of lines scrolled?
// With one of the precision mouses, one click is always a multiple of 120,
// but the "smooth scrolling" mode results in non-int values
// Conhost seems to use four lines at a time, so we'll emulate that for now.
double newValue = (4 * rowDelta) + (currentOffset);
double newValue = (_rowsToScroll * rowDelta) + (currentOffset);
// Clear our expected scroll offset. The viewport will now move in
// response to our user input.
@ -1321,6 +1321,7 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation
// - Event handler for the GotFocus event. This is used to...
// - enable accessibility notifications for this TermControl
// - start blinking the cursor when the window is focused
// - update the number of lines to scroll to the value set in the system
void TermControl::_GotFocusHandler(Windows::Foundation::IInspectable const& /* sender */,
RoutedEventArgs const& /* args */)
{
@ -1346,6 +1347,7 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation
_terminal->SetCursorVisible(true);
_cursorTimer.value().Start();
}
_rowsToScroll = _settings.RowsToScroll();
}
// Method Description:

View file

@ -132,6 +132,8 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation
FontInfoDesired _desiredFont;
FontInfo _actualFont;
int _rowsToScroll;
std::optional<int> _lastScrollOffset;
// Auto scroll occurs when user, while selecting, drags cursor outside viewport. View is then scrolled to 'follow' the cursor.

View file

@ -22,6 +22,8 @@ namespace Microsoft.Terminal.Settings
Int32 HistorySize;
Int32 InitialRows;
Int32 InitialCols;
Int32 RowsToScroll;
Boolean SnapOnInput;
UInt32 CursorColor;

View file

@ -21,6 +21,7 @@ namespace winrt::Microsoft::Terminal::Settings::implementation
_historySize{ DEFAULT_HISTORY_SIZE },
_initialRows{ 30 },
_initialCols{ 80 },
_rowsToScroll{ 0 },
_snapOnInput{ true },
_cursorColor{ DEFAULT_CURSOR_COLOR },
_cursorShape{ CursorStyle::Vintage },
@ -114,6 +115,25 @@ namespace winrt::Microsoft::Terminal::Settings::implementation
_initialCols = value;
}
int32_t TerminalSettings::RowsToScroll() noexcept
{
if (_rowsToScroll != 0)
{
return _rowsToScroll;
}
int systemRowsToScroll;
if (!SystemParametersInfo(SPI_GETWHEELSCROLLLINES, 0, &systemRowsToScroll, 0))
{
systemRowsToScroll = 4;
}
return systemRowsToScroll;
}
void TerminalSettings::RowsToScroll(int32_t value) noexcept
{
_rowsToScroll = value;
}
bool TerminalSettings::SnapOnInput() noexcept
{
return _snapOnInput;

View file

@ -39,6 +39,8 @@ namespace winrt::Microsoft::Terminal::Settings::implementation
void InitialRows(int32_t value) noexcept;
int32_t InitialCols() noexcept;
void InitialCols(int32_t value) noexcept;
int32_t RowsToScroll() noexcept;
void RowsToScroll(int32_t value) noexcept;
bool SnapOnInput() noexcept;
void SnapOnInput(bool value) noexcept;
uint32_t CursorColor() noexcept;
@ -108,6 +110,7 @@ namespace winrt::Microsoft::Terminal::Settings::implementation
int32_t _historySize;
int32_t _initialRows;
int32_t _initialCols;
int32_t _rowsToScroll;
bool _snapOnInput;
uint32_t _cursorColor;
Settings::CursorStyle _cursorShape;

View file

@ -25,6 +25,7 @@ namespace TerminalCoreUnitTests
int32_t HistorySize() { return _historySize; }
int32_t InitialRows() { return _initialRows; }
int32_t InitialCols() { return _initialCols; }
int32_t RowsToScroll() { return 4; }
uint32_t DefaultForeground() { return COLOR_WHITE; }
uint32_t DefaultBackground() { return COLOR_BLACK; }
bool SnapOnInput() { return false; }
@ -44,6 +45,7 @@ namespace TerminalCoreUnitTests
void HistorySize(int32_t) {}
void InitialRows(int32_t) {}
void InitialCols(int32_t) {}
void RowsToScroll(int32_t) {}
void DefaultForeground(uint32_t) {}
void DefaultBackground(uint32_t) {}
void SnapOnInput(bool) {}

View file

@ -35,6 +35,7 @@ constexpr int DEFAULT_FONT_SIZE = 12;
constexpr int DEFAULT_ROWS = 30;
constexpr int DEFAULT_COLS = 120;
constexpr int DEFAULT_ROWSTOSCROLL = 0;
const std::wstring DEFAULT_PADDING{ L"8, 8, 8, 8" };
const std::wstring DEFAULT_STARTING_DIRECTORY{ L"%USERPROFILE%" };