Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Two clicks required to show window with "Minimize qBittorrent to notification area" active only for maximised window. #13016

Open
ghost opened this issue Jun 14, 2020 · 6 comments
Labels
GUI GUI-related issues/changes OS: Linux Issues specific to Linux distributions Qt bugs Bug resides in Qt library

Comments

@ghost
Copy link

ghost commented Jun 14, 2020

qBittorrent version and Operating System

v4.2.5 (64 bit)
Manjaro (KDE)
Plasma version: 5.18.5

If on linux, libtorrent-rasterbar and Qt version

libtorrent-rasterbar: ?
Qt: 5.15.0

What is the problem

As the title says, two clicks are needed to show the window again when the "Minimize qBittorrent to notification area" is active, but the problem only applies when the window is maximised. Every other combination of actions, such as minimising and showing a non-maximised window, closing the window with the "Close qBittorrent to notification area" active, and clicking on the tray icon to hide and show it works as expected. This problem also applies to "Start qBittorrent minimized", which isn't that surprising.
Below is a screen recording demonstrating the behaviours of the above scenarios. First, I minimise the window using the minimise button and attempt to show it again (needs two clicks). Then I do the same for a non-maximised window, closing the window instead of minimising it (close to notification area is active), and using the tray icon to hide and show the window. And then I end by repeating the problem.

2020-06-14 13-29-50.zip

What is the expected behavior

When the "Minimize qBittorrent to notification area" option is active, and I either click minimise button or "Start qBittorrent minimized" is active, then I should be able to show the (maximised) window again by clicking the tray icon once, not twice.

Steps to reproduce

Enable "Minimize qBittorrent to notification area" in settings. Make sure the window is maximised, then minimise the window (either by clicking 'minimise' or having "Start qBittorrent minimized" enabled and starting up qBittorrent), and then attempt to show it again by clicking on the tray icon once (which will fail).

@thalieht thalieht added GUI GUI-related issues/changes OS: Linux Issues specific to Linux distributions labels Jun 14, 2020
@ghost
Copy link
Author

ghost commented Jul 18, 2020

I'd also like to add that sometimes, after locking qBT, the UI lock password window won't be visible, even when the main window isn't maximised. I can type in my password and then press enter as if it were visible, and it functions normally, but it's just not visible.
This usually happens when it's been locked for some time, but sometimes it isn't invisible.

@ghost
Copy link
Author

ghost commented Jul 21, 2020

A big update for Manjaro was released, and it seems like the locking issue was fixed by it. However, minimising a maximised window to the tray still needs two clicks to re-open.
Also, this new version of KDE (5.19.3) doesn't process the tray icon's tooltip text properly; it's just a garble of HTML code instead of text that looks nice. Should I open a new issue for this?

@FranciscoPombal
Copy link
Member

Also, this new version of KDE (5.19.3) doesn't process the tray icon's tooltip text properly; it's just a garble of HTML code instead of text that looks nice. Should I open a new issue for this?

No need, it's already tracked here: #13030.

@a-sum-duma
Copy link
Contributor

a-sum-duma commented Aug 15, 2021

I can confirm that this happens exactly as @azsorlex described it.
I'm on Xubuntu (Xfce 4.16, QT 5.15.2, qBittorrent compiled from latest source code).

Window must be first maximized and then minimized to tray. First attempt to raise it from tray results in window only blinking and getting hidden in tray again. Second time it raises properly.

I did some debugging and found the root of the problem - bug in QT or somewhere deeper. When raising from tray (unminimize+show) the window state changes 3 times: ->not minimized->minimized->not minimized. The window enters "minimized" state for a while which triggers auto-hiding. Now the window is hidden but it's no longer in "minimized" state. When raising it for the second time the state doesn't change (the window is already "unminimized") and the window appears.

I made a test program:

#include <QApplication>
#include <QMainWindow>
#include <QWindowStateChangeEvent>
#include <QDebug>
#include <QTimer>
#include <QElapsedTimer>

int t = 0;
const int period = 2000;
template <typename F> void shoot(F f) { QTimer::singleShot(t += period, f); }

QElapsedTimer timer;
auto dbg = [] () { return qDebug() << timer.elapsed(); };

class MainWindow : public QMainWindow
{
public:
    bool autoHideEnabled = true;

    void changeEvent(QEvent *e) override
    {
        if (e->type() == QEvent::WindowStateChange) {
            dbg()
                << "state change event (spontaneous:" << e->spontaneous()
                << "):" << static_cast<QWindowStateChangeEvent*>(e)->oldState()
                << "-->" << this->windowState();

            if (autoHideEnabled && isMinimized()) {
                dbg() << "window got minimized, scheduling auto-hide";
                QTimer::singleShot(0, [this] () { dbg() << "auto-hiding"; hide(); });
            }
        }
        return QMainWindow::changeEvent(e);
    }
};

int main(int argc, char** argv)
{
    QApplication app(argc, argv);
    MainWindow w;
    timer.start();

    shoot([&w] () {
      qDebug() << "--- SIMULATION 1 - mimic qBittorrent ---"; w.autoHideEnabled = true;
      qDebug() << "--- Window must be maximized to observe the effect ---";
      dbg() << "showing maximized"; w.showMaximized();
    });
    shoot([&w] () {
        qDebug() << "--- Minimize it to trigger auto-hiding ---";
        dbg() << "minimising"; w.setWindowState(w.windowState() | Qt::WindowMinimized);
    });
    shoot([&w] () {
        qDebug() << "--- Show it for the first time. ---";
        dbg() << "un-mininimsing showing"; w.setWindowState(w.windowState() & ~Qt::WindowMinimized); w.show();
    });
    shoot([&w] () {
        qDebug() << "--- Show it for the seond time. ---";
        dbg() << "un-mininimsing showing"; w.setWindowState(w.windowState() & ~Qt::WindowMinimized); w.show();
    });

    shoot([&w] () { qDebug() << "--- SIMULATION 2 - narrow ---"; w.autoHideEnabled = false; });
    shoot([&w] () { dbg() << "showing maximized"; w.showMaximized(); });
    shoot([&w] () { dbg() << "minimising"; w.setWindowState(w.windowState() | Qt::WindowMinimized); });
    shoot([&w] () { dbg() << "hiding"; w.hide(); });
    shoot([&w] () { dbg() << "showing maximized"; w.showMaximized(); });

    return app.exec();
}
--- SIMULATION 1 - mimic qBittorrent ---
--- Window must be maximized to observe the effect ---
1924 showing maximized
2058 state change event (spontaneous: false ): QFlags<Qt::WindowState>(WindowNoState) --> QFlags<Qt::WindowState>(WindowMaximized)
--- Minimize it to trigger auto-hiding ---
3923 minimising
3927 state change event (spontaneous: false ): QFlags<Qt::WindowState>(WindowMaximized) --> QFlags<Qt::WindowState>(WindowMinimized|WindowMaximized)
3927 window got minimized, scheduling auto-hide
3927 auto-hiding
--- Show it for the first time. ---
6303 un-mininimsing showing
6325 state change event (spontaneous: false ): QFlags<Qt::WindowState>(WindowMinimized|WindowMaximized) --> QFlags<Qt::WindowState>(WindowMaximized)
6338 state change event (spontaneous: true ): QFlags<Qt::WindowState>(WindowMaximized) --> QFlags<Qt::WindowState>(WindowMinimized|WindowMaximized)
6338 window got minimized, scheduling auto-hide
6338 state change event (spontaneous: true ): QFlags<Qt::WindowState>(WindowMaximized) --> QFlags<Qt::WindowState>(WindowMaximized)
6343 auto-hiding
6388 state change event (spontaneous: true ): QFlags<Qt::WindowState>(WindowMaximized) --> QFlags<Qt::WindowState>(WindowNoState)
--- Show it for the seond time. ---
8403 un-mininimsing showing
8433 state change event (spontaneous: true ): QFlags<Qt::WindowState>(WindowNoState) --> QFlags<Qt::WindowState>(WindowMaximized)
--- SIMULATION 2 - narrow ---
11423 showing maximized
13423 minimising
13425 state change event (spontaneous: false ): QFlags<Qt::WindowState>(WindowMaximized) --> QFlags<Qt::WindowState>(WindowMinimized|WindowMaximized)
15423 hiding
17422 showing maximized
17445 state change event (spontaneous: false ): QFlags<Qt::WindowState>(WindowMinimized|WindowMaximized) --> QFlags<Qt::WindowState>(WindowMaximized)
17468 state change event (spontaneous: true ): QFlags<Qt::WindowState>(WindowMaximized) --> QFlags<Qt::WindowState>(WindowMinimized|WindowMaximized)
17469 state change event (spontaneous: true ): QFlags<Qt::WindowState>(WindowMaximized) --> QFlags<Qt::WindowState>(WindowMaximized)

Focus on the last three lines of the output. If a window is maximized+minimized+hidden and you un-minimize it and show it, three QWindowStateChangeEvent events will follow. There is definitely something bad happening here. Beside the fact that we get 3 events, the "old state" has invalid value (WindowMaximized two times in a row).

I tried different combinations - swapping calls, adding 0-time one-shot timers, un-minimizing while hiding - nothing helped to get rid of the window state change events tandem. Finally my workaround is this: do not decide to hide the window right after it enters minimized state, instead check if it is still minimized after a while (see my commit a-sum-duma@ef795fb).

@FranciscoPombal FranciscoPombal added the Qt bugs Bug resides in Qt library label Oct 15, 2021
a-sum-duma added a commit to a-sum-duma/qBittorrent that referenced this issue Oct 29, 2021
Fixes/workarounds the need of raising from tray twice after window got minimized to tray while being maximized (qbittorrent#13016)
@corvus1
Copy link

corvus1 commented Nov 28, 2022

4.5.0 is still affected. #18099

@luzpaz
Copy link
Contributor

luzpaz commented Dec 6, 2023

See #19940

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
GUI GUI-related issues/changes OS: Linux Issues specific to Linux distributions Qt bugs Bug resides in Qt library
Projects
None yet
Development

No branches or pull requests

5 participants