Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Terminal uses system default for number of rows scrolled at a time. Can be overridden in settings file. #3575

Merged
merged 19 commits into from
Jan 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/cascadia/SettingsSchema.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. |
Expand Down
7 changes: 7 additions & 0 deletions doc/cascadia/profiles.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
8 changes: 6 additions & 2 deletions src/cascadia/LocalTests_TerminalApp/SettingsTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -433,15 +433,17 @@ namespace TerminalAppLocalTests
"globals": {
"alwaysShowTabs": true,
"initialCols" : 120,
"initialRows" : 30
"initialRows" : 30,
"rowsToScroll" : 4,
}
Comment on lines 433 to 438
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure why this wasn't picked up by the build bot, but this test now fails for me when run locally because of the trailing comma (that's not valid JSON).

})" };
const std::string settings1String{ R"(
{
"globals": {
"showTabsInTitlebar": false,
"initialCols" : 240,
"initialRows" : 60
"initialRows" : 60,
"rowsToScroll" : 8
}
})" };
const auto settings0Json = VerifyParseSucceeded(settings0String);
Expand All @@ -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);
}

Expand Down
16 changes: 16 additions & 0 deletions src/cascadia/TerminalApp/GlobalAppSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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" };
Expand All @@ -41,6 +42,7 @@ GlobalAppSettings::GlobalAppSettings() :
_alwaysShowTabs{ true },
_initialRows{ DEFAULT_ROWS },
_initialCols{ DEFAULT_COLS },
_rowsToScroll{ DEFAULT_ROWSTOSCROLL },
_initialX{},
_initialY{},
_showTitleInTitlebar{ true },
Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions src/cascadia/TerminalApp/GlobalAppSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ class TerminalApp::GlobalAppSettings final
int32_t _initialRows;
int32_t _initialCols;

int32_t _rowsToScroll;

std::optional<int32_t> _initialX;
std::optional<int32_t> _initialY;

Expand Down
10 changes: 6 additions & 4 deletions src/cascadia/TerminalControl/TermControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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 */)
{
Expand All @@ -1346,6 +1347,7 @@ namespace winrt::Microsoft::Terminal::TerminalControl::implementation
_terminal->SetCursorVisible(true);
_cursorTimer.value().Start();
}
_rowsToScroll = _settings.RowsToScroll();
}

// Method Description:
Expand Down
2 changes: 2 additions & 0 deletions src/cascadia/TerminalControl/TermControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions src/cascadia/TerminalSettings/ICoreSettings.idl
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ namespace Microsoft.Terminal.Settings
Int32 HistorySize;
Int32 InitialRows;
Int32 InitialCols;
Int32 RowsToScroll;

Boolean SnapOnInput;

UInt32 CursorColor;
Expand Down
20 changes: 20 additions & 0 deletions src/cascadia/TerminalSettings/TerminalSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions src/cascadia/TerminalSettings/terminalsettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions src/cascadia/UnitTests_TerminalCore/MockTermSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand All @@ -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) {}
Expand Down
1 change: 1 addition & 0 deletions src/inc/DefaultSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -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%" };
Expand Down