Skip to content

Commit

Permalink
Allow showing Syncthing Tray as normal application/window
Browse files Browse the repository at this point in the history
* Remove experimental pinning feature again and instead allow using a
  normal window
    * Pinning made it inconvenient to close the (frameless) window again
    * Pinning required hiding/showing the window which didn't look very
      nice (and setting flags directly via `QWindow` didn't work as well)
* As normal application/window positioning issues on Wayland are less
  problematic (and those aren't going to be fixed any time soon, if at all)
  • Loading branch information
Martchus committed Nov 29, 2022
1 parent 71675c7 commit 71c56ed
Show file tree
Hide file tree
Showing 18 changed files with 614 additions and 567 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,11 @@ configuration like this:
for_window [title="^Syncthing Tray( \(.*\))?$"] floating enable, border none, resize set 450 400, move position 916 0
```

Alternatively, one can also configure Syncthing Tray to use a normal window in
the appearance settings. That doesn't fix the positioning issue but then it
looks just like a normal application so not being positioned in the tray area is
less problematic.

### Workaround broken High-DPI scaling of Plasmoid under X11
Setting the environment variable `PLASMA_USE_QT_SCALING=1` should fix the
[issue](https://bugs.kde.org/show_bug.cgi?id=356446) on recent Plasma versions but
Expand Down
16 changes: 9 additions & 7 deletions tray/gui/traymenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include <QApplication>
#include <QHBoxLayout>
#include <QWindow>

using namespace QtUtilities;

Expand All @@ -16,7 +17,7 @@ namespace QtGui {
TrayMenu::TrayMenu(TrayIcon *trayIcon, QWidget *parent)
: QMenu(parent)
, m_trayIcon(trayIcon)
, m_pinned(false)
, m_windowed(false)
{
setObjectName(QStringLiteral("QtGui::TrayMenu"));
auto *const menuLayout = new QHBoxLayout;
Expand All @@ -26,6 +27,7 @@ TrayMenu::TrayMenu(TrayIcon *trayIcon, QWidget *parent)
setLayout(menuLayout);
setPlatformMenu(nullptr);
setWindowFlags(Qt::FramelessWindowHint | Qt::Popup);
setWindowIcon(m_trayWidget->windowIcon());
}

QSize TrayMenu::sizeHint() const
Expand Down Expand Up @@ -60,23 +62,23 @@ void TrayMenu::showUsingPositioningSettings()
activateWindow();
}

void TrayMenu::setPinned(bool pinned)
void TrayMenu::setWindowed(bool windowed)
{
setWindowFlags(Qt::FramelessWindowHint | ((m_pinned = pinned) ? Qt::Window : Qt::Popup));
show();
activateWindow();
if (m_windowed != windowed) {
setWindowFlags((m_windowed = windowed) ? Qt::Window : Qt::FramelessWindowHint | Qt::Popup);
}
}

void TrayMenu::mousePressEvent(QMouseEvent *event)
{
if (!m_pinned) {
if (!m_windowed) {
QMenu::mousePressEvent(event);
}
}

void TrayMenu::mouseReleaseEvent(QMouseEvent *event)
{
if (!m_pinned) {
if (!m_windowed) {
QMenu::mouseReleaseEvent(event);
}
}
Expand Down
12 changes: 6 additions & 6 deletions tray/gui/traymenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class TrayWidget;

class TrayMenu : public QMenu {
Q_OBJECT
Q_PROPERTY(bool pinned READ isPinned WRITE setPinned)
Q_PROPERTY(bool windowed READ isWindowed WRITE setWindowed)

public:
explicit TrayMenu(TrayIcon *trayIcon = nullptr, QWidget *parent = nullptr);
Expand All @@ -19,11 +19,11 @@ class TrayMenu : public QMenu {
TrayWidget &widget();
const TrayWidget &widget() const;
TrayIcon *icon();
bool isPinned() const;
bool isWindowed() const;

public Q_SLOTS:
void showUsingPositioningSettings();
void setPinned(bool pinned);
void setWindowed(bool windowed);

protected:
void mouseReleaseEvent(QMouseEvent *) override;
Expand All @@ -32,7 +32,7 @@ public Q_SLOTS:
private:
TrayWidget *m_trayWidget;
TrayIcon *m_trayIcon;
bool m_pinned = false;
bool m_windowed = false;
};

inline TrayWidget &TrayMenu::widget()
Expand All @@ -50,9 +50,9 @@ inline TrayIcon *TrayMenu::icon()
return m_trayIcon;
}

inline bool TrayMenu::isPinned() const
inline bool TrayMenu::isWindowed() const
{
return m_pinned;
return m_windowed;
}

} // namespace QtGui
Expand Down
19 changes: 4 additions & 15 deletions tray/gui/traywidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,11 +220,6 @@ TrayWidget::TrayWidget(TrayMenu *parent)
if (const auto *const launcher = SyncthingLauncher::mainInstance()) {
connect(launcher, &SyncthingLauncher::runningChanged, this, &TrayWidget::handleLauncherStatusChanged);
}
if (m_menu && Settings::values().enableWipFeatures) {
connect(m_ui->pinPushButton, &QPushButton::toggled, this, &TrayWidget::handlePinnedChanged);
} else {
m_ui->pinPushButton->hide();
}
#ifdef LIB_SYNCTHING_CONNECTOR_SUPPORT_SYSTEMD
if (const auto *const service = SyncthingService::mainInstance()) {
connect(service, &SyncthingService::systemdAvailableChanged, this, &TrayWidget::handleSystemdStatusChanged);
Expand Down Expand Up @@ -331,14 +326,6 @@ void TrayWidget::applySettingsChangesFromWizard()
}
}

void TrayWidget::handlePinnedChanged(bool pinned)
{
Settings::values().appearance.pinned = pinned;
if (m_menu) {
m_menu->setPinned(pinned);
}
}

void TrayWidget::showAboutDialog()
{
if (!s_dialogParent) {
Expand Down Expand Up @@ -604,7 +591,9 @@ void TrayWidget::applySettings(const QString &connectionConfig)
}
}
}
m_ui->pinPushButton->setChecked(settings.appearance.pinned);
if (m_menu) {
m_menu->setWindowed(settings.appearance.windowed);
}

// update status icon and text of tray icon because reconnect interval might have changed
if (m_menu && m_menu->icon()) {
Expand Down Expand Up @@ -941,7 +930,7 @@ void TrayWidget::concludeWizard(const QString &errorMessage)

void TrayWidget::showDialog(QWidget *dlg, bool maximized)
{
if (m_menu && !m_menu->isPinned()) {
if (m_menu && !m_menu->isWindowed()) {
m_menu->close();
}
if (maximized) {
Expand Down
1 change: 0 additions & 1 deletion tray/gui/traywidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ public Q_SLOTS:

private Q_SLOTS:
void handleStatusChanged(Data::SyncthingStatus status);
void handlePinnedChanged(bool pinned);
static void applySettingsOnAllInstances();
void openDir(const Data::SyncthingDir &dir);
void openItemDir(const Data::SyncthingItemDownloadProgress &item);
Expand Down
24 changes: 0 additions & 24 deletions tray/gui/traywidget.ui
Original file line number Diff line number Diff line change
Expand Up @@ -156,29 +156,6 @@
</item>
</layout>
</item>
<item>
<widget class="QPushButton" name="pinPushButton">
<property name="toolTip">
<string>Pin window</string>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset theme="window-pin" resource="../resources/syncthingtrayicons.qrc">
<normaloff>:/icons/hicolor/scalable/actions/window-pin.svg</normaloff>:/icons/hicolor/scalable/actions/window-pin.svg</iconset>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>false</bool>
</property>
<property name="flat">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</item>
Expand Down Expand Up @@ -575,7 +552,6 @@ For &lt;i&gt;all&lt;/i&gt; notifications, checkout the log</string>
</customwidgets>
<resources>
<include location="../../model/resources/syncthingmodelicons.qrc"/>
<include location="../resources/syncthingtrayicons.qrc"/>
<include location="../../widgets/resources/syncthingwidgetsicons.qrc"/>
</resources>
<connections/>
Expand Down
Loading

0 comments on commit 71c56ed

Please sign in to comment.