2 * Copyright (C) 2015 Canonical, Ltd.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 3.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18#include <QGuiApplication>
20#include <QKeySequence>
22#include "globalshortcutregistry.h"
24static qulonglong s_windowId = 0;
26GlobalShortcutRegistry::GlobalShortcutRegistry(QObject *parent)
31GlobalShortcutList GlobalShortcutRegistry::shortcuts() const
36bool GlobalShortcutRegistry::hasShortcut(const QVariant &seq) const
38 return m_shortcuts.contains(seq);
41void GlobalShortcutRegistry::addShortcut(const QVariant &seq, GlobalShortcut *sc)
44 if (!m_shortcuts.contains(seq)) { // create a new entry
45 m_shortcuts.insert(seq, {sc});
46 } else { // append to an existing one
47 auto shortcuts = m_shortcuts[seq];
49 m_shortcuts.insert(seq, shortcuts);
52 connect(sc, &GlobalShortcut::destroyed, this, &GlobalShortcutRegistry::removeShortcut);
56void GlobalShortcutRegistry::removeShortcut(QObject *obj)
58 QMutableMapIterator<QVariant, QVector<QPointer<GlobalShortcut>>> it(m_shortcuts);
59 while (it.hasNext()) {
61 GlobalShortcut * scObj = static_cast<GlobalShortcut *>(obj);
62 if (scObj && it.value().contains(scObj)) {
63 it.value().removeAll(scObj);
64 if (it.value().isEmpty()) {
71bool GlobalShortcutRegistry::eventFilter(QObject *obj, QEvent *event)
73 Q_ASSERT(m_filteredWindow);
74 Q_ASSERT(obj == static_cast<QObject*>(m_filteredWindow.data()));
76 if (event->type() == QEvent::KeyPress) {
77 QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event);
78 int seq = keyEvent->key() + keyEvent->modifiers();
79 if (m_shortcuts.contains(seq)) {
80 const auto shortcuts = m_shortcuts.value(seq);
81 Q_FOREACH(const auto &shortcut, shortcuts) {
83 qApp->sendEvent(shortcut, keyEvent);
89 return event->isAccepted();
92 return QObject::eventFilter(obj, event);
95void GlobalShortcutRegistry::setupFilterOnWindow(qulonglong wid)
97 if (wid == s_windowId) {
101 if (m_filteredWindow) {
102 m_filteredWindow->removeEventFilter(this);
103 m_filteredWindow.clear();
107 Q_FOREACH(QWindow *window, qApp->allWindows()) {
108 if (window && window->winId() == wid) {
109 m_filteredWindow = window;
110 window->installEventFilter(this);
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list