Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions applets/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
add_subdirectory(dde-am)
add_subdirectory(dde-appearance)
add_subdirectory(dde-apps)
add_subdirectory(dde-key-notify)
add_subdirectory(dde-shutdown)
30 changes: 30 additions & 0 deletions applets/dde-key-notify/CMakeLists.txt
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
Comment thread
yixinshark marked this conversation as resolved.
)

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)
75 changes: 75 additions & 0 deletions applets/dde-key-notify/keynotifyapplet.cpp
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"

Check warning on line 7 in applets/dde-key-notify/keynotifyapplet.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "pluginfactory.h" not found.
#include "treelandkeynotify.h"

#include <DDBusSender>

Check warning on line 10 in applets/dde-key-notify/keynotifyapplet.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <DDBusSender> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <DGuiApplicationHelper>

Check warning on line 11 in applets/dde-key-notify/keynotifyapplet.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <DGuiApplicationHelper> not found. Please note: Cppcheck does not need standard library headers to get proper results.

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();
Comment thread
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"

Check warning on line 75 in applets/dde-key-notify/keynotifyapplet.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "keynotifyapplet.moc" not found.
44 changes: 44 additions & 0 deletions applets/dde-key-notify/keynotifyapplet.h
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"

Check warning on line 7 in applets/dde-key-notify/keynotifyapplet.h

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "applet.h" not found.

#include <DConfig>

Check warning on line 9 in applets/dde-key-notify/keynotifyapplet.h

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <DConfig> not found. Please note: Cppcheck does not need standard library headers to get proper results.

#include <QPointer>

Check warning on line 11 in applets/dde-key-notify/keynotifyapplet.h

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QPointer> not found. Please note: Cppcheck does not need standard library headers to get proper results.

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:

Check warning on line 29 in applets/dde-key-notify/keynotifyapplet.h

View workflow job for this annotation

GitHub Actions / cppcheck

There is an unknown macro here somewhere. Configuration is required. If Q_SLOTS is a macro then please configure it.
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
7 changes: 7 additions & 0 deletions applets/dde-key-notify/package/metadata.json
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"
}
}
99 changes: 99 additions & 0 deletions applets/dde-key-notify/treelandkeynotify.cpp
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"

Check warning on line 7 in applets/dde-key-notify/treelandkeynotify.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "wayland-treeland-keyboard-state-notify-unstable-v1-client-protocol.h" not found.

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
62 changes: 62 additions & 0 deletions applets/dde-key-notify/treelandkeynotify.h
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"

Check warning on line 7 in applets/dde-key-notify/treelandkeynotify.h

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "dsglobal.h" not found.
#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
2 changes: 1 addition & 1 deletion debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Build-Depends:
qt6-wayland-dev-tools,
qt6-wayland-private-dev,
systemd,
treeland-protocols (>= 0.5.7),
treeland-protocols (>> 0.5.7),
wayland-protocols,
Standards-Version: 4.6.2
Homepage: https://github.com/linuxdeepin/dde-shell
Expand Down
2 changes: 2 additions & 0 deletions debian/dde-shell.install
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ usr/bin/*
usr/lib/*/dde-shell/org.deepin.ds.dde-am*
usr/lib/*/dde-shell/org.deepin.ds.dde-appearance*
usr/lib/*/dde-shell/org.deepin.ds.dde-apps*
usr/lib/*/dde-shell/org.deepin.ds.dde-key-notify*
usr/lib/*/dde-shell/org.deepin.ds.dde-shutdown*
usr/lib/*/dde-shell/org.deepin.ds.dock*
usr/lib/*/dde-shell/org.deepin.ds.notification*
Expand All @@ -19,6 +20,7 @@ usr/share/dde-shell/*/translations
usr/share/dde-shell/org.deepin.ds.dde-am*/
usr/share/dde-shell/org.deepin.ds.dde-appearance*/
usr/share/dde-shell/org.deepin.ds.dde-apps*/
usr/share/dde-shell/org.deepin.ds.dde-key-notify*/
usr/share/dde-shell/org.deepin.ds.dde-shutdown*/
usr/share/dde-shell/org.deepin.ds.dock*/
usr/share/dde-shell/org.deepin.ds.notification*/
Expand Down
Loading