Trayicon tweaks
This fixes two minor inconveniences: - When closing the chat window and re-showing it from the systray icon, the geometry was not properly restored. The window was always shown in the middle of the screen. Now, one gets the window back with it's actual last position and size. - It is now possible to not only show the window from the systray icon, but also to close it. This is the way other chat programs do it (Kopete back in the day, Konversation, Quassel IRC etc.)
This commit is contained in:
committed by
Tobias Fella
parent
3c7fcee244
commit
c1604a9c4f
@@ -124,9 +124,21 @@ Controller &Controller::instance()
|
||||
return _instance;
|
||||
}
|
||||
|
||||
void Controller::showWindow()
|
||||
void Controller::toggleWindow()
|
||||
{
|
||||
WindowController::instance().showAndRaiseWindow(QString());
|
||||
auto &instance = WindowController::instance();
|
||||
auto window = instance.window();
|
||||
if (window->isVisible()) {
|
||||
if (window->windowStates() & Qt::WindowMinimized) {
|
||||
window->showNormal();
|
||||
window->requestActivate();
|
||||
} else {
|
||||
window->close();
|
||||
}
|
||||
} else {
|
||||
instance.showAndRaiseWindow({});
|
||||
instance.window()->requestActivate();
|
||||
}
|
||||
}
|
||||
|
||||
void Controller::logout(Connection *conn, bool serverSideLogout)
|
||||
@@ -399,10 +411,10 @@ void Controller::setQuitOnLastWindowClosed()
|
||||
if (NeoChatConfig::self()->systemTray()) {
|
||||
m_trayIcon = new TrayIcon(this);
|
||||
m_trayIcon->show();
|
||||
connect(m_trayIcon, &TrayIcon::showWindow, this, &Controller::showWindow);
|
||||
connect(m_trayIcon, &TrayIcon::toggleWindow, this, &Controller::toggleWindow);
|
||||
} else {
|
||||
if (m_trayIcon) {
|
||||
disconnect(m_trayIcon, &TrayIcon::showWindow, this, &Controller::showWindow);
|
||||
disconnect(m_trayIcon, &TrayIcon::toggleWindow, this, &Controller::toggleWindow);
|
||||
delete m_trayIcon;
|
||||
m_trayIcon = nullptr;
|
||||
}
|
||||
|
||||
@@ -234,7 +234,7 @@ private:
|
||||
|
||||
private Q_SLOTS:
|
||||
void invokeLogin();
|
||||
void showWindow();
|
||||
void toggleWindow();
|
||||
void setQuitOnLastWindowClosed();
|
||||
|
||||
Q_SIGNALS:
|
||||
|
||||
@@ -16,10 +16,10 @@ TrayIcon::TrayIcon(QObject *parent)
|
||||
QMenu *menu = new QMenu();
|
||||
auto viewAction_ = new QAction(i18n("Show"), parent);
|
||||
|
||||
connect(viewAction_, &QAction::triggered, this, &TrayIcon::showWindow);
|
||||
connect(viewAction_, &QAction::triggered, this, &TrayIcon::toggleWindow);
|
||||
connect(this, &QSystemTrayIcon::activated, this, [this](QSystemTrayIcon::ActivationReason reason) {
|
||||
if (reason == QSystemTrayIcon::Trigger) {
|
||||
Q_EMIT showWindow();
|
||||
Q_EMIT toggleWindow();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ public:
|
||||
|
||||
Q_SIGNALS:
|
||||
/**
|
||||
* @brief Triggered when the system tray icon is clicked to request NeoChat be shown.
|
||||
* @brief Triggered when the system tray icon is clicked to request NeoChat be shown or hidden.
|
||||
*/
|
||||
void showWindow();
|
||||
void toggleWindow();
|
||||
};
|
||||
|
||||
@@ -13,7 +13,7 @@ TrayIcon::TrayIcon(QObject *parent)
|
||||
setIconByName(QStringLiteral("org.kde.neochat.tray"));
|
||||
connect(this, &KStatusNotifierItem::activateRequested, this, [this] {
|
||||
KWindowSystem::setCurrentXdgActivationToken(providedToken());
|
||||
Q_EMIT showWindow();
|
||||
Q_EMIT toggleWindow();
|
||||
});
|
||||
|
||||
connect(&WindowController::instance(), &WindowController::windowChanged, this, [this] {
|
||||
|
||||
@@ -30,7 +30,7 @@ public:
|
||||
|
||||
Q_SIGNALS:
|
||||
/**
|
||||
* @brief Triggered when the system tray icon is clicked to request NeoChat be shown.
|
||||
* @brief Triggered when the system tray icon is clicked to request NeoChat be shown or hidden.
|
||||
*/
|
||||
void showWindow();
|
||||
void toggleWindow();
|
||||
};
|
||||
|
||||
@@ -53,6 +53,7 @@ void WindowController::showAndRaiseWindow(const QString &startupId)
|
||||
{
|
||||
if (!m_window->isVisible()) {
|
||||
m_window->show();
|
||||
restoreGeometry();
|
||||
}
|
||||
|
||||
#ifdef HAVE_WINDOWSYSTEM
|
||||
|
||||
Reference in New Issue
Block a user