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

Handle cloak event to improve virtual desktop behavior #116

Merged
merged 1 commit into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/ManagedShell.Interop/NativeMethods.User32.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1916,6 +1916,7 @@ public enum TBPFLAG
public static IntPtr HWND_BROADCAST = new IntPtr(0xffff);
public static int WINEVENT_OUTOFCONTEXT = 0;
public static int WINEVENT_SKIPOWNPROCESS = 2;
public static int EVENT_OBJECT_CLOAKED = 0x8017;
public static int EVENT_OBJECT_UNCLOAKED = 0x8018;
public static int EVENT_OBJECT_LOCATIONCHANGE = 0x800B;

Expand Down
7 changes: 0 additions & 7 deletions src/ManagedShell.WindowsTasks/ApplicationWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -411,13 +411,6 @@ private string getFileDescription()
return desc;
}

internal void Uncloak()
{
ShellLogger.Debug($"ApplicationWindow: Uncloak event received for {Title}");

SetShowInTaskbar();
}

private void setIcon()
{
if (!_iconLoading && ShowInTaskbar)
Expand Down
23 changes: 12 additions & 11 deletions src/ManagedShell.WindowsTasks/TasksService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ public class TasksService : DependencyObject, IDisposable
private static int WM_SHELLHOOKMESSAGE = -1;
private static int WM_TASKBARCREATEDMESSAGE = -1;
private static int TASKBARBUTTONCREATEDMESSAGE = -1;
private static IntPtr uncloakEventHook = IntPtr.Zero;
private WinEventProc uncloakEventProc;
private static IntPtr cloakEventHook = IntPtr.Zero;
private WinEventProc cloakEventProc;
private static IntPtr moveEventHook = IntPtr.Zero;
private WinEventProc moveEventProc;

Expand Down Expand Up @@ -103,16 +103,16 @@ internal void Initialize(bool withMultiMonTracking)

if (EnvironmentHelper.IsWindows8OrBetter)
{
// set event hook for uncloak events
uncloakEventProc = UncloakEventCallback;
// set event hook for cloak/uncloak events
cloakEventProc = CloakEventCallback;

if (uncloakEventHook == IntPtr.Zero)
if (cloakEventHook == IntPtr.Zero)
{
uncloakEventHook = SetWinEventHook(
EVENT_OBJECT_UNCLOAKED,
cloakEventHook = SetWinEventHook(
EVENT_OBJECT_CLOAKED,
EVENT_OBJECT_UNCLOAKED,
IntPtr.Zero,
uncloakEventProc,
cloakEventProc,
0,
0,
WINEVENT_OUTOFCONTEXT | WINEVENT_SKIPOWNPROCESS);
Expand Down Expand Up @@ -197,7 +197,7 @@ public void Dispose()
{
ShellLogger.Debug("TasksService: Deregistering hooks");
DeregisterShellHookWindow(_HookWin.Handle);
if (uncloakEventHook != IntPtr.Zero) UnhookWinEvent(uncloakEventHook);
if (cloakEventHook != IntPtr.Zero) UnhookWinEvent(cloakEventHook);
if (moveEventHook != IntPtr.Zero) UnhookWinEvent(moveEventHook);
_HookWin.DestroyHandle();
setTaskbarListHwnd(IntPtr.Zero);
Expand Down Expand Up @@ -618,14 +618,15 @@ private void MoveEventCallback(IntPtr hWinEventHook, uint eventType, IntPtr hWnd
}
}

private void UncloakEventCallback(IntPtr hWinEventHook, uint eventType, IntPtr hWnd, int idObject, int idChild, uint dwEventThread, uint dwmsEventTime)
private void CloakEventCallback(IntPtr hWinEventHook, uint eventType, IntPtr hWnd, int idObject, int idChild, uint dwEventThread, uint dwmsEventTime)
{
if (hWnd != IntPtr.Zero && idObject == 0 && idChild == 0)
{
if (Windows.Any(i => i.Handle == hWnd))
{
ApplicationWindow win = Windows.First(wnd => wnd.Handle == hWnd);
win.Uncloak();
ShellLogger.Debug($"TasksService: {(eventType == EVENT_OBJECT_CLOAKED ? "Cloak" : "Uncloak")} event received for {win.Title}");
win.SetShowInTaskbar();
}
}
}
Expand Down