Commit a91ff4e4 authored by Neal Gompa's avatar Neal Gompa
Browse files

containmentactions/contextmenu: Add "Open Terminal" action

This adds the ability to open the terminal from the main Plasma Shell
context menu. It was originally written as a Red Hat/Fedora patch
for KDE Workspace 4 to open Konsole from the desktop context menu
when Fedora switched to KDE 4, and ported forward to KDE Plasma 5
when Fedora Linux switched to Plasma 5 in Fedora 22.

It has been maintained as a downstream patch since then.

This version of the patch genericizes the patch by not implying that
Konsole is the user's terminal (it actually opens the user's chosen
terminal anyway), can be restricted via the desktop kiosk mode
settings, and is disabled by default.

The major maintainers of this patch are being honored as co-authors
for this patch. They have all helped keep this functionality working
across two KDE major versions for a decade.

Co-authored-by: Daniel Vrátil's avatarDaniel Vrátil <>
Co-authored-by: Jan Grulich's avatarJan Grulich <>
Co-authored-by: default avatarMarc Deop <>
parent d8be398b
Pipeline #230125 passed with stage
in 10 minutes and 59 seconds
......@@ -18,6 +18,7 @@
#include <KIO/CommandLauncherJob>
#include <KLocalizedString>
#include <KService>
#include <KTerminalLauncherJob>
#include <QDebug>
#include <QIcon>
......@@ -62,6 +63,7 @@ void ContextMenu::restore(const KConfigGroup &config)
<< QStringLiteral("configure shortcuts")
<< QStringLiteral("_sep1")
<< QStringLiteral("_context")
<< QStringLiteral("_open_terminal")
<< QStringLiteral("_run_command")
<< QStringLiteral("add widgets")
<< QStringLiteral("_add panel")
......@@ -74,6 +76,7 @@ void ContextMenu::restore(const KConfigGroup &config)
<< QStringLiteral("_sep3")
<< QStringLiteral("_wallpaper");
disabled.insert(QStringLiteral("configure shortcuts"));
disabled.insert(QStringLiteral("run associated application"));
......@@ -98,6 +101,10 @@ void ContextMenu::restore(const KConfigGroup &config)
m_runCommandAction->setShortcut(KGlobalAccel::self()->globalShortcut(QStringLiteral("krunner.desktop"), QStringLiteral("_launch")).value(0));
connect(m_runCommandAction, &QAction::triggered, this, &ContextMenu::runCommand);
m_openTerminalAction = new QAction(i18n("Open Terminal"), this);
connect(m_openTerminalAction, &QAction::triggered, this, &ContextMenu::openTerminal);
m_lockScreenAction = new QAction(i18nc("plasma_containmentactions_contextmenu", "Lock Screen"), this);
m_lockScreenAction->setShortcut(KGlobalAccel::self()->globalShortcut(QStringLiteral("ksmserver"), QStringLiteral("Lock Session")).value(0));
......@@ -180,6 +187,10 @@ QAction *ContextMenu::action(const QString &name)
if (KAuthorized::authorizeAction(QStringLiteral("run_command")) && KAuthorized::authorize(QStringLiteral("run_command"))) {
return m_runCommandAction;
} else if (name == QLatin1String("_open_terminal")) {
if (KAuthorized::authorizeAction(QStringLiteral("shell_access"))) {
return m_openTerminalAction;
} else if (name == QLatin1String("_lock_screen")) {
if (KAuthorized::authorizeAction(QStringLiteral("lock_screen"))) {
return m_lockScreenAction;
......@@ -213,6 +224,16 @@ QAction *ContextMenu::action(const QString &name)
return nullptr;
void ContextMenu::openTerminal()
if (!KAuthorized::authorizeAction(QStringLiteral("shell_access"))) {
auto job = new KTerminalLauncherJob(QString());
void ContextMenu::runCommand()
if (!KAuthorized::authorizeAction(QStringLiteral("run_command"))) {
......@@ -29,11 +29,13 @@ public:
void save(KConfigGroup &config) override;
public Q_SLOTS:
void openTerminal();
void runCommand();
void startLogout();
void configureDisplays();
QAction *m_openTerminalAction = nullptr;
QAction *m_runCommandAction = nullptr;
QAction *m_lockScreenAction = nullptr;
QAction *m_logoutAction = nullptr;
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment