-
Notifications
You must be signed in to change notification settings - Fork 71
feat: add key state notification applet for Wayland #1614
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| # SPDX-FileCopyrightText: 2026 UnionTech Software Technology Co., Ltd. | ||
| # | ||
| # SPDX-License-Identifier: GPL-3.0-or-later | ||
|
|
||
| find_package(TreelandProtocols REQUIRED) | ||
|
|
||
| set(TREELAND_KEYBOARD_STATE_NOTIFY_PROTOCOL | ||
| ${TREELAND_PROTOCOLS_DATA_DIR}/treeland-keyboard-state-notify-unstable-v1.xml | ||
| ) | ||
|
|
||
| add_library(dde-key-notify SHARED | ||
| keynotifyapplet.cpp | ||
| keynotifyapplet.h | ||
| treelandkeynotify.cpp | ||
| treelandkeynotify.h | ||
| ) | ||
|
|
||
| qt_generate_wayland_protocol_client_sources(dde-key-notify | ||
| NO_INCLUDE_CORE_ONLY | ||
| FILES | ||
| ${TREELAND_KEYBOARD_STATE_NOTIFY_PROTOCOL} | ||
| ) | ||
|
|
||
| target_link_libraries(dde-key-notify PRIVATE | ||
| dde-shell-frame | ||
| Qt${QT_VERSION_MAJOR}::DBus | ||
| Qt${QT_VERSION_MAJOR}::WaylandClient | ||
| ) | ||
|
|
||
| ds_install_package(PACKAGE org.deepin.ds.dde-key-notify TARGET dde-key-notify) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| // SPDX-FileCopyrightText: 2026 UnionTech Software Technology Co., Ltd. | ||
| // | ||
| // SPDX-License-Identifier: GPL-3.0-or-later | ||
|
|
||
| #include "keynotifyapplet.h" | ||
|
|
||
| #include "pluginfactory.h" | ||
| #include "treelandkeynotify.h" | ||
|
|
||
| #include <DDBusSender> | ||
| #include <DGuiApplicationHelper> | ||
|
|
||
| DCORE_USE_NAMESPACE | ||
|
|
||
| DS_BEGIN_NAMESPACE | ||
| namespace keynotify | ||
| { | ||
|
|
||
| KeyNotifyApplet::KeyNotifyApplet(QObject *parent) | ||
| : DApplet(parent) | ||
| { | ||
| } | ||
|
|
||
| KeyNotifyApplet::~KeyNotifyApplet() = default; | ||
|
|
||
| bool KeyNotifyApplet::load() | ||
| { | ||
| if (!Dtk::Gui::DGuiApplicationHelper::testAttribute(Dtk::Gui::DGuiApplicationHelper::IsWaylandPlatform)) { | ||
| return DApplet::load(); | ||
| } | ||
|
|
||
| m_keyNotify = new TreelandKeyNotify(this); | ||
| connect(m_keyNotify, &TreelandKeyNotify::capsLockChanged, this, &KeyNotifyApplet::showCapsLockOsd); | ||
| connect(m_keyNotify, &TreelandKeyNotify::numLockChanged, this, &KeyNotifyApplet::showNumLockOsd); | ||
| initConfig(); | ||
| m_keyNotify->setCapsLockEnabled(m_config->value(QStringLiteral("capslockToggle")).toBool()); | ||
| return DApplet::load(); | ||
| } | ||
|
|
||
| void KeyNotifyApplet::showCapsLockOsd(bool locked) | ||
| { | ||
| sendOsd(locked ? QStringLiteral("CapsLockOn") : QStringLiteral("CapsLockOff")); | ||
| } | ||
|
|
||
| void KeyNotifyApplet::showNumLockOsd(bool locked) | ||
| { | ||
| sendOsd(locked ? QStringLiteral("NumLockOn") : QStringLiteral("NumLockOff")); | ||
| } | ||
|
|
||
| void KeyNotifyApplet::updateCapsLockToggle(const QString &key) | ||
| { | ||
| if (key != QStringLiteral("capslockToggle")) { | ||
| return; | ||
| } | ||
|
|
||
| m_keyNotify->setCapsLockEnabled(m_config->value(key).toBool()); | ||
| } | ||
|
|
||
| void KeyNotifyApplet::sendOsd(const QString &osdType) | ||
| { | ||
| DDBusSender().service("org.deepin.dde.shell").path("/org/deepin/dde/shell/osd").interface("org.deepin.dde.shell.osd").method("ShowOSD").arg(osdType).call(); | ||
|
yixinshark marked this conversation as resolved.
|
||
| } | ||
|
|
||
| void KeyNotifyApplet::initConfig() | ||
| { | ||
| m_config = Dtk::Core::DConfig::create(QStringLiteral("org.deepin.dde.daemon"), QStringLiteral("org.deepin.dde.daemon.keyboard"), QString(), this); | ||
| connect(m_config, &Dtk::Core::DConfig::valueChanged, this, &KeyNotifyApplet::updateCapsLockToggle); | ||
| } | ||
|
|
||
| D_APPLET_CLASS(KeyNotifyApplet) | ||
|
|
||
| } | ||
| DS_END_NAMESPACE | ||
|
|
||
| #include "keynotifyapplet.moc" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| // SPDX-FileCopyrightText: 2026 UnionTech Software Technology Co., Ltd. | ||
| // | ||
| // SPDX-License-Identifier: GPL-3.0-or-later | ||
|
|
||
| #pragma once | ||
|
|
||
| #include "applet.h" | ||
|
|
||
| #include <DConfig> | ||
|
|
||
| #include <QPointer> | ||
|
|
||
| DS_BEGIN_NAMESPACE | ||
| namespace keynotify | ||
| { | ||
|
|
||
| class TreelandKeyNotify; | ||
|
|
||
| class KeyNotifyApplet : public DApplet | ||
| { | ||
| Q_OBJECT | ||
|
|
||
| public: | ||
| explicit KeyNotifyApplet(QObject *parent = nullptr); | ||
| ~KeyNotifyApplet() override; | ||
|
|
||
| bool load() override; | ||
|
|
||
| private Q_SLOTS: | ||
| void showCapsLockOsd(bool locked); | ||
| void showNumLockOsd(bool locked); | ||
| void updateCapsLockToggle(const QString &key); | ||
|
|
||
| private: | ||
| void sendOsd(const QString &osdType); | ||
| void initConfig(); | ||
|
|
||
| private: | ||
| QPointer<TreelandKeyNotify> m_keyNotify; | ||
| Dtk::Core::DConfig *m_config = nullptr; | ||
| }; | ||
|
|
||
| } | ||
| DS_END_NAMESPACE | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "Plugin": { | ||
| "Version": "1.0", | ||
| "Id": "org.deepin.ds.dde-key-notify", | ||
| "Category": "DDE" | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| // SPDX-FileCopyrightText: 2026 UnionTech Software Technology Co., Ltd. | ||
| // | ||
| // SPDX-License-Identifier: GPL-3.0-or-later | ||
|
|
||
| #include "treelandkeynotify.h" | ||
|
|
||
| #include "wayland-treeland-keyboard-state-notify-unstable-v1-client-protocol.h" | ||
|
|
||
| DS_BEGIN_NAMESPACE | ||
| namespace keynotify | ||
| { | ||
|
|
||
| TreelandKeyNotify::TreelandKeyNotify(QObject *parent) | ||
| : QWaylandClientExtensionTemplate<TreelandKeyNotify>(treeland_keyboard_state_notify_manager_v1_interface.version) | ||
| { | ||
| setParent(parent); | ||
| connect(this, &TreelandKeyNotify::activeChanged, this, &TreelandKeyNotify::updateWatcher); | ||
| } | ||
|
|
||
| void TreelandKeyNotify::setCapsLockEnabled(bool enabled) | ||
| { | ||
| if (m_capsLockEnabled == enabled) { | ||
| return; | ||
| } | ||
|
|
||
| m_capsLockEnabled = enabled; | ||
| updateWatcher(); | ||
| } | ||
|
|
||
| void TreelandKeyNotify::updateWatcher() | ||
| { | ||
| if (!isActive()) { | ||
| if (m_watcher) { | ||
| m_watcher->deleteLater(); | ||
| m_watcher = nullptr; | ||
| } | ||
| return; | ||
| } | ||
|
|
||
| if (!m_watcher) { | ||
| m_watcher = createWatcher(this); | ||
| if (!m_watcher) { | ||
| return; | ||
| } | ||
|
|
||
| connect(m_watcher, &TreelandKeyWatcher::stateChanged, this, [this](uint32_t modifier, uint32_t state) { | ||
| if (modifier == TreelandKeyWatcher::modifier_caps_lock) { | ||
| if (state == TreelandKeyWatcher::modifier_state_locked) { | ||
| Q_EMIT capsLockChanged(true); | ||
| } else if (state == TreelandKeyWatcher::modifier_state_unlocked) { | ||
| Q_EMIT capsLockChanged(false); | ||
| } | ||
| } else if (modifier == TreelandKeyWatcher::modifier_num_lock) { | ||
| if (state == TreelandKeyWatcher::modifier_state_locked) { | ||
| Q_EMIT numLockChanged(true); | ||
| } else if (state == TreelandKeyWatcher::modifier_state_unlocked) { | ||
| Q_EMIT numLockChanged(false); | ||
| } | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| m_watcher->watchLocks(m_capsLockEnabled); | ||
| } | ||
|
|
||
| TreelandKeyWatcher *TreelandKeyNotify::createWatcher(QObject *parent) | ||
| { | ||
| if (!isActive()) { | ||
| return nullptr; | ||
| } | ||
|
|
||
| auto *watcher = get_keyboard_state_watcher(nullptr); | ||
| if (!watcher) { | ||
| return nullptr; | ||
| } | ||
|
|
||
| return new TreelandKeyWatcher(watcher, parent); | ||
| } | ||
|
|
||
| TreelandKeyWatcher::TreelandKeyWatcher(struct ::treeland_keyboard_state_watcher_v1 *object, QObject *parent) | ||
| : QObject(parent) | ||
| , QtWayland::treeland_keyboard_state_watcher_v1(object) | ||
| { | ||
| } | ||
|
|
||
| void TreelandKeyWatcher::watchLocks(bool watchCapsLock) | ||
| { | ||
| set_modifiers(watchCapsLock ? modifier_caps_lock | modifier_num_lock : modifier_num_lock); | ||
| set_flags(watch_flag_locked | watch_flag_unlocked); | ||
| apply(); | ||
| } | ||
|
|
||
| void TreelandKeyWatcher::treeland_keyboard_state_watcher_v1_state_changed(uint32_t modifier, uint32_t state) | ||
| { | ||
| Q_EMIT stateChanged(modifier, state); | ||
| } | ||
|
|
||
| } | ||
| DS_END_NAMESPACE | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| // SPDX-FileCopyrightText: 2026 UnionTech Software Technology Co., Ltd. | ||
| // | ||
| // SPDX-License-Identifier: GPL-3.0-or-later | ||
|
|
||
| #pragma once | ||
|
|
||
| #include "dsglobal.h" | ||
| #include "qwayland-treeland-keyboard-state-notify-unstable-v1.h" | ||
|
|
||
| #include <QPointer> | ||
| #include <QtWaylandClient/QWaylandClientExtension> | ||
|
|
||
| struct treeland_keyboard_state_watcher_v1; | ||
|
|
||
| DS_BEGIN_NAMESPACE | ||
| namespace keynotify | ||
| { | ||
|
|
||
| class TreelandKeyWatcher; | ||
|
|
||
| class TreelandKeyNotify : public QWaylandClientExtensionTemplate<TreelandKeyNotify>, public QtWayland::treeland_keyboard_state_notify_manager_v1 | ||
| { | ||
| Q_OBJECT | ||
|
|
||
| public: | ||
| explicit TreelandKeyNotify(QObject *parent = nullptr); | ||
|
|
||
| void setCapsLockEnabled(bool enabled); | ||
|
|
||
| Q_SIGNALS: | ||
| void capsLockChanged(bool locked); | ||
| void numLockChanged(bool locked); | ||
|
|
||
| private Q_SLOTS: | ||
| void updateWatcher(); | ||
|
|
||
| private: | ||
| TreelandKeyWatcher *createWatcher(QObject *parent = nullptr); | ||
|
|
||
| private: | ||
| bool m_capsLockEnabled = false; | ||
| QPointer<TreelandKeyWatcher> m_watcher; | ||
| }; | ||
|
|
||
| class TreelandKeyWatcher : public QObject, public QtWayland::treeland_keyboard_state_watcher_v1 | ||
| { | ||
| Q_OBJECT | ||
|
|
||
| public: | ||
| explicit TreelandKeyWatcher(struct ::treeland_keyboard_state_watcher_v1 *object, QObject *parent = nullptr); | ||
|
|
||
| void watchLocks(bool watchCapsLock); | ||
|
|
||
| Q_SIGNALS: | ||
| void stateChanged(uint32_t modifier, uint32_t state); | ||
|
|
||
| protected: | ||
| void treeland_keyboard_state_watcher_v1_state_changed(uint32_t modifier, uint32_t state) override; | ||
| }; | ||
|
|
||
| } | ||
| DS_END_NAMESPACE | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.