Powertoys: [PreviewHandler] SVG preview handler steals focus from Explorer

Created on 13 May 2020  路  12Comments  路  Source: microsoft/PowerToys

Environment

Windows build number: 10.0.17763.1158
PowerToys version: 0.17.0-x64
PowerToy module for which you are reporting the bug (if applicable): PreviewHandler

Steps to reproduce

  1. Start the Explorer with a folder containing SVG files
  2. Click on a file which is NOT an SVG file, but is located above or below one in the file list
  3. Use the cursor keys to go to the SVG file

Expected behavior

With all other preview handlers, Explorer keeps the focus, and we can switch to the next file with the cursor keys.

Actual behavior

Explorer loses the focus (title bar changes color), and we cannot switch to the next file with the cursor keys any more. This sometimes even happens when clicking on a file, but with the above instructions it happens every time.

Screenshots

Not needed

Reason

This happens because the preview window does NOT have the WS_CHILD style, so the SetParent() function fails. When calling GetParent() on the preview, it returns 0. Preview handlers are supposed to create a child window within the window received via SetWindow() method.

Suggested bugfix

Call (via pInvoke) SetWindowLong to add the WS_CHILD style after creating the form.

Issue-Bug Priority-1 Product-File Explorer Resolution-Fix-Committed

Most helpful comment

I have created a pull request:
https://github.com/microsoft/PowerToys/pull/3048

I have compiled the new PreviewHandlerCommon.dll, and it fixes the issue in my tests. This is my first GitHub pull request, so I'm sorry if I did anything wrong.

All 12 comments

if you'd like to create a PR, that would be amazing here as it sounds like you know the issue / solution

I have created a pull request:
https://github.com/microsoft/PowerToys/pull/3048

I have compiled the new PreviewHandlerCommon.dll, and it fixes the issue in my tests. This is my first GitHub pull request, so I'm sorry if I did anything wrong.

We will do a look next week, we are finalizing 0.18. This is awesome!

@chrisgch, i can't reproduce this, nor can @jyuwono.

Here is a short video of the issue. I can reproduce it every time this way. You can see it better when changing apps to dark mode via new settings - colors. Only in dark mode the title bar changes color.

explorertest.zip

The problem doesn't occur when going from one svg to another once the Explorer has received the focus back. You need to open a new Explorer window, go to a directory of SVG files, and then click on one. The focus will be lost and you can't switch to the next file any more. Once you click on another svg, the focus stays on the Explorer and you can use the keyboard.

@chrisgch can we setup a teams call here? [email protected] is my email address. For the life of me, i can't repro it but i do see it happening in your video.

Sorry, I don't have teams since I don't use MS Office, I only have skype.

The reason why I reported this issue is that it happens in my own Windows desktop program, even on the latest Windows 10, I checked whether it also happens in the Explorer so I can report it to you (it would be too much to ask you to support 3rd party programs). I didn't expect that the Explorer would contain measures against misbehaving shell extensions. I will therefore implement my own workaround in my program for your extension.

we could do skype too. trying to figure out how we can repro it. Teams can also do webclient as well.

can you email me, [email protected] so i can set something up?

I have just tried it in Windows 10 inside a virtual machine, and it doesn't occur there in the Explorer. It still occurs in my own app (but only with the Power Toys preview handler). I think I will close this issue and distribute the fixed previewer dll to my users myself.

@chrisgch, is there maybe another app that could be causing a conflict here? We're happy to do the fix, we just need to see the E2E and validate

I have thought about that too, but couldn't find anything low level which might cause this. I'm using the normal Windows Defender, no extra antivirus or firewall. I have closed all other programs which might interfere, including Visual Studio, Android Studio, AutoHotkey, but it still occurs. However, it only occurs on a real PC, it doesn't occur within Virtualbox (Windows 10 1803 and 1809). I don't know what else I can do to reproduce it.
Maybe you could check in the debugger whether the inner part of
if ((windowStyle & wsChild) == 0)
is reached or not. If not, then the window already has the WS_CHILD style.

Fixed in 0.19.0, please visit https://github.com/microsoft/PowerToys/releases/ for the latest release

Was this page helpful?
0 / 5 - 0 ratings

Related issues

patware picture patware  路  3Comments

amorenew picture amorenew  路  3Comments

aminya picture aminya  路  3Comments

21cpDev picture 21cpDev  路  3Comments

smz picture smz  路  3Comments