Skip to content

Commit

Permalink
Merge pull request #1203 from contour-terminal/improvement/sizeIndicator
Browse files Browse the repository at this point in the history
implement size indicator on resize
  • Loading branch information
christianparpart committed Sep 19, 2023
2 parents 34dd35c + 54ba5cb commit 7d271cc
Show file tree
Hide file tree
Showing 10 changed files with 79 additions and 0 deletions.
5 changes: 5 additions & 0 deletions docs/demo/size_indicator.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Size indicator

On resize window with current terminal size will apear

![type:video](../videos/size-indicator.mp4)
1 change: 1 addition & 0 deletions docs/features.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@
:material-check-bold:{.check-mark} Builtin [Fira Code inspired progress bar](https://github.com/contour-terminal/contour/issues/521) support. <br/>
:material-check-bold:{.check-mark} Read-only mode, protecting against accidental user-input to the running application, such as <kbd>Ctrl</kbd>+<kbd>C</kbd>. <br/>
:material-check-bold:{.check-mark} [VT320 Host-programmable and Indicator statusline support](demo/statusline.md) <br/>
:material-check-bold:{.check-mark} [Size indicator on resize](demo/size_indicator.md) <br/>
Binary file added docs/screenshots/size-indicator.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/videos/size-indicator.mp4
Binary file not shown.
2 changes: 2 additions & 0 deletions metainfo.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
<li>Builtin Fira Code inspired progress bar support.</li>
<li>Read-only mode, protecting against accidental user-input to the running application, such as Ctrl+C.</li>
<li>VT320 Host-programmable and Indicator status line support.</li>
<li>Size indicator on resize.</li>
<li>and much more ...</li>
</ul>
</description>
Expand Down Expand Up @@ -118,6 +119,7 @@
<li>Adds config option `profile.*.bell` to adjust BEL behavior and fixes (#1162) and (#1163).</li>
<li>Adds config option `profile.*.frozen_dec_modes` to permanently enable/disable certain DEC modes.</li>
<li>Adds capital `A` and `I` keys to switch from normal mode back to insert mode, too.</li>
<li>Adds size indicator window on resize (#1203).</li>
</ul>
</description>
</release>
Expand Down
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ nav:
- Line marks: demo/line-marks.md
- Status line: demo/statusline.md
- Input modes: input-modes.md
- Size indicator: demo/size_indicator.md
- VT extensions:
- vt-extensions/index.md
- vt-extensions/clickable-links.md
Expand Down
4 changes: 4 additions & 0 deletions src/contour/TerminalSession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -827,6 +827,8 @@ bool TerminalSession::operator()(actions::DecreaseFontSize)
{
auto constexpr OnePt = text::font_size { 1.0 };
setFontSize(profile().fonts.size - OnePt);

emit fontSizeChanged();
// auto const currentFontSize = view().renderer().fontDescriptions().size;
// auto const newFontSize = currentFontSize - OnePt;
// setFontSize(newFontSize);
Expand Down Expand Up @@ -882,6 +884,8 @@ bool TerminalSession::operator()(actions::IncreaseFontSize)
// auto const currentFontSize = view().renderer().fontDescriptions().size;
// auto const newFontSize = currentFontSize + OnePt;
// setFontSize(newFontSize);

emit fontSizeChanged();
setFontSize(profile().fonts.size + OnePt);
return true;
}
Expand Down
16 changes: 16 additions & 0 deletions src/contour/TerminalSession.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class TerminalSession: public QAbstractItemModel, public terminal::Terminal::Eve
Q_OBJECT
Q_PROPERTY(int id READ id)
Q_PROPERTY(int pageLineCount READ pageLineCount NOTIFY lineCountChanged)
Q_PROPERTY(int pageColumnsCount READ pageColumnsCount NOTIFY columnsCountChanged)
Q_PROPERTY(int historyLineCount READ historyLineCount NOTIFY historyLineCountChanged)
Q_PROPERTY(int scrollOffset READ scrollOffset WRITE setScrollOffset NOTIFY scrollOffsetChanged)
Q_PROPERTY(QString title READ title WRITE setTitle NOTIFY titleChanged)
Expand All @@ -75,11 +76,22 @@ class TerminalSession: public QAbstractItemModel, public terminal::Terminal::Eve
Q_PROPERTY(QColor backgroundColor READ getBackgroundColor NOTIFY backgroundColorChanged)
Q_PROPERTY(bool isScrollbarRight READ getIsScrollbarRight NOTIFY isScrollbarRightChanged)
Q_PROPERTY(bool isScrollbarVisible READ getIsScrollbarVisible NOTIFY isScrollbarVisibleChanged)
Q_PROPERTY(int fontSize READ getFontSize)
Q_PROPERTY(int upTime READ getUptime)

// Q_PROPERTY(QString profileName READ profileName NOTIFY profileNameChanged)

public:
// {{{ Model property helper

int getUptime() const noexcept
{
auto const now = std::chrono::steady_clock::now();
auto const diff = std::chrono::duration_cast<std::chrono::seconds>(now - _startTime);
return diff.count();
}

int getFontSize() const noexcept { return static_cast<int>(_profile.fonts.size.pt); }
float getOpacity() const noexcept
{
return static_cast<float>(_profile.backgroundOpacity) / std::numeric_limits<uint8_t>::max();
Expand Down Expand Up @@ -141,6 +153,8 @@ class TerminalSession: public QAbstractItemModel, public terminal::Terminal::Eve

int pageLineCount() const noexcept { return unbox(_terminal.pageSize().lines); }

int pageColumnsCount() const noexcept { return unbox(_terminal.pageSize().columns); }

int historyLineCount() const noexcept { return unbox(_terminal.currentScreen().historyLineCount()); }

int scrollOffset() const noexcept { return unbox(terminal().viewport().scrollOffset()); }
Expand Down Expand Up @@ -317,6 +331,7 @@ class TerminalSession: public QAbstractItemModel, public terminal::Terminal::Eve
void sessionClosed(TerminalSession&);
void profileNameChanged(QString newValue);
void lineCountChanged(int newValue);
void columnsCountChanged(int newValue);
void historyLineCountChanged(int newValue);
void scrollOffsetChanged(int newValue);
void titleChanged(QString const& value);
Expand All @@ -333,6 +348,7 @@ class TerminalSession: public QAbstractItemModel, public terminal::Terminal::Eve
void requestPermissionForBufferCapture();
void requestPermissionForShowHostWritableStatusLine();
void showNotification(QString const& title, QString const& content);
void fontSizeChanged();

public slots:
void onConfigReload();
Expand Down
48 changes: 48 additions & 0 deletions src/contour/ui.template/Terminal.qml.in
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,35 @@ ContourTerminal
focus : false
}



Rectangle {
Timer {
id: sizeWidgetTimer
interval: 1000;
running: false;
onTriggered: sizeWidget.visible = false
}
id : sizeWidget
anchors.centerIn: parent
border.width: 1
border.color: "black"
property int minWidth: 70
property int minHeight: 30
width: vtWidget.width * 0.1 < minWidth ? minWidth : vtWidget.width * 0.1
height: vtWidget.height * 0.1 < minHeight ? minHeight : vtWidget.height * 0.1
color: "white"
visible : false
focus : false
Text {
id : sizeWidgetText
anchors.centerIn: parent
font.pointSize: vtWidget.fontSize
text : "Size: " + session.pageColumnsCount.toString() + " x " + session.pageLineCount.toString()
}
}


Image {
id: backgroundImage
width: vtWidget.width
Expand Down Expand Up @@ -148,6 +177,15 @@ ContourTerminal
vbar.position = (vt.historyLineCount - vt.scrollOffset) / totalLineCount;
}

function updateSizeWidget() {
if (vtWidget.session.upTime > 1.0)
{
sizeWidget.visible = true
sizeWidgetTimer.running = true
sizeWidgetText.text = "Size: " + vtWidget.session.pageColumnsCount.toString() + " x " + vtWidget.session.pageLineCount.toString()
}
}

onTerminated: {
console.log("Client process terminated. Closing the window.");
Window.window.close(); // https://stackoverflow.com/a/53829662/386670
Expand All @@ -159,6 +197,12 @@ ContourTerminal
bellSoundEffect.play()
}

function updateFontSize() {
sizeWidgetText.font.pointSize = vtWidget.session.fontSize
sizeWidget.minWidth = vtWidget.session.fontSize * 10
sizeWidget.minHeight = vtWidget.session.fontSize * 3
}

onSessionChanged: (s) => {
let vt = vtWidget.session;

Expand All @@ -181,6 +225,10 @@ ContourTerminal
// Update the scrollbar's position whenever the VT's viewport changes.
vt.onScrollOffsetChanged.connect(updateScrollBarPosition);

// Update font size of elements
vt.fontSizeChanged.connect(updateFontSize);
updateFontSize();

// Permission-wall related hooks.
vt.requestPermissionForFontChange.connect(requestFontChangeDialog.open);
vt.requestPermissionForBufferCapture.connect(requestBufferCaptureDialog.open);
Expand Down
2 changes: 2 additions & 0 deletions src/contour/ui.template/main.qml.in
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,13 @@ ApplicationWindow
onWidthChanged : function() {
vtui.width = width
vtui.session.requestWindowResize(width, height)
vtui.updateSizeWidget()
}

onHeightChanged: function() {
vtui.height = height
vtui.session.requestWindowResize(width, height)
vtui.updateSizeWidget()
}

function applyOpacity() {
Expand Down

0 comments on commit 7d271cc

Please sign in to comment.