diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 3b4f999a5..7881dd24c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -116,6 +116,8 @@ qt_add_qml_module(libtreeland input/inputdevice.h input/togglablegesture.cpp input/togglablegesture.h + input/globalshortcut.h + input/globalshortcut.cpp interfaces/baseplugininterface.h interfaces/lockscreeninterface.h interfaces/multitaskviewinterface.h diff --git a/src/input/globalshortcut.cpp b/src/input/globalshortcut.cpp new file mode 100644 index 000000000..52fc7bdb7 --- /dev/null +++ b/src/input/globalshortcut.cpp @@ -0,0 +1,67 @@ +// Copyright (C) 2024 UnionTech Software Technology Co., Ltd. +// SPDX-License-Identifier: Apache-2.0 OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only + +#include "globalshortcut.h" + +#include +#include + +namespace Treeland { +class GlobalShortcutPrivate : public QObject +{ + Q_OBJECT + Q_DECLARE_PUBLIC(GlobalShortcut) + + GlobalShortcut *q_ptr; + QHash> shortcuts; + +public: + explicit GlobalShortcutPrivate(GlobalShortcut *parent) + : q_ptr(parent) + { + } + + void init() + { + // Initialization code for global shortcuts can go here. + } +}; + +bool GlobalShortcut::setShortcut(QAction *action, const QList &shortcut) +{ + Q_D(GlobalShortcut); + if (!action || shortcut.isEmpty()) { + return false; + } + d->shortcuts[action] = shortcut; + return true; +} + +QList GlobalShortcut::shortcut(const QAction *action) const +{ + Q_D(const GlobalShortcut); + return d->shortcuts.value(action); +} + +bool GlobalShortcut::hasShortcut(const QAction *action) const +{ + Q_D(const GlobalShortcut); + return d->shortcuts.contains(action); +} + +void GlobalShortcut::removeAllShortcuts(QAction *action) +{ + Q_D(GlobalShortcut); + d->shortcuts.remove(action); +} + +GlobalShortcut::GlobalShortcut(QObject *parent) + : QObject(parent) + , d_ptr(new GlobalShortcutPrivate(this)) +{ + Q_D(GlobalShortcut); + d->init(); +} +} // namespace Treeland + +#include "globalshortcut.moc" diff --git a/src/input/globalshortcut.h b/src/input/globalshortcut.h new file mode 100644 index 000000000..09a31fffd --- /dev/null +++ b/src/input/globalshortcut.h @@ -0,0 +1,29 @@ +// Copyright (C) 2024 UnionTech Software Technology Co., Ltd. +// SPDX-License-Identifier: Apache-2.0 OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only + +#pragma once + +#include + +class QAction; + +namespace Treeland { + +class GlobalShortcutPrivate; + +class GlobalShortcut : public QObject +{ + Q_OBJECT + Q_DECLARE_PRIVATE(GlobalShortcut) +public: + explicit GlobalShortcut(QObject *parent = nullptr); + + bool setShortcut(QAction *action, const QList &shortcut); + QList shortcut(const QAction *action) const; + bool hasShortcut(const QAction *action) const; + void removeAllShortcuts(QAction *action); + +private: + GlobalShortcutPrivate *d_ptr; +}; +} // namespace Treeland \ No newline at end of file