Skip to content

Commit 1636a3f

Browse files
committed
Add platform shortcut manager implementations
Introduce platform-specific ShortcutManager implementations and refactor core API. - Add native implementations for Linux (X11), macOS (Carbon/Carbon HotKey API), and Windows (RegisterHotKey) including accelerator parsing, registration/unregistration, and event monitoring/threads. - Add stub implementations for Android, iOS, and OHOS to provide platform placeholders. - Expose a PIMPL interface in shortcut_manager.h (Impl) and add EmitShortcutActivated() for platform backends to notify the manager. - Update shortcut_manager.cpp to use the PIMPL idiom, switch mutex guards to std::unique_lock where unlocking/relocking is required, remove the internal default Impl, and add EmitShortcutActivated implementation. - Update CMakeLists.txt to link the Carbon framework on Apple builds. The change centralizes platform differences behind the Impl interface and implements full hotkey handling on major desktop platforms while providing no-op stubs for mobile/embedded platforms.
1 parent 92c305e commit 1636a3f

File tree

9 files changed

+1122
-72
lines changed

9 files changed

+1122
-72
lines changed

src/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ elseif (CMAKE_SYSTEM_NAME STREQUAL "Linux")
7676
target_link_libraries(nativeapi PUBLIC PkgConfig::GTK PkgConfig::X11 PkgConfig::XI PkgConfig::AYATANA_APPINDICATOR pthread)
7777
elseif(APPLE)
7878
target_link_libraries(nativeapi PUBLIC "-framework Cocoa")
79+
target_link_libraries(nativeapi PUBLIC "-framework Carbon")
7980
target_compile_options(nativeapi PRIVATE "-x" "objective-c++")
8081
elseif(CMAKE_SYSTEM_NAME STREQUAL "OHOS")
8182
target_link_libraries(nativeapi PUBLIC hilog_ndk.z)
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#include "../../shortcut_manager.h"
2+
3+
namespace nativeapi {
4+
5+
class ShortcutManagerImpl final : public ShortcutManager::Impl {
6+
public:
7+
explicit ShortcutManagerImpl(ShortcutManager* manager) : manager_(manager) {}
8+
~ShortcutManagerImpl() override = default;
9+
10+
bool IsSupported() override { return false; }
11+
bool RegisterShortcut(const std::shared_ptr<Shortcut>& /*shortcut*/) override { return false; }
12+
bool UnregisterShortcut(const std::shared_ptr<Shortcut>& /*shortcut*/) override { return false; }
13+
void SetupEventMonitoring() override {}
14+
void CleanupEventMonitoring() override {}
15+
16+
private:
17+
ShortcutManager* manager_;
18+
};
19+
20+
ShortcutManager::ShortcutManager()
21+
: pimpl_(std::make_unique<ShortcutManagerImpl>(this)), next_shortcut_id_(1), enabled_(true) {}
22+
23+
ShortcutManager::~ShortcutManager() {
24+
UnregisterAll();
25+
}
26+
27+
} // namespace nativeapi
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#include "../../shortcut_manager.h"
2+
3+
namespace nativeapi {
4+
5+
class ShortcutManagerImpl final : public ShortcutManager::Impl {
6+
public:
7+
explicit ShortcutManagerImpl(ShortcutManager* manager) : manager_(manager) {}
8+
~ShortcutManagerImpl() override = default;
9+
10+
bool IsSupported() override { return false; }
11+
bool RegisterShortcut(const std::shared_ptr<Shortcut>& /*shortcut*/) override { return false; }
12+
bool UnregisterShortcut(const std::shared_ptr<Shortcut>& /*shortcut*/) override { return false; }
13+
void SetupEventMonitoring() override {}
14+
void CleanupEventMonitoring() override {}
15+
16+
private:
17+
ShortcutManager* manager_;
18+
};
19+
20+
ShortcutManager::ShortcutManager()
21+
: pimpl_(std::make_unique<ShortcutManagerImpl>(this)), next_shortcut_id_(1), enabled_(true) {}
22+
23+
ShortcutManager::~ShortcutManager() {
24+
UnregisterAll();
25+
}
26+
27+
} // namespace nativeapi

0 commit comments

Comments
 (0)