strawberry-audio-player-win.../src/globalshortcuts/globalshortcut.h

84 lines
2.5 KiB
C
Raw Normal View History

/*
* Strawberry Music Player
2021-03-20 21:14:47 +01:00
* Copyright 2018-2021, Jonas Kvinge <jonas@jkvinge.net>
*
* Strawberry is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Strawberry is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Strawberry. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef GLOBALSHORTCUT_H
#define GLOBALSHORTCUT_H
#include "config.h"
#include <QtGlobal>
#include <QObject>
#include <QAbstractNativeEventFilter>
#include <QKeySequence>
#include <QPair>
#include <QVector>
#include <QHash>
#include <QByteArray>
2020-02-09 02:29:35 +01:00
#include <QString>
2021-01-26 19:13:29 +01:00
class GlobalShortcutsBackend;
class GlobalShortcut : public QObject, QAbstractNativeEventFilter {
Q_OBJECT
public:
explicit GlobalShortcut(QObject *parent = nullptr);
2021-06-20 19:04:08 +02:00
explicit GlobalShortcut(const QKeySequence &shortcut, GlobalShortcutsBackend *backend, QObject *parent = nullptr);
2020-06-15 21:55:05 +02:00
~GlobalShortcut() override;
2021-01-26 19:13:29 +01:00
GlobalShortcutsBackend *backend() const { return backend_; }
QKeySequence shortcut() const { return shortcut_; }
bool setShortcut(const QKeySequence &shortcut);
bool unsetShortcut();
signals:
void activated();
private:
2021-06-22 13:41:38 +02:00
static void activateShortcut(quint32 native_key, quint32 native_mods);
2021-06-22 13:41:38 +02:00
static quint32 nativeModifiers(Qt::KeyboardModifiers qt_mods);
static quint32 nativeKeycode(Qt::Key qt_keycode);
2021-06-22 13:41:38 +02:00
static bool registerShortcut(quint32 native_key, quint32 native_mods);
static bool unregisterShortcut(quint32 native_key, quint32 native_mods);
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
bool nativeEventFilter(const QByteArray &eventtype, void *message, qintptr *result) override;
#else
2020-06-15 21:55:05 +02:00
bool nativeEventFilter(const QByteArray &eventtype, void *message, long *result) override;
#endif
static GlobalShortcut *initialized_;
static QHash<QPair<quint32, quint32>, GlobalShortcut*> internal_shortcuts_;
static const QVector<quint32> mask_modifiers_;
2021-01-26 19:13:29 +01:00
GlobalShortcutsBackend *backend_;
QKeySequence shortcut_;
Qt::Key qt_key_;
Qt::KeyboardModifiers qt_mods_;
quint32 native_key_;
quint32 native_mods_;
};
#endif // GLOBALSHORTCUT_H