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 9 namespace base { 10 11 class GlobalShortcutValue { 12 public: 13 [[nodiscard]] virtual QString toDisplayString() = 0; 14 [[nodiscard]] virtual QByteArray serialize() = 0; 15 16 virtual ~GlobalShortcutValue() = default; 17 }; 18 19 using GlobalShortcut = std::shared_ptr<GlobalShortcutValue>; 20 21 // Callbacks are called from unspecified thread. 22 class GlobalShortcutManager { 23 public: 24 virtual void startRecording( 25 Fn<void(GlobalShortcut)> progress, 26 Fn<void(GlobalShortcut)> done) = 0; 27 virtual void stopRecording() = 0; 28 virtual void startWatching( 29 GlobalShortcut shortcut, 30 Fn<void(bool pressed)> callback) = 0; 31 virtual void stopWatching(GlobalShortcut shortcut) = 0; 32 33 [[nodiscard]] virtual GlobalShortcut shortcutFromSerialized( 34 QByteArray serialized) = 0; 35 36 virtual ~GlobalShortcutManager() = default; 37 }; 38 39 [[nodiscard]] bool GlobalShortcutsAvailable(); 40 [[nodiscard]] bool GlobalShortcutsAllowed(); 41 [[nodiscard]] std::unique_ptr<GlobalShortcutManager> CreateGlobalShortcutManager(); 42 43 } // namespace base 44