mirror of
https://github.com/Skycoder42/QHotkey.git
synced 2026-11-19 12:49:58 +03:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
91f3542b5d | ||
|
|
1833a053f6 | ||
|
|
f288e85ef1 | ||
|
|
2578b69dc5 | ||
|
|
a0678c4cfc | ||
|
|
cdb4d37453 | ||
|
|
9eace8fbbd | ||
|
|
6baf644b40 | ||
|
|
3fa176a380 |
@@ -1,11 +1,20 @@
|
|||||||
#include "hottestwidget.h"
|
#include "hottestwidget.h"
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
|
|
||||||
|
//#define START_BACKGROUND
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
QApplication a(argc, argv);
|
QApplication a(argc, argv);
|
||||||
HotTestWidget w;
|
HotTestWidget w;
|
||||||
|
|
||||||
|
#ifdef START_BACKGROUND
|
||||||
|
auto startKey = new QHotkey(QKeySequence(Qt::MetaModifier | Qt::ControlModifier | Qt::Key_S), true, &w);
|
||||||
|
QObject::connect(startKey, &QHotkey::activated,
|
||||||
|
&w, &QWidget::show);
|
||||||
|
#else
|
||||||
w.show();
|
w.show();
|
||||||
|
#endif
|
||||||
|
|
||||||
return a.exec();
|
return a.exec();
|
||||||
}
|
}
|
||||||
|
|||||||
+11
-5
@@ -106,6 +106,7 @@ bool QHotkeyPrivateX11::registerShortcut(QHotkey::NativeShortcut shortcut)
|
|||||||
GrabModeAsync,
|
GrabModeAsync,
|
||||||
GrabModeAsync);
|
GrabModeAsync);
|
||||||
}
|
}
|
||||||
|
XSync(display, False);
|
||||||
|
|
||||||
if(errorHandler.hasError) {
|
if(errorHandler.hasError) {
|
||||||
qCWarning(logQHotkey) << "Failed to register hotkey. Error:"
|
qCWarning(logQHotkey) << "Failed to register hotkey. Error:"
|
||||||
@@ -129,11 +130,11 @@ bool QHotkeyPrivateX11::unregisterShortcut(QHotkey::NativeShortcut shortcut)
|
|||||||
shortcut.modifier | specialMod,
|
shortcut.modifier | specialMod,
|
||||||
DefaultRootWindow(display));
|
DefaultRootWindow(display));
|
||||||
}
|
}
|
||||||
|
XSync(display, False);
|
||||||
|
|
||||||
if(errorHandler.hasError) {
|
if(errorHandler.hasError) {
|
||||||
qCWarning(logQHotkey) << "Failed to unregister hotkey. Error:"
|
qCWarning(logQHotkey) << "Failed to unregister hotkey. Error:"
|
||||||
<< qPrintable(errorHandler.errorString);
|
<< qPrintable(errorHandler.errorString);
|
||||||
this->unregisterShortcut(shortcut);
|
|
||||||
return false;
|
return false;
|
||||||
} else
|
} else
|
||||||
return true;
|
return true;
|
||||||
@@ -155,27 +156,32 @@ QString QHotkeyPrivateX11::HotkeyErrorHandler::errorString;
|
|||||||
|
|
||||||
QHotkeyPrivateX11::HotkeyErrorHandler::HotkeyErrorHandler()
|
QHotkeyPrivateX11::HotkeyErrorHandler::HotkeyErrorHandler()
|
||||||
{
|
{
|
||||||
this->prevHandler = XSetErrorHandler(&HotkeyErrorHandler::handleError);
|
prevHandler = XSetErrorHandler(&HotkeyErrorHandler::handleError);
|
||||||
}
|
}
|
||||||
|
|
||||||
QHotkeyPrivateX11::HotkeyErrorHandler::~HotkeyErrorHandler()
|
QHotkeyPrivateX11::HotkeyErrorHandler::~HotkeyErrorHandler()
|
||||||
{
|
{
|
||||||
XSetErrorHandler(this->prevHandler);
|
XSetErrorHandler(prevHandler);
|
||||||
|
hasError = false;
|
||||||
|
errorString.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
int QHotkeyPrivateX11::HotkeyErrorHandler::handleError(Display *display, XErrorEvent *error)
|
int QHotkeyPrivateX11::HotkeyErrorHandler::handleError(Display *display, XErrorEvent *error)
|
||||||
{
|
{
|
||||||
|
QT_WARNING_PUSH
|
||||||
|
QT_WARNING_DISABLE_GCC("-Wimplicit-fallthrough")
|
||||||
switch (error->error_code) {
|
switch (error->error_code) {
|
||||||
case BadAccess:
|
case BadAccess:
|
||||||
case BadValue:
|
case BadValue:
|
||||||
case BadWindow:
|
case BadWindow:
|
||||||
if (error->request_code == 33 || //grab key
|
if (error->request_code == 33 || //grab key
|
||||||
error->request_code == 34) {// ungrab key
|
error->request_code == 34) {// ungrab key
|
||||||
HotkeyErrorHandler::hasError = true;
|
hasError = true;
|
||||||
HotkeyErrorHandler::errorString = QHotkeyPrivateX11::formatX11Error(display, error->error_code);
|
errorString = QHotkeyPrivateX11::formatX11Error(display, error->error_code);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
QT_WARNING_POP
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,12 +15,16 @@ The QHotkey is a class that can be used to create hotkeys/global shortcuts, aka
|
|||||||
## Installation
|
## Installation
|
||||||
The package is providet as qpm package, [`de.skycoder42.qhotkey`](https://www.qpm.io/packages/de.skycoder42.qhotkey/index.html). To install:
|
The package is providet as qpm package, [`de.skycoder42.qhotkey`](https://www.qpm.io/packages/de.skycoder42.qhotkey/index.html). To install:
|
||||||
|
|
||||||
1. Install qpm (See [GitHub - Installing](https://github.com/Cutehacks/qpm/blob/master/README.md#installing))
|
1. Install qpm (See [GitHub - Installing](https://github.com/Cutehacks/qpm/blob/master/README.md#installing), for **windows** see below)
|
||||||
2. In your projects root directory, run `qpm install de.skycoder42.qhotkey`
|
2. In your projects root directory, run `qpm install de.skycoder42.qhotkey`
|
||||||
3. Include qpm to your project by adding `include(vendor/vendor.pri)` to your `.pro` file
|
3. Include qpm to your project by adding `include(vendor/vendor.pri)` to your `.pro` file
|
||||||
|
|
||||||
Check their [GitHub - Usage for App Developers](https://github.com/Cutehacks/qpm/blob/master/README.md#usage-for-app-developers) to learn more about qpm.
|
Check their [GitHub - Usage for App Developers](https://github.com/Cutehacks/qpm/blob/master/README.md#usage-for-app-developers) to learn more about qpm.
|
||||||
|
|
||||||
|
**Important for Windows users:** QPM Version *0.10.0* (the one you can download on the website) is currently broken on windows! It's already fixed in master, but not released yet. Until a newer versions gets released, you can download the latest dev build from here:
|
||||||
|
- https://storage.googleapis.com/www.qpm.io/download/latest/windows_amd64/qpm.exe
|
||||||
|
- https://storage.googleapis.com/www.qpm.io/download/latest/windows_386/qpm.exe
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
The general usage is to create QHotkey instances for specific hotkeys, register them and then simply connect to the signal emitted once the hotkey is pressed.
|
The general usage is to create QHotkey instances for specific hotkeys, register them and then simply connect to the signal emitted once the hotkey is pressed.
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
"url": "https://github.com/Skycoder42/QHotkey.git"
|
"url": "https://github.com/Skycoder42/QHotkey.git"
|
||||||
},
|
},
|
||||||
"version": {
|
"version": {
|
||||||
"label": "1.1.2",
|
"label": "1.1.4",
|
||||||
"revision": "",
|
"revision": "",
|
||||||
"fingerprint": ""
|
"fingerprint": ""
|
||||||
},
|
},
|
||||||
@@ -19,4 +19,4 @@
|
|||||||
"license": "BSD_3_CLAUSE",
|
"license": "BSD_3_CLAUSE",
|
||||||
"pri_filename": "qhotkey.pri",
|
"pri_filename": "qhotkey.pri",
|
||||||
"webpage": "https://github.com/Skycoder42/QHotkey"
|
"webpage": "https://github.com/Skycoder42/QHotkey"
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user