Skip to content

Commit 018c302

Browse files
ahmubashshirmominul
authored andcommitted
frontend: Tray launch improvements
* Hide running in tray notification if ran with `--tray` * Keep running after last visible window is closed when hidden in tray Fixes #446 Fixes #320 Signed-off-by: Mubashshir <ahmubashshir@gmail.com>
1 parent b29dce3 commit 018c302

3 files changed

Lines changed: 35 additions & 21 deletions

File tree

src/engine/fcitx/openbangla.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[InputMethod]
22
Name=OpenBangla Keyboard
33
Icon=openbangla-keyboard
4-
Label=বাং
4+
Label=বা
55
LangCode=bn
66
Addon=openbangla
77
Configurable=True

src/frontend/TopBar.cpp

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,20 @@
3636
#include "FileSystem.h"
3737
#include "ui_TopBar.h"
3838

39+
#include <iostream>
40+
41+
static void notifyTrayStart(QSystemTrayIcon* tray) {
42+
if (qApp->property("invokedAsTray").toBool()) return;
43+
uint count = gSettings->getTrayInfoCount();
44+
if (count >= 4) return;
45+
if (gSettings->getTopBarVisibility()) return;
46+
47+
tray->showMessage("OpenBangla Keyboard", "Currently running in the system tray.\n"
48+
"You can use the tray icon to change keyboard layouts and other "
49+
"settings and to show the TopBar again.");
50+
// Update the counter to show only the message for the first three times
51+
gSettings->setTrayInfoCount(count + 1);
52+
}
3953

4054
TopBar::TopBar(bool darkIcon, QWidget *parent) :
4155
QMainWindow(parent),
@@ -74,17 +88,11 @@ TopBar::TopBar(bool darkIcon, QWidget *parent) :
7488
SetupPopupMenus();
7589
SetupTrayIcon();
7690
DataMigration();
77-
78-
uint count = gSettings->getTrayInfoCount();
79-
if(count < 4 && !gSettings->getTopBarVisibility()) {
80-
tray->showMessage("OpenBangla Keyboard", "Currently running in the system tray.\n"
81-
"You can use the tray icon to change keyboard layouts and other "
82-
"settings and to show the TopBar again.");
83-
// Update the counter to show only the message for the first three times
84-
gSettings->setTrayInfoCount(count + 1);
85-
}
91+
notifyTrayStart(tray);
8692
}
8793

94+
95+
8896
TopBar::~TopBar() {
8997
/* Dialogs */
9098
delete layoutViewer;
@@ -140,7 +148,7 @@ void TopBar::SetupPopupMenus() {
140148
// Icon Button Popup Menu
141149
iconMenuHide = new QAction("Hide this TopBar", this);
142150
connect(iconMenuHide, &QAction::triggered, [&]() {
143-
this->setVisible(false);
151+
this->hide();
144152
trayTopBarVisibility->setText("Show the TopBar");
145153
});
146154

@@ -184,16 +192,18 @@ void TopBar::SetupTrayIcon() {
184192
connect(traySettings, &QAction::triggered, this, &TopBar::on_buttonSettings_clicked);
185193

186194
trayTopBarVisibility = new QAction(
187-
gSettings->getTopBarVisibility() ? "Hide the TopBar" : "Show the TopBar",
195+
(this->isVisible())
196+
? "Hide the TopBar"
197+
: "Show the TopBar",
188198
this
189199
);
190200

191201
connect(trayTopBarVisibility, &QAction::triggered, [&]() {
192202
if(this->isVisible()) {
193-
this->setVisible(false);
203+
this->hide();
194204
trayTopBarVisibility->setText("Show the TopBar");
195205
} else {
196-
this->setVisible(true);
206+
this->show();
197207
trayTopBarVisibility->setText("Hide the TopBar");
198208
}
199209
});
@@ -211,7 +221,7 @@ void TopBar::SetupTrayIcon() {
211221
trayMenu->addAction(trayQuit);
212222

213223
tray->setContextMenu(trayMenu);
214-
tray->setVisible(true);
224+
tray->show();
215225
}
216226

217227
void TopBar::RefreshLayouts() {
@@ -335,7 +345,8 @@ void TopBar::on_buttonIcon_clicked() {
335345

336346
void TopBar::closeEvent(QCloseEvent *event) {
337347
gSettings->setTopBarWindowPosition(this->pos());
338-
gSettings->setTopBarVisibility(this->isVisible());
348+
if(! qApp->property("invokedAsTray").toBool())
349+
gSettings->setTopBarVisibility(this->isVisible());
339350
event->accept();
340351
}
341352

@@ -377,7 +388,8 @@ void TopBar::on_buttonSetLayout_clicked() {
377388

378389
void TopBar::on_buttonShutdown_clicked() {
379390
gSettings->setTopBarWindowPosition(this->pos());
380-
gSettings->setTopBarVisibility(this->isVisible());
391+
if(! qApp->property("invokedAsTray").toBool())
392+
gSettings->setTopBarVisibility(this->isVisible());
381393
QApplication::exit();
382394
}
383395

src/frontend/main.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,11 @@ int main(int argc, char *argv[]) {
6565
bool darkMode = (color == darker) || parser.isSet(darkIcon);
6666

6767
TopBar w(darkMode);
68-
w.show();
69-
if (parser.isSet(startInTray) || !gSettings->getTopBarVisibility()) {
70-
w.setVisible(false);
71-
}
68+
if (parser.isSet(startInTray))
69+
app.setProperty("invokedAsTray", parser.isSet(startInTray));
70+
else if(gSettings->getTopBarVisibility())
71+
w.show();
72+
73+
app.setQuitOnLastWindowClosed(false);
7274
return app.exec();
7375
}

0 commit comments

Comments
 (0)