diff --git a/Telegram/SourceFiles/core/shortcuts.cpp b/Telegram/SourceFiles/core/shortcuts.cpp index 84b35fbc5f..2c6dbcfaa4 100644 --- a/Telegram/SourceFiles/core/shortcuts.cpp +++ b/Telegram/SourceFiles/core/shortcuts.cpp @@ -37,6 +37,12 @@ const auto MediaCommands = base::flat_set{ Command::MediaNext, }; +const auto SupportCommands = base::flat_set{ + Command::SupportReloadTemplates, + Command::SupportToggleMuted, + Command::SupportScrollToCurrent, +}; + const auto CommandByName = base::flat_map{ { qsl("close_telegram") , Command::Close }, { qsl("lock_telegram") , Command::Lock }, @@ -86,6 +92,7 @@ public: std::optional lookup(int shortcutId) const; void toggleMedia(bool toggled); + void toggleSupport(bool toggled); const QStringList &errors() const; @@ -104,6 +111,7 @@ private: base::flat_map _commandByShortcutId; base::flat_set _mediaShortcuts; + base::flat_set _supportShortcuts; }; @@ -168,6 +176,7 @@ void Manager::clear() { _shortcuts.clear(); _commandByShortcutId.clear(); _mediaShortcuts.clear(); + _supportShortcuts.clear(); } const QStringList &Manager::errors() const { @@ -187,6 +196,12 @@ void Manager::toggleMedia(bool toggled) { } } +void Manager::toggleSupport(bool toggled) { + for (const auto shortcut : _supportShortcuts) { + shortcut->setEnabled(toggled); + } +} + bool Manager::readCustomFile() { // read custom shortcuts from file if it exists or write an empty custom shortcuts file QFile file(CustomFilePath()); @@ -352,7 +367,8 @@ void Manager::set(const QString &keys, Command command) { shortcut->setAutoRepeat(false); } const auto isMediaShortcut = MediaCommands.contains(command); - if (isMediaShortcut) { + const auto isSupportShortcut = SupportCommands.contains(command); + if (isMediaShortcut || isSupportShortcut) { shortcut->setEnabled(false); } const auto id = shortcut->id(); @@ -370,6 +386,9 @@ void Manager::set(const QString &keys, Command command) { if (isMediaShortcut) { _mediaShortcuts.emplace(i->second.get()); } + if (isSupportShortcut) { + _supportShortcuts.emplace(i->second.get()); + } } void Manager::remove(const QString &keys) { @@ -394,6 +413,7 @@ void Manager::unregister(base::unique_qptr shortcut) { if (shortcut) { _commandByShortcutId.erase(shortcut->id()); _mediaShortcuts.erase(shortcut.get()); + _supportShortcuts.erase(shortcut.get()); } } @@ -451,14 +471,13 @@ bool HandleEvent(not_null event) { return false; } -void EnableMediaShortcuts() { - Data.toggleMedia(true); - Platform::SetWatchingMediaKeys(true); +void ToggleMediaShortcuts(bool toggled) { + Data.toggleMedia(toggled); + Platform::SetWatchingMediaKeys(toggled); } -void DisableMediaShortcuts() { - Data.toggleMedia(false); - Platform::SetWatchingMediaKeys(false); +void ToggleSupportShortcuts(bool toggled) { + Data.toggleSupport(toggled); } void Finish() { diff --git a/Telegram/SourceFiles/core/shortcuts.h b/Telegram/SourceFiles/core/shortcuts.h index b818eeeea4..ac7e1db564 100644 --- a/Telegram/SourceFiles/core/shortcuts.h +++ b/Telegram/SourceFiles/core/shortcuts.h @@ -65,7 +65,10 @@ const QStringList &Errors(); // Media shortcuts are not enabled by default, because other // applications also use them. They are enabled only when // the in-app player is active and disabled back after. -void EnableMediaShortcuts(); -void DisableMediaShortcuts(); +void ToggleMediaShortcuts(bool toggled); + +// Support shortcuts are not enabled by default, because they +// have some conflicts with default input shortcuts, like Ctrl+Delete. +void ToggleSupportShortcuts(bool toggled); } // namespace Shortcuts diff --git a/Telegram/SourceFiles/mainwidget.cpp b/Telegram/SourceFiles/mainwidget.cpp index e732fd3e68..8a015b2118 100644 --- a/Telegram/SourceFiles/mainwidget.cpp +++ b/Telegram/SourceFiles/mainwidget.cpp @@ -1210,7 +1210,7 @@ void MainWidget::closeBothPlayers() { Media::Player::instance()->stop(AudioMsgId::Type::Voice); Media::Player::instance()->stop(AudioMsgId::Type::Song); - Shortcuts::DisableMediaShortcuts(); + Shortcuts::ToggleMediaShortcuts(false); } void MainWidget::createPlayer() { @@ -1232,7 +1232,7 @@ void MainWidget::createPlayer() { if (_a_show.animating()) { _player->show(anim::type::instant); _player->setVisible(false); - Shortcuts::EnableMediaShortcuts(); + Shortcuts::ToggleMediaShortcuts(true); } else { _player->hide(anim::type::instant); } @@ -1242,7 +1242,7 @@ void MainWidget::createPlayer() { _player->show(anim::type::normal); _playerHeight = _contentScrollAddToY = _player->contentHeight(); updateControlsGeometry(); - Shortcuts::EnableMediaShortcuts(); + Shortcuts::ToggleMediaShortcuts(true); } } } diff --git a/Telegram/SourceFiles/messenger.cpp b/Telegram/SourceFiles/messenger.cpp index 85cc096596..2e61741882 100644 --- a/Telegram/SourceFiles/messenger.cpp +++ b/Telegram/SourceFiles/messenger.cpp @@ -593,6 +593,8 @@ void Messenger::startLocalStorage() { _mtproto->requestConfig(); } Platform::SetApplicationIcon(Window::CreateIcon()); + Shortcuts::ToggleSupportShortcuts( + _authSession && _authSession->supportMode()); }); }); }