Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Qt 6 linux support #6

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 47 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,67 @@
## UGlobalHotkey
# UGlobalHotkey

A Qt extension library to provide global hotkey access across Windows, Mac, and Linux.

This project has been forked. The original readme below details that effort. This section defines changes and reasoning for these changes.

## Changes from ckaiser

* Resolves naming issues for Mac
* `GetSimpleKeys` -> `getSimpleKeys`
* `GetModifiers` -> `getModifiers`
* Removes qDebug notes for which keys are enabled.

## Usage

Key combinations are set using plain text key names, separated by either `,` or `+`. Spacing between keys is not important. Modifier keys, such as `shift` are repsented by words. Note: not all modifier keys are supported.

### Modifier keys

| Key | Name | Alternate Name |
| ------------ | --------- | -------------- |
| Shift | `shift` | `shft` |
| Control | `control` | `ctrl` |
| Alt | `alt` | -- |
| Windows/Meta | `meta` | `win` |

### Example

* `ctrl+shift+p`

## Original readme below

---

## Decription

### Decription
UGlobalHotkey is an extension for Qt framework, which implements global hotkeys functionality for Windows Linux and MacOSX platforms.
It is written by [bakwc](https://github.com/bakwc), extracted from [Pastexen](https://github.com/bakwc/Pastexen) and turned into a shared library by [falceeffect](https://github.com/falceeffect).

### Modifications in this fork:
## Modifications in this fork

Mostly code style changes, better Windows support and whatever else I might need for [Lightscreen](http://github.com/ckaiser/Lightscreen).

### Building from source
## Building from source

* You can either open project with QtCreator and press Build button
* Or build it using terminal:
```

``` sh
qmake
make
```

### Usage example
```
UGlobalHotkeys *hotkeyManager = new UGlobalHotkeys();
## Usage example

``` c++
UGlobalHotkeys *hotkeyManager = new UGlobalHotkeys();
hotkeyManager->registerHotkey("Ctrl+Shift+F12");
connect(hotkeyManager, &UGlobalHotkeys::activated, [=](size_t id)
{
qDebug() << "Activated: " << QString::number(id);
});
```

### License
## License

UGlobalHotkey library is licensed as Public Domain, so you are free to do anything with it.
4 changes: 2 additions & 2 deletions hotkeymap.h
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,8 @@ static std::unordered_map<uint32_t, uint32_t> MOD_MAP = {
inline UKeyData QtKeyToMac(const UKeySequence &keySeq)
{
UKeyData data = {0, 0};
auto key = keySeq.GetSimpleKeys();
auto mods = keySeq.GetModifiers();
auto key = keySeq.getSimpleKeys();
auto mods = keySeq.getModifiers();

if (key.size() == 1 && KEY_MAP.find(key[0]) != KEY_MAP.end()) {
data.key = KEY_MAP[key[0]];
Expand Down
6 changes: 4 additions & 2 deletions uglobalhotkeys.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
#include "hotkeymap.h"
#include "uglobalhotkeys.h"

#include <QDebug>

UGlobalHotkeys::UGlobalHotkeys(QWidget *parent)
: QWidget(parent)
{
Expand Down Expand Up @@ -178,7 +176,11 @@ bool UGlobalHotkeys::nativeEvent(const QByteArray &eventType,

#elif defined(Q_OS_LINUX)

#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
bool UGlobalHotkeys::nativeEventFilter(const QByteArray &eventType, void *message, qintptr *result)
#else
bool UGlobalHotkeys::nativeEventFilter(const QByteArray &eventType, void *message, long *result)
#endif
{
Q_UNUSED(eventType);
Q_UNUSED(result);
Expand Down
7 changes: 6 additions & 1 deletion uglobalhotkeys.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,12 @@ class UGLOBALHOTKEY_EXPORT UGlobalHotkeys : public QWidget
bool winEvent(MSG *message, long *result);
bool nativeEvent(const QByteArray &eventType, void *message, long *result);
#elif defined(Q_OS_LINUX)
bool nativeEventFilter(const QByteArray &eventType, void *message, long *result);

#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
bool nativeEventFilter(const QByteArray &eventType, void *message, long *result) override;
#else
bool nativeEventFilter(const QByteArray &eventType, void *message, qintptr *result) override;
#endif
bool linuxEvent(xcb_generic_event_t *message);
void regLinuxHotkey(const UKeySequence &keySeq, size_t id);
void unregLinuxHotkey(size_t id);
Expand Down
4 changes: 2 additions & 2 deletions ukeysequence.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ void UKeySequence::addKey(const QString &key)
}

QString mod = key.toLower();
qDebug() << "mod: " << mod;
// qDebug() << "mod: " << mod;
if (mod == "alt") {
addKey(Qt::Key_Alt);
return;
Expand Down Expand Up @@ -119,7 +119,7 @@ void UKeySequence::addKey(Qt::Key key)
return;
}
}
qDebug() << "Key added: " << key;
// qDebug() << "Key added: " << key;
mKeys.push_back(key);
}

Expand Down