Unity 8
GlobalShortcutRegistry Class Reference

The GlobalShortcutRegistry class. More...

#include <plugins/GlobalShortcut/globalshortcutregistry.h>

Inherits QObject.

Public Member Functions

 GlobalShortcutRegistry (QObject *parent=nullptr)
 
GlobalShortcutList shortcuts () const
 
bool hasShortcut (const QVariant &seq) const
 
void addShortcut (const QVariant &seq, GlobalShortcut *sc)
 
void setupFilterOnWindow (qulonglong wid)
 

Protected Member Functions

bool eventFilter (QObject *obj, QEvent *event) override
 

Detailed Description

The GlobalShortcutRegistry class.

Serves as a central point for shortcut registration.

Definition at line 34 of file globalshortcutregistry.h.

Member Function Documentation

void GlobalShortcutRegistry::addShortcut ( const QVariant &  seq,
GlobalShortcut sc 
)

Adds a shortcut seq to the registry

Definition at line 41 of file globalshortcutregistry.cpp.

42 {
43  if (sc) {
44  if (!m_shortcuts.keys().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];
48  shortcuts.append(sc);
49  m_shortcuts.insert(seq, shortcuts);
50  }
51 
52  connect(sc, &GlobalShortcut::destroyed, this, &GlobalShortcutRegistry::removeShortcut);
53  }
54 }
GlobalShortcutList shortcuts() const
bool GlobalShortcutRegistry::hasShortcut ( const QVariant &  seq) const
Returns
whether shortcut seq is currently registered

Definition at line 36 of file globalshortcutregistry.cpp.

37 {
38  return m_shortcuts.keys().contains(seq);
39 }
void GlobalShortcutRegistry::setupFilterOnWindow ( qulonglong  wid)

Sets up key events filtering on window wid

Definition at line 95 of file globalshortcutregistry.cpp.

96 {
97  if (wid == s_windowId) {
98  return;
99  }
100 
101  if (m_filteredWindow) {
102  m_filteredWindow->removeEventFilter(this);
103  m_filteredWindow.clear();
104  s_windowId = 0;
105  }
106 
107  for(QWindow *window: qApp->allWindows()) {
108  if (window && window->winId() == wid) {
109  m_filteredWindow = window;
110  window->installEventFilter(this);
111  s_windowId = wid;
112  break;
113  }
114  }
115 }
GlobalShortcutList GlobalShortcutRegistry::shortcuts ( ) const
Returns
the list of shortcuts currently registered

Definition at line 31 of file globalshortcutregistry.cpp.

32 {
33  return m_shortcuts;
34 }

The documentation for this class was generated from the following files: