-
Notifications
You must be signed in to change notification settings - Fork 44
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
If "Allow multiple instances" disabled, then make it focus and visible if trying to start dublicate #145
Comments
It seems to be a Wayland issue. The code below is used and works elsewhere
|
I have the same problem on Windows. SetForegroundWindow(hWnd) is the standard way of doing this in Win32 API. |
How do you launch Qalculate? |
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\AppKey\18] [HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\AppKey\18]
Assume I have this z-order when I press the shortcut key: Desktop has the focus: application window 1 has the focus: application window 2 has the focus: |
I've not been able to replicate this issue using the software for my Logitech keyboard, using the WinHotKey program, or setting a shortcut key in the properties of the desktop icon. Does qalculate-gtk behave in the same way? A related issue: Qalculate/qalculate-gtk#347. |
I just tried it, and yes, the GTK version does the same thing. The only strange thing is that it opens in a 'random' position every time (I started it 3 times, and 3 times the window was placed somewhere else). Is it really not possible to simply call the SetForegroundWindow() function? I have used that many times myself, and I've yet to see that fail. It is incredibly confusing as it is now, because you think Qalculate didn't actually start (making me press the button a few times and then thinking "ooooooooh yeah, I forgot"). If you want, you can send me a debug version which logs a ton of stuff. I can then send you the debug log. I have Visual Studio 2022 including all debug libraries on my computer, so a debug version may work out of the box for me. |
I've compiled an executable which calls |
Yep, it works. Edit: |
Version without delay: https://github.com/Qalculate/qalculate-qt/releases/download/v5.4.0/qalculate-qt-setforegroundwindow-test-b.zip
Yes, there are no differences (except a few minor fixes/improvements).
I did, and |
Ok, that is super weird. So: Edit: |
A final test with multiple executables with varied set foreground delays (milliseconds indicated in file name) for both new and existing instances: Does other applications work as expected with the shortcut key? |
All of them fail. I also notice that the Qalculate window never gets activated. Not when starting new, and not when it was already running. The focus remains on the application (or desktop) which had the focus when starting Qalculate with the shortcut key. I tried Windows Explorer, and that fails (like Qalculate). Here is the code I use when starting fresh:
And here is my code when another instance is already running:
WorkaroundI found a workaround; if you set the Qalculate window 'always on top', then it actually does come to the front and correctly activates the window. But, then it is always over other windows, so this may not be what a user wants. |
That is odd considering that the first version (with 2 s delay) was a partial success.
This makes it obvious that the keyboard software (or something else on your system) is broken. Does it work properly if you assign a shortcut key to a link (e.g. a desktop icon) to qalculate-qt.exe. |
Ah yes, I forgot to mention that I indeed tried that. But, when I assign a shortcut in the favorite it is the same thing. Even when I set it to MAXIMIZE in the shortcut, it still doesn't active it. Also, I only installed Windows 11 a few weeks ago on my new computer (I came from a Windows 10 computer). I recall there was a setting where you could turn off that the taskbar icons 'flashed' when they wanted your attention. I hate that, so I turned it off. Having said that, it doesn't explain why my own application works perfectly fine. |
Next attempt: https://github.com/Qalculate/qalculate-qt/releases/download/v5.4.0/qalculate-qt-setforegroundwindow-test-d.zip Code on new instance:
In my tests both methods for window handler retrieval returns the same valid pointer. Code when another instance is already running:
|
No, no success. It's so weird, because you are calling the right functions (the same I am). Maybe you are calling the functions too early. Are you calling these functions while the window itself hasn't been completely created? Don't handle this in the WM_CREATE message, but rather in the first WM_SHOWWINDOW message. Or maybe you can wait until your message pump is running, and then bring the window to the front? Workaround:I know that when I set the 'keep above other windows' to on, it works. I assume you are supplying the WS_EX_TOPMOST flag? Or else you are calling the SetWindowPos function with the HWND_TOPMOST flag. So, when starting a new or existing instance, just pretend the 'keep above other windows' setting is on (for a moment), and then turn the setting off again. After you are showing the Qalculate window, you can call this function to turn it off again (if needed):
|
With keep above other windows temporary enabled:
I use
I've confirmed that the new code, with the old code disabled, works for already running instances. The code for the new instance likely does not add anything to what is already done by Qt when a window is shown. |
Ok, we are very close now! But, you are somehow confusing Windows, because now two applications seem to have the focus (their titlebar is highlighted). But, unfortunately, it's still the originally activated window which is actually the activated one, because the keyboard focus is on the original window.
|
Very oftenly when I need calculator, I just press [Meta] and type "calc" and press Enter. I don't need multiple instances. But I don't close Qalculate either. If it was opened already and are minimized or behind other windows and I try to open Qalculate, it just ignores my command. Instead existing Qalculate instance could appear on top and on focus when I do that... Because that's exactly what this setting was suppost to do.
QT Qalculate, Arch, KDE Plasma 6.1, Wayland, Nvidia555
The text was updated successfully, but these errors were encountered: