Skip to content
Draft
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
2 changes: 2 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
67 changes: 67 additions & 0 deletions src/input/globalshortcut.cpp
Original file line number Diff line number Diff line change
@@ -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 <QHash>

Check warning on line 6 in src/input/globalshortcut.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QHash> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QKeySequence>

Check warning on line 7 in src/input/globalshortcut.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QKeySequence> not found. Please note: Cppcheck does not need standard library headers to get proper results.

namespace Treeland {
class GlobalShortcutPrivate : public QObject
{
Q_OBJECT
Q_DECLARE_PUBLIC(GlobalShortcut)

GlobalShortcut *q_ptr;
QHash<const QAction*, QList<QKeySequence>> 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<QKeySequence> &shortcut)

Check warning on line 30 in src/input/globalshortcut.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

The function 'setShortcut' is never used.
{
Q_D(GlobalShortcut);
if (!action || shortcut.isEmpty()) {
return false;
}
d->shortcuts[action] = shortcut;
return true;
}

QList<QKeySequence> GlobalShortcut::shortcut(const QAction *action) const
{
Q_D(const GlobalShortcut);
return d->shortcuts.value(action);
}

bool GlobalShortcut::hasShortcut(const QAction *action) const

Check warning on line 46 in src/input/globalshortcut.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

The function 'hasShortcut' is never used.
{
Q_D(const GlobalShortcut);
return d->shortcuts.contains(action);
}

void GlobalShortcut::removeAllShortcuts(QAction *action)

Check warning on line 52 in src/input/globalshortcut.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

The function 'removeAllShortcuts' is never used.
{
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"

Check warning on line 67 in src/input/globalshortcut.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "globalshortcut.moc" not found.
29 changes: 29 additions & 0 deletions src/input/globalshortcut.h
Original file line number Diff line number Diff line change
@@ -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 <QObject>

Check warning on line 6 in src/input/globalshortcut.h

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QObject> not found. Please note: Cppcheck does not need standard library headers to get proper results.

class QAction;

namespace Treeland {

class GlobalShortcutPrivate;

class GlobalShortcut : public QObject
{
Q_OBJECT
Q_DECLARE_PRIVATE(GlobalShortcut)

Check warning on line 17 in src/input/globalshortcut.h

View workflow job for this annotation

GitHub Actions / cppcheck

The function 'd_func' is never used.
public:
explicit GlobalShortcut(QObject *parent = nullptr);

bool setShortcut(QAction *action, const QList<QKeySequence> &shortcut);
QList<QKeySequence> shortcut(const QAction *action) const;
bool hasShortcut(const QAction *action) const;
void removeAllShortcuts(QAction *action);

private:
GlobalShortcutPrivate *d_ptr;
};
} // namespace Treeland
Loading