Allow triggering current tray
This commit is contained in:
parent
0ecb26a4cf
commit
6c99293087
|
@ -86,6 +86,19 @@ int initSyncthingTray(bool windowed, bool waitForTray)
|
|||
return 0;
|
||||
}
|
||||
|
||||
void trigger(bool tray, bool webUi)
|
||||
{
|
||||
if(!TrayWidget::instances().empty() && (tray || webUi)) {
|
||||
TrayWidget *trayWidget = TrayWidget::instances().front();
|
||||
if(webUi) {
|
||||
trayWidget->showWebUi();
|
||||
}
|
||||
if(tray) {
|
||||
trayWidget->showAtCursor();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int runApplication(int argc, const char *const *argv)
|
||||
{
|
||||
static bool firstRun = true;
|
||||
|
@ -98,13 +111,18 @@ int runApplication(int argc, const char *const *argv)
|
|||
QT_CONFIG_ARGUMENTS qtConfigArgs;
|
||||
Argument windowedArg("windowed", 'w', "opens the tray menu as a regular window");
|
||||
windowedArg.setCombinable(true);
|
||||
Argument showWebUi("webui", '\0', "instantly shows the web UI - meant for creating shortcut to web UI");
|
||||
showWebUi.setCombinable(true);
|
||||
Argument showWebUiArg("webui", '\0', "instantly shows the web UI - meant for creating shortcut to web UI");
|
||||
showWebUiArg.setCombinable(true);
|
||||
Argument triggerArg("trigger", '\0', "instantly shows the left-click tray menu - meant for creating a shortcut");
|
||||
triggerArg.setCombinable(true);
|
||||
Argument waitForTrayArg("wait", '\0', "wait until the system tray becomes available instead of showing an error message if the system tray is not available on start-up");
|
||||
waitForTrayArg.setCombinable(true);
|
||||
qtConfigArgs.qtWidgetsGuiArg().addSubArgument(&windowedArg);
|
||||
qtConfigArgs.qtWidgetsGuiArg().addSubArgument(&showWebUi);
|
||||
qtConfigArgs.qtWidgetsGuiArg().addSubArgument(&waitForTrayArg);
|
||||
Argument &widgetsGuiArg = qtConfigArgs.qtWidgetsGuiArg();
|
||||
widgetsGuiArg.addSubArgument(&windowedArg);
|
||||
widgetsGuiArg.addSubArgument(&showWebUiArg);
|
||||
widgetsGuiArg.addSubArgument(&triggerArg);
|
||||
widgetsGuiArg.addSubArgument(&waitForTrayArg);
|
||||
|
||||
parser.setMainArguments({&qtConfigArgs.qtWidgetsGuiArg(), &helpArg});
|
||||
try {
|
||||
parser.parseArgs(argc, argv);
|
||||
|
@ -130,9 +148,7 @@ int runApplication(int argc, const char *const *argv)
|
|||
|
||||
int res = initSyncthingTray(windowedArg.isPresent(), waitForTrayArg.isPresent());
|
||||
if(!res) {
|
||||
if(!TrayWidget::instances().empty() && showWebUi.isPresent()) {
|
||||
TrayWidget::instances().front()->showWebUi();
|
||||
}
|
||||
trigger(triggerArg.isPresent(), showWebUiArg.isPresent());
|
||||
res = application.exec();
|
||||
}
|
||||
|
||||
|
@ -140,11 +156,15 @@ int runApplication(int argc, const char *const *argv)
|
|||
QtUtilitiesResources::cleanup();
|
||||
return res;
|
||||
} else {
|
||||
if(!TrayWidget::instances().empty() && showWebUi.isPresent()) {
|
||||
// if --webui is present don't create a new tray icon, just show the web UI of the present one
|
||||
TrayWidget::instances().front()->showWebUi();
|
||||
if(!TrayWidget::instances().empty() && (showWebUiArg.isPresent() || triggerArg.isPresent())) {
|
||||
// if --webui or --trigger is present don't create a new tray icon, just trigger actions
|
||||
trigger(triggerArg.isPresent(), showWebUiArg.isPresent());
|
||||
} else {
|
||||
return initSyncthingTray(windowedArg.isPresent(), waitForTrayArg.isPresent());
|
||||
const int res = initSyncthingTray(windowedArg.isPresent(), waitForTrayArg.isPresent());
|
||||
if(!res) {
|
||||
trigger(triggerArg.isPresent(), showWebUiArg.isPresent());
|
||||
}
|
||||
return res;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,12 +7,10 @@
|
|||
|
||||
#include <qtutilities/misc/dialogutils.h>
|
||||
|
||||
#include <QApplication>
|
||||
#include <QCoreApplication>
|
||||
#include <QSvgRenderer>
|
||||
#include <QPainter>
|
||||
#include <QPixmap>
|
||||
#include <QCursor>
|
||||
#include <QDesktopWidget>
|
||||
|
||||
using namespace std;
|
||||
using namespace Dialogs;
|
||||
|
@ -99,24 +97,6 @@ void moveInside(QPoint &point, const QRect &rect)
|
|||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Moves the specified \a innerRect at the specified \a point into the specified \a outerRect
|
||||
* by altering \a point.
|
||||
*/
|
||||
void moveInside(QPoint &point, const QSize &innerRect, const QRect &outerRect)
|
||||
{
|
||||
if(point.y() < outerRect.top()) {
|
||||
point.setY(outerRect.top());
|
||||
} else if(point.y() + innerRect.height() > outerRect.bottom()) {
|
||||
point.setY(outerRect.bottom() - innerRect.height());
|
||||
}
|
||||
if(point.x() < outerRect.left()) {
|
||||
point.setX(outerRect.left());
|
||||
} else if(point.x() + innerRect.width() > outerRect.right()) {
|
||||
point.setX(outerRect.right() - innerRect.width());
|
||||
}
|
||||
}
|
||||
|
||||
void TrayIcon::handleActivated(QSystemTrayIcon::ActivationReason reason)
|
||||
{
|
||||
switch(reason) {
|
||||
|
@ -127,10 +107,7 @@ void TrayIcon::handleActivated(QSystemTrayIcon::ActivationReason reason)
|
|||
m_trayMenu.widget()->showWebUi();
|
||||
break;
|
||||
case QSystemTrayIcon::Trigger: {
|
||||
m_trayMenu.resize(m_trayMenu.sizeHint());
|
||||
QPoint pos(QCursor::pos());
|
||||
moveInside(pos, m_trayMenu.size(), QApplication::desktop()->availableGeometry(pos));
|
||||
m_trayMenu.popup(pos);
|
||||
m_trayMenu.showAtCursor();
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
|
|
@ -4,7 +4,10 @@
|
|||
|
||||
#include "../application/settings.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QHBoxLayout>
|
||||
#include <QCursor>
|
||||
#include <QDesktopWidget>
|
||||
|
||||
namespace QtGui {
|
||||
|
||||
|
@ -30,4 +33,30 @@ QSize TrayMenu::sizeHint() const
|
|||
return Settings::values().appearance.trayMenuSize;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Moves the specified \a innerRect at the specified \a point into the specified \a outerRect
|
||||
* by altering \a point.
|
||||
*/
|
||||
void moveInside(QPoint &point, const QSize &innerRect, const QRect &outerRect)
|
||||
{
|
||||
if(point.y() < outerRect.top()) {
|
||||
point.setY(outerRect.top());
|
||||
} else if(point.y() + innerRect.height() > outerRect.bottom()) {
|
||||
point.setY(outerRect.bottom() - innerRect.height());
|
||||
}
|
||||
if(point.x() < outerRect.left()) {
|
||||
point.setX(outerRect.left());
|
||||
} else if(point.x() + innerRect.width() > outerRect.right()) {
|
||||
point.setX(outerRect.right() - innerRect.width());
|
||||
}
|
||||
}
|
||||
|
||||
void TrayMenu::showAtCursor()
|
||||
{
|
||||
resize(sizeHint());
|
||||
QPoint pos(QCursor::pos());
|
||||
moveInside(pos, size(), QApplication::desktop()->availableGeometry(pos));
|
||||
popup(pos);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -20,6 +20,9 @@ public:
|
|||
TrayWidget *widget();
|
||||
TrayIcon *icon();
|
||||
|
||||
public slots:
|
||||
void showAtCursor();
|
||||
|
||||
private:
|
||||
TrayWidget *m_trayWidget;
|
||||
TrayIcon *m_trayIcon;
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
#include <QTextBrowser>
|
||||
#include <QStringBuilder>
|
||||
#include <QFontDatabase>
|
||||
#include <QCursor>
|
||||
|
||||
#include <functional>
|
||||
#include <algorithm>
|
||||
|
@ -267,6 +268,16 @@ void TrayWidget::showNotifications()
|
|||
dismissNotifications();
|
||||
}
|
||||
|
||||
void TrayWidget::showAtCursor()
|
||||
{
|
||||
if(m_menu) {
|
||||
m_menu->showAtCursor();
|
||||
} else {
|
||||
move(QCursor::pos());
|
||||
show();
|
||||
}
|
||||
}
|
||||
|
||||
void TrayWidget::dismissNotifications()
|
||||
{
|
||||
m_connection.considerAllNotificationsRead();
|
||||
|
|
|
@ -57,6 +57,7 @@ public slots:
|
|||
void showOwnDeviceId();
|
||||
void showLog();
|
||||
void showNotifications();
|
||||
void showAtCursor();
|
||||
void dismissNotifications();
|
||||
void restartSyncthing();
|
||||
void quitTray();
|
||||
|
|
Loading…
Reference in New Issue