global_shortcuts.h 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // This file is part of Desktop App Toolkit,
  2. // a set of libraries for developing nice desktop applications.
  3. //
  4. // For license and copyright information please follow this link:
  5. // https://github.com/desktop-app/legal/blob/master/LEGAL
  6. //
  7. #pragma once
  8. namespace base {
  9. class GlobalShortcutValue {
  10. public:
  11. [[nodiscard]] virtual QString toDisplayString() = 0;
  12. [[nodiscard]] virtual QByteArray serialize() = 0;
  13. virtual ~GlobalShortcutValue() = default;
  14. };
  15. using GlobalShortcut = std::shared_ptr<GlobalShortcutValue>;
  16. // Callbacks are called from unspecified thread.
  17. class GlobalShortcutManager {
  18. public:
  19. virtual void startRecording(
  20. Fn<void(GlobalShortcut)> progress,
  21. Fn<void(GlobalShortcut)> done) = 0;
  22. virtual void stopRecording() = 0;
  23. virtual void startWatching(
  24. GlobalShortcut shortcut,
  25. Fn<void(bool pressed)> callback) = 0;
  26. virtual void stopWatching(GlobalShortcut shortcut) = 0;
  27. [[nodiscard]] virtual GlobalShortcut shortcutFromSerialized(
  28. QByteArray serialized) = 0;
  29. virtual ~GlobalShortcutManager() = default;
  30. };
  31. [[nodiscard]] bool GlobalShortcutsAvailable();
  32. [[nodiscard]] bool GlobalShortcutsAllowed();
  33. [[nodiscard]] std::unique_ptr<GlobalShortcutManager> CreateGlobalShortcutManager();
  34. } // namespace base