mirror of
https://github.com/Skycoder42/QHotkey.git
synced 2026-11-19 12:49:58 +03:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4e3a244d87 | ||
|
|
d7b2589855 | ||
|
|
6c0e98492c | ||
|
|
8f90bdf90c | ||
|
|
bb63025268 | ||
|
|
b519155479 | ||
|
|
cd72a01327 | ||
|
|
34777f2e91 | ||
|
|
94efd5fb61 | ||
|
|
6b1c6f1f4e | ||
|
|
c501fbbada | ||
|
|
52e25acf22 | ||
|
|
308c96c28f |
@@ -14,10 +14,10 @@ jobs:
|
|||||||
build:
|
build:
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
qt_version: [5.12.11, 5.15.2, 6.2.0]
|
qt_version: [5.12.12, 5.15.2, 6.2.2]
|
||||||
platform: [ubuntu-20.04, windows-latest, macos-latest]
|
platform: [ubuntu-20.04, windows-latest, macos-latest]
|
||||||
include:
|
include:
|
||||||
- qt_version: 6.2.0
|
- qt_version: 6.2.2
|
||||||
additional_arguments: -D QT_DEFAULT_MAJOR_VERSION=6
|
additional_arguments: -D QT_DEFAULT_MAJOR_VERSION=6
|
||||||
- platform: ubuntu-20.04
|
- platform: ubuntu-20.04
|
||||||
make: make
|
make: make
|
||||||
@@ -41,31 +41,16 @@ jobs:
|
|||||||
uses: actions/checkout@v2.3.4
|
uses: actions/checkout@v2.3.4
|
||||||
|
|
||||||
- name: Install Qt
|
- name: Install Qt
|
||||||
uses: jurplel/install-qt-action@v2.14.0
|
uses: jurplel/install-qt-action@v3.3.0
|
||||||
with:
|
with:
|
||||||
version: ${{ matrix.qt_version }}
|
version: ${{ matrix.qt_version }}
|
||||||
|
|
||||||
- name: Build with CMake as static
|
- name: Build with CMake as static
|
||||||
run: |
|
run: |
|
||||||
cmake . -D QHOTKEY_EXAMPLES=ON ${{ matrix.additional_arguments }}
|
cmake . -D QHOTKEY_EXAMPLES=ON -D CMAKE_OSX_ARCHITECTURES="x86_64" ${{ matrix.additional_arguments }}
|
||||||
cmake --build .
|
cmake --build .
|
||||||
|
|
||||||
- name: Build with CMake as shared
|
- name: Build with CMake as shared
|
||||||
run: |
|
run: |
|
||||||
cmake . -D BUILD_SHARED_LIBS=ON -D QHOTKEY_EXAMPLES=ON ${{ matrix.additional_arguments }}
|
cmake . -D BUILD_SHARED_LIBS=ON -D QHOTKEY_EXAMPLES=ON -D CMAKE_OSX_ARCHITECTURES="x86_64" ${{ matrix.additional_arguments }}
|
||||||
cmake --build .
|
cmake --build .
|
||||||
|
|
||||||
- name: Setup MSVC environment for QMake
|
|
||||||
uses: ilammy/msvc-dev-cmd@v1
|
|
||||||
|
|
||||||
- name: Build with QMake as static
|
|
||||||
working-directory: HotkeyTest
|
|
||||||
run: |
|
|
||||||
qmake
|
|
||||||
${{ matrix.make }}
|
|
||||||
|
|
||||||
- name: Build with QMake as shared
|
|
||||||
working-directory: HotkeyTest
|
|
||||||
run: |
|
|
||||||
qmake "DEFINES+=QHOTKEY_SHARED QHOTKEY_LIBRARY"
|
|
||||||
${{ matrix.make }}
|
|
||||||
|
|||||||
+23
-2
@@ -1,6 +1,10 @@
|
|||||||
cmake_minimum_required(VERSION 3.1)
|
cmake_minimum_required(VERSION 3.10)
|
||||||
|
|
||||||
project(qhotkey VERSION 1.5.0 LANGUAGES CXX)
|
project(qhotkey
|
||||||
|
VERSION 1.5.0
|
||||||
|
DESCRIPTION "Global hotkey library for Qt software"
|
||||||
|
HOMEPAGE_URL "https://skycoder42.github.io/QHotkey/"
|
||||||
|
LANGUAGES CXX)
|
||||||
|
|
||||||
option(QHOTKEY_EXAMPLES "Build examples" OFF)
|
option(QHOTKEY_EXAMPLES "Build examples" OFF)
|
||||||
option(QHOTKEY_INSTALL "Enable install rule" ON)
|
option(QHOTKEY_INSTALL "Enable install rule" ON)
|
||||||
@@ -18,10 +22,27 @@ else()
|
|||||||
find_package(Qt${QT_DEFAULT_MAJOR_VERSION} COMPONENTS Core Gui REQUIRED)
|
find_package(Qt${QT_DEFAULT_MAJOR_VERSION} COMPONENTS Core Gui REQUIRED)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
# General settings
|
||||||
|
set(CPACK_PACKAGE_VENDOR "Skycoder42")
|
||||||
|
set(CPACK_PACKAGE_CONTACT "Shatur")
|
||||||
|
set(CPACK_RESOURCE_FILE_README "${CMAKE_SOURCE_DIR}/README.md")
|
||||||
|
# CPACK: DEB Specific Settings
|
||||||
|
set(CPACK_DEBIAN_PACKAGE_NAME "libqhotkey")
|
||||||
|
set(CPACK_DEBIAN_PACKAGE_SECTION "Libraries")
|
||||||
|
# Set dependencies
|
||||||
|
if(QT_DEFAULT_MAJOR_VERSION EQUAL 6)
|
||||||
|
set(CPACK_DEBIAN_PACKAGE_DEPENDS "libqt6x11extras6 (>= 6.2.0)")
|
||||||
|
else()
|
||||||
|
set(CPACK_DEBIAN_PACKAGE_DEPENDS "libqt5x11extras5 (>= 5.15.2)")
|
||||||
|
endif()
|
||||||
|
include(CPack)
|
||||||
|
|
||||||
add_library(qhotkey QHotkey/qhotkey.cpp)
|
add_library(qhotkey QHotkey/qhotkey.cpp)
|
||||||
add_library(QHotkey::QHotkey ALIAS qhotkey)
|
add_library(QHotkey::QHotkey ALIAS qhotkey)
|
||||||
target_link_libraries(qhotkey PUBLIC Qt${QT_DEFAULT_MAJOR_VERSION}::Core Qt${QT_DEFAULT_MAJOR_VERSION}::Gui)
|
target_link_libraries(qhotkey PUBLIC Qt${QT_DEFAULT_MAJOR_VERSION}::Core Qt${QT_DEFAULT_MAJOR_VERSION}::Gui)
|
||||||
|
|
||||||
|
target_compile_definitions(qhotkey PRIVATE QT_NO_SIGNALS_SLOTS_KEYWORDS)
|
||||||
|
|
||||||
if(BUILD_SHARED_LIBS)
|
if(BUILD_SHARED_LIBS)
|
||||||
target_compile_definitions(qhotkey PRIVATE QHOTKEY_LIBRARY)
|
target_compile_definitions(qhotkey PRIVATE QHOTKEY_LIBRARY)
|
||||||
target_compile_definitions(qhotkey PUBLIC QHOTKEY_SHARED)
|
target_compile_definitions(qhotkey PUBLIC QHOTKEY_SHARED)
|
||||||
|
|||||||
@@ -1,21 +0,0 @@
|
|||||||
#-------------------------------------------------
|
|
||||||
#
|
|
||||||
# Project created by QtCreator 2016-02-05T22:01:03
|
|
||||||
#
|
|
||||||
#-------------------------------------------------
|
|
||||||
|
|
||||||
QT += core gui
|
|
||||||
|
|
||||||
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
|
|
||||||
|
|
||||||
TARGET = HotkeyTest
|
|
||||||
TEMPLATE = app
|
|
||||||
|
|
||||||
include(../qhotkey.pri)
|
|
||||||
|
|
||||||
SOURCES += main.cpp\
|
|
||||||
hottestwidget.cpp
|
|
||||||
|
|
||||||
HEADERS += hottestwidget.h
|
|
||||||
|
|
||||||
FORMS += hottestwidget.ui
|
|
||||||
@@ -769,7 +769,7 @@
|
|||||||
<item>
|
<item>
|
||||||
<widget class="QLabel" name="label_6">
|
<widget class="QLabel" name="label_6">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string><b>Testing:</b> Please press the combinations listed below to check whether they work properly or not. Everytime a shortcut is triggered, the checkbox will toggle it's value. Set the test active to begin.</string>
|
<string><b>Testing:</b> Please press the combinations listed below to check whether they work properly or not. Every time a shortcut is triggered, the checkbox will toggle it's value. Set the test active to begin.</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="wordWrap">
|
<property name="wordWrap">
|
||||||
<bool>true</bool>
|
<bool>true</bool>
|
||||||
@@ -927,7 +927,7 @@
|
|||||||
<item>
|
<item>
|
||||||
<widget class="QLabel" name="label_7">
|
<widget class="QLabel" name="label_7">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string><html><head/><body><p>This test was designed to try out multi-threaded shortcuts. The QHotkey class is completly <span style=" font-weight:600;">threadsafe</span>, but this test can help to see if it acutally works (It does).</p><p>If activated, <span style=" font-style:italic;">Hotkey 4 and Hotkey 5 </span>of the Playground will each run on their own thread. This means:</p><ul style="margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; -qt-list-indent: 1;"><li style=" margin-top:12px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" text-decoration: underline;">Mainthread:</span> Hotkey 1, 2, 3</li><li style=" margin-top:12px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" text-decoration: underline;">Second thread:</span> Hotkey 4</li><li style=" margin-top:12px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" text-decoration: underline;">Third thread:</span> Hotkey 5</li></ul><p><span style=" font-weight:600;">Note:</span> The two hotkeys will be moved to the threads. For simplicity-reasons, you can't move them back in this test (But its possible, just not done here). Restart the test to get them back.</p></body></html></string>
|
<string><html><head/><body><p>This test was designed to try out multi-threaded shortcuts. The QHotkey class is completely <span style=" font-weight:600;">threadsafe</span>, but this test can help to see if it actually works (It does).</p><p>If activated, <span style=" font-style:italic;">Hotkey 4 and Hotkey 5 </span>of the Playground will each run on their own thread. This means:</p><ul style="margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; -qt-list-indent: 1;"><li style=" margin-top:12px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" text-decoration: underline;">Mainthread:</span> Hotkey 1, 2, 3</li><li style=" margin-top:12px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" text-decoration: underline;">Second thread:</span> Hotkey 4</li><li style=" margin-top:12px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" text-decoration: underline;">Third thread:</span> Hotkey 5</li></ul><p><span style=" font-weight:600;">Note:</span> The two hotkeys will be moved to the threads. For simplicity-reasons, you can't move them back in this test (But its possible, just not done here). Restart the test to get them back.</p></body></html></string>
|
||||||
</property>
|
</property>
|
||||||
<property name="textFormat">
|
<property name="textFormat">
|
||||||
<enum>Qt::RichText</enum>
|
<enum>Qt::RichText</enum>
|
||||||
@@ -973,7 +973,7 @@
|
|||||||
<item>
|
<item>
|
||||||
<widget class="QLabel" name="label_8">
|
<widget class="QLabel" name="label_8">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string><html><head/><body><p>QHotkey allows you to set native shortcuts explicitly. These, of course, only work on the platform they were choosen for. All platform use special constants for their key codes and modifiers, which makes it pretty simple to use them from code. If you want to test them out here, google for the tables.</p><p>In most cases, you will not need to specify native shortcuts directly. However, as explaind on previos tabs, some shotcuts may not be creatable from Qt's key (e.g. Numblock numbers). In that case, you can set the directly.</p><p><span style=" text-decoration: underline;">Example: Ctrl+A</span></p><ul style="margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; -qt-list-indent: 1;"><li style=" margin-top:12px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-weight:600;">Windows:</span> Key: <span style=" font-style:italic;">0x0041</span>, Modifier: <span style=" font-style:italic;">0x0002</span></li><li style=" margin-top:12px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-weight:600;">X11:</span> Key: <span style=" font-style:italic;">0x0026</span>, Modifier: <span style=" font-style:italic;">0x0004</span></li><li style=" margin-top:12px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-weight:600;">OsX:</span> Key: <span style=" font-style:italic;">0x0000</span>, Modifier: <span style=" font-style:italic;">0x0100</span><span style=" text-decoration: underline;"><br/></span></li></ul></body></html></string>
|
<string><html><head/><body><p>QHotkey allows you to set native shortcuts explicitly. These, of course, only work on the platform they were chosen for. All platform use special constants for their key codes and modifiers, which makes it pretty simple to use them from code. If you want to test them out here, google for the tables.</p><p>In most cases, you will not need to specify native shortcuts directly. However, as explained on previous tabs, some shortcuts may not be creatable from Qt's key (e.g. Numblock numbers). In that case, you can set the directly.</p><p><span style=" text-decoration: underline;">Example: Ctrl+A</span></p><ul style="margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; -qt-list-indent: 1;"><li style=" margin-top:12px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-weight:600;">Windows:</span> Key: <span style=" font-style:italic;">0x0041</span>, Modifier: <span style=" font-style:italic;">0x0002</span></li><li style=" margin-top:12px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-weight:600;">X11:</span> Key: <span style=" font-style:italic;">0x0026</span>, Modifier: <span style=" font-style:italic;">0x0004</span></li><li style=" margin-top:12px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-weight:600;">OsX:</span> Key: <span style=" font-style:italic;">0x0000</span>, Modifier: <span style=" font-style:italic;">0x0100</span><span style=" text-decoration: underline;"><br/></span></li></ul></body></html></string>
|
||||||
</property>
|
</property>
|
||||||
<property name="wordWrap">
|
<property name="wordWrap">
|
||||||
<bool>true</bool>
|
<bool>true</bool>
|
||||||
|
|||||||
-10
@@ -1,10 +0,0 @@
|
|||||||
TEMPLATE = subdirs
|
|
||||||
|
|
||||||
SUBDIRS += \
|
|
||||||
HotkeyTest \
|
|
||||||
QHotkey
|
|
||||||
|
|
||||||
DISTFILES += README.md \
|
|
||||||
LICENSE \
|
|
||||||
doc/qhotkey.doxy \
|
|
||||||
doc/qhotkey.dox
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
TEMPLATE = lib
|
|
||||||
win32: CONFIG += dll
|
|
||||||
|
|
||||||
TARGET = QHotkey
|
|
||||||
VERSION = 1.5.0
|
|
||||||
|
|
||||||
include(../qhotkey.pri)
|
|
||||||
|
|
||||||
DEFINES += QHOTKEY_SHARED QHOTKEY_LIBRARY
|
|
||||||
|
|
||||||
# use INSTALL_ROOT to modify the install location
|
|
||||||
headers.files = $$PUBLIC_HEADERS
|
|
||||||
headers.path = $$[QT_INSTALL_HEADERS]
|
|
||||||
target.path = $$[QT_INSTALL_LIBS]
|
|
||||||
INSTALLS += target headers
|
|
||||||
|
|
||||||
+2
-2
@@ -88,7 +88,7 @@ public:
|
|||||||
//! Get the current native shortcut
|
//! Get the current native shortcut
|
||||||
NativeShortcut currentNativeShortcut() const;
|
NativeShortcut currentNativeShortcut() const;
|
||||||
|
|
||||||
public slots:
|
public Q_SLOTS:
|
||||||
//! @writeAcFn{QHotkey::registered}
|
//! @writeAcFn{QHotkey::registered}
|
||||||
bool setRegistered(bool registered);
|
bool setRegistered(bool registered);
|
||||||
|
|
||||||
@@ -102,7 +102,7 @@ public slots:
|
|||||||
//! Set this hotkey to a native shortcut
|
//! Set this hotkey to a native shortcut
|
||||||
bool setNativeShortcut(QHotkey::NativeShortcut nativeShortcut, bool autoRegister = false);
|
bool setNativeShortcut(QHotkey::NativeShortcut nativeShortcut, bool autoRegister = false);
|
||||||
|
|
||||||
signals:
|
Q_SIGNALS:
|
||||||
//! Will be emitted if the shortcut is pressed
|
//! Will be emitted if the shortcut is pressed
|
||||||
void activated(QPrivateSignal);
|
void activated(QPrivateSignal);
|
||||||
|
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
message(The pri file has been moved one directory up! use that one instead)
|
|
||||||
@@ -134,7 +134,7 @@ quint32 QHotkeyPrivateMac::nativeKeycode(Qt::Key keycode, bool &ok)
|
|||||||
UTF16Char ch = keycode;
|
UTF16Char ch = keycode;
|
||||||
|
|
||||||
CFDataRef currentLayoutData;
|
CFDataRef currentLayoutData;
|
||||||
TISInputSourceRef currentKeyboard = TISCopyCurrentKeyboardInputSource();
|
TISInputSourceRef currentKeyboard = TISCopyCurrentASCIICapableKeyboardLayoutInputSource();
|
||||||
|
|
||||||
if (currentKeyboard == NULL)
|
if (currentKeyboard == NULL)
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
+15
-8
@@ -1,7 +1,9 @@
|
|||||||
#include "qhotkey.h"
|
#include "qhotkey.h"
|
||||||
#include "qhotkey_p.h"
|
#include "qhotkey_p.h"
|
||||||
#include <qt_windows.h>
|
#include <qt_windows.h>
|
||||||
|
#include <algorithm>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
#include <QList>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
|
||||||
#define HKEY_ID(nativeShortcut) (((nativeShortcut.key ^ (nativeShortcut.modifier << 8)) & 0x0FFF) | 0x7000)
|
#define HKEY_ID(nativeShortcut) (((nativeShortcut.key ^ (nativeShortcut.modifier << 8)) & 0x0FFF) | 0x7000)
|
||||||
@@ -28,7 +30,7 @@ protected:
|
|||||||
private:
|
private:
|
||||||
static QString formatWinError(DWORD winError);
|
static QString formatWinError(DWORD winError);
|
||||||
QTimer pollTimer;
|
QTimer pollTimer;
|
||||||
QHotkey::NativeShortcut polledShortcut;
|
QList<QHotkey::NativeShortcut> polledShortcuts;
|
||||||
};
|
};
|
||||||
NATIVE_INSTANCE(QHotkeyPrivateWin)
|
NATIVE_INSTANCE(QHotkeyPrivateWin)
|
||||||
|
|
||||||
@@ -51,8 +53,9 @@ bool QHotkeyPrivateWin::nativeEventFilter(const QByteArray &eventType, void *mes
|
|||||||
if(msg->message == WM_HOTKEY) {
|
if(msg->message == WM_HOTKEY) {
|
||||||
QHotkey::NativeShortcut shortcut = {HIWORD(msg->lParam), LOWORD(msg->lParam)};
|
QHotkey::NativeShortcut shortcut = {HIWORD(msg->lParam), LOWORD(msg->lParam)};
|
||||||
this->activateShortcut(shortcut);
|
this->activateShortcut(shortcut);
|
||||||
this->polledShortcut = shortcut;
|
if (this->polledShortcuts.empty())
|
||||||
this->pollTimer.start();
|
this->pollTimer.start();
|
||||||
|
this->polledShortcuts.append(shortcut);
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
@@ -60,11 +63,15 @@ bool QHotkeyPrivateWin::nativeEventFilter(const QByteArray &eventType, void *mes
|
|||||||
|
|
||||||
void QHotkeyPrivateWin::pollForHotkeyRelease()
|
void QHotkeyPrivateWin::pollForHotkeyRelease()
|
||||||
{
|
{
|
||||||
bool pressed = (GetAsyncKeyState(this->polledShortcut.key) & (1 << 15)) != 0;
|
auto it = std::remove_if(this->polledShortcuts.begin(), this->polledShortcuts.end(), [this](const QHotkey::NativeShortcut &shortcut) {
|
||||||
if(!pressed) {
|
bool pressed = (GetAsyncKeyState(shortcut.key) & (1 << 15)) != 0;
|
||||||
|
if (!pressed)
|
||||||
|
this->releaseShortcut(shortcut);
|
||||||
|
return !pressed;
|
||||||
|
});
|
||||||
|
this->polledShortcuts.erase(it, this->polledShortcuts.end());
|
||||||
|
if (this->polledShortcuts.empty())
|
||||||
this->pollTimer.stop();
|
this->pollTimer.stop();
|
||||||
this->releaseShortcut(this->polledShortcut);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
quint32 QHotkeyPrivateWin::nativeKeycode(Qt::Key keycode, bool &ok)
|
quint32 QHotkeyPrivateWin::nativeKeycode(Qt::Key keycode, bool &ok)
|
||||||
@@ -235,7 +242,7 @@ quint32 QHotkeyPrivateWin::nativeKeycode(Qt::Key keycode, bool &ok)
|
|||||||
|
|
||||||
default:
|
default:
|
||||||
if(keycode <= 0xFFFF)
|
if(keycode <= 0xFFFF)
|
||||||
return (byte)keycode;
|
return static_cast<BYTE>(keycode);
|
||||||
else {
|
else {
|
||||||
ok = false;
|
ok = false;
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@@ -13,7 +13,7 @@
|
|||||||
#include <X11/Xlib.h>
|
#include <X11/Xlib.h>
|
||||||
#include <xcb/xcb.h>
|
#include <xcb/xcb.h>
|
||||||
|
|
||||||
//compability to pre Qt 5.8
|
//compatibility to pre Qt 5.8
|
||||||
#ifndef Q_FALLTHROUGH
|
#ifndef Q_FALLTHROUGH
|
||||||
#define Q_FALLTHROUGH() (void)0
|
#define Q_FALLTHROUGH() (void)0
|
||||||
#endif
|
#endif
|
||||||
@@ -132,13 +132,16 @@ quint32 QHotkeyPrivateX11::nativeKeycode(Qt::Key keycode, bool &ok)
|
|||||||
|
|
||||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 2, 0)
|
#if QT_VERSION >= QT_VERSION_CHECK(6, 2, 0)
|
||||||
const QNativeInterface::QX11Application *x11Interface = qGuiApp->nativeInterface<QNativeInterface::QX11Application>();
|
const QNativeInterface::QX11Application *x11Interface = qGuiApp->nativeInterface<QNativeInterface::QX11Application>();
|
||||||
Display *display = x11Interface->display();
|
|
||||||
#else
|
#else
|
||||||
const bool x11Interface = QX11Info::isPlatformX11();
|
const bool x11Interface = QX11Info::isPlatformX11();
|
||||||
Display *display = QX11Info::display();
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if(x11Interface) {
|
if(x11Interface) {
|
||||||
|
#if QT_VERSION >= QT_VERSION_CHECK(6, 2, 0)
|
||||||
|
Display *display = x11Interface->display();
|
||||||
|
#else
|
||||||
|
Display *display = QX11Info::display();
|
||||||
|
#endif
|
||||||
auto res = XKeysymToKeycode(display, keysym);
|
auto res = XKeysymToKeycode(display, keysym);
|
||||||
if(res != 0)
|
if(res != 0)
|
||||||
ok = true;
|
ok = true;
|
||||||
|
|||||||
@@ -16,30 +16,19 @@ The QHotkey is a class that can be used to create hotkeys/global shortcuts, aka
|
|||||||
|
|
||||||
## Building
|
## Building
|
||||||
|
|
||||||
QHotkey supports both Qt6 and Qt5. When using Qt6, version 6.2.0 or later required. It can be built by either the CMake or qmake building systems.
|
QHotkey supports both Qt6 and Qt5. When using Qt6, version 6.2.0 or later required. It can be built using the CMake building system.
|
||||||
|
|
||||||
### CMake
|
### CMake
|
||||||
|
|
||||||
The CMake `QT_MAJOR` variable controls which major version of Qt is used for building, and defaults to `5`. For example, use the CMake command line option `-DQT_MAJOR=6` for building with Qt6. To build the testing application `QHotkeyTest`, specify `-DQHOTKEY_EXAMPLES=ON`. CMake example usage:
|
The CMake `QT_DEFAULT_MAJOR_VERSION` variable controls which major version of Qt is used for building, and defaults to `5`. For example, use the CMake command line option `-DQT_DEFAULT_MAJOR_VERSION=6` for building with Qt6. To build the testing application `QHotkeyTest`, specify `-DQHOTKEY_EXAMPLES=ON`. CMake example usage:
|
||||||
|
|
||||||
```
|
```
|
||||||
$ cd QHotkey
|
$ cd QHotkey
|
||||||
$ cmake -B build -S . -DQT_MAJOR=6
|
$ cmake -B build -S . -DQT_DEFAULT_MAJOR_VERSION=6
|
||||||
$ cmake --build build
|
$ cmake --build build
|
||||||
# cmake --install build
|
# cmake --install build
|
||||||
```
|
```
|
||||||
|
|
||||||
### qmake
|
|
||||||
|
|
||||||
The major version of Qt is chosen by the qmake invokation itself, as the qmake executable is tied to a specific Qt version. The executable name can vary between operating systems. qmake example usage:
|
|
||||||
|
|
||||||
```
|
|
||||||
$ cd QHotkey
|
|
||||||
$ qmake
|
|
||||||
$ make
|
|
||||||
# make install
|
|
||||||
```
|
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
The package is providet as qpm package, [`de.skycoder42.qhotkey`](https://www.qpm.io/packages/de.skycoder42.qhotkey/index.html). You can install it either via qpmx (preferred) or directly via qpm.
|
The package is providet as qpm package, [`de.skycoder42.qhotkey`](https://www.qpm.io/packages/de.skycoder42.qhotkey/index.html). You can install it either via qpmx (preferred) or directly via qpm.
|
||||||
|
|
||||||
@@ -77,7 +66,7 @@ int main(int argc, char *argv[])
|
|||||||
QApplication app(argc, argv);
|
QApplication app(argc, argv);
|
||||||
|
|
||||||
QHotkey hotkey(QKeySequence("Ctrl+Alt+Q"), true, &app); //The hotkey will be automatically registered
|
QHotkey hotkey(QKeySequence("Ctrl+Alt+Q"), true, &app); //The hotkey will be automatically registered
|
||||||
qDebug() << "Is segistered:" << hotkey.isRegistered();
|
qDebug() << "Is registered:" << hotkey.isRegistered();
|
||||||
|
|
||||||
QObject::connect(&hotkey, &QHotkey::activated, qApp, [&](){
|
QObject::connect(&hotkey, &QHotkey::activated, qApp, [&](){
|
||||||
qDebug() << "Hotkey Activated - the application will quit now";
|
qDebug() << "Hotkey Activated - the application will quit now";
|
||||||
@@ -94,18 +83,18 @@ int main(int argc, char *argv[])
|
|||||||
By running the example in `./HotkeyTest` you can test out the QHotkey class. There are 4 sections:
|
By running the example in `./HotkeyTest` you can test out the QHotkey class. There are 4 sections:
|
||||||
- **Playground:** You can enter some sequences here and try it out with different key combinations.
|
- **Playground:** You can enter some sequences here and try it out with different key combinations.
|
||||||
- **Testings:** A list of selected hotkeys. Activate it and try out which ones work for you (*Hint:* Depending on OS and keyboard layout, it's very possible that a few don't work).
|
- **Testings:** A list of selected hotkeys. Activate it and try out which ones work for you (*Hint:* Depending on OS and keyboard layout, it's very possible that a few don't work).
|
||||||
- **Threading:** Activate the checkbox to move 2 Hotkeys of the playground to seperate threads. It should work without a difference.
|
- **Threading:** Activate the checkbox to move 2 Hotkeys of the playground to separate threads. It should work without a difference.
|
||||||
- **Native Shortcut**: Allows you to try out the direct usage of native shortcuts
|
- **Native Shortcut**: Allows you to try out the direct usage of native shortcuts
|
||||||
|
|
||||||
### Logging
|
### Logging
|
||||||
By default, QHotkey prints some warning messages if something goes wrong (For example, a key that cannot be translated). All messages of QHotkey are grouped into the [QLoggingCategory](https://doc.qt.io/qt-5/qloggingcategory.html) `"QHotkey"`. If you want to simply disable the logging, call the folling function somewhere in your code:
|
By default, QHotkey prints some warning messages if something goes wrong (For example, a key that cannot be translated). All messages of QHotkey are grouped into the [QLoggingCategory](https://doc.qt.io/qt-5/qloggingcategory.html) `"QHotkey"`. If you want to simply disable the logging, call the following function somewhere in your code:
|
||||||
```cpp
|
```cpp
|
||||||
QLoggingCategory::setFilterRules(QStringLiteral("QHotkey.warning=false"));
|
QLoggingCategory::setFilterRules(QStringLiteral("QHotkey.warning=false"));
|
||||||
```
|
```
|
||||||
This will turn all warnings of QHotkey of (It only uses warnings for now, thats why this is enough). For more information about all the things you can do with the logging categories, check the Qt-Documentation
|
This will turn all warnings of QHotkey of (It only uses warnings for now, that's why this is enough). For more information about all the things you can do with the logging categories, check the Qt-Documentation
|
||||||
|
|
||||||
## Thread saftey
|
## Thread safety
|
||||||
The QHotkey class itself is reentrant - wich means you can create as many instances as required on any thread. This allows you to use the QHotkey on all threads. **But** you should never use the QHotkey instance on a thread that is different from the one the instance belongs to! Internally the system uses a singleton instance that handles the hotkey events and distributes them to the QHotkey instances. This internal class is completley threadsafe.
|
The QHotkey class itself is reentrant - which means you can create as many instances as required on any thread. This allows you to use the QHotkey on all threads. **But** you should never use the QHotkey instance on a thread that is different from the one the instance belongs to! Internally the system uses a singleton instance that handles the hotkey events and distributes them to the QHotkey instances. This internal class is completely threadsafe.
|
||||||
|
|
||||||
However, this singleton instance only runs on the main thread. (One reason is that some of the OS-Functions are not thread safe). To make threaded hotkeys possible, the critical functions (registering/unregistering hotkeys and keytranslation) are all run on the mainthread too. The QHotkey instances on other threads use `QMetaObject::invokeMethod` with a `Qt::BlockingQueuedConnection`.
|
However, this singleton instance only runs on the main thread. (One reason is that some of the OS-Functions are not thread safe). To make threaded hotkeys possible, the critical functions (registering/unregistering hotkeys and keytranslation) are all run on the mainthread too. The QHotkey instances on other threads use `QMetaObject::invokeMethod` with a `Qt::BlockingQueuedConnection`.
|
||||||
|
|
||||||
|
|||||||
+3
-3
@@ -38,7 +38,7 @@ In addition to the normal accessors, a modification of the QHotkey::shortcut pro
|
|||||||
@default{`QKeySequence()` (`Qt::Key_unknown` + `Qt::NoModifier`)}
|
@default{`QKeySequence()` (`Qt::Key_unknown` + `Qt::NoModifier`)}
|
||||||
|
|
||||||
Holds the shortcut this hotkey will be registered on. It can be used as QKeySequence or as a combination of
|
Holds the shortcut this hotkey will be registered on. It can be used as QKeySequence or as a combination of
|
||||||
a Qt::Key and Qt::KeyboardModifiers. All write-accessors specifiy an additional parameter to immediatly register
|
a Qt::Key and Qt::KeyboardModifiers. All write-accessors specify an additional parameter to immediately register
|
||||||
the hotkey.
|
the hotkey.
|
||||||
|
|
||||||
@note Since the operating systems do not support hotkeys that consist of multiple key-combinations in a sequence,
|
@note Since the operating systems do not support hotkeys that consist of multiple key-combinations in a sequence,
|
||||||
@@ -107,7 +107,7 @@ it does. This does not happen if used from the main thread.
|
|||||||
|
|
||||||
If the hotkey is still registered on destruction, it will automatically unregister itself.
|
If the hotkey is still registered on destruction, it will automatically unregister itself.
|
||||||
|
|
||||||
@warning If using a hotkey on a thread other than the main thread, make shure the QApplication is still running it's eventloop.
|
@warning If using a hotkey on a thread other than the main thread, make sure the QApplication is still running it's eventloop.
|
||||||
Otherwise your application will hang up.
|
Otherwise your application will hang up.
|
||||||
|
|
||||||
@sa QHotkey::registered
|
@sa QHotkey::registered
|
||||||
@@ -144,7 +144,7 @@ from the thread this instance lives on.
|
|||||||
|
|
||||||
This method can be used to remap specific hotkey to a different native representation than the
|
This method can be used to remap specific hotkey to a different native representation than the
|
||||||
one that would be used by default. This can be useful if specific key combinations work fine
|
one that would be used by default. This can be useful if specific key combinations work fine
|
||||||
on allmost all platforms, but on one you need a different keycode for the same effect. See
|
on almost all platforms, but on one you need a different keycode for the same effect. See
|
||||||
[Issue #15](https://github.com/Skycoder42/QHotkey/issues/15) for an example where this is the
|
[Issue #15](https://github.com/Skycoder42/QHotkey/issues/15) for an example where this is the
|
||||||
case.
|
case.
|
||||||
|
|
||||||
|
|||||||
-15
@@ -1,15 +0,0 @@
|
|||||||
mac: LIBS += -framework Carbon
|
|
||||||
else:win32: LIBS += -luser32
|
|
||||||
else:unix {
|
|
||||||
equals(QT_MAJOR_VERSION, 6) {
|
|
||||||
lessThan(QT_VERSION, 6.2.0) {
|
|
||||||
error("Qt 6.2.0 or greater is required when using Qt6")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
lessThan(QT_MAJOR_VERSION, 6) {
|
|
||||||
QT += x11extras
|
|
||||||
}
|
|
||||||
}
|
|
||||||
LIBS += -lX11
|
|
||||||
}
|
|
||||||
-17
@@ -1,17 +0,0 @@
|
|||||||
CONFIG += C++11
|
|
||||||
|
|
||||||
PUBLIC_HEADERS += $$PWD/QHotkey/qhotkey.h \
|
|
||||||
$$PWD/QHotkey/QHotkey
|
|
||||||
|
|
||||||
HEADERS += $$PUBLIC_HEADERS \
|
|
||||||
$$PWD/QHotkey/qhotkey_p.h
|
|
||||||
|
|
||||||
SOURCES += $$PWD/QHotkey/qhotkey.cpp
|
|
||||||
|
|
||||||
mac: SOURCES += $$PWD/QHotkey/qhotkey_mac.cpp
|
|
||||||
else:win32: SOURCES += $$PWD/QHotkey/qhotkey_win.cpp
|
|
||||||
else:unix: SOURCES += $$PWD/QHotkey/qhotkey_x11.cpp
|
|
||||||
|
|
||||||
INCLUDEPATH += $$PWD/QHotkey
|
|
||||||
|
|
||||||
include($$PWD/qhotkey.prc)
|
|
||||||
Reference in New Issue
Block a user