klipper: set global shortctut for the "Open Klipper at Mouse Position" action

if it is not full Katana session neither plasma-desktop nor its systemtray
applet will setup the shortcut so its better done by klipper itself

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2023-08-29 03:53:02 +03:00
parent e158808da9
commit 0121acd1ab
3 changed files with 2 additions and 35 deletions

View file

@ -216,7 +216,7 @@ Klipper::Klipper(QObject* parent, const KSharedConfigPtr& config)
// Action to show Klipper popup on mouse position
m_showOnMousePos = m_collection->addAction("show-on-mouse-pos");
m_showOnMousePos->setText(i18n("Open Klipper at Mouse Position"));
m_showOnMousePos->setGlobalShortcut(KShortcut());
m_showOnMousePos->setGlobalShortcut(KShortcut(Qt::CTRL+Qt::ALT+Qt::Key_V));
connect(m_showOnMousePos, SIGNAL(triggered(bool)), this, SLOT(slotPopupMenu()));
KlipperPopup* popup = history()->popup();

View file

@ -59,7 +59,6 @@ static const bool DEFAULT_SHOW_COMMUNICATION = true;
static const bool DEFAULT_SHOW_SERVICES = true;
static const bool DEFAULT_SHOW_HARDWARE = true;
static const bool DEFAULT_SHOW_UNKNOWN = true;
static const char KlipperName[] = "Klipper";
namespace SystemTray
{
@ -212,40 +211,11 @@ void Applet::_onAddedTask(Task *task)
DBusSystemTrayTask *dbus_task = qobject_cast<DBusSystemTrayTask*>(task);
if (dbus_task && !dbus_task->objectName().isEmpty() && dbus_task->shortcut().isEmpty()) {
// try to set shortcut
bool is_klipper = false;
QString default_shortcut;
if (dbus_task->name() == KlipperName) {
// for klipper we have to read its default hotkey from its config
is_klipper = true;
QString file = KStandardDirs::locateLocal("config", "kglobalshortcutsrc");
KConfig config(file);
KConfigGroup cg(&config, "klipper");
QStringList shortcutTextList = cg.readEntry("show_klipper_popup", QStringList());
if (shortcutTextList.size() >= 2) {
default_shortcut = shortcutTextList.first();
if (default_shortcut.isEmpty()) {
default_shortcut = shortcutTextList[1];
}
}
if (default_shortcut.isEmpty()) {
default_shortcut = "Ctrl+Alt+V";
}
}
QString action_name = _getActionName(task);
KConfigGroup cg = config();
KConfigGroup shortcutsConfig = KConfigGroup(&cg, "Shortcuts");
QString shortcut = shortcutsConfig.readEntryUntranslated(action_name, default_shortcut);
QString shortcut = shortcutsConfig.readEntryUntranslated(action_name);
dbus_task->setShortcut(shortcut);
if (is_klipper && shortcut == default_shortcut) {
// we have to write klipper's hotkey to config
if (shortcut.isEmpty())
shortcutsConfig.deleteEntry(action_name);
else
shortcutsConfig.writeEntry(action_name, shortcut);
}
}
}

View file

@ -86,9 +86,6 @@ zvalue=0
DialogHeight=102
DialogWidth=372
[Containments][1][Applets][5][Configuration][Shortcuts]
SystemTray-Klipper-5=Ctrl+Alt+V
[Containments][1][Applets][5][LayoutInformation]
Order=3