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 || event->type() == QEvent::KeyRelease) {
78 QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event);
80 // Make a copy of the event so we don't alter it for passing on.
81 QKeyEvent eCopy(keyEvent->type(),
83 keyEvent->modifiers(),
85 keyEvent->isAutoRepeat(),
89 int seq = keyEvent->key() + keyEvent->modifiers();
90 if (m_shortcuts.contains(seq)) {
91 const auto shortcuts = m_shortcuts.value(seq);
92 Q_FOREACH(const auto &shortcut, shortcuts) {
94 qApp->sendEvent(shortcut, &eCopy);
99 return eCopy.isAccepted();
102 return QObject::eventFilter(obj, event);
105void GlobalShortcutRegistry::setupFilterOnWindow(qulonglong wid)
107 if (wid == s_windowId) {
111 if (m_filteredWindow) {
112 m_filteredWindow->removeEventFilter(this);
113 m_filteredWindow.clear();
117 Q_FOREACH(QWindow *window, qApp->allWindows()) {
118 if (window && window->winId() == wid) {
119 m_filteredWindow = window;
120 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