File indexing completed on 2024-10-06 10:55:50

0001 /*
0002     SPDX-FileCopyrightText: 2016 Smith AR <audoban@openmailbox.org>
0003     SPDX-FileCopyrightText: 2016 Michail Vourlakos <mvourlakos@gmail.com>
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #ifndef GLOBALSHORTCUTS_H
0008 #define GLOBALSHORTCUTS_H
0009 
0010 // local
0011 #include <coretypes.h>
0012 
0013 // Qt
0014 #include <QAction>
0015 #include <QPointer>
0016 #include <QTimer>
0017 
0018 // KDE
0019 #include <kmodifierkeyinfo.h>
0020 
0021 
0022 namespace Plasma {
0023 class Containment;
0024 }
0025 
0026 namespace Latte {
0027 class Corona;
0028 class View;
0029 namespace ShortcutsPart{
0030 class ModifierTracker;
0031 class ShortcutsTracker;
0032 }
0033 }
0034 
0035 namespace Latte {
0036 
0037 class GlobalShortcuts : public QObject
0038 {
0039     Q_OBJECT
0040 
0041 public:
0042     static constexpr const char* SHORTCUTBLOCKHIDINGTYPE  = "globalshortcuts::blockHiding()";
0043 
0044     GlobalShortcuts(QObject *parent = nullptr);
0045     ~GlobalShortcuts() override;
0046 
0047     void activateLauncherMenu();
0048     void updateViewItemBadge(QString identifier, QString value);
0049 
0050     ShortcutsPart::ShortcutsTracker *shortcutsTracker() const;
0051 
0052 signals:
0053     void modifiersChanged();
0054 
0055 private slots:
0056     void hideViewsTimerSlot();
0057 
0058 private:
0059     void init();
0060     void initModifiers();
0061     void activateEntry(int index, Qt::Key modifier);
0062     void showViews();
0063     void showSettings();
0064 
0065     bool activateLatteEntry(Latte::View *view, int index, Qt::Key modifier, bool *delayedExecution);
0066     bool activatePlasmaTaskManager(const Latte::View *view, int index, Qt::Key modifier, bool *delayedExecution);
0067     bool activateEntryForView(Latte::View *view, int index, Qt::Key modifier);
0068     bool viewAtLowerEdgePriority(Latte::View *test, Latte::View *base);
0069     bool viewAtLowerScreenPriority(Latte::View *test, Latte::View *base);
0070     bool viewsToHideAreValid();
0071 
0072     //! highest priority application launcher view
0073     Latte::View *highestApplicationLauncherView(const QList<Latte::View *> &views) const;
0074 
0075     QList<Latte::View *> sortedViewsList(QHash<const Plasma::Containment *, Latte::View *> *views);
0076 
0077 private:
0078     bool m_metaShowedViews{false};
0079 
0080     //! last action that was trigerred from the user
0081     QAction *m_lastInvokedAction;
0082     //! it is used for code compatibility reasons in order to replicate a single Meta action
0083     QAction *m_singleMetaAction;
0084 
0085     //! delayer for hiding the shown latte views
0086     QTimer m_hideViewsTimer;
0087     QList<Latte::View *> m_hideViews;
0088 
0089     QPointer<ShortcutsPart::ModifierTracker> m_modifierTracker;
0090     QPointer<ShortcutsPart::ShortcutsTracker> m_shortcutsTracker;
0091     QPointer<Latte::Corona> m_corona;
0092 };
0093 
0094 }
0095 
0096 #endif // GLOBALSHORTCUTS_H