bool ShortcutManager::setEnabled(bool enabled_) { if(enabled_) { if(enabled) return true; if(!enabled) { enabled = registerShortcut(sequence); return enabled; } } if(!enabled_) { if(!enabled) return true; if(enabled) { unregisterShortcut(); return true; } } return false; }
bool QtGlobalShortcutPrivate::unsetShortcut() { const quint32 nativeKey = nativeKeycode(key); const quint32 nativeMods = nativeModifiers(mods); const bool res = unregisterShortcut(nativeKey, nativeMods); shortcuts.remove(qMakePair(nativeKey, nativeMods)); if (!res) qWarning() << "QtGlobalShortcut failed to unregister:" << QKeySequence(key + mods).toString(); key = Qt::Key(0); mods = Qt::KeyboardModifiers(0); return res; }
bool ShortcutManager::setShortcut(QKeySequence sequence) { if(enabled) { unregisterShortcut(); enabled = false; } this->sequence = sequence; enabled = registerShortcut(sequence); return enabled; }
bool QxtGlobalShortcutPrivate::unsetShortcut() { bool res = false; const quint32 nativeKey = nativeKeycode(key); const quint32 nativeMods = nativeModifiers(mods); if (shortcuts.value(qMakePair(nativeKey, nativeMods)) == &qxt_p()) res = unregisterShortcut(nativeKey, nativeMods); if (res) shortcuts.remove(qMakePair(nativeKey, nativeMods)); else qWarning() << "QxtGlobalShortcut failed to unregister:" << QKeySequence(key + mods).toString(); key = Qt::Key(0); mods = Qt::KeyboardModifiers(0); return res; }
bool QxtGlobalShortcutPrivate::unsetShortcut() { Q_Q(QxtGlobalShortcut); bool res = false; const quint32 nativeKey = nativeKeycode(key); const quint32 nativeMods = nativeModifiers(mods); if (shortcuts.value({nativeKey, nativeMods}) == q) res = unregisterShortcut(nativeKey, nativeMods); if (res) shortcuts.remove({nativeKey, nativeMods}); else qWarning("QxtGlobalShortcut failed to unregister: %s", qPrintable(QKeySequence(key + mods).toString())); key = Qt::Key(0); mods = Qt::KeyboardModifiers(Qt::NoModifier); return res; }
bool QxtGlobalShortcutPrivate::registerShortcut(quint32 nativeKey, quint32 nativeMods) { xcb_connection_t *xcbConnection = QX11Info::connection(); QList<xcb_void_cookie_t> xcbCookies; for (quint32 maskMods : maskModifiers) { xcbCookies << xcb_grab_key_checked(xcbConnection, 1, QX11Info::appRootWindow(), nativeMods | maskMods, nativeKey, XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC); } bool failed = false; for (xcb_void_cookie_t cookie : xcbCookies) { QScopedPointer<xcb_generic_error_t, QScopedPointerPodDeleter> error(xcb_request_check(xcbConnection, cookie)); failed = !error.isNull(); } if (failed) unregisterShortcut(nativeKey, nativeMods); return !failed; }
bool ShortcutManager::setDisabled(bool disabled) { if(disabled) { unregisterShortcut(); enabled = false; return true; } if(!disabled) { if(enabled) return true; if(!enabled) { enabled = registerShortcut(sequence); return enabled; } } return false; }