Skip to content
Open
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
31 changes: 23 additions & 8 deletions src/plugin-keyboard/operation/keyboardcontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
#include "dccfactory.h"
#include "layoutsmodel.h"

#include <PolkitQt1/Authority>

Check warning on line 9 in src/plugin-keyboard/operation/keyboardcontroller.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <PolkitQt1/Authority> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QFileInfo>

Check warning on line 10 in src/plugin-keyboard/operation/keyboardcontroller.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

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

namespace dccV25 {
DCC_FACTORY_CLASS(KeyboardController)

Check warning on line 13 in src/plugin-keyboard/operation/keyboardcontroller.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

There is an unknown macro here somewhere. Configuration is required. If DCC_FACTORY_CLASS is a macro then please configure it.

KeyboardController::KeyboardController(QObject *parent)
: QObject(parent)
Expand Down Expand Up @@ -228,14 +229,28 @@
return ShortcutModel::formatKeys(shortcuts);
}

QString KeyboardController::checkDesktopCmd(const QString &cmd)
{
// Check and process desktop commands, add dde-am prefix if desktop file exists
if (!cmd.isEmpty() && cmd.startsWith("/") && cmd.endsWith(".desktop")) {
QFileInfo fileInfo(cmd);
if (fileInfo.exists() && fileInfo.isFile()) {
return "dde-am " + cmd;
}
}
return cmd;
}

void KeyboardController::addCustomShortcut(const QString &name, const QString &cmd, const QString &accels)
{
// 添加时清理冲突快捷键
// Clear conflicting shortcuts when adding
if (auto conflict = m_shortcutModel->getInfo(accels)) {
m_worker->onDisableShortcut(conflict);
}

m_worker->addCustomShortcut(name, cmd, accels);
// Check and process desktop commands, add dde-am prefix if needed
QString newCmd = checkDesktopCmd(cmd);
m_worker->addCustomShortcut(name, newCmd, accels);
}

void KeyboardController::modifyCustomShortcut(const QString &id, const QString &name, const QString &cmd, const QString &accels)
Expand All @@ -246,13 +261,13 @@
return;
}

// 修改时清理冲突快捷键
// Clear conflicting shortcuts when modifying
if (auto conflict = m_shortcutModel->getInfo(accels)) {
m_worker->onDisableShortcut(conflict);
}

shortcut->name = name;
shortcut->command = cmd;
shortcut->command = checkDesktopCmd(cmd);
shortcut->accels = accels;

m_worker->modifyCustomShortcut(shortcut);
Expand All @@ -278,7 +293,7 @@
}

if (shortcut->accels != accels) {
// 修改时清理冲突快捷键
// Clear conflicting shortcuts when modifying
if (auto conflict = m_shortcutModel->getInfo(accels)) {
m_worker->onDisableShortcut(conflict);
shortcut->accels = accels;
Expand Down Expand Up @@ -353,7 +368,7 @@

const auto customInfos = m_shortcutModel->customInfo();
for (const auto *info : customInfos) {
// 排除当前编辑的快捷键(如果是修改模式)
// Exclude the current editing shortcut (if in edit mode)
if (!excludeId.isEmpty() && info->id == excludeId)
continue;

Expand All @@ -379,12 +394,12 @@
return false;
}

// 优先检查系统快捷键冲突
// Check system shortcut conflicts first
if (isSystemShortcutNameExists(name)) {
return true;
}

// 然后检查自定义快捷键冲突
// Then check custom shortcut conflicts
return isCustomShortcutNameExists(name, excludeId);
}

Expand Down
3 changes: 3 additions & 0 deletions src/plugin-keyboard/operation/keyboardcontroller.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ public Q_SLOTS:
void keyboardEnabledChanged();

private:
// 检查并处理desktop命令,如果desktop文件存在则添加dde-am前缀
QString checkDesktopCmd(const QString &cmd);

uint m_repeatInterval;
uint m_repeatDelay;
bool m_numLock;
Expand Down