diff --git a/src/contour/TerminalSession.cpp b/src/contour/TerminalSession.cpp index 27de7de8c0..b491048608 100644 --- a/src/contour/TerminalSession.cpp +++ b/src/contour/TerminalSession.cpp @@ -833,7 +833,8 @@ void TerminalSession::sendKeyEvent(Key key, Modifiers modifiers, KeyboardEventTy if (auto const* actions = config::apply(_config.inputMappings.value().keyMappings, key, modifiers, matchModeFlags())) { - executeAllActions(*actions); + if (eventType == KeyboardEventType::Press) + executeAllActions(*actions); return; } } @@ -868,7 +869,8 @@ void TerminalSession::sendCharEvent( config::apply(_config.inputMappings.value().charMappings, value, modifiers, matchModeFlags()); actions && !_terminal.inputHandler().isEditingSearch()) { - executeAllActions(*actions); + if (eventType == KeyboardEventType::Press) + executeAllActions(*actions); return; } } @@ -1440,7 +1442,7 @@ bool TerminalSession::operator()(actions::CreateNewTab) bool TerminalSession::operator()(actions::CloseTab) { - emit closeTab(); + _manager->closeTab(); return true; } @@ -1464,25 +1466,25 @@ bool TerminalSession::operator()(actions::MoveTabToRight) bool TerminalSession::operator()(actions::SwitchToTab const& event) { - emit switchToTab(event.position); + _manager->switchToTab(event.position); return true; } bool TerminalSession::operator()(actions::SwitchToPreviousTab) { - emit switchToPreviousTab(); + _manager->switchToPreviousTab(); return true; } bool TerminalSession::operator()(actions::SwitchToTabLeft) { - emit switchToTabLeft(); + _manager->switchToTabLeft(); return true; } bool TerminalSession::operator()(actions::SwitchToTabRight) { - emit switchToTabRight(); + _manager->switchToTabRight(); return true; } diff --git a/src/contour/TerminalSessionManager.cpp b/src/contour/TerminalSessionManager.cpp index 7a5c92aaaf..06171a2c89 100644 --- a/src/contour/TerminalSessionManager.cpp +++ b/src/contour/TerminalSessionManager.cpp @@ -42,11 +42,6 @@ std::unique_ptr TerminalSessionManager::createPty(std::optionalescapeSandbox.value()); } -TerminalSession* TerminalSessionManager::createSession() -{ - return activateSession(createSessionInBackground()); -} - TerminalSession* TerminalSessionManager::createSessionInBackground() { // TODO: Remove dependency on app-knowledge and pass shell / terminal-size instead. @@ -101,9 +96,6 @@ void TerminalSessionManager::setSession(size_t index) Require(index <= _sessions.size()); managerLog()(std::format("SET SESSION: index: {}, _sessions.size(): {}", index, _sessions.size())); - if (!isAllowedToChangeTabs()) - return; - if (index < _sessions.size()) activateSession(_sessions[index]); else @@ -126,7 +118,6 @@ TerminalSession* TerminalSessionManager::activateSession(TerminalSession* sessio _previousActiveSession = _activeSession; _activeSession = session; - _lastTabChange = std::chrono::steady_clock::now(); updateStatusLine(); if (display) @@ -150,9 +141,9 @@ TerminalSession* TerminalSessionManager::activateSession(TerminalSession* sessio return session; } -void TerminalSessionManager::addSession() +TerminalSession* TerminalSessionManager::createSession() { - activateSession(createSessionInBackground(), true /*force resize on before display-attach*/); + return activateSession(createSessionInBackground(), true /*force resize on before display-attach*/); } void TerminalSessionManager::switchToPreviousTab() @@ -161,9 +152,6 @@ void TerminalSessionManager::switchToPreviousTab() getSessionIndexOf(_activeSession).value_or(-1), getSessionIndexOf(_previousActiveSession).value_or(-1)); - if (!isAllowedToChangeTabs()) - return; - activateSession(_previousActiveSession); } @@ -207,9 +195,6 @@ void TerminalSessionManager::switchToTab(int position) position - 1, _sessions.size()); - if (!isAllowedToChangeTabs()) - return; - if (1 <= position && position <= static_cast(_sessions.size())) activateSession(_sessions[position - 1]); } @@ -272,9 +257,6 @@ void TerminalSessionManager::removeSession(TerminalSession& thatSession) { managerLog()("REMOVE SESSION: session: {}, _sessions.size(): {}", (void*) &thatSession, _sessions.size()); - if (!isAllowedToChangeTabs()) - return; - if (&thatSession == _activeSession && _previousActiveSession) activateSession(_previousActiveSession); diff --git a/src/contour/TerminalSessionManager.h b/src/contour/TerminalSessionManager.h index 42c690d563..cfc54b64c0 100644 --- a/src/contour/TerminalSessionManager.h +++ b/src/contour/TerminalSessionManager.h @@ -7,7 +7,6 @@ #include #include -#include #include namespace contour @@ -31,16 +30,15 @@ class TerminalSessionManager: public QAbstractListModel contour::TerminalSession* activateSession(TerminalSession* session, bool isNewSession = false); Q_INVOKABLE contour::TerminalSession* createSession(); - Q_INVOKABLE void addSession(); - Q_INVOKABLE void switchToPreviousTab(); - Q_INVOKABLE void switchToTabLeft(); - Q_INVOKABLE void switchToTabRight(); - Q_INVOKABLE void switchToTab(int position); - Q_INVOKABLE void closeTab(); - Q_INVOKABLE void moveTabTo(int position); - Q_INVOKABLE void moveTabToLeft(TerminalSession* session); - Q_INVOKABLE void moveTabToRight(TerminalSession* session); + void switchToPreviousTab(); + void switchToTabLeft(); + void switchToTabRight(); + void switchToTab(int position); + void closeTab(); + void moveTabTo(int position); + void moveTabToLeft(TerminalSession* session); + void moveTabToRight(TerminalSession* session); void setSession(size_t index); @@ -82,25 +80,11 @@ class TerminalSessionManager: public QAbstractListModel }); } - [[nodiscard]] bool isAllowedToChangeTabs() const - { - // QML for some reason sends multiple signals requests in a row, so we need to ignore them. - auto now = std::chrono::steady_clock::now(); - if (abs(now - _lastTabChange) < _timeBetweenTabSwitches) - { - managerLog()("Ignoring change request due to too frequent change requests."); - return false; - } - return true; - } - ContourGuiApp& _app; std::chrono::seconds _earlyExitThreshold; TerminalSession* _activeSession = nullptr; TerminalSession* _previousActiveSession = nullptr; std::vector _sessions; - std::chrono::time_point _lastTabChange; - std::chrono::milliseconds _timeBetweenTabSwitches { 50 }; }; } // namespace contour diff --git a/src/contour/ui.template/Terminal.qml.in b/src/contour/ui.template/Terminal.qml.in index 15d3aebfc0..a2a823c4b7 100644 --- a/src/contour/ui.template/Terminal.qml.in +++ b/src/contour/ui.template/Terminal.qml.in @@ -16,18 +16,6 @@ ContourTerminal session: terminalSessions.createSession() - signal switchToTab(int index) - signal switchToPreviousTab - signal switchToTabLeft - signal switchToTabRight - signal closeTab - - onSwitchToPreviousTab: terminalSessions.switchToPreviousTab() - onSwitchToTabLeft: terminalSessions.switchToTabLeft() - onSwitchToTabRight: terminalSessions.switchToTabRight() - onCloseTab: terminalSessions.closeTab() - onSwitchToTab: (i) => terminalSessions.switchToTab(i) - Rectangle { id : backgroundColor anchors.centerIn: parent @@ -288,12 +276,5 @@ ContourTerminal vt.requestPermissionForPasteLargeFile.connect(requestLargeFilePaste.open); forceActiveFocus(); - // TAB handling - vt.createNewTab.connect(onCreateNewTab); - vt.closeTab.connect(closeTab); - vt.switchToTab.connect(switchToTab); - vt.switchToPreviousTab.connect(switchToPreviousTab); - vt.switchToTabLeft.connect(switchToTabLeft); - vt.switchToTabRight.connect(switchToTabRight); } }