[plugins/stickykeys] Show notification when keys are locked
If the relevant setting is enabled CCBUG: 395559
This commit is contained in:
parent
4ae33be104
commit
0419c9a3b1
3 changed files with 41 additions and 1 deletions
|
@ -14,5 +14,8 @@ target_sources(StickyKeysPlugin PRIVATE
|
|||
main.cpp
|
||||
stickykeys.cpp
|
||||
)
|
||||
target_link_libraries(StickyKeysPlugin PRIVATE kwin KF6::WindowSystem XKB::XKB)
|
||||
target_link_libraries(StickyKeysPlugin PRIVATE kwin KF6::WindowSystem KF6::I18n XKB::XKB)
|
||||
|
||||
if (KWIN_BUILD_NOTIFICATIONS)
|
||||
target_link_libraries(StickyKeysPlugin PRIVATE KF6::Notifications)
|
||||
endif()
|
||||
|
|
|
@ -8,6 +8,25 @@
|
|||
#include "keyboard_input.h"
|
||||
#include "xkb.h"
|
||||
|
||||
#include <KLazyLocalizedString>
|
||||
#if KWIN_BUILD_NOTIFICATIONS
|
||||
#include <KNotification>
|
||||
#endif
|
||||
|
||||
struct Modifier
|
||||
{
|
||||
Qt::Key key;
|
||||
KLazyLocalizedString lockedText;
|
||||
};
|
||||
|
||||
static const std::array<Modifier, 5> modifiers = {
|
||||
Modifier{Qt::Key_Shift, kli18n("The Shift key has been locked and is now active for all of the following keypresses.")},
|
||||
Modifier{Qt::Key_Control, kli18n("The Control key has been locked and is now active for all of the following keypresses.")},
|
||||
Modifier{Qt::Key_Alt, kli18n("The Alt key has been locked and is now active for all of the following keypresses.")},
|
||||
Modifier{Qt::Key_Meta, kli18n("The Meta key has been locked and is now active for all of the following keypresses.")},
|
||||
Modifier{Qt::Key_AltGr, kli18n("The AltGr key has been locked and is now active for all of the following keypresses.")},
|
||||
};
|
||||
|
||||
StickyKeysFilter::StickyKeysFilter()
|
||||
: m_configWatcher(KConfigWatcher::create(KSharedConfig::openConfig("kaccessrc")))
|
||||
{
|
||||
|
@ -46,6 +65,7 @@ void StickyKeysFilter::loadConfig(const KConfigGroup &group)
|
|||
KWin::input()->uninstallInputEventFilter(this);
|
||||
|
||||
m_lockKeys = group.readEntry<bool>("StickyKeysLatch", true);
|
||||
m_showNotificationForLockedKeys = group.readEntry<bool>("kNotifyModifiers", false);
|
||||
|
||||
if (!m_lockKeys) {
|
||||
// locking keys is deactivated, unlock all locked keys
|
||||
|
@ -89,6 +109,22 @@ bool StickyKeysFilter::keyEvent(KWin::KeyEvent *event)
|
|||
else if (keyState.value() == Latched && m_lockKeys) {
|
||||
keyState.value() = Locked;
|
||||
KWin::input()->keyboard()->xkb()->setModifierLocked(keyToModifier(static_cast<Qt::Key>(event->key())), true);
|
||||
|
||||
if (m_showNotificationForLockedKeys) {
|
||||
#if KWIN_BUILD_NOTIFICATIONS
|
||||
KNotification *noti = new KNotification("modifierkey-locked");
|
||||
noti->setComponentName("kaccess");
|
||||
|
||||
for (const auto mod : modifiers) {
|
||||
if (mod.key == event->key()) {
|
||||
noti->setText(mod.lockedText.toString());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
noti->sendEvent();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
// A locked modifier was pressed, unlock it
|
||||
else if (keyState.value() == Locked && m_lockKeys) {
|
||||
|
|
|
@ -32,4 +32,5 @@ private:
|
|||
QMap<int, KeyState> m_keyStates;
|
||||
QList<int> m_modifiers = {Qt::Key_Shift, Qt::Key_Control, Qt::Key_Alt, Qt::Key_AltGr, Qt::Key_Meta};
|
||||
bool m_lockKeys = false;
|
||||
bool m_showNotificationForLockedKeys = false;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue