Compare commits

...

1 Commits

Author SHA1 Message Date
Jesse Qu 8c372a136a experiment for macOS 2025-09-15 20:07:42 +08:00
3 changed files with 12 additions and 10 deletions

View File

@ -28,3 +28,5 @@ include(cmake/library.cmake)
include(cmake/platform.cmake)
include(cmake/qt.cmake)
include(cmake/pkg-config.cmake)
add_subdirectory(example)

View File

@ -1,11 +1,7 @@
cmake_minimum_required(VERSION 2.8.8)
project(qxtglobalshortcut_test)
find_package(qxtglobalshortcut REQUIRED)
find_package(Qt6 REQUIRED COMPONENTS Widgets)
set(bin qxtglobalshortcut_test)
add_executable(${bin} src/main.cpp)
include_directories(${PROJECT_BINARY_DIR}/exports)
target_link_libraries(${bin} qxtglobalshortcut)
target_link_libraries(${bin} Qt6::Widgets)
add_executable(qxtglobalshortcut_test src/main.cpp)
target_link_libraries(qxtglobalshortcut_test qxtglobalshortcut Qt6::Widgets)

View File

@ -34,6 +34,7 @@
#include <QHash>
#include <QtDebug>
#include <QApplication>
#include <QTextStream>
using Identifier = QPair<uint, uint>;
static QMap<quint32, EventHotKeyRef> keyRefs;
@ -43,6 +44,9 @@ static bool qxt_mac_handler_installed = false;
OSStatus qxt_mac_handle_hot_key(EventHandlerCallRef nextHandler, EventRef event, void* data)
{
QTextStream out(stdout);
out << QLatin1String("Shortcut maybe pressed!") << Qt::endl;
Q_UNUSED(nextHandler);
Q_UNUSED(data);
if (GetEventClass(event) == kEventClassKeyboard && GetEventKind(event) == kEventHotKeyPressed)
@ -359,7 +363,7 @@ bool QxtGlobalShortcutPrivate::registerShortcut(quint32 nativeKey, quint32 nativ
EventTypeSpec t;
t.eventClass = kEventClassKeyboard;
t.eventKind = kEventHotKeyPressed;
InstallApplicationEventHandler(&qxt_mac_handle_hot_key, 1, &t, nullptr, nullptr);
// InstallApplicationEventHandler(&qxt_mac_handle_hot_key, 1, &t, nullptr, nullptr);
}
EventHotKeyID keyID;
@ -367,7 +371,7 @@ bool QxtGlobalShortcutPrivate::registerShortcut(quint32 nativeKey, quint32 nativ
keyID.id = ++hotKeySerial;
EventHotKeyRef ref = 0;
bool rv = !RegisterEventHotKey(nativeKey, nativeMods, keyID, GetApplicationEventTarget(), 0, &ref);
bool rv = true; // = !RegisterEventHotKey(nativeKey, nativeMods, keyID, GetApplicationEventTarget(), 0, &ref);
if (rv)
{
keyIDs.insert(Identifier(nativeMods, nativeKey), keyID.id);