support_common.cpp 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. /*
  2. This file is part of Telegram Desktop,
  3. the official desktop application for the Telegram messaging service.
  4. For license and copyright information please follow this link:
  5. https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
  6. */
  7. #include "support/support_common.h"
  8. #include "core/shortcuts.h"
  9. namespace Support {
  10. bool HandleSwitch(Qt::KeyboardModifiers modifiers) {
  11. return !(modifiers & Qt::ShiftModifier)
  12. || (!(modifiers & Qt::ControlModifier)
  13. && !(modifiers & Qt::MetaModifier));
  14. }
  15. Qt::KeyboardModifiers SkipSwitchModifiers() {
  16. return Qt::ControlModifier | Qt::ShiftModifier;
  17. }
  18. std::optional<Shortcuts::Command> GetSwitchCommand(SwitchSettings value) {
  19. switch (value) {
  20. case SwitchSettings::Next:
  21. return Shortcuts::Command::ChatNext;
  22. case SwitchSettings::Previous:
  23. return Shortcuts::Command::ChatPrevious;
  24. }
  25. return std::nullopt;
  26. }
  27. FnMut<bool()> GetSwitchMethod(SwitchSettings value) {
  28. const auto command = GetSwitchCommand(value);
  29. return command ? Shortcuts::RequestHandler(*command) : nullptr;
  30. }
  31. } // namespace Support