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

switching desktop causes focused window to blink in taskbar #59

Closed
Aran-Fey opened this issue May 9, 2017 · 33 comments
Closed

switching desktop causes focused window to blink in taskbar #59

Aran-Fey opened this issue May 9, 2017 · 33 comments
Assignees

Comments

@Aran-Fey
Copy link

Aran-Fey commented May 9, 2017

Sometimes when I switch desktop, the application that's focused on that desktop becomes highlighted in the task bar.

Example:
On desktop A, I have Firefox:
untitled

On desktop B I have Steam (note that Firefox is pinned to my task bar, which is why it's visible on this desktop):
untitled2

When I switch from A to B, Steam becomes highlighted:
untitled3
(It's possible to stop the blinking by explicitly selecting the blinking window with the mouse or alt+tab.)

When I switch back to A, Firefox also becomes highlighted (and Steam stays visible in the taskbar because it is highlighted):
untitled4

This doesn't always happen; I'm not sure if it depends on the programs or where the mouse/keyboard focus is when switching desktops. That said, it happens far too often, to the point where it defeats the point of having multiple desktops at all.

(The problem isn't limited to Firefox and Steam, the same thing also happens with other programs like Explorer.)

@mzomparelli
Copy link
Owner

I'm aware of this. I actually haven't seen it in awhile since I've been using Desktop View for everything. It's so much easier this way because you can go to the exact window that you want. I don't use the hotkeys for moving windows either because even that is easier in Desktop View.

I do understand that others may prefer the hotkeys so I will investigate deeper as to why this is happening so I can address it before it interferes with your work. I think it has something to do with the focused window. That's why I'm not seeing when using Desktop View because with that I am explicitly setting focus to a window.

@mzomparelli mzomparelli self-assigned this May 9, 2017
@mzomparelli mzomparelli added the bug label May 9, 2017
@mzomparelli
Copy link
Owner

You say it is happening a lot with you though. While I have seen this, it was never a lot. Just once in a while. I have been able to reproduce this when quickly switching desktops so perhaps you are switching desktops too quickly. Nonetheless, I will get to the bottom of it.

@mzomparelli
Copy link
Owner

I think I have this fixed. I'll release version 1.0.48 in a little bit. Let me know if you still experience any issues. I'll leave this open until you confirm it has stopped.

@mzomparelli
Copy link
Owner

mzomparelli commented May 9, 2017

To fix this bug you need to kill focus for all of the windows on the desktop that you are leaving.

SendMessage(this.Handle, WindowsMessage.WM_KILLFOCUS, IntPtr.Zero, IntPtr.Zero);

@Aran-Fey
Copy link
Author

Aran-Fey commented May 9, 2017

It happens less frequently now, but it's still there. Sometimes a window will flash once and then stop.

There's a new problem now though: Sometimes when I switch desktop the active window loses focus. I have to click or alt+tab into it to restore the keyboard focus.

@mzomparelli
Copy link
Owner

When you switch desktops there is no active window. Your active window was on a different desktop. If you're trying to get to a specific window on a desktop then you would be better off using Desktop View.

I'll look into your new issue of losing focus.

I've been unable to make a window flash since yesterday's update.

@Aran-Fey
Copy link
Author

Aran-Fey commented May 9, 2017

Of course when I say "active window" I'm referring to the window that's active on the desktop I've switched to. I've experimented a bit to see where the keyboard focus goes, but as far as I can tell, nothing is focused at all.

If it helps you reproduce the problem - I've created hotkeys to switch to specific desktops and am using those. I.e. "Navigate to Desktop # 1" and "Navigate to Desktop # 2".

@mzomparelli
Copy link
Owner

Thanks, I will try and fix this. So basically, you want the last active window on that desktop to become the current active window?

@Aran-Fey
Copy link
Author

Aran-Fey commented May 9, 2017

That's right. That's the default behavior, isn't it? Windows maintains the keyboard focus for each desktop. If I use the builtin Windows hotkeys to switch desktop, it works as expected. It's only if I use zVD hotkeys that the focus disappears. So I don't think you need to implement anything; if you just change the desktop and do nothing else, Windows should take care of the rest.

@mzomparelli
Copy link
Owner

ok, Sounds simple. I should be able to resolve this tonight.

@mzomparelli
Copy link
Owner

In my testing I have successfully reactivated the last active window for each desktop. However, I am unable to reproduce a flashing window or a window whose taskbar button leaks into the wrong desktop after switching.

@Aran-Fey
Copy link
Author

Aran-Fey commented May 10, 2017

Something very odd happens now. Continuing from my Steam/Firefox example, say Steam has keyboard focus. When I switch desktop, Steam keeps the keyboard focus even though it's on a different desktop. If I press buttons and then switch back to Steam, all the letters have been typed into the steam chat.

I have discovered something that might help you reproduce my problem with flashing windows. It seems to happen only if the currently active window (before the desktop switch) can have the keyboard focus. For example programs like Notepad, Steam chat and Firefox. If the active window is an app like Explorer (or if there is no active app, i.e. the Desktop is focused) it doesn't happen.
In other words: Switching from Notepad to Explorer will cause the issue, while switching from Explorer to Notepad will not.

So I think you can reproduce the problem if you open Notepad on 2 desktops and switch between them.

P.S.: Now that the error with the "go to next desktop" and "go to previous desktop" actions is fixed, I've confirmed that they also cause this issue.

@mzomparelli
Copy link
Owner

I'll check this out this evening.

@mzomparelli
Copy link
Owner

I was able to reproduce this using Notepad, but only if no window was selected before switching and then switching back. I added some code that I will be testing in a little bit. This code sets the focus to the desktop if you don't have a window to focus on. This could mean an empty desktop or a window wasn't focused before you left the desktop.

@m0ngr31
Copy link

m0ngr31 commented Jul 22, 2017

Just checking the app out. I have this issue a ton. Driving me crazy.

@mzomparelli
Copy link
Owner

Yeah it sucks. I'm looking for a solution. It does not happen to me at all when I use DesktopView which is really the only way I switch now anyway. I haven't stopped looking for a solution though. If you have any ideas how to handle then let me know.

@mzomparelli
Copy link
Owner

I wonder if Microsoft is aware of this issue and is why they don't have a hotkey to move windows from one desktop to another. Virtual Desktops is not fully documented and this means there is likely going to be changes. It would't surprise me if they created a view just like DesktopView.

@mzomparelli
Copy link
Owner

I'm pretty certain this has something to do with focused windows so I'm going to try something to fix it. When you use DesktopView, you change the focus to DesktopView. This is why it doesn't happen when using that method.

@m0ngr31
Copy link

m0ngr31 commented Jul 22, 2017

You mentioned that you are killing focus when you leave. What if you tried to do that again when you came back?

@mzomparelli
Copy link
Owner

it's worth a shot. I was going to try and create a hidden window and give that focus. I'll report back here to inform you how it goes. If I feel good about it, I'll give you a link to a version for you to try.

@mzomparelli
Copy link
Owner

@m0ngr31 Ok, instead of creating a new hidden window I decided to use the settings form since it is always there just hidden. By setting focus to the settings form before switching desktops I seem to have solved this. You still may get a blink but it should quickly stop. Please note that if the settings window is visible when you switch then you will cause this issue to appear, so don't do that.

Use this to get an updated version and let me know if it works ok.
https://zomp.co/files.aspx?id=zvd

@m0ngr31
Copy link

m0ngr31 commented Jul 25, 2017

Same issue :/

@mzomparelli
Copy link
Owner

mzomparelli commented Jul 25, 2017

Yes, I can still reproduce it too. I am now forcing the flash to stop. It's the flashing that keeps it around so if I can stop the flashing then I can stop the window from leaking into another Desktop. Try out the fresh compilation:

Yes, same link

https://zomp.co/files.aspx?id=zvd

@m0ngr31
Copy link

m0ngr31 commented Jul 25, 2017

Hey that works pretty good. How are you forcing it to stop the flashing? Occasionally an app icon will show up, but it's not flashing anymore, so that's great.

@mzomparelli
Copy link
Owner

I can make it flash if I wanted to lol. We don't want that though.

public bool Flash(UInt32 timout, UInt32 count)
        {
            FLASHWINFO fInfo = new FLASHWINFO();

            fInfo.cbSize = Convert.ToUInt32(Marshal.SizeOf(fInfo));
            fInfo.hwnd = this.Handle;
            fInfo.dwFlags = FlashWindow.FLASHW_ALL;
            fInfo.uCount = count;
            fInfo.dwTimeout = timout;

            return FlashWindowEx(ref fInfo);

        }

        public bool FlashStop()
        {
            FLASHWINFO fInfo = new FLASHWINFO();

            fInfo.cbSize = Convert.ToUInt32(Marshal.SizeOf(fInfo));
            fInfo.hwnd = this.Handle;
            fInfo.dwFlags = FlashWindow.FLASHW_STOP;
            fInfo.uCount = 0;
            fInfo.dwTimeout = 0;

            return FlashWindowEx(ref fInfo);
        }

@m0ngr31
Copy link

m0ngr31 commented Jul 25, 2017

Although, it does seem to crash pretty easily. Trying to hammer down what the cause is.

@mzomparelli
Copy link
Owner

mzomparelli commented Jul 25, 2017

zVD crashing? Visit the Windows log and let me know. You can only get the needed info for a crash from the event logs. I need the stack trace please.

It never crashes for me. Not since I handled the memory leak in DesktopView

@mzomparelli
Copy link
Owner

Start a new issue for the crash

@mzomparelli
Copy link
Owner

mzomparelli commented Jul 25, 2017

I may have fixed the window issue. I'm forcing the Taskbar to get focus and I'm posting a click message to it.

https://zomp.co/files.aspx?id=zvd

@m0ngr31
Copy link

m0ngr31 commented Jul 25, 2017

Does this have the fix for the crash earlier too?

@m0ngr31
Copy link

m0ngr31 commented Jul 25, 2017

Seems to. I can't make it crash anymore. And the highlighting apps is gone. Nice job!

One small request... If I hold down Ctrl+Win and do left or right, and I can go left and right as many times as I want until I try and do the "round robin". In that case, I have to take my fingers off of Ctrl+Win and go left or right to get to the opposite desktop. Anyway around that issue?

@mzomparelli
Copy link
Owner

Sorry, I created that bug just now. Sorry about that. Try the update.

https://zomp.co/files.aspx?id=zvd

@mzomparelli
Copy link
Owner

Closing as fixed as good as it is going to get in version 1.0.63. I might revisit later.

FuPeiJiang added a commit to FuPeiJiang/VD.ahk that referenced this issue Nov 23, 2020
1) switching desktop causes focused window to blink in taskbar
mzomparelli/zVirtualDesktop#59 (comment)

so I winactivate the taskbar and then when I arrive at new Virtual Desktop, I emulate alt-tab.

2) Added VD_isValidWindow(hWnd) to only select valid window : It wasn't working for ("ahk_exe devenv.exe")

3) renamed some global vars
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants