Qalculate / qalculate-gtk

Qalculate! GTK+ UI
https://qalculate.github.io/
GNU General Public License v2.0
945 stars 68 forks source link

The Dancing Qalculator #365

Open Gitoffthelawn opened 2 years ago

Gitoffthelawn commented 2 years ago

Something changed in Qalculate v4.0 that is causing the Qalculate window to "dance" when it is opened by the user in certain situations.

Allow me to provide details. I have Qalculate set to Use system tray icon, Hide on startup, and Remember window position. I also have the Qalculate icon pinned to the Win7 taskbar. I've used this configuration for months, so it appears that Qalculate v4.0 likely has a regression causing this new issue. Specifically, when the Qalculate window is closed, and one clicks on the pinned taskbar icon, the Qalculate window will open, close itself, and then open for a second time.

STR:

  1. Configure Qalculate and the OS as described above.
  2. Open Qalculate by using either the pinned toolbar icon or the system tray icon.
  3. Close Qalculate by using OS's close (X) button in the upper-right corner.
  4. Open Qalculate by using the pinned toolbar icon.
  5. Watch the Dancing Qalculator.

A workaround I discovered is to always close the Qalculate window using the minimize button instead of the close button (a bit of a hassle because that button is not as easy to click as the close button in the corner).

If fixing this issue is onerous, a reasonable hack would be to simply remove the close button from the UI when Qalculate is set to minimize to the system tray. Thinking more about it, removing the close and maximize buttons from the Qalculate window when it is set to minimize to the system tray may be a good idea regardless of trying to work around bug. The more I think about that, the more I like it.

h-h-h-h commented 2 years ago

Why shouldn't one still be able to maximize the window?


Anyway, I don't have Qalculate pinned to the Windows 10 taskbar, but I have a custom quick launch toolbar created on my taskbar that contains a Qalculate shortcut. I have the same settings except "Minimize to tray" if this exists.


There's also another, related bug (for my settings):

hanna-kn commented 2 years ago

Qalculate is minimized once when activated to bring the window to the front, otherwise the window might be placed behind other windows. On my system this is not really visible.

Gitoffthelawn commented 2 years ago

Qalculate is minimized once when activated to bring the window to the front, otherwise the window might be placed behind other windows. On my system this is not really visible.

Was this always the case, or is this something new?

Note that Qalculate doesn't just minimize when activated... it also appears to minimize while keeping its width at full size, resulting in the majority of the taskbar temporarily changing color to that of the Qalculate window's title bar. When other apps are minimized, they shrink to the width of a taskbar icon as they minimize.

With a high contrast color scheme, the visual effect is quite pronounced and involves quite a bit of flashing and changing colours. I don't know whether or not it can trigger a seizure.

Other applications that I use that minimize to the system tray never appear behind other windows, but don't do the "Qalculate dance" when they are opened. On the other hand, Qalculate is the only one that I also have pinned to the taskbar.

What do you think about adding options to allow the user to hide the close and maximize buttons (if desired)? Actually, is that already possible with a little CSS code? Or would that have to effect every GTK application?

hanna-kn commented 2 years ago

Should be fixed now (by using AllowSetForegroundWindow instead of the previous workaround).

Gitoffthelawn commented 2 years ago

Thank you! Just curious... any thoughts on a date for a new release?

h-h-h-h commented 2 years ago

Please test, @Gitoffthelawn.

Gitoffthelawn commented 2 years ago

@h-h-h-h You got it. I put it on my calendar to test it this Sunday.

Gitoffthelawn commented 2 years ago

I had a chance to test this earlier than expected.

If you can scan the releases with VirusTotal (see #358), that will really help. Thanks!

I tested using qalculate-4.1.0-i386.zip on Win7 64-bit.

Note that determining what is really going on was made a touch more challenging because of a Qalculate issue that is not a regression in v4.1.0: When the user quits Qalculate via File > Quit, the Qalculate system tray icon is not automatically removed. Instead, the user has to move the cursor over the system tray to see that the Qalculate system tray icon is a "phantom icon" and will disappear only if and when the cursor is moved to the Qalculate icon in the system tray.

I originally thought perhaps this issue was universal, but the cross-platform CopyQ tool works as expected, without this issue.

With this other issue in mind, here are the results of my testing:

Testing Task 1: With Qalculate not running, launch Qalculate from its pinned taskbar icon. Result: Works well. There is a quick flash showing an empty Qalculate window before Qalculate almost instantly minimizes to the system tray. Ideally, that quick flash will be avoided, but it's no big deal.

Testing Task 2: After performing Task 1, click the Qalculate pinned taskbar icon. Result: Flawless. Works perfectly.

Testing Task 3: After performing Task 2, click the close button in the upper-right corner of the Qalculate window. Result: Flawless. Works perfectly.

Testing Task 4: After performing Task 3, click the Qalculate pinned taskbar icon. Then click the close button in the upper-right corner of the Qalculate window. Result: Broken. Qalculate terminates. The Qalculate icon is still visible in the system tray, but moving the cursor over that icon causes it to disappear (phantom Qalculate icon).

Testing Task 5: Perform Task 4 two times in succession. Results: Two adjacent Qalculate icons now appear in the system tray. Moving the cursor over the leftmost Qalculate system tray icon (on a LTR localized system), will cause that icon to disappear (phantom Qalculate icon).

I hope this is helpful.

(BTW, is there a way for the user to add some CSS to remove the maximize and close buttons?)

h-h-h-h commented 2 years ago

When the user quits Qalculate via File > Quit, the Qalculate system tray icon is not automatically removed. Instead, the user has to move the cursor over the system tray

This is a Windows issue that's also the case with many other apps. It's a mystery why Microsoft doesn't fix such small issues that existed for a long time. Although I can't say whether an app can circumvent the Windows bug by somehow removing and refreshing the tray icon before terminating the process. Your CopyQ reference seems to suggest this.

There is a quick flash showing an empty Qalculate window before Qalculate almost instantly minimizes to the system tray. Ideally, that quick flash will be avoided

Agree. Isn't it possible to create the window with invisible initial state? With pure WinAPI, I believe it would be possible and still set the window's minimized state, if necessary.

Testing Task 4: After performing Task 3, click the Qalculate pinned taskbar icon. Then click the close button in the upper-right corner of the Qalculate window. Result: Broken. Qalculate terminates.

This doesn't happen for me. The app normally continues to reside in the tray while still running. I could deminimize from tray and close to tray indefinitely.

Testing Task 5: Perform Task 4 two times in succession. Results: Two adjacent Qalculate icons now appear in the system tray.

This has to do with the Windows bug described above.

hanna-kn commented 2 years ago

"phantom icon" has now been fixed (the system tray icon is not automatically removed when terminating the application that created it).

Gitoffthelawn commented 2 years ago

@h-h-h-h Thank you for your feedback. Regarding why Microsoft doesn't fix many bugs, I speculate so they can push people onto new "improved" versions of Windows with even more mandatory telemetry.

For testing task 4, can you try increasing/decreasing the amount of time between clicking the "close" button in Qalculate, and opening Qalculate via a pinned taskbar icon?

@hanna-kn Thank you for the pull to fix the Qalculate "phantom icon".

h-h-h-h commented 2 years ago

@Gitoffthelawn:

For testing task 4, can you try increasing/decreasing the amount of time between clicking the "close" button in Qalculate, and opening Qalculate via a pinned taskbar icon?

I couldn't reproduce the behavior you described where the app's process suddenly isn't available anymore, neither with quick nor with slow succession of actions.


@Gitoffthelawn: Now that we know that Shell_NotifyIcon(NIM_DELETE, ...) solves the problem, we can recommend it to any software we encounter that still has this problem.

Gitoffthelawn commented 2 years ago

I ran some more tests. This sequence causes Qalculate v4.1.0 to completely terminate its process, even when it is set to only minimize to the system tray:

  1. Launch Qalculate.
  2. Set Qalculate to minimize to the system tray instead of closing.
  3. Quit Qalculate.
  4. Launch Qalculate via a pinned taskbar button. It will minimize to the system tray.
  5. Open Qalculate via the pinned taskbar button.
  6. Click the close button in the Qalculate window.
  7. Repeat steps 5 & 6.

My experience is that this causes Qalculate to completely terminate.

h-h-h-h commented 2 years ago

2. Set Qalculate to minimize to the system tray instead of closing. ... 4. Launch Qalculate via a pinned taskbar button. It will minimize to the system tray.

As far as I know, there is no "minimize to system tray" in Qalculate, only "close to system tray" (effectively, not called that way). Clicking the window's minimize button always minimizes to taskbar normally. I can only speculate that you instruct to activate the setting "Use system tray icon". And point 4 only implies, but points before don't explicitly instruct to also activate the setting "Hide on startup". Currently, I can't replicate the bug you encountered.

Gitoffthelawn commented 2 years ago

The English strings for the options I enabled are: "Use system tray icon" and "Hide on startup". When those are enabled in step 2, and I follow all the steps, the bug happens for me 100% of the time.

hanna-kn commented 2 years ago

When those are enabled in step 2, and I follow all the steps, the bug happens for me 100% of the time.

I can confirm this, but only with the 32-bit binaries. "Use system tray icon" is simply broken for the 32-bit version. This is caused by the addition of result clearing on close to system tray in version 4.1. I do not yet understand why this is the case.

Gitoffthelawn commented 2 years ago

@hanna-kn Thanks for the confirmation Hanna.

hanna-kn commented 2 years ago

32-bit system tray issues (and potential 64-bit issues) should be fixed now.

Gitoffthelawn commented 2 years ago

Oh wow, that was fast. Thanks Hanna. Why was the 32-bit version behaving differently from the 64-bit version?

Gitoffthelawn commented 2 years ago

Oh, as a quick note while I remember... while I was testing the 64-bit version, I was sometimes getting a momentary outline of the Qalculate window at coords [0,0] before the full window appeared at the correct coords. It wasn't consistently reproducible, so I didn't file an issue report.