Skip to content
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
10 changes: 5 additions & 5 deletions hotkeymap.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ inline size_t QtKeyToWin(Qt::Key key)
#include "X11/keysym.h"

struct UKeyData {
int key;
int mods;
xcb_keysym_t key;
uint16_t mods;
};

static std::unordered_map<uint32_t, uint32_t> KEY_MAP = {
Expand Down Expand Up @@ -165,7 +165,7 @@ inline UKeyData QtKeyToLinux(const UKeySequence &keySeq)
if (key.size() > 0) {
data.key = key[0];
} else {
qWarning() << "Invalid hotkey";
qCWarning(ughDebug) << "Invalid hotkey";
return data;
}
// Key conversion
Expand All @@ -178,7 +178,7 @@ inline UKeyData QtKeyToLinux(const UKeySequence &keySeq)
} else if (data.key >= Qt::Key_Space && data.key <= Qt::Key_QuoteLeft) {
// conversion is not necessary, if the value in the range Qt::Key_Space - Qt::Key_QuoteLeft
} else {
qWarning() << "Invalid hotkey: key conversion is not defined";
qCWarning(ughDebug) << "Invalid hotkey: key conversion is not defined";
return data;
}

Expand Down Expand Up @@ -280,7 +280,7 @@ inline UKeyData QtKeyToMac(const UKeySequence &keySeq)
if (key.size() == 1 && KEY_MAP.find(key[0]) != KEY_MAP.end()) {
data.key = KEY_MAP[key[0]];
} else {
qWarning() << "Invalid hotkey";
qCWarning(ughDebug) << "Invalid hotkey";
return data;
}

Expand Down
12 changes: 5 additions & 7 deletions uglobalhotkeys.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,14 @@
#include "hotkeymap.h"
#include "uglobalhotkeys.h"

#include <QDebug>

UGlobalHotkeys::UGlobalHotkeys(QWidget *parent)
: QWidget(parent)
{
#if defined(Q_OS_LINUX)
qApp->installNativeEventFilter(this);
QWindow wndw;
void *v = qApp->platformNativeInterface()->nativeResourceForWindow("connection", &wndw);
X11Connection = (xcb_connection_t *)v;
X11Connection = static_cast<xcb_connection_t *>(v);
X11Wid = xcb_setup_roots_iterator(xcb_get_setup(X11Connection)).data->root;
X11KeySymbs = xcb_key_symbols_alloc(X11Connection);
#endif
Expand Down Expand Up @@ -188,8 +186,8 @@ bool UGlobalHotkeys::nativeEventFilter(const QByteArray &eventType, void *messag
bool UGlobalHotkeys::linuxEvent(xcb_generic_event_t *message)
{
if ((message->response_type & ~0x80) == XCB_KEY_PRESS) {
xcb_key_press_event_t *ev = (xcb_key_press_event_t *)message;
auto ind = Registered.key({ev->detail, (ev->state & ~XCB_MOD_MASK_2)});
xcb_key_press_event_t *ev = reinterpret_cast<xcb_key_press_event_t *>(message);
auto ind = Registered.key({ev->detail, uint16_t(ev->state & ~XCB_MOD_MASK_2)});

if (ind == 0) // this is not hotkeys
return false;
Expand All @@ -207,8 +205,8 @@ void UGlobalHotkeys::regLinuxHotkey(const UKeySequence &keySeq, size_t id)

xcb_keycode_t *keyC = xcb_key_symbols_get_keycode(X11KeySymbs, keyData.key);

if (keyC == XCB_NO_SYMBOL) { // 0x0
qWarning() << "Cannot find symbol";
if (keyC == nullptr) {
qCWarning(ughDebug) << "Cannot find symbol";
return;
}

Expand Down
4 changes: 2 additions & 2 deletions uglobalhotkeys.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#if defined(Q_OS_LINUX)
struct UHotkeyData {
xcb_keycode_t keyCode;
int mods;
uint16_t mods;
bool operator ==(const UHotkeyData &data) const
{
return data.keyCode == this->keyCode && data.mods == this->mods;
Expand All @@ -33,7 +33,7 @@ class UGLOBALHOTKEY_EXPORT UGlobalHotkeys : public QWidget
Q_OBJECT

public:
explicit UGlobalHotkeys(QWidget *parent = 0);
explicit UGlobalHotkeys(QWidget *parent = nullptr);
bool registerHotkey(const QString &keySeq, size_t id = 1);
bool registerHotkey(const UKeySequence &keySeq, size_t id = 1);
void unregisterHotkey(size_t id = 1);
Expand Down
14 changes: 7 additions & 7 deletions ukeysequence.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "ukeysequence.h"

#include <QDebug>
Q_LOGGING_CATEGORY(ughDebug, "uglobalhotkey", QtInfoMsg)

UKeySequence::UKeySequence(QObject *parent)
: QObject(parent)
Expand Down Expand Up @@ -79,12 +79,12 @@ void UKeySequence::addModifiers(Qt::KeyboardModifiers mod)
void UKeySequence::addKey(const QString &key)
{
if (key.contains("+") || key.contains(",")) {
qWarning() << "Wrong key";
qCWarning(ughDebug) << "Wrong key";
return;
}

QString mod = key.toLower();
qDebug() << "mod: " << mod;
qCDebug(ughDebug) << "mod: " << mod;
if (mod == "alt") {
addKey(Qt::Key_Alt);
return;
Expand All @@ -103,10 +103,10 @@ void UKeySequence::addKey(const QString &key)
}
QKeySequence seq(key);
if (seq.count() != 1) {
qWarning() << "Wrong key";
qCWarning(ughDebug) << "Wrong key";
return;
}
addKey((Qt::Key) seq[0]);
addKey(static_cast<Qt::Key>(seq[0]));
}

void UKeySequence::addKey(Qt::Key key)
Expand All @@ -119,12 +119,12 @@ void UKeySequence::addKey(Qt::Key key)
return;
}
}
qDebug() << "Key added: " << key;
qCDebug(ughDebug) << "Key added: " << key;
mKeys.push_back(key);
}

void UKeySequence::addKey(const QKeyEvent *event)
{
addKey((Qt::Key) event->key());
addKey(static_cast<Qt::Key>(event->key()));
addModifiers(event->modifiers());
}
14 changes: 8 additions & 6 deletions ukeysequence.h
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
#pragma once

#include <QObject>
#include <QLoggingCategory>
#include <QString>
#include <QVector>
#include <QStringList>
#include <QKeyEvent>

#include "uglobal.h"

Q_DECLARE_LOGGING_CATEGORY(ughDebug)

class UGLOBALHOTKEY_EXPORT UKeySequence : public QObject
{
Q_OBJECT

public:
explicit UKeySequence(QObject *parent = 0);
explicit UKeySequence(const QString &str, QObject *parent = 0);
explicit UKeySequence(QObject *parent = nullptr);
explicit UKeySequence(const QString &str, QObject *parent = nullptr);

void fromString(const QString &str);
QString toString();
Expand All @@ -23,13 +26,13 @@ class UGLOBALHOTKEY_EXPORT UKeySequence : public QObject
void addModifiers(Qt::KeyboardModifiers mod);
void addKey(const QKeyEvent *event);

inline size_t size() const
inline int size() const
{
return mKeys.size();
}
inline Qt::Key operator [](size_t n) const
inline Qt::Key operator [](int n) const
{
if ((int)n > mKeys.size()) {
if (n > mKeys.size()) {
return Qt::Key_unknown;
}

Expand Down Expand Up @@ -70,4 +73,3 @@ class UGLOBALHOTKEY_EXPORT UKeySequence : public QObject
}

};