mirror of
https://github.com/vale981/tdesktop
synced 2025-03-05 09:41:41 -05:00
parent
980d20473a
commit
e876c9b6a6
4 changed files with 36 additions and 12 deletions
|
@ -37,6 +37,12 @@ const auto MediaCommands = base::flat_set<Command>{
|
|||
Command::MediaNext,
|
||||
};
|
||||
|
||||
const auto SupportCommands = base::flat_set<Command>{
|
||||
Command::SupportReloadTemplates,
|
||||
Command::SupportToggleMuted,
|
||||
Command::SupportScrollToCurrent,
|
||||
};
|
||||
|
||||
const auto CommandByName = base::flat_map<QString, Command>{
|
||||
{ qsl("close_telegram") , Command::Close },
|
||||
{ qsl("lock_telegram") , Command::Lock },
|
||||
|
@ -86,6 +92,7 @@ public:
|
|||
|
||||
std::optional<Command> lookup(int shortcutId) const;
|
||||
void toggleMedia(bool toggled);
|
||||
void toggleSupport(bool toggled);
|
||||
|
||||
const QStringList &errors() const;
|
||||
|
||||
|
@ -104,6 +111,7 @@ private:
|
|||
base::flat_map<int, Command> _commandByShortcutId;
|
||||
|
||||
base::flat_set<QShortcut*> _mediaShortcuts;
|
||||
base::flat_set<QShortcut*> _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<QShortcut> shortcut) {
|
|||
if (shortcut) {
|
||||
_commandByShortcutId.erase(shortcut->id());
|
||||
_mediaShortcuts.erase(shortcut.get());
|
||||
_supportShortcuts.erase(shortcut.get());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -451,14 +471,13 @@ bool HandleEvent(not_null<QShortcutEvent*> 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() {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -593,6 +593,8 @@ void Messenger::startLocalStorage() {
|
|||
_mtproto->requestConfig();
|
||||
}
|
||||
Platform::SetApplicationIcon(Window::CreateIcon());
|
||||
Shortcuts::ToggleSupportShortcuts(
|
||||
_authSession && _authSession->supportMode());
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue