Commit 59227025 authored by Maximilian Schiller's avatar Maximilian Schiller
Browse files

Add option to toggle the systray icon

This patch adds a option to enable and disable the yakuake systray icon.

Because KStatusNotifier doesnt provided support for disabling it has to
be removed and readded whenever the option changes. But deleting causes
the QMenu to be deleted therefore also recreate the menu on deletion.

BUG: 423408
parent 491f5a20
......@@ -102,6 +102,16 @@
</property>
</widget>
</item>
<item row="8" column="0" colspan="2">
<widget class="QCheckBox" name="kcfg_ShowSystrayIcon">
<property name="text">
<string>Show system tray icon</string>
</property>
<property name="enabled">
<bool>true</bool>
</property>
</widget>
</item>
<item row="2" column="0" colspan="2">
<widget class="QCheckBox" name="kcfg_KeepOpen">
<property name="text">
......
......@@ -66,6 +66,11 @@
<whatsthis context="@info:whatsthis">Whether to update tab titles along with the title bar.</whatsthis>
<default>false</default>
</entry>
<entry name="ShowSystrayIcon" type="Bool">
<label context="@label">Show a system tray icon</label>
<whatsthis context="@info:whatsthis">Whether to show a system tray icon.</whatsthis>
<default>true</default>
</entry>
</group>
<group name="Behavior">
<entry name="FocusFollowsMouse" type="Bool">
......
......@@ -91,7 +91,7 @@ MainWindow::MainWindow(QWidget* parent)
m_sessionStack = new SessionStack(this);
m_titleBar = new TitleBar(this);
m_tabBar = new TabBar(this);
m_notifierItem = new KStatusNotifierItem(this);
m_notifierItem = nullptr;
m_firstRunDialog = nullptr;
......@@ -145,16 +145,6 @@ MainWindow::MainWindow(QWidget* parent)
m_sessionStack->addSession();
m_notifierItem->setStandardActionsEnabled(false);
m_notifierItem->setIconByName(QStringLiteral("yakuake"));
m_notifierItem->setStatus(KStatusNotifierItem::Active);
m_notifierItem->setContextMenu(m_menu);
// Prevent the default implementation of showing
// and instead run toggleWindowState
m_notifierItem->setAssociatedWidget(nullptr);
connect(m_notifierItem, &KStatusNotifierItem::activateRequested, this, &MainWindow::toggleWindowState);
if (Settings::firstRun())
{
QMetaObject::invokeMethod(this, "toggleWindowState", Qt::QueuedConnection);
......@@ -835,6 +825,28 @@ void MainWindow::applySettings()
m_tabBar->setVisible(Settings::showTabBar());
if (!Settings::showSystrayIcon() && m_notifierItem) {
delete m_notifierItem;
m_notifierItem = nullptr;
// Removing the notifier item deletes the menu
// add a new one
m_menu = new QMenu(this);
setupMenu();
} else if (Settings::showSystrayIcon() && !m_notifierItem) {
m_notifierItem = new KStatusNotifierItem(this);
m_notifierItem->setStandardActionsEnabled(false);
m_notifierItem->setIconByName(QStringLiteral("yakuake"));
m_notifierItem->setStatus(KStatusNotifierItem::Active);
m_notifierItem->setContextMenu(m_menu);
// Prevent the default implementation of showing
// and instead run toggleWindowState
m_notifierItem->setAssociatedWidget(nullptr);
connect(m_notifierItem, &KStatusNotifierItem::activateRequested, this, &MainWindow::toggleWindowState);
updateTrayTooltip();
}
setKeepOpen(Settings::keepOpen());
updateScreenMenu();
......@@ -1617,6 +1629,10 @@ void MainWindow::updateUseTranslucency()
void MainWindow::updateTrayTooltip()
{
if (!m_notifierItem) {
return;
}
auto* action = actionCollection()->action(QStringLiteral("toggle-window-state"));
const QList<QKeySequence> &shortcuts = KGlobalAccel::self()->shortcut(action);
if (!shortcuts.isEmpty()) {
......
Markdown is supported
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