diff --git a/AmethystWindowsSystray/DesktopWindowManager.Internal/Utils.cs b/AmethystWindowsSystray/DesktopWindowManager.Internal/Utils.cs index 6724b0e..ab466ff 100644 --- a/AmethystWindowsSystray/DesktopWindowManager.Internal/Utils.cs +++ b/AmethystWindowsSystray/DesktopWindowManager.Internal/Utils.cs @@ -101,14 +101,18 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist Point point = new Point(properties[1].Value.ToObject() + 100, properties[2].Value.ToObject() + 100); HMONITOR monitor = User32.MonitorFromPoint(point, User32.MonitorFlags.MONITOR_DEFAULTTONEAREST); + int virtualDesktopIndex = VirtualDesktop.SearchDesktop(properties[0].Value.ToString()); - virtualDesktop = VirtualDesktop.FromIndex(VirtualDesktop.SearchDesktop(properties[0].Value.ToString())); - hMONITOR = monitor; - layout = (Layout)properties[3].Value.ToObject(); - } + if (virtualDesktopIndex != -1) + { + virtualDesktop = VirtualDesktop.FromIndex(virtualDesktopIndex); + hMONITOR = monitor; + layout = (Layout)properties[3].Value.ToObject(); - var key = new Pair(virtualDesktop, hMONITOR); - list.Add(new KeyValuePair, Layout>(key, layout)); + var key = new Pair(virtualDesktop, hMONITOR); + list.Add(new KeyValuePair, Layout>(key, layout)); + } + } return list; } @@ -160,13 +164,18 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist Point point = new Point(properties[1].Value.ToObject() + 100, properties[2].Value.ToObject() + 100); HMONITOR monitor = User32.MonitorFromPoint(point, User32.MonitorFlags.MONITOR_DEFAULTTONEAREST); - virtualDesktop = VirtualDesktop.FromIndex(VirtualDesktop.SearchDesktop(properties[0].Value.ToString())); - hMONITOR = monitor; - factor = properties[3].Value.ToObject(); - } + int virtualDesktopIndex = VirtualDesktop.SearchDesktop(properties[0].Value.ToString()); - var key = new Pair(virtualDesktop, hMONITOR); - list.Add(new KeyValuePair, int>(key, factor)); + if (virtualDesktopIndex != -1) + { + virtualDesktop = VirtualDesktop.FromIndex(virtualDesktopIndex); + hMONITOR = monitor; + factor = properties[3].Value.ToObject(); + + var key = new Pair(virtualDesktop, hMONITOR); + list.Add(new KeyValuePair, int>(key, factor)); + } + } return list; } diff --git a/AmethystWindowsSystray/SystrayContext.cs b/AmethystWindowsSystray/SystrayContext.cs index ca3d88f..e418376 100644 --- a/AmethystWindowsSystray/SystrayContext.cs +++ b/AmethystWindowsSystray/SystrayContext.cs @@ -509,7 +509,7 @@ private async void App_Refresh() item.Add(w.value.Window.DangerousGetHandle().ToString()); item.Add(w.value.AppName); item.Add(w.value.ClassName); - item.Add(w.value.VirtualDesktop.ToString()); + item.Add(VirtualDesktop.DesktopNameFromDesktop(w.value.VirtualDesktop)); item.Add(screen.DeviceName.ToString().Remove(0,4)); item.Add(w.value.Info.rcWindow.ToString()); item.Add(w.value.Info.dwStyle.ToString());