ililim / dual-key-remap

Remap any key to any other two keys on Windows 🔥. Remap CapsLock to both Ctrl and Escape! (It's like xcape for windows!)
GNU General Public License v2.0
499 stars 36 forks source link

Program window does not go to background on windows 11 #43

Closed ascii78 closed 2 years ago

ascii78 commented 2 years ago

Just noticed that on windows 11 the program window stays in the foreground, see image. Clicked on the 0.6 version, so probably the version string is old as well ? Rest of the program works fine.

Screenshot 2022-02-28 150556 .

ililim commented 2 years ago

Ah interesting. I don't have w11 myself so can't test, but I'll do some reading as to why this might be. If anyone has any ideas it would be much appreciated.

ililim commented 2 years ago

@ascii78 can you confirm that you don't have debug=1 set in your config?

ascii78 commented 2 years ago

Hi,

So, I won't have access anymore to the windows 11 install, so this is just from memory. I did not configure anything and just used the stock config.txt from the zipfile, so that would be without debug=1.

directspeed commented 2 years ago

Just noticed that on windows 11 the program window stays in the foreground, see image. Clicked on the 0.6 version, so probably the version string is old as well ? Rest of the program works fine.

Screenshot 2022-02-28 150556 .

I am facing same issue in windows 11

mrgauravcs commented 2 years ago

I observed this problem only happens If we change the default terminal console to the windows terminal. If I change it to the default console problem disappears. Please look into this issue too if there is any way to fix it. image

ililim commented 2 years ago

Thanks @mrgauravcs that helped me identify the cause.

Looks like this is due to the new windows terminal not supporting show/hiding functionality the same way as the old terminal app did. Looks like they're working on it though: https://github.com/microsoft/terminal/issues/12570

Not sure what I can do other than to wait for the MS Terminal Team to fix this on their end. If anyone has any suggestions it would be much appreciated.

bsiegel commented 2 years ago

Also ran into this, it seems like the stance of the Windows Terminal developers is that applications should not launch a window and then attempt to hide it - see https://github.com/microsoft/terminal/issues/11627#issuecomment-953164498. The trick no longer works because Windows Terminal doesn't have a 1:1 mapping of processes to windows.

The recommended approach seems to be to build the application targeting the Windows GUI subsystem (/SUBSYSTEM:WINDOWS) rather than the Console subsystem. You can probably also set /ENTRY:mainCRTStartup to avoid having to change the main() entrypoint. If you want to still be able to see the console output in debug mode, you can explicitly allocate a console with AllocConsole. There's a bit of plumbing needed to hook it up to stdout & co, but that would only need to run when debug mode is enabled.

Apologies for not just bundling this up as a PR to submit, but unfortunately I don't currently have access to a machine with the MSVC toolchain.

ililim commented 2 years ago

Nice summary @bsiegel! I'll give this a shot and will distribute a new build if I can get it work :)

ililim commented 2 years ago

Alrighty - I think I got some form of fix in. Don't think it's perfect, but hopefully it's good enough to fix this issue. Thanks for the tips @bsiegel!

Can someone on W11 (or with the new Terminal as their default console) give the new version a shot to confirm the issue is resolved?

dual-key-remap-v0.7.zip

Dual key remap is now compiled as a GUI app, and the console window is manually created and destroyed using the AllocConsole/FreeConsole. This should resolve the issue reported here.

It still might flicker a window on startup, but should hide it after loading. I imagine on most computers it happens so quickly that Windows won't render the window - but if turns out to be a problem/annoyance then I could look into optimizing this later (by only creating a console on error/debug).

bsiegel commented 2 years ago

Sorry for the delay - tested here and confirmed this seems to fix the issue. When Windows Terminal is the default console host application, v0.6 would cause a new WT window to appear upon launch. v0.7 does not cause a new window to appear. Also verified that when debug=1 is added to the config file, the app does create its own terminal window and that the logging output works as expected.

Also just useful to note, this is not just a Win11 issue - any user who has installed Windows Terminal and selected to use Windows Terminal as the default console host application from within its Settings will experience the issue. Win11 is just the first version of Windows to come with WT installed by default.

ililim commented 2 years ago

Great to hear! I published the 0.7 release. Thanks for you help @bsiegel!