mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-16 11:48:06 +01:00
[Workspaces] implement the move feature (#35480)
* [Workspaces] Add move functionality * spell checker * [Workspaces] Modify Arranger to move apps without launch * moved ipc helper * removed callback * use LauncherStatus in WindowArranger * wait for launching next app * launch in a separate thread and protect by mutexes * update app version in advance * changed canceling launch * increased waiting time * Fix optional parameter load from json * changed arranger waiting time * additional waiting time for Outlook * added app id * ensure ids before launch * set id in editor * minor updates * [Workspaces] Move: Get the nearest window when moving a window * [Workspaces] convert optional boolean to enum to avoid json problems * Handle case when the new Application Property "moveIfExists" does not exist * Re-implementing app-window pairing for moving feature. * spell checker * XAML formatting * Fixing bug: IPC message not arriving * spell checker * Removing app-level-setting for move app. Also fixed compiler errors due styling. * Updating editor window layout * Re-implementing window positioning UI elements * XAML formatting * Code review findings * Code cleanup * Code cleanup * Code cleanup * code cleanup * Code cleanup * Code cleanup * fix Move attribute after launch and snapshot * Extend WindowArranger with PWA functionality to detect different PWA apps. PwaHelper moved to the common library * fix repeat counter in the editor * Code optimization * code cleanup, optimization * fix double-processing window --------- Co-authored-by: Seraphima <zykovas91@gmail.com> Co-authored-by: donlaci <donlaci@yahoo.com>
This commit is contained in:
@@ -109,6 +109,24 @@ namespace DPIAware
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void InverseConvert(HMONITOR monitor_handle, RECT& rect)
|
||||||
|
{
|
||||||
|
if (monitor_handle == NULL)
|
||||||
|
{
|
||||||
|
const POINT ptZero = { 0, 0 };
|
||||||
|
monitor_handle = MonitorFromPoint(ptZero, MONITOR_DEFAULTTOPRIMARY);
|
||||||
|
}
|
||||||
|
|
||||||
|
UINT dpi_x, dpi_y;
|
||||||
|
if (GetDpiForMonitor(monitor_handle, MDT_EFFECTIVE_DPI, &dpi_x, &dpi_y) == S_OK)
|
||||||
|
{
|
||||||
|
rect.left = static_cast<long>(std::round(rect.left * static_cast<float>(DEFAULT_DPI) / dpi_x));
|
||||||
|
rect.right = static_cast<long>(std::round(rect.right * static_cast<float>(DEFAULT_DPI) / dpi_x));
|
||||||
|
rect.top = static_cast<long>(std::round(rect.top * static_cast<float>(DEFAULT_DPI) / dpi_y));
|
||||||
|
rect.bottom = static_cast<long>(std::round(rect.bottom * static_cast<float>(DEFAULT_DPI) / dpi_y));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void EnableDPIAwarenessForThisProcess()
|
void EnableDPIAwarenessForThisProcess()
|
||||||
{
|
{
|
||||||
SetProcessDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2);
|
SetProcessDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2);
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ namespace DPIAware
|
|||||||
void Convert(HMONITOR monitor_handle, RECT& rect);
|
void Convert(HMONITOR monitor_handle, RECT& rect);
|
||||||
void ConvertByCursorPosition(float& width, float& height);
|
void ConvertByCursorPosition(float& width, float& height);
|
||||||
void InverseConvert(HMONITOR monitor_handle, float& width, float& height);
|
void InverseConvert(HMONITOR monitor_handle, float& width, float& height);
|
||||||
|
void InverseConvert(HMONITOR monitor_handle, RECT& rect);
|
||||||
void EnableDPIAwarenessForThisProcess();
|
void EnableDPIAwarenessForThisProcess();
|
||||||
|
|
||||||
enum AwarenessLevel
|
enum AwarenessLevel
|
||||||
|
|||||||
@@ -3,9 +3,6 @@
|
|||||||
// See the LICENSE file in the project root for more information.
|
// See the LICENSE file in the project root for more information.
|
||||||
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
||||||
using Workspaces.Data;
|
|
||||||
|
|
||||||
using static WorkspacesEditor.Data.ProjectData;
|
using static WorkspacesEditor.Data.ProjectData;
|
||||||
|
|
||||||
namespace WorkspacesEditor.Data
|
namespace WorkspacesEditor.Data
|
||||||
|
|||||||
@@ -8,13 +8,7 @@ namespace WorkspacesEditor.Data
|
|||||||
{
|
{
|
||||||
public class TempProjectData : ProjectData
|
public class TempProjectData : ProjectData
|
||||||
{
|
{
|
||||||
public static string File
|
public static string File => FolderUtils.DataFolder() + "\\temp-workspaces.json";
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return FolderUtils.DataFolder() + "\\temp-workspaces.json";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void DeleteTempFile()
|
public static void DeleteTempFile()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -3,8 +3,6 @@
|
|||||||
// See the LICENSE file in the project root for more information.
|
// See the LICENSE file in the project root for more information.
|
||||||
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
||||||
using Workspaces.Data;
|
|
||||||
using WorkspacesEditor.Utils;
|
using WorkspacesEditor.Utils;
|
||||||
|
|
||||||
using static WorkspacesEditor.Data.ProjectData;
|
using static WorkspacesEditor.Data.ProjectData;
|
||||||
@@ -14,13 +12,7 @@ namespace WorkspacesEditor.Data
|
|||||||
{
|
{
|
||||||
public class WorkspacesData : WorkspacesEditorData<WorkspacesListWrapper>
|
public class WorkspacesData : WorkspacesEditorData<WorkspacesListWrapper>
|
||||||
{
|
{
|
||||||
public string File
|
public string File => FolderUtils.DataFolder() + "\\workspaces.json";
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return FolderUtils.DataFolder() + "\\workspaces.json";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public struct WorkspacesListWrapper
|
public struct WorkspacesListWrapper
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -3,28 +3,24 @@
|
|||||||
// See the LICENSE file in the project root for more information.
|
// See the LICENSE file in the project root for more information.
|
||||||
|
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
|
|
||||||
using WorkspacesEditor.Utils;
|
using WorkspacesEditor.Utils;
|
||||||
|
|
||||||
namespace Workspaces.Data
|
namespace WorkspacesEditor.Data
|
||||||
{
|
{
|
||||||
public class WorkspacesEditorData<T>
|
public class WorkspacesEditorData<T>
|
||||||
{
|
{
|
||||||
protected JsonSerializerOptions JsonOptions
|
protected JsonSerializerOptions JsonOptions
|
||||||
{
|
{
|
||||||
get
|
get => new()
|
||||||
{
|
|
||||||
return new JsonSerializerOptions
|
|
||||||
{
|
{
|
||||||
PropertyNamingPolicy = new DashCaseNamingPolicy(),
|
PropertyNamingPolicy = new DashCaseNamingPolicy(),
|
||||||
WriteIndented = true,
|
WriteIndented = true,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public T Read(string file)
|
public T Read(string file)
|
||||||
{
|
{
|
||||||
IOUtils ioUtils = new IOUtils();
|
IOUtils ioUtils = new();
|
||||||
string data = ioUtils.ReadFile(file);
|
string data = ioUtils.ReadFile(file);
|
||||||
return JsonSerializer.Deserialize<T>(data, JsonOptions);
|
return JsonSerializer.Deserialize<T>(data, JsonOptions);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
xmlns:ui="http://schemas.modernwpf.com/2019"
|
xmlns:ui="http://schemas.modernwpf.com/2019"
|
||||||
x:Name="WorkspacesMainWindow"
|
x:Name="WorkspacesMainWindow"
|
||||||
Title="{x:Static props:Resources.MainTitle}"
|
Title="{x:Static props:Resources.MainTitle}"
|
||||||
MinWidth="700"
|
MinWidth="750"
|
||||||
MinHeight="680"
|
MinHeight="680"
|
||||||
ui:TitleBar.Background="{DynamicResource PrimaryBackgroundBrush}"
|
ui:TitleBar.Background="{DynamicResource PrimaryBackgroundBrush}"
|
||||||
ui:TitleBar.InactiveBackground="{DynamicResource TertiaryBackgroundBrush}"
|
ui:TitleBar.InactiveBackground="{DynamicResource TertiaryBackgroundBrush}"
|
||||||
|
|||||||
@@ -18,14 +18,7 @@ namespace WorkspacesEditor.Models
|
|||||||
|
|
||||||
public override System.Windows.DataTemplate SelectTemplate(object item, System.Windows.DependencyObject container)
|
public override System.Windows.DataTemplate SelectTemplate(object item, System.Windows.DependencyObject container)
|
||||||
{
|
{
|
||||||
if (item is MonitorHeaderRow)
|
return item is MonitorHeaderRow ? HeaderTemplate : AppTemplate;
|
||||||
{
|
|
||||||
return HeaderTemplate;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return AppTemplate;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,25 +1,22 @@
|
|||||||
// Copyright (c) Microsoft Corporation
|
// Copyright (c) Microsoft Corporation
|
||||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||||
// See the LICENSE file in the project root for more information.
|
// See the LICENSE file in the project root for more information.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
using System.Drawing;
|
|
||||||
using System.Drawing.Drawing2D;
|
|
||||||
using System.Drawing.Imaging;
|
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.IO;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text.Json.Serialization;
|
using System.Text.Json.Serialization;
|
||||||
using System.Text.RegularExpressions;
|
|
||||||
using System.Windows.Media.Imaging;
|
|
||||||
using ManagedCommon;
|
|
||||||
using Windows.Management.Deployment;
|
|
||||||
using WorkspacesCsharpLibrary;
|
|
||||||
using WorkspacesCsharpLibrary.Models;
|
using WorkspacesCsharpLibrary.Models;
|
||||||
|
|
||||||
namespace WorkspacesEditor.Models
|
namespace WorkspacesEditor.Models
|
||||||
{
|
{
|
||||||
|
public enum WindowPositionKind
|
||||||
|
{
|
||||||
|
Custom = 0,
|
||||||
|
Maximized = 1,
|
||||||
|
Minimized = 2,
|
||||||
|
}
|
||||||
|
|
||||||
public class Application : BaseApplication, IDisposable
|
public class Application : BaseApplication, IDisposable
|
||||||
{
|
{
|
||||||
private bool _isInitialized;
|
private bool _isInitialized;
|
||||||
@@ -79,7 +76,7 @@ namespace WorkspacesEditor.Models
|
|||||||
return left.X != right.X || left.Y != right.Y || left.Width != right.Width || left.Height != right.Height;
|
return left.X != right.X || left.Y != right.Y || left.Width != right.Width || left.Height != right.Height;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool Equals(object obj)
|
public override readonly bool Equals(object obj)
|
||||||
{
|
{
|
||||||
if (obj == null || GetType() != obj.GetType())
|
if (obj == null || GetType() != obj.GetType())
|
||||||
{
|
{
|
||||||
@@ -90,7 +87,7 @@ namespace WorkspacesEditor.Models
|
|||||||
return X == pos.X && Y == pos.Y && Width == pos.Width && Height == pos.Height;
|
return X == pos.X && Y == pos.Y && Width == pos.Width && Height == pos.Height;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override int GetHashCode()
|
public override readonly int GetHashCode()
|
||||||
{
|
{
|
||||||
return base.GetHashCode();
|
return base.GetHashCode();
|
||||||
}
|
}
|
||||||
@@ -136,36 +133,24 @@ namespace WorkspacesEditor.Models
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool _minimized;
|
public bool Minimized { get; set; }
|
||||||
|
|
||||||
public bool Minimized
|
public bool Maximized { get; set; }
|
||||||
|
|
||||||
|
public bool EditPositionEnabled => !Minimized && !Maximized;
|
||||||
|
|
||||||
|
public int PositionComboboxIndex
|
||||||
{
|
{
|
||||||
get => _minimized;
|
get => Maximized ? (int)WindowPositionKind.Maximized : Minimized ? (int)WindowPositionKind.Minimized : (int)WindowPositionKind.Custom;
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
_minimized = value;
|
Maximized = value == (int)WindowPositionKind.Maximized;
|
||||||
OnPropertyChanged(new PropertyChangedEventArgs(nameof(Minimized)));
|
Minimized = value == (int)WindowPositionKind.Minimized;
|
||||||
OnPropertyChanged(new PropertyChangedEventArgs(nameof(EditPositionEnabled)));
|
OnPropertyChanged(new PropertyChangedEventArgs(nameof(EditPositionEnabled)));
|
||||||
RedrawPreviewImage();
|
RedrawPreviewImage();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool _maximized;
|
|
||||||
|
|
||||||
public bool Maximized
|
|
||||||
{
|
|
||||||
get => _maximized;
|
|
||||||
set
|
|
||||||
{
|
|
||||||
_maximized = value;
|
|
||||||
OnPropertyChanged(new PropertyChangedEventArgs(nameof(Maximized)));
|
|
||||||
OnPropertyChanged(new PropertyChangedEventArgs(nameof(EditPositionEnabled)));
|
|
||||||
RedrawPreviewImage();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool EditPositionEnabled { get => !Minimized && !Maximized; }
|
|
||||||
|
|
||||||
private string _appMainParams;
|
private string _appMainParams;
|
||||||
|
|
||||||
public string AppMainParams
|
public string AppMainParams
|
||||||
@@ -183,7 +168,7 @@ namespace WorkspacesEditor.Models
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool IsAppMainParamVisible { get => !string.IsNullOrWhiteSpace(_appMainParams); }
|
public bool IsAppMainParamVisible => !string.IsNullOrWhiteSpace(_appMainParams);
|
||||||
|
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public bool IsHighlighted { get; set; }
|
public bool IsHighlighted { get; set; }
|
||||||
@@ -192,13 +177,7 @@ namespace WorkspacesEditor.Models
|
|||||||
public int RepeatIndex { get; set; }
|
public int RepeatIndex { get; set; }
|
||||||
|
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public string RepeatIndexString
|
public string RepeatIndexString => RepeatIndex <= 1 ? string.Empty : RepeatIndex.ToString(CultureInfo.InvariantCulture);
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return RepeatIndex <= 1 ? string.Empty : RepeatIndex.ToString(CultureInfo.InvariantCulture);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private WindowPosition _position;
|
private WindowPosition _position;
|
||||||
|
|
||||||
@@ -242,10 +221,7 @@ namespace WorkspacesEditor.Models
|
|||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
if (_monitorSetup == null)
|
_monitorSetup ??= Parent.GetMonitorForApp(this);
|
||||||
{
|
|
||||||
_monitorSetup = Parent.GetMonitorForApp(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
return _monitorSetup;
|
return _monitorSetup;
|
||||||
}
|
}
|
||||||
@@ -271,7 +247,7 @@ namespace WorkspacesEditor.Models
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public string DeleteButtonContent { get => _isIncluded ? Properties.Resources.Delete : Properties.Resources.AddBack; }
|
public string DeleteButtonContent => _isIncluded ? Properties.Resources.Delete : Properties.Resources.AddBack;
|
||||||
|
|
||||||
private bool _isIncluded = true;
|
private bool _isIncluded = true;
|
||||||
|
|
||||||
@@ -298,15 +274,5 @@ namespace WorkspacesEditor.Models
|
|||||||
CommandLineArguments = newCommandLineValue;
|
CommandLineArguments = newCommandLineValue;
|
||||||
OnPropertyChanged(new PropertyChangedEventArgs(nameof(AppMainParams)));
|
OnPropertyChanged(new PropertyChangedEventArgs(nameof(AppMainParams)));
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void MaximizedChecked()
|
|
||||||
{
|
|
||||||
Minimized = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
internal void MinimizedChecked()
|
|
||||||
{
|
|
||||||
Maximized = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,28 +6,18 @@ using System.Windows;
|
|||||||
|
|
||||||
namespace WorkspacesEditor.Models
|
namespace WorkspacesEditor.Models
|
||||||
{
|
{
|
||||||
public class Monitor
|
public class Monitor(string monitorName, string monitorInstanceId, int number, int dpi, Rect dpiAwareBounds, Rect dpiUnawareBounds)
|
||||||
{
|
{
|
||||||
public string MonitorName { get; private set; }
|
public string MonitorName { get; private set; } = monitorName;
|
||||||
|
|
||||||
public string MonitorInstanceId { get; private set; }
|
public string MonitorInstanceId { get; private set; } = monitorInstanceId;
|
||||||
|
|
||||||
public int MonitorNumber { get; private set; }
|
public int MonitorNumber { get; private set; } = number;
|
||||||
|
|
||||||
public int Dpi { get; private set; }
|
public int Dpi { get; private set; } = dpi;
|
||||||
|
|
||||||
public Rect MonitorDpiUnawareBounds { get; private set; }
|
public Rect MonitorDpiUnawareBounds { get; private set; } = dpiUnawareBounds;
|
||||||
|
|
||||||
public Rect MonitorDpiAwareBounds { get; private set; }
|
public Rect MonitorDpiAwareBounds { get; private set; } = dpiAwareBounds;
|
||||||
|
|
||||||
public Monitor(string monitorName, string monitorInstanceId, int number, int dpi, Rect dpiAwareBounds, Rect dpiUnawareBounds)
|
|
||||||
{
|
|
||||||
MonitorName = monitorName;
|
|
||||||
MonitorInstanceId = monitorInstanceId;
|
|
||||||
MonitorNumber = number;
|
|
||||||
Dpi = dpi;
|
|
||||||
MonitorDpiAwareBounds = dpiAwareBounds;
|
|
||||||
MonitorDpiUnawareBounds = dpiUnawareBounds;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,9 +16,9 @@ namespace WorkspacesEditor.Models
|
|||||||
PropertyChanged?.Invoke(this, e);
|
PropertyChanged?.Invoke(this, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
public string MonitorInfo { get => MonitorName; }
|
public string MonitorInfo => MonitorName;
|
||||||
|
|
||||||
public string MonitorInfoWithResolution { get => $"{MonitorName} {MonitorDpiAwareBounds.Width}x{MonitorDpiAwareBounds.Height}"; }
|
public string MonitorInfoWithResolution => $"{MonitorName} {MonitorDpiAwareBounds.Width}x{MonitorDpiAwareBounds.Height}";
|
||||||
|
|
||||||
public MonitorSetup(string monitorName, string monitorInstanceId, int number, int dpi, Rect dpiAwareBounds, Rect dpiUnawareBounds)
|
public MonitorSetup(string monitorName, string monitorInstanceId, int number, int dpi, Rect dpiAwareBounds, Rect dpiUnawareBounds)
|
||||||
: base(monitorName, monitorInstanceId, number, dpi, dpiAwareBounds, dpiUnawareBounds)
|
: base(monitorName, monitorInstanceId, number, dpi, dpiAwareBounds, dpiUnawareBounds)
|
||||||
|
|||||||
@@ -29,10 +29,7 @@ namespace WorkspacesEditor.Models
|
|||||||
|
|
||||||
public string Name
|
public string Name
|
||||||
{
|
{
|
||||||
get
|
get => _name;
|
||||||
{
|
|
||||||
return _name;
|
|
||||||
}
|
|
||||||
|
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
@@ -68,8 +65,7 @@ namespace WorkspacesEditor.Models
|
|||||||
|
|
||||||
DateTime lastLaunchDateTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc).AddSeconds(LastLaunchedTime);
|
DateTime lastLaunchDateTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc).AddSeconds(LastLaunchedTime);
|
||||||
|
|
||||||
var now = DateTime.UtcNow.Ticks;
|
TimeSpan ts = DateTime.UtcNow - lastLaunchDateTime;
|
||||||
var ts = DateTime.UtcNow - lastLaunchDateTime;
|
|
||||||
double delta = Math.Abs(ts.TotalSeconds);
|
double delta = Math.Abs(ts.TotalSeconds);
|
||||||
|
|
||||||
if (delta < 1 * MINUTE)
|
if (delta < 1 * MINUTE)
|
||||||
@@ -120,10 +116,7 @@ namespace WorkspacesEditor.Models
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool CanBeSaved
|
public bool CanBeSaved => Name.Length > 0 && Applications.Count > 0;
|
||||||
{
|
|
||||||
get => Name.Length > 0 && Applications.Count > 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
private bool _isRevertEnabled;
|
private bool _isRevertEnabled;
|
||||||
|
|
||||||
@@ -145,10 +138,7 @@ namespace WorkspacesEditor.Models
|
|||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public bool IsPopupVisible
|
public bool IsPopupVisible
|
||||||
{
|
{
|
||||||
get
|
get => _isPopupVisible;
|
||||||
{
|
|
||||||
return _isPopupVisible;
|
|
||||||
}
|
|
||||||
|
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
@@ -163,11 +153,11 @@ namespace WorkspacesEditor.Models
|
|||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
List<object> applicationsListed = new List<object>();
|
List<object> applicationsListed = [];
|
||||||
ILookup<MonitorSetup, Application> apps = Applications.Where(x => !x.Minimized).ToLookup(x => x.MonitorSetup);
|
ILookup<MonitorSetup, Application> apps = Applications.Where(x => !x.Minimized).ToLookup(x => x.MonitorSetup);
|
||||||
foreach (var appItem in apps.OrderBy(x => x.Key.MonitorDpiUnawareBounds.Left).ThenBy(x => x.Key.MonitorDpiUnawareBounds.Top))
|
foreach (IGrouping<MonitorSetup, Application> appItem in apps.OrderBy(x => x.Key.MonitorDpiUnawareBounds.Left).ThenBy(x => x.Key.MonitorDpiUnawareBounds.Top))
|
||||||
{
|
{
|
||||||
MonitorHeaderRow headerRow = new MonitorHeaderRow { MonitorName = "Screen " + appItem.Key.MonitorNumber, SelectString = Properties.Resources.SelectAllAppsOnMonitor + " " + appItem.Key.MonitorInfo };
|
MonitorHeaderRow headerRow = new() { MonitorName = "Screen " + appItem.Key.MonitorNumber, SelectString = Properties.Resources.SelectAllAppsOnMonitor + " " + appItem.Key.MonitorInfo };
|
||||||
applicationsListed.Add(headerRow);
|
applicationsListed.Add(headerRow);
|
||||||
foreach (Application app in appItem)
|
foreach (Application app in appItem)
|
||||||
{
|
{
|
||||||
@@ -175,10 +165,10 @@ namespace WorkspacesEditor.Models
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var minimizedApps = Applications.Where(x => x.Minimized);
|
IEnumerable<Application> minimizedApps = Applications.Where(x => x.Minimized);
|
||||||
if (minimizedApps.Any())
|
if (minimizedApps.Any())
|
||||||
{
|
{
|
||||||
MonitorHeaderRow headerRow = new MonitorHeaderRow { MonitorName = Properties.Resources.Minimized_Apps, SelectString = Properties.Resources.SelectAllMinimizedApps };
|
MonitorHeaderRow headerRow = new() { MonitorName = Properties.Resources.Minimized_Apps, SelectString = Properties.Resources.SelectAllMinimizedApps };
|
||||||
applicationsListed.Add(headerRow);
|
applicationsListed.Add(headerRow);
|
||||||
foreach (Application app in minimizedApps)
|
foreach (Application app in minimizedApps)
|
||||||
{
|
{
|
||||||
@@ -219,17 +209,17 @@ namespace WorkspacesEditor.Models
|
|||||||
|
|
||||||
int screenIndex = 1;
|
int screenIndex = 1;
|
||||||
|
|
||||||
Monitors = new List<MonitorSetup>();
|
Monitors = [];
|
||||||
foreach (var item in selectedProject.Monitors.OrderBy(x => x.MonitorDpiAwareBounds.Left).ThenBy(x => x.MonitorDpiAwareBounds.Top))
|
foreach (MonitorSetup item in selectedProject.Monitors.OrderBy(x => x.MonitorDpiAwareBounds.Left).ThenBy(x => x.MonitorDpiAwareBounds.Top))
|
||||||
{
|
{
|
||||||
Monitors.Add(item);
|
Monitors.Add(item);
|
||||||
screenIndex++;
|
screenIndex++;
|
||||||
}
|
}
|
||||||
|
|
||||||
Applications = new List<Application>();
|
Applications = [];
|
||||||
foreach (var item in selectedProject.Applications)
|
foreach (Application item in selectedProject.Applications)
|
||||||
{
|
{
|
||||||
Application newApp = new Application(item);
|
Application newApp = new(item);
|
||||||
newApp.Parent = this;
|
newApp.Parent = this;
|
||||||
newApp.InitializationFinished();
|
newApp.InitializationFinished();
|
||||||
Applications.Add(newApp);
|
Applications.Add(newApp);
|
||||||
@@ -244,14 +234,14 @@ namespace WorkspacesEditor.Models
|
|||||||
LastLaunchedTime = project.LastLaunchedTime;
|
LastLaunchedTime = project.LastLaunchedTime;
|
||||||
IsShortcutNeeded = project.IsShortcutNeeded;
|
IsShortcutNeeded = project.IsShortcutNeeded;
|
||||||
MoveExistingWindows = project.MoveExistingWindows;
|
MoveExistingWindows = project.MoveExistingWindows;
|
||||||
Monitors = new List<MonitorSetup>() { };
|
Monitors = [];
|
||||||
Applications = new List<Models.Application> { };
|
Applications = [];
|
||||||
|
|
||||||
foreach (var app in project.Applications)
|
foreach (ProjectData.ApplicationWrapper app in project.Applications)
|
||||||
{
|
{
|
||||||
Models.Application newApp = new Models.Application()
|
Models.Application newApp = new()
|
||||||
{
|
{
|
||||||
Id = string.IsNullOrEmpty(app.Id) ? $"{{{Guid.NewGuid().ToString()}}}" : app.Id,
|
Id = string.IsNullOrEmpty(app.Id) ? $"{{{Guid.NewGuid()}}}" : app.Id,
|
||||||
AppName = app.Application,
|
AppName = app.Application,
|
||||||
AppPath = app.ApplicationPath,
|
AppPath = app.ApplicationPath,
|
||||||
AppTitle = app.Title,
|
AppTitle = app.Title,
|
||||||
@@ -278,20 +268,17 @@ namespace WorkspacesEditor.Models
|
|||||||
Applications.Add(newApp);
|
Applications.Add(newApp);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (var monitor in project.MonitorConfiguration)
|
foreach (ProjectData.MonitorConfigurationWrapper monitor in project.MonitorConfiguration)
|
||||||
{
|
{
|
||||||
System.Windows.Rect dpiAware = new System.Windows.Rect(monitor.MonitorRectDpiAware.Left, monitor.MonitorRectDpiAware.Top, monitor.MonitorRectDpiAware.Width, monitor.MonitorRectDpiAware.Height);
|
System.Windows.Rect dpiAware = new(monitor.MonitorRectDpiAware.Left, monitor.MonitorRectDpiAware.Top, monitor.MonitorRectDpiAware.Width, monitor.MonitorRectDpiAware.Height);
|
||||||
System.Windows.Rect dpiUnaware = new System.Windows.Rect(monitor.MonitorRectDpiUnaware.Left, monitor.MonitorRectDpiUnaware.Top, monitor.MonitorRectDpiUnaware.Width, monitor.MonitorRectDpiUnaware.Height);
|
System.Windows.Rect dpiUnaware = new(monitor.MonitorRectDpiUnaware.Left, monitor.MonitorRectDpiUnaware.Top, monitor.MonitorRectDpiUnaware.Width, monitor.MonitorRectDpiUnaware.Height);
|
||||||
Monitors.Add(new MonitorSetup(monitor.Id, monitor.InstanceId, monitor.MonitorNumber, monitor.Dpi, dpiAware, dpiUnaware));
|
Monitors.Add(new MonitorSetup(monitor.Id, monitor.InstanceId, monitor.MonitorNumber, monitor.Dpi, dpiAware, dpiUnaware));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public BitmapImage PreviewIcons
|
public BitmapImage PreviewIcons
|
||||||
{
|
{
|
||||||
get
|
get => _previewIcons;
|
||||||
{
|
|
||||||
return _previewIcons;
|
|
||||||
}
|
|
||||||
|
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
@@ -302,10 +289,7 @@ namespace WorkspacesEditor.Models
|
|||||||
|
|
||||||
public BitmapImage PreviewImage
|
public BitmapImage PreviewImage
|
||||||
{
|
{
|
||||||
get
|
get => _previewImage;
|
||||||
{
|
|
||||||
return _previewImage;
|
|
||||||
}
|
|
||||||
|
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
@@ -316,10 +300,7 @@ namespace WorkspacesEditor.Models
|
|||||||
|
|
||||||
public double PreviewImageWidth
|
public double PreviewImageWidth
|
||||||
{
|
{
|
||||||
get
|
get => _previewImageWidth;
|
||||||
{
|
|
||||||
return _previewImageWidth;
|
|
||||||
}
|
|
||||||
|
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
@@ -366,6 +347,7 @@ namespace WorkspacesEditor.Models
|
|||||||
Id = other.Id;
|
Id = other.Id;
|
||||||
Name = other.Name;
|
Name = other.Name;
|
||||||
IsRevertEnabled = true;
|
IsRevertEnabled = true;
|
||||||
|
MoveExistingWindows = other.MoveExistingWindows;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void CloseExpanders()
|
internal void CloseExpanders()
|
||||||
@@ -378,13 +360,13 @@ namespace WorkspacesEditor.Models
|
|||||||
|
|
||||||
internal MonitorSetup GetMonitorForApp(Application app)
|
internal MonitorSetup GetMonitorForApp(Application app)
|
||||||
{
|
{
|
||||||
var monitorSetup = Monitors.Where(x => x.MonitorNumber == app.MonitorNumber).FirstOrDefault();
|
MonitorSetup monitorSetup = Monitors.Where(x => x.MonitorNumber == app.MonitorNumber).FirstOrDefault();
|
||||||
if (monitorSetup == null)
|
if (monitorSetup == null)
|
||||||
{
|
{
|
||||||
// monitors changed: try to determine monitor id based on middle point
|
// monitors changed: try to determine monitor id based on middle point
|
||||||
int middleX = app.Position.X + (app.Position.Width / 2);
|
int middleX = app.Position.X + (app.Position.Width / 2);
|
||||||
int middleY = app.Position.Y + (app.Position.Height / 2);
|
int middleY = app.Position.Y + (app.Position.Height / 2);
|
||||||
var monitorCandidate = Monitors.Where(x =>
|
MonitorSetup monitorCandidate = Monitors.Where(x =>
|
||||||
(x.MonitorDpiUnawareBounds.Left < middleX) &&
|
(x.MonitorDpiUnawareBounds.Left < middleX) &&
|
||||||
(x.MonitorDpiUnawareBounds.Right > middleX) &&
|
(x.MonitorDpiUnawareBounds.Right > middleX) &&
|
||||||
(x.MonitorDpiUnawareBounds.Top < middleY) &&
|
(x.MonitorDpiUnawareBounds.Top < middleY) &&
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ namespace WorkspacesEditor.Properties {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Looks up a localized string similar to Add Back.
|
/// Looks up a localized string similar to Add back.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static string AddBack {
|
public static string AddBack {
|
||||||
get {
|
get {
|
||||||
@@ -78,15 +78,6 @@ namespace WorkspacesEditor.Properties {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Looks up a localized string similar to Launch new app instances.
|
|
||||||
/// </summary>
|
|
||||||
public static string AlwaysLaunch {
|
|
||||||
get {
|
|
||||||
return ResourceManager.GetString("AlwaysLaunch", resourceCulture);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Looks up a localized string similar to app.
|
/// Looks up a localized string similar to app.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -169,7 +160,7 @@ namespace WorkspacesEditor.Properties {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Looks up a localized string similar to Create Desktop Shortcut.
|
/// Looks up a localized string similar to Create desktop shortcut.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static string CreateShortcut {
|
public static string CreateShortcut {
|
||||||
get {
|
get {
|
||||||
@@ -186,6 +177,15 @@ namespace WorkspacesEditor.Properties {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized string similar to Custom.
|
||||||
|
/// </summary>
|
||||||
|
public static string Custom {
|
||||||
|
get {
|
||||||
|
return ResourceManager.GetString("Custom", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Looks up a localized string similar to days ago.
|
/// Looks up a localized string similar to days ago.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -223,7 +223,7 @@ namespace WorkspacesEditor.Properties {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Looks up a localized string similar to Remove Selected Apps.
|
/// Looks up a localized string similar to Remove selected apps.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static string DeleteSelected {
|
public static string DeleteSelected {
|
||||||
get {
|
get {
|
||||||
@@ -322,7 +322,7 @@ namespace WorkspacesEditor.Properties {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Looks up a localized string similar to Launch & Edit.
|
/// Looks up a localized string similar to Launch & edit.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static string LaunchEdit {
|
public static string LaunchEdit {
|
||||||
get {
|
get {
|
||||||
@@ -367,7 +367,7 @@ namespace WorkspacesEditor.Properties {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Looks up a localized string similar to Minimized Apps.
|
/// Looks up a localized string similar to Minimized apps.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static string Minimized_Apps {
|
public static string Minimized_Apps {
|
||||||
get {
|
get {
|
||||||
@@ -394,7 +394,7 @@ namespace WorkspacesEditor.Properties {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Looks up a localized string similar to Move apps if present.
|
/// Looks up a localized string similar to Move existing windows.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static string MoveIfExist {
|
public static string MoveIfExist {
|
||||||
get {
|
get {
|
||||||
@@ -502,7 +502,7 @@ namespace WorkspacesEditor.Properties {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Looks up a localized string similar to Pin Workspaces to Taskbar.
|
/// Looks up a localized string similar to Pin Workspaces to taskbar.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static string PinToTaskbar {
|
public static string PinToTaskbar {
|
||||||
get {
|
get {
|
||||||
@@ -565,7 +565,7 @@ namespace WorkspacesEditor.Properties {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Looks up a localized string similar to Select All Apps on.
|
/// Looks up a localized string similar to Select all apps on.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static string SelectAllAppsOnMonitor {
|
public static string SelectAllAppsOnMonitor {
|
||||||
get {
|
get {
|
||||||
@@ -574,7 +574,7 @@ namespace WorkspacesEditor.Properties {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Looks up a localized string similar to Select All Minimized Apps.
|
/// Looks up a localized string similar to Select all minimized apps.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static string SelectAllMinimizedApps {
|
public static string SelectAllMinimizedApps {
|
||||||
get {
|
get {
|
||||||
@@ -583,7 +583,7 @@ namespace WorkspacesEditor.Properties {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Looks up a localized string similar to Select All Apps in Workspace.
|
/// Looks up a localized string similar to Select all apps in Workspace.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static string SelectedAllInWorkspace {
|
public static string SelectedAllInWorkspace {
|
||||||
get {
|
get {
|
||||||
@@ -645,6 +645,15 @@ namespace WorkspacesEditor.Properties {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up a localized string similar to Window position.
|
||||||
|
/// </summary>
|
||||||
|
public static string WindowPosition {
|
||||||
|
get {
|
||||||
|
return ResourceManager.GetString("WindowPosition", resourceCulture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Looks up a localized string similar to Workspace name.
|
/// Looks up a localized string similar to Workspace name.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -123,9 +123,6 @@
|
|||||||
<data name="Admin" xml:space="preserve">
|
<data name="Admin" xml:space="preserve">
|
||||||
<value>Admin</value>
|
<value>Admin</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="AlwaysLaunch" xml:space="preserve">
|
|
||||||
<value>Launch new app instances</value>
|
|
||||||
</data>
|
|
||||||
<data name="App" xml:space="preserve">
|
<data name="App" xml:space="preserve">
|
||||||
<value>app</value>
|
<value>app</value>
|
||||||
</data>
|
</data>
|
||||||
@@ -160,6 +157,9 @@
|
|||||||
<data name="CreateShortcut" xml:space="preserve">
|
<data name="CreateShortcut" xml:space="preserve">
|
||||||
<value>Create desktop shortcut</value>
|
<value>Create desktop shortcut</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="Custom" xml:space="preserve">
|
||||||
|
<value>Custom</value>
|
||||||
|
</data>
|
||||||
<data name="DaysAgo" xml:space="preserve">
|
<data name="DaysAgo" xml:space="preserve">
|
||||||
<value>days ago</value>
|
<value>days ago</value>
|
||||||
</data>
|
</data>
|
||||||
@@ -231,7 +231,7 @@
|
|||||||
<value>months ago</value>
|
<value>months ago</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="MoveIfExist" xml:space="preserve">
|
<data name="MoveIfExist" xml:space="preserve">
|
||||||
<value>Move apps if present</value>
|
<value>Move existing windows</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="Name" xml:space="preserve">
|
<data name="Name" xml:space="preserve">
|
||||||
<value>Name</value>
|
<value>Name</value>
|
||||||
@@ -321,6 +321,9 @@
|
|||||||
<data name="Width" xml:space="preserve">
|
<data name="Width" xml:space="preserve">
|
||||||
<value>Width</value>
|
<value>Width</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="WindowPosition" xml:space="preserve">
|
||||||
|
<value>Window position</value>
|
||||||
|
</data>
|
||||||
<data name="WriteArgs" xml:space="preserve">
|
<data name="WriteArgs" xml:space="preserve">
|
||||||
<value>Write arguments here</value>
|
<value>Write arguments here</value>
|
||||||
</data>
|
</data>
|
||||||
|
|||||||
@@ -20,21 +20,21 @@ namespace WorkspacesEditor.Utils
|
|||||||
{
|
{
|
||||||
public class DrawHelper
|
public class DrawHelper
|
||||||
{
|
{
|
||||||
private static Font font = new("Tahoma", 24);
|
private static readonly Font Font = new("Tahoma", 24);
|
||||||
private static double scale = 0.1;
|
private static readonly double Scale = 0.1;
|
||||||
private static double gapWidth;
|
private static double gapWidth;
|
||||||
private static double gapHeight;
|
private static double gapHeight;
|
||||||
|
|
||||||
public static BitmapImage DrawPreview(Project project, Rectangle bounds, Theme currentTheme)
|
public static BitmapImage DrawPreview(Project project, Rectangle bounds, Theme currentTheme)
|
||||||
{
|
{
|
||||||
List<double> horizontalGaps = new List<double>();
|
List<double> horizontalGaps = [];
|
||||||
List<double> verticalGaps = new List<double>();
|
List<double> verticalGaps = [];
|
||||||
gapWidth = bounds.Width * 0.01;
|
gapWidth = bounds.Width * 0.01;
|
||||||
gapHeight = bounds.Height * 0.01;
|
gapHeight = bounds.Height * 0.01;
|
||||||
|
|
||||||
int Scaled(double value)
|
int Scaled(double value)
|
||||||
{
|
{
|
||||||
return (int)(value * scale);
|
return (int)(value * Scale);
|
||||||
}
|
}
|
||||||
|
|
||||||
int TransformX(double posX)
|
int TransformX(double posX)
|
||||||
@@ -54,7 +54,7 @@ namespace WorkspacesEditor.Utils
|
|||||||
if (app.Maximized)
|
if (app.Maximized)
|
||||||
{
|
{
|
||||||
Project project = app.Parent;
|
Project project = app.Parent;
|
||||||
var monitor = project.GetMonitorForApp(app);
|
MonitorSetup monitor = project.GetMonitorForApp(app);
|
||||||
if (monitor == null)
|
if (monitor == null)
|
||||||
{
|
{
|
||||||
// unrealistic case, there are no monitors at all in the workspace, use original rect
|
// unrealistic case, there are no monitors at all in the workspace, use original rect
|
||||||
@@ -69,22 +69,23 @@ namespace WorkspacesEditor.Utils
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Dictionary<string, int> repeatCounter = new Dictionary<string, int>();
|
Dictionary<string, int> repeatCounter = [];
|
||||||
|
|
||||||
var appsIncluded = project.Applications.Where(x => x.IsIncluded);
|
IEnumerable<Application> appsIncluded = project.Applications.Where(x => x.IsIncluded);
|
||||||
|
|
||||||
foreach (Application app in appsIncluded)
|
foreach (Application app in appsIncluded)
|
||||||
{
|
{
|
||||||
if (repeatCounter.TryGetValue(app.AppPath + app.AppTitle, out int value))
|
string appIdentifier = app.AppPath + app.PwaAppId;
|
||||||
|
if (repeatCounter.TryGetValue(appIdentifier, out int value))
|
||||||
{
|
{
|
||||||
repeatCounter[app.AppPath + app.AppTitle] = ++value;
|
repeatCounter[appIdentifier] = ++value;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
repeatCounter.Add(app.AppPath + app.AppTitle, 1);
|
repeatCounter.Add(appIdentifier, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
app.RepeatIndex = repeatCounter[app.AppPath + app.AppTitle];
|
app.RepeatIndex = repeatCounter[appIdentifier];
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (Application app in project.Applications.Where(x => !x.IsIncluded))
|
foreach (Application app in project.Applications.Where(x => !x.IsIncluded))
|
||||||
@@ -113,7 +114,7 @@ namespace WorkspacesEditor.Utils
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Bitmap previewBitmap = new Bitmap(Scaled(bounds.Width + (verticalGaps.Count * gapWidth)), Scaled((bounds.Height * 1.2) + (horizontalGaps.Count * gapHeight)));
|
Bitmap previewBitmap = new(Scaled(bounds.Width + (verticalGaps.Count * gapWidth)), Scaled((bounds.Height * 1.2) + (horizontalGaps.Count * gapHeight)));
|
||||||
double desiredIconSize = Scaled(Math.Min(bounds.Width, bounds.Height)) * 0.25;
|
double desiredIconSize = Scaled(Math.Min(bounds.Width, bounds.Height)) * 0.25;
|
||||||
using (Graphics g = Graphics.FromImage(previewBitmap))
|
using (Graphics g = Graphics.FromImage(previewBitmap))
|
||||||
{
|
{
|
||||||
@@ -131,7 +132,7 @@ namespace WorkspacesEditor.Utils
|
|||||||
g.FillRectangle(monitorBrush, new Rectangle(TransformX(monitor.MonitorDpiAwareBounds.Left), TransformY(monitor.MonitorDpiAwareBounds.Top), Scaled(monitor.MonitorDpiAwareBounds.Width), Scaled(monitor.MonitorDpiAwareBounds.Height)));
|
g.FillRectangle(monitorBrush, new Rectangle(TransformX(monitor.MonitorDpiAwareBounds.Left), TransformY(monitor.MonitorDpiAwareBounds.Top), Scaled(monitor.MonitorDpiAwareBounds.Width), Scaled(monitor.MonitorDpiAwareBounds.Height)));
|
||||||
}
|
}
|
||||||
|
|
||||||
var appsToDraw = appsIncluded.Where(x => !x.Minimized);
|
IEnumerable<Application> appsToDraw = appsIncluded.Where(x => !x.Minimized);
|
||||||
|
|
||||||
// draw the highlighted app at the end to have its icon in the foreground for the case there are overlapping icons
|
// draw the highlighted app at the end to have its icon in the foreground for the case there are overlapping icons
|
||||||
foreach (Application app in appsToDraw.Where(x => !x.IsHighlighted))
|
foreach (Application app in appsToDraw.Where(x => !x.IsHighlighted))
|
||||||
@@ -147,16 +148,15 @@ namespace WorkspacesEditor.Utils
|
|||||||
}
|
}
|
||||||
|
|
||||||
// draw the minimized windows
|
// draw the minimized windows
|
||||||
Rectangle rectMinimized = new Rectangle(0, Scaled((bounds.Height * 1.02) + (horizontalGaps.Count * gapHeight)), Scaled(bounds.Width + (verticalGaps.Count * gapWidth)), Scaled(bounds.Height * 0.18));
|
Rectangle rectMinimized = new(0, Scaled((bounds.Height * 1.02) + (horizontalGaps.Count * gapHeight)), Scaled(bounds.Width + (verticalGaps.Count * gapWidth)), Scaled(bounds.Height * 0.18));
|
||||||
DrawWindow(g, brush, brushForHighlight, rectMinimized, appsIncluded.Where(x => x.Minimized), currentTheme);
|
DrawWindow(g, brush, brushForHighlight, rectMinimized, appsIncluded.Where(x => x.Minimized), currentTheme);
|
||||||
}
|
}
|
||||||
|
|
||||||
using (var memory = new MemoryStream())
|
using MemoryStream memory = new();
|
||||||
{
|
|
||||||
previewBitmap.Save(memory, ImageFormat.Png);
|
previewBitmap.Save(memory, ImageFormat.Png);
|
||||||
memory.Position = 0;
|
memory.Position = 0;
|
||||||
|
|
||||||
var bitmapImage = new BitmapImage();
|
BitmapImage bitmapImage = new();
|
||||||
bitmapImage.BeginInit();
|
bitmapImage.BeginInit();
|
||||||
bitmapImage.StreamSource = memory;
|
bitmapImage.StreamSource = memory;
|
||||||
bitmapImage.CacheOption = BitmapCacheOption.OnLoad;
|
bitmapImage.CacheOption = BitmapCacheOption.OnLoad;
|
||||||
@@ -165,7 +165,6 @@ namespace WorkspacesEditor.Utils
|
|||||||
|
|
||||||
return bitmapImage;
|
return bitmapImage;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public static void DrawWindow(Graphics graphics, Brush brush, Rectangle bounds, Application app, double desiredIconSize, Theme currentTheme)
|
public static void DrawWindow(Graphics graphics, Brush brush, Rectangle bounds, Application app, double desiredIconSize, Theme currentTheme)
|
||||||
{
|
{
|
||||||
@@ -194,7 +193,7 @@ namespace WorkspacesEditor.Utils
|
|||||||
}
|
}
|
||||||
|
|
||||||
double iconSize = Math.Min(Math.Min(bounds.Width - 4, bounds.Height - 4), desiredIconSize);
|
double iconSize = Math.Min(Math.Min(bounds.Width - 4, bounds.Height - 4), desiredIconSize);
|
||||||
Rectangle iconBounds = new Rectangle((int)(bounds.Left + (bounds.Width / 2) - (iconSize / 2)), (int)(bounds.Top + (bounds.Height / 2) - (iconSize / 2)), (int)iconSize, (int)iconSize);
|
Rectangle iconBounds = new((int)(bounds.Left + (bounds.Width / 2) - (iconSize / 2)), (int)(bounds.Top + (bounds.Height / 2) - (iconSize / 2)), (int)iconSize, (int)iconSize);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -203,13 +202,13 @@ namespace WorkspacesEditor.Utils
|
|||||||
{
|
{
|
||||||
string indexString = app.RepeatIndex.ToString(CultureInfo.InvariantCulture);
|
string indexString = app.RepeatIndex.ToString(CultureInfo.InvariantCulture);
|
||||||
int indexSize = (int)(iconBounds.Width * 0.5);
|
int indexSize = (int)(iconBounds.Width * 0.5);
|
||||||
Rectangle indexBounds = new Rectangle(iconBounds.Right - indexSize, iconBounds.Bottom - indexSize, indexSize, indexSize);
|
Rectangle indexBounds = new(iconBounds.Right - indexSize, iconBounds.Bottom - indexSize, indexSize, indexSize);
|
||||||
|
|
||||||
var textSize = graphics.MeasureString(indexString, font);
|
SizeF textSize = graphics.MeasureString(indexString, Font);
|
||||||
var state = graphics.Save();
|
GraphicsState state = graphics.Save();
|
||||||
graphics.TranslateTransform(indexBounds.Left, indexBounds.Top);
|
graphics.TranslateTransform(indexBounds.Left, indexBounds.Top);
|
||||||
graphics.ScaleTransform(indexBounds.Width / textSize.Width, indexBounds.Height / textSize.Height);
|
graphics.ScaleTransform(indexBounds.Width / textSize.Width, indexBounds.Height / textSize.Height);
|
||||||
graphics.DrawString(indexString, font, Brushes.Black, PointF.Empty);
|
graphics.DrawString(indexString, Font, Brushes.Black, PointF.Empty);
|
||||||
graphics.Restore(state);
|
graphics.Restore(state);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -255,7 +254,7 @@ namespace WorkspacesEditor.Utils
|
|||||||
for (int iconCounter = 0; iconCounter < appsCount; iconCounter++)
|
for (int iconCounter = 0; iconCounter < appsCount; iconCounter++)
|
||||||
{
|
{
|
||||||
Application app = apps.ElementAt(iconCounter);
|
Application app = apps.ElementAt(iconCounter);
|
||||||
Rectangle iconBounds = new Rectangle((int)(bounds.Left + (bounds.Width / 2) - (iconSize * ((appsCount / 2) - iconCounter))), (int)(bounds.Top + (bounds.Height / 2) - (iconSize / 2)), (int)iconSize, (int)iconSize);
|
Rectangle iconBounds = new((int)(bounds.Left + (bounds.Width / 2) - (iconSize * ((appsCount / 2) - iconCounter))), (int)(bounds.Top + (bounds.Height / 2) - (iconSize / 2)), (int)iconSize, (int)iconSize);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -264,13 +263,13 @@ namespace WorkspacesEditor.Utils
|
|||||||
{
|
{
|
||||||
string indexString = app.RepeatIndex.ToString(CultureInfo.InvariantCulture);
|
string indexString = app.RepeatIndex.ToString(CultureInfo.InvariantCulture);
|
||||||
int indexSize = (int)(iconBounds.Width * 0.5);
|
int indexSize = (int)(iconBounds.Width * 0.5);
|
||||||
Rectangle indexBounds = new Rectangle(iconBounds.Right - indexSize, iconBounds.Bottom - indexSize, indexSize, indexSize);
|
Rectangle indexBounds = new(iconBounds.Right - indexSize, iconBounds.Bottom - indexSize, indexSize, indexSize);
|
||||||
|
|
||||||
var textSize = graphics.MeasureString(indexString, font);
|
SizeF textSize = graphics.MeasureString(indexString, Font);
|
||||||
var state = graphics.Save();
|
GraphicsState state = graphics.Save();
|
||||||
graphics.TranslateTransform(indexBounds.Left, indexBounds.Top);
|
graphics.TranslateTransform(indexBounds.Left, indexBounds.Top);
|
||||||
graphics.ScaleTransform(indexBounds.Width / textSize.Width, indexBounds.Height / textSize.Height);
|
graphics.ScaleTransform(indexBounds.Width / textSize.Width, indexBounds.Height / textSize.Height);
|
||||||
graphics.DrawString(indexString, font, Brushes.Black, PointF.Empty);
|
graphics.DrawString(indexString, Font, Brushes.Black, PointF.Empty);
|
||||||
graphics.Restore(state);
|
graphics.Restore(state);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -289,14 +288,14 @@ namespace WorkspacesEditor.Utils
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
Bitmap previewBitmap = new Bitmap(32 * appsCount, 24);
|
Bitmap previewBitmap = new(32 * appsCount, 24);
|
||||||
using (Graphics graphics = Graphics.FromImage(previewBitmap))
|
using (Graphics graphics = Graphics.FromImage(previewBitmap))
|
||||||
{
|
{
|
||||||
graphics.SmoothingMode = SmoothingMode.AntiAlias;
|
graphics.SmoothingMode = SmoothingMode.AntiAlias;
|
||||||
graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
|
graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
|
||||||
graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;
|
graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;
|
||||||
int appIndex = 0;
|
int appIndex = 0;
|
||||||
foreach (var app in project.Applications)
|
foreach (Application app in project.Applications)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -311,12 +310,11 @@ namespace WorkspacesEditor.Utils
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
using (var memory = new MemoryStream())
|
using MemoryStream memory = new();
|
||||||
{
|
|
||||||
previewBitmap.Save(memory, ImageFormat.Png);
|
previewBitmap.Save(memory, ImageFormat.Png);
|
||||||
memory.Position = 0;
|
memory.Position = 0;
|
||||||
|
|
||||||
var bitmapImage = new BitmapImage();
|
BitmapImage bitmapImage = new();
|
||||||
bitmapImage.BeginInit();
|
bitmapImage.BeginInit();
|
||||||
bitmapImage.StreamSource = memory;
|
bitmapImage.StreamSource = memory;
|
||||||
bitmapImage.CacheOption = BitmapCacheOption.OnLoad;
|
bitmapImage.CacheOption = BitmapCacheOption.OnLoad;
|
||||||
@@ -325,7 +323,6 @@ namespace WorkspacesEditor.Utils
|
|||||||
|
|
||||||
return bitmapImage;
|
return bitmapImage;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private static GraphicsPath RoundedRect(Rectangle bounds)
|
private static GraphicsPath RoundedRect(Rectangle bounds)
|
||||||
{
|
{
|
||||||
@@ -333,9 +330,9 @@ namespace WorkspacesEditor.Utils
|
|||||||
int radius = (int)(minorSize / 8);
|
int radius = (int)(minorSize / 8);
|
||||||
|
|
||||||
int diameter = radius * 2;
|
int diameter = radius * 2;
|
||||||
Size size = new Size(diameter, diameter);
|
Size size = new(diameter, diameter);
|
||||||
Rectangle arc = new Rectangle(bounds.Location, size);
|
Rectangle arc = new(bounds.Location, size);
|
||||||
GraphicsPath path = new GraphicsPath();
|
GraphicsPath path = new();
|
||||||
|
|
||||||
if (radius == 0)
|
if (radius == 0)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -26,19 +26,17 @@ namespace WorkspacesEditor.Utils
|
|||||||
{
|
{
|
||||||
if (_fileSystem.File.Exists(fileName))
|
if (_fileSystem.File.Exists(fileName))
|
||||||
{
|
{
|
||||||
var attempts = 0;
|
int attempts = 0;
|
||||||
while (attempts < 10)
|
while (attempts < 10)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using (FileSystemStream inputStream = _fileSystem.File.Open(fileName, FileMode.Open))
|
using FileSystemStream inputStream = _fileSystem.File.Open(fileName, FileMode.Open);
|
||||||
using (StreamReader reader = new StreamReader(inputStream))
|
using StreamReader reader = new(inputStream);
|
||||||
{
|
|
||||||
string data = reader.ReadToEnd();
|
string data = reader.ReadToEnd();
|
||||||
inputStream.Close();
|
inputStream.Close();
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
Task.Delay(10).Wait();
|
Task.Delay(10).Wait();
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ namespace WorkspacesEditor.Utils
|
|||||||
|
|
||||||
private Screen[] GetDpiUnawareScreenBounds()
|
private Screen[] GetDpiUnawareScreenBounds()
|
||||||
{
|
{
|
||||||
Thread dpiUnawareThread = new Thread(new ThreadStart(SaveDpiUnawareScreens));
|
Thread dpiUnawareThread = new(new ThreadStart(SaveDpiUnawareScreens));
|
||||||
dpiUnawareThread.Start();
|
dpiUnawareThread.Start();
|
||||||
dpiUnawareThread.Join();
|
dpiUnawareThread.Join();
|
||||||
|
|
||||||
@@ -35,15 +35,15 @@ namespace WorkspacesEditor.Utils
|
|||||||
|
|
||||||
public static Screen[] GetDpiUnawareScreens()
|
public static Screen[] GetDpiUnawareScreens()
|
||||||
{
|
{
|
||||||
MonitorHelper monitorHelper = new MonitorHelper();
|
MonitorHelper monitorHelper = new();
|
||||||
return monitorHelper.GetDpiUnawareScreenBounds();
|
return monitorHelper.GetDpiUnawareScreenBounds();
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static double GetScreenDpiFromScreen(Screen screen)
|
internal static double GetScreenDpiFromScreen(Screen screen)
|
||||||
{
|
{
|
||||||
var point = new System.Drawing.Point(screen.Bounds.Left + 1, screen.Bounds.Top + 1);
|
System.Drawing.Point point = new(screen.Bounds.Left + 1, screen.Bounds.Top + 1);
|
||||||
var monitor = NativeMethods.MonitorFromPoint(point, NativeMethods._MONITOR_DEFAULTTONEAREST);
|
nint monitor = NativeMethods.MonitorFromPoint(point, NativeMethods._MONITOR_DEFAULTTONEAREST);
|
||||||
NativeMethods.GetDpiForMonitor(monitor, NativeMethods.DpiType.EFFECTIVE, out uint dpiX, out uint dpiY);
|
_ = NativeMethods.GetDpiForMonitor(monitor, NativeMethods.DpiType.EFFECTIVE, out uint dpiX, out _);
|
||||||
return dpiX / 96.0;
|
return dpiX / 96.0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,19 +4,12 @@
|
|||||||
|
|
||||||
namespace WorkspacesEditor.Utils
|
namespace WorkspacesEditor.Utils
|
||||||
{
|
{
|
||||||
public struct ParsingResult
|
public readonly struct ParsingResult(bool result, string message = "", string data = "")
|
||||||
{
|
{
|
||||||
public bool Result { get; }
|
public bool Result { get; } = result;
|
||||||
|
|
||||||
public string Message { get; }
|
public string Message { get; } = message;
|
||||||
|
|
||||||
public string MalformedData { get; }
|
public string MalformedData { get; } = data;
|
||||||
|
|
||||||
public ParsingResult(bool result, string message = "", string data = "")
|
|
||||||
{
|
|
||||||
Result = result;
|
|
||||||
Message = message;
|
|
||||||
MalformedData = data;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,13 +9,13 @@ namespace WorkspacesEditor.Utils
|
|||||||
public class Settings
|
public class Settings
|
||||||
{
|
{
|
||||||
private const string WorkspacesModuleName = "Workspaces";
|
private const string WorkspacesModuleName = "Workspaces";
|
||||||
private static SettingsUtils _settingsUtils = new SettingsUtils();
|
private static readonly SettingsUtils _settingsUtils = new();
|
||||||
|
|
||||||
public static WorkspacesSettings ReadSettings()
|
public static WorkspacesSettings ReadSettings()
|
||||||
{
|
{
|
||||||
if (!_settingsUtils.SettingsExists(WorkspacesModuleName))
|
if (!_settingsUtils.SettingsExists(WorkspacesModuleName))
|
||||||
{
|
{
|
||||||
var defaultWorkspacesSettings = new WorkspacesSettings();
|
WorkspacesSettings defaultWorkspacesSettings = new();
|
||||||
defaultWorkspacesSettings.Save(_settingsUtils);
|
defaultWorkspacesSettings.Save(_settingsUtils);
|
||||||
return defaultWorkspacesSettings;
|
return defaultWorkspacesSettings;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,12 +11,9 @@ namespace WorkspacesEditor.Utils
|
|||||||
public static string UpperCamelCaseToDashCase(this string str)
|
public static string UpperCamelCaseToDashCase(this string str)
|
||||||
{
|
{
|
||||||
// If it's single letter variable, leave it as it is
|
// If it's single letter variable, leave it as it is
|
||||||
if (str.Length == 1)
|
return str.Length == 1
|
||||||
{
|
? str
|
||||||
return str;
|
: string.Concat(str.Select((x, i) => i > 0 && char.IsUpper(x) ? "-" + x.ToString() : x.ToString())).ToLowerInvariant();
|
||||||
}
|
|
||||||
|
|
||||||
return string.Concat(str.Select((x, i) => i > 0 && char.IsUpper(x) ? "-" + x.ToString() : x.ToString())).ToLowerInvariant();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ namespace WorkspacesEditor.Utils
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
WorkspacesData parser = new WorkspacesData();
|
WorkspacesData parser = new();
|
||||||
if (!File.Exists(parser.File))
|
if (!File.Exists(parser.File))
|
||||||
{
|
{
|
||||||
Logger.LogWarning($"Workspaces storage file not found: {parser.File}");
|
Logger.LogWarning($"Workspaces storage file not found: {parser.File}");
|
||||||
@@ -56,14 +56,14 @@ namespace WorkspacesEditor.Utils
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
ProjectData parser = new ProjectData();
|
ProjectData parser = new();
|
||||||
if (!File.Exists(TempProjectData.File))
|
if (!File.Exists(TempProjectData.File))
|
||||||
{
|
{
|
||||||
Logger.LogWarning($"ParseProject method. Workspaces storage file not found: {TempProjectData.File}");
|
Logger.LogWarning($"ParseProject method. Workspaces storage file not found: {TempProjectData.File}");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
Project project = new Project(parser.Read(TempProjectData.File));
|
Project project = new(parser.Read(TempProjectData.File));
|
||||||
return project;
|
return project;
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
@@ -75,13 +75,13 @@ namespace WorkspacesEditor.Utils
|
|||||||
|
|
||||||
public void SerializeWorkspaces(List<Project> workspaces, bool useTempFile = false)
|
public void SerializeWorkspaces(List<Project> workspaces, bool useTempFile = false)
|
||||||
{
|
{
|
||||||
WorkspacesData serializer = new WorkspacesData();
|
WorkspacesData serializer = new();
|
||||||
WorkspacesData.WorkspacesListWrapper workspacesWrapper = new WorkspacesData.WorkspacesListWrapper { };
|
WorkspacesData.WorkspacesListWrapper workspacesWrapper = new() { };
|
||||||
workspacesWrapper.Workspaces = new List<ProjectData.ProjectWrapper>();
|
workspacesWrapper.Workspaces = [];
|
||||||
|
|
||||||
foreach (Project project in workspaces)
|
foreach (Project project in workspaces)
|
||||||
{
|
{
|
||||||
ProjectData.ProjectWrapper wrapper = new ProjectData.ProjectWrapper
|
ProjectData.ProjectWrapper wrapper = new()
|
||||||
{
|
{
|
||||||
Id = project.Id,
|
Id = project.Id,
|
||||||
Name = project.Name,
|
Name = project.Name,
|
||||||
@@ -89,11 +89,11 @@ namespace WorkspacesEditor.Utils
|
|||||||
IsShortcutNeeded = project.IsShortcutNeeded,
|
IsShortcutNeeded = project.IsShortcutNeeded,
|
||||||
MoveExistingWindows = project.MoveExistingWindows,
|
MoveExistingWindows = project.MoveExistingWindows,
|
||||||
LastLaunchedTime = project.LastLaunchedTime,
|
LastLaunchedTime = project.LastLaunchedTime,
|
||||||
Applications = new List<ProjectData.ApplicationWrapper> { },
|
Applications = [],
|
||||||
MonitorConfiguration = new List<ProjectData.MonitorConfigurationWrapper> { },
|
MonitorConfiguration = [],
|
||||||
};
|
};
|
||||||
|
|
||||||
foreach (var app in project.Applications.Where(x => x.IsIncluded))
|
foreach (Application app in project.Applications.Where(x => x.IsIncluded))
|
||||||
{
|
{
|
||||||
wrapper.Applications.Add(new ProjectData.ApplicationWrapper
|
wrapper.Applications.Add(new ProjectData.ApplicationWrapper
|
||||||
{
|
{
|
||||||
@@ -120,7 +120,7 @@ namespace WorkspacesEditor.Utils
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (var monitor in project.Monitors)
|
foreach (MonitorSetup monitor in project.Monitors)
|
||||||
{
|
{
|
||||||
wrapper.MonitorConfiguration.Add(new ProjectData.MonitorConfigurationWrapper
|
wrapper.MonitorConfiguration.Add(new ProjectData.MonitorConfigurationWrapper
|
||||||
{
|
{
|
||||||
@@ -150,7 +150,7 @@ namespace WorkspacesEditor.Utils
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
IOUtils ioUtils = new IOUtils();
|
IOUtils ioUtils = new();
|
||||||
ioUtils.WriteFile(useTempFile ? TempProjectData.File : serializer.File, serializer.Serialize(workspacesWrapper));
|
ioUtils.WriteFile(useTempFile ? TempProjectData.File : serializer.File, serializer.Serialize(workspacesWrapper));
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
@@ -162,7 +162,7 @@ namespace WorkspacesEditor.Utils
|
|||||||
|
|
||||||
private bool AddWorkspaces(MainViewModel mainViewModel, WorkspacesData.WorkspacesListWrapper workspaces)
|
private bool AddWorkspaces(MainViewModel mainViewModel, WorkspacesData.WorkspacesListWrapper workspaces)
|
||||||
{
|
{
|
||||||
foreach (var project in workspaces.Workspaces)
|
foreach (ProjectData.ProjectWrapper project in workspaces.Workspaces)
|
||||||
{
|
{
|
||||||
mainViewModel.Workspaces.Add(new Project(project));
|
mainViewModel.Workspaces.Add(new Project(project));
|
||||||
}
|
}
|
||||||
@@ -173,13 +173,13 @@ namespace WorkspacesEditor.Utils
|
|||||||
|
|
||||||
private bool SetWorkspaces(MainViewModel mainViewModel, WorkspacesData.WorkspacesListWrapper workspaces)
|
private bool SetWorkspaces(MainViewModel mainViewModel, WorkspacesData.WorkspacesListWrapper workspaces)
|
||||||
{
|
{
|
||||||
mainViewModel.Workspaces = new System.Collections.ObjectModel.ObservableCollection<Project> { };
|
mainViewModel.Workspaces = [];
|
||||||
return AddWorkspaces(mainViewModel, workspaces);
|
return AddWorkspaces(mainViewModel, workspaces);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void SerializeTempProject(Project project)
|
internal void SerializeTempProject(Project project)
|
||||||
{
|
{
|
||||||
SerializeWorkspaces(new List<Project>() { project }, true);
|
SerializeWorkspaces([project], true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -156,24 +156,33 @@
|
|||||||
Content="{x:Static props:Resources.LaunchAsAdmin}"
|
Content="{x:Static props:Resources.LaunchAsAdmin}"
|
||||||
IsChecked="{Binding IsElevated, Mode=TwoWay}"
|
IsChecked="{Binding IsElevated, Mode=TwoWay}"
|
||||||
IsEnabled="{Binding CanLaunchElevated, Mode=OneWay}" />
|
IsEnabled="{Binding CanLaunchElevated, Mode=OneWay}" />
|
||||||
<CheckBox
|
|
||||||
MinWidth="10"
|
|
||||||
Margin="15,0,0,0"
|
|
||||||
Checked="MaximizedChecked"
|
|
||||||
Content="{x:Static props:Resources.Maximized}"
|
|
||||||
IsChecked="{Binding Maximized, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
|
|
||||||
<CheckBox
|
|
||||||
MinWidth="10"
|
|
||||||
Margin="15,0,0,0"
|
|
||||||
Checked="MinimizedChecked"
|
|
||||||
Content="{x:Static props:Resources.Minimized}"
|
|
||||||
IsChecked="{Binding Minimized, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
|
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
<StackPanel
|
<StackPanel
|
||||||
Grid.Row="2"
|
Grid.Row="2"
|
||||||
Margin="100,5,0,0"
|
Margin="100,5,0,0"
|
||||||
Orientation="Horizontal">
|
Orientation="Horizontal">
|
||||||
<TextBlock
|
<TextBlock
|
||||||
|
VerticalAlignment="Center"
|
||||||
|
FontSize="14"
|
||||||
|
FontWeight="Normal"
|
||||||
|
IsEnabled="{Binding EditPositionEnabled, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"
|
||||||
|
Style="{StaticResource TextBlockEnabledStyle}"
|
||||||
|
Text="{x:Static props:Resources.WindowPosition}" />
|
||||||
|
<ComboBox
|
||||||
|
Margin="15,0,0,0"
|
||||||
|
VerticalAlignment="Center"
|
||||||
|
Background="{DynamicResource SecondaryBackgroundBrush}"
|
||||||
|
BorderBrush="{DynamicResource PrimaryBorderBrush}"
|
||||||
|
BorderThickness="2"
|
||||||
|
FontSize="14"
|
||||||
|
FontWeight="Normal"
|
||||||
|
SelectedIndex="{Binding PositionComboboxIndex, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
|
||||||
|
<ComboBoxItem Content="{x:Static props:Resources.Custom}" />
|
||||||
|
<ComboBoxItem Content="{x:Static props:Resources.Maximized}" />
|
||||||
|
<ComboBoxItem Content="{x:Static props:Resources.Minimized}" />
|
||||||
|
</ComboBox>
|
||||||
|
<TextBlock
|
||||||
|
Margin="15,0,0,0"
|
||||||
VerticalAlignment="Center"
|
VerticalAlignment="Center"
|
||||||
FontSize="14"
|
FontSize="14"
|
||||||
FontWeight="Normal"
|
FontWeight="Normal"
|
||||||
@@ -267,14 +276,12 @@
|
|||||||
<RowDefinition Height="Auto" />
|
<RowDefinition Height="Auto" />
|
||||||
<RowDefinition Height="Auto" />
|
<RowDefinition Height="Auto" />
|
||||||
<RowDefinition Height="Auto" />
|
<RowDefinition Height="Auto" />
|
||||||
<RowDefinition Height="Auto" />
|
|
||||||
<RowDefinition Height="*" />
|
<RowDefinition Height="*" />
|
||||||
<RowDefinition Height="Auto" />
|
<RowDefinition Height="Auto" />
|
||||||
<RowDefinition Height="Auto" />
|
|
||||||
</Grid.RowDefinitions>
|
</Grid.RowDefinitions>
|
||||||
<StackPanel Grid.Row="0" Orientation="Horizontal">
|
<StackPanel Grid.Row="0" Orientation="Horizontal">
|
||||||
<Button
|
<Button
|
||||||
Margin="0,20,0,20"
|
Margin="0,10,0,20"
|
||||||
VerticalAlignment="Center"
|
VerticalAlignment="Center"
|
||||||
Background="Transparent"
|
Background="Transparent"
|
||||||
Click="CancelButtonClicked">
|
Click="CancelButtonClicked">
|
||||||
@@ -300,27 +307,8 @@
|
|||||||
Foreground="{DynamicResource PrimaryForegroundBrush}"
|
Foreground="{DynamicResource PrimaryForegroundBrush}"
|
||||||
Text="{Binding EditorWindowTitle}" />
|
Text="{Binding EditorWindowTitle}" />
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
<StackPanel Grid.Row="1" Orientation="Vertical">
|
|
||||||
<TextBlock
|
|
||||||
FontSize="14"
|
|
||||||
FontWeight="Normal"
|
|
||||||
Foreground="{DynamicResource PrimaryForegroundBrush}"
|
|
||||||
Text="{x:Static props:Resources.WorkspaceName}" />
|
|
||||||
<TextBox
|
|
||||||
x:Name="EditNameTextBox"
|
|
||||||
Width="320"
|
|
||||||
Margin="0,6,0,6"
|
|
||||||
HorizontalAlignment="Left"
|
|
||||||
Background="{DynamicResource SecondaryBackgroundBrush}"
|
|
||||||
BorderBrush="{DynamicResource PrimaryBorderBrush}"
|
|
||||||
BorderThickness="2"
|
|
||||||
GotFocus="EditNameTextBox_GotFocus"
|
|
||||||
KeyDown="EditNameTextBoxKeyDown"
|
|
||||||
Text="{Binding Name, Mode=TwoWay}"
|
|
||||||
TextChanged="EditNameTextBox_TextChanged" />
|
|
||||||
</StackPanel>
|
|
||||||
<Border
|
<Border
|
||||||
Grid.Row="2"
|
Grid.Row="1"
|
||||||
HorizontalAlignment="Stretch"
|
HorizontalAlignment="Stretch"
|
||||||
Background="{DynamicResource MonitorViewBackgroundBrush}"
|
Background="{DynamicResource MonitorViewBackgroundBrush}"
|
||||||
CornerRadius="5">
|
CornerRadius="5">
|
||||||
@@ -361,8 +349,47 @@
|
|||||||
DockPanel.Dock="Right" />
|
DockPanel.Dock="Right" />
|
||||||
</DockPanel>
|
</DockPanel>
|
||||||
</Border>
|
</Border>
|
||||||
|
<DockPanel Grid.Row="2" HorizontalAlignment="Stretch">
|
||||||
|
<StackPanel Orientation="Vertical">
|
||||||
|
<TextBlock
|
||||||
|
Margin="0,10,0,0"
|
||||||
|
FontSize="14"
|
||||||
|
FontWeight="Normal"
|
||||||
|
Foreground="{DynamicResource PrimaryForegroundBrush}"
|
||||||
|
Text="{x:Static props:Resources.WorkspaceName}" />
|
||||||
|
<TextBox
|
||||||
|
x:Name="EditNameTextBox"
|
||||||
|
Width="300"
|
||||||
|
Margin="0,6,0,6"
|
||||||
|
HorizontalAlignment="Left"
|
||||||
|
Background="{DynamicResource SecondaryBackgroundBrush}"
|
||||||
|
BorderBrush="{DynamicResource PrimaryBorderBrush}"
|
||||||
|
BorderThickness="2"
|
||||||
|
GotFocus="EditNameTextBox_GotFocus"
|
||||||
|
KeyDown="EditNameTextBoxKeyDown"
|
||||||
|
Text="{Binding Name, Mode=TwoWay}"
|
||||||
|
TextChanged="EditNameTextBox_TextChanged" />
|
||||||
|
</StackPanel>
|
||||||
|
<StackPanel
|
||||||
|
HorizontalAlignment="Right"
|
||||||
|
DockPanel.Dock="Right"
|
||||||
|
Orientation="Horizontal">
|
||||||
|
<CheckBox
|
||||||
|
Margin="20,0,0,0"
|
||||||
|
VerticalAlignment="Bottom"
|
||||||
|
Content="{x:Static props:Resources.CreateShortcut}"
|
||||||
|
FontSize="14"
|
||||||
|
IsChecked="{Binding IsShortcutNeeded, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
|
||||||
|
<CheckBox
|
||||||
|
Margin="20,0,0,0"
|
||||||
|
VerticalAlignment="Bottom"
|
||||||
|
Content="{x:Static props:Resources.MoveIfExist}"
|
||||||
|
FontSize="14"
|
||||||
|
IsChecked="{Binding MoveExistingWindows, Mode=TwoWay}" />
|
||||||
|
</StackPanel>
|
||||||
|
</DockPanel>
|
||||||
<ScrollViewer
|
<ScrollViewer
|
||||||
Grid.Row="4"
|
Grid.Row="3"
|
||||||
Margin="0,10,0,0"
|
Margin="0,10,0,0"
|
||||||
PreviewMouseWheel="ScrollViewer_PreviewMouseWheel"
|
PreviewMouseWheel="ScrollViewer_PreviewMouseWheel"
|
||||||
VerticalScrollBarVisibility="Auto">
|
VerticalScrollBarVisibility="Auto">
|
||||||
@@ -377,29 +404,9 @@
|
|||||||
</StackPanel>
|
</StackPanel>
|
||||||
</ScrollViewer>
|
</ScrollViewer>
|
||||||
<StackPanel
|
<StackPanel
|
||||||
Grid.Row="5"
|
Grid.Row="4"
|
||||||
Margin="0,5,0,0"
|
Margin="40,20,0,0"
|
||||||
Orientation="Horizontal"
|
|
||||||
Visibility="Collapsed">
|
|
||||||
<CheckBox
|
|
||||||
Margin="0,0,0,0"
|
|
||||||
VerticalAlignment="Center"
|
|
||||||
Content="{x:Static props:Resources.MoveIfExist}"
|
|
||||||
FontSize="14"
|
|
||||||
FontWeight="Normal"
|
|
||||||
Foreground="{DynamicResource PrimaryForegroundBrush}"
|
|
||||||
IsChecked="{Binding MoveExistingWindows, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
|
|
||||||
</StackPanel>
|
|
||||||
<DockPanel Grid.Row="6" Margin="0,20,0,20">
|
|
||||||
<CheckBox
|
|
||||||
Content="{x:Static props:Resources.CreateShortcut}"
|
|
||||||
DockPanel.Dock="Left"
|
|
||||||
FontSize="14"
|
|
||||||
IsChecked="{Binding IsShortcutNeeded, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
|
|
||||||
<StackPanel
|
|
||||||
Margin="40,0,0,0"
|
|
||||||
HorizontalAlignment="Right"
|
HorizontalAlignment="Right"
|
||||||
DockPanel.Dock="Right"
|
|
||||||
Orientation="Horizontal">
|
Orientation="Horizontal">
|
||||||
<Button
|
<Button
|
||||||
x:Name="CancelButton"
|
x:Name="CancelButton"
|
||||||
@@ -423,6 +430,5 @@
|
|||||||
IsEnabled="{Binding CanBeSaved, UpdateSourceTrigger=PropertyChanged}"
|
IsEnabled="{Binding CanBeSaved, UpdateSourceTrigger=PropertyChanged}"
|
||||||
Style="{StaticResource AccentButtonStyle}" />
|
Style="{StaticResource AccentButtonStyle}" />
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
</DockPanel>
|
|
||||||
</Grid>
|
</Grid>
|
||||||
</Page>
|
</Page>
|
||||||
|
|||||||
@@ -185,20 +185,6 @@ namespace WorkspacesEditor
|
|||||||
application.CommandLineTextChanged(textBox.Text);
|
application.CommandLineTextChanged(textBox.Text);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void MaximizedChecked(object sender, RoutedEventArgs e)
|
|
||||||
{
|
|
||||||
CheckBox checkBox = sender as CheckBox;
|
|
||||||
Models.Application application = checkBox.DataContext as Models.Application;
|
|
||||||
application.MaximizedChecked();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void MinimizedChecked(object sender, RoutedEventArgs e)
|
|
||||||
{
|
|
||||||
CheckBox checkBox = sender as CheckBox;
|
|
||||||
Models.Application application = checkBox.DataContext as Models.Application;
|
|
||||||
application.MinimizedChecked();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void LaunchEditButtonClicked(object sender, RoutedEventArgs e)
|
private void LaunchEditButtonClicked(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
Button button = sender as Button;
|
Button button = sender as Button;
|
||||||
|
|||||||
@@ -157,7 +157,7 @@ void Launcher::Launch() // Launching thread
|
|||||||
{
|
{
|
||||||
std::lock_guard lock(m_uiHelperMutex);
|
std::lock_guard lock(m_uiHelperMutex);
|
||||||
m_uiHelper->UpdateLaunchStatus(m_launchingStatus.Get());
|
m_uiHelper->UpdateLaunchStatus(m_launchingStatus.Get());
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -31,6 +31,9 @@ namespace Utils
|
|||||||
constexpr const wchar_t* PowerToysSettings = L"PowerToys.Settings.exe";
|
constexpr const wchar_t* PowerToysSettings = L"PowerToys.Settings.exe";
|
||||||
constexpr const wchar_t* ApplicationFrameHost = L"APPLICATIONFRAMEHOST.EXE";
|
constexpr const wchar_t* ApplicationFrameHost = L"APPLICATIONFRAMEHOST.EXE";
|
||||||
constexpr const wchar_t* Exe = L".EXE";
|
constexpr const wchar_t* Exe = L".EXE";
|
||||||
|
|
||||||
|
constexpr const wchar_t* EdgeFilename = L"msedge.exe";
|
||||||
|
constexpr const wchar_t* ChromeFilename = L"chrome.exe";
|
||||||
}
|
}
|
||||||
|
|
||||||
AppList IterateAppsFolder()
|
AppList IterateAppsFolder()
|
||||||
@@ -378,5 +381,15 @@ namespace Utils
|
|||||||
return updated;
|
return updated;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool AppData::IsEdge() const
|
||||||
|
{
|
||||||
|
return installPath.ends_with(NonLocalizable::EdgeFilename);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool AppData::IsChrome() const
|
||||||
|
{
|
||||||
|
return installPath.ends_with(NonLocalizable::ChromeFilename);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -12,7 +12,11 @@ namespace Utils
|
|||||||
std::wstring installPath;
|
std::wstring installPath;
|
||||||
std::wstring packageFullName;
|
std::wstring packageFullName;
|
||||||
std::wstring appUserModelId;
|
std::wstring appUserModelId;
|
||||||
|
std::wstring pwaAppId;
|
||||||
bool canLaunchElevated = false;
|
bool canLaunchElevated = false;
|
||||||
|
|
||||||
|
bool IsEdge() const;
|
||||||
|
bool IsChrome() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
using AppList = std::vector<AppData>;
|
using AppList = std::vector<AppData>;
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
#include "pch.h"
|
#include "pch.h"
|
||||||
#include "PwaHelper.h"
|
#include "PwaHelper.h"
|
||||||
|
#include "AppUtils.h"
|
||||||
#include <ShlObj.h>
|
#include <ShlObj.h>
|
||||||
#include <tlhelp32.h>
|
#include <tlhelp32.h>
|
||||||
#include <winternl.h>
|
#include <winternl.h>
|
||||||
@@ -11,7 +12,7 @@
|
|||||||
#include <wil\com.h>
|
#include <wil\com.h>
|
||||||
#pragma comment(lib, "ntdll.lib")
|
#pragma comment(lib, "ntdll.lib")
|
||||||
|
|
||||||
namespace SnapshotUtils
|
namespace Utils
|
||||||
{
|
{
|
||||||
namespace NonLocalizable
|
namespace NonLocalizable
|
||||||
{
|
{
|
||||||
@@ -22,6 +23,7 @@ namespace SnapshotUtils
|
|||||||
const std::wstring ChromeDirPrefix = L"_crx_";
|
const std::wstring ChromeDirPrefix = L"_crx_";
|
||||||
const std::wstring EdgeDirPrefix = L"_crx__";
|
const std::wstring EdgeDirPrefix = L"_crx__";
|
||||||
}
|
}
|
||||||
|
|
||||||
// {c8900b66-a973-584b-8cae-355b7f55341b}
|
// {c8900b66-a973-584b-8cae-355b7f55341b}
|
||||||
DEFINE_GUID(CLSID_StartMenuCacheAndAppResolver, 0x660b90c8, 0x73a9, 0x4b58, 0x8c, 0xae, 0x35, 0x5b, 0x7f, 0x55, 0x34, 0x1b);
|
DEFINE_GUID(CLSID_StartMenuCacheAndAppResolver, 0x660b90c8, 0x73a9, 0x4b58, 0x8c, 0xae, 0x35, 0x5b, 0x7f, 0x55, 0x34, 0x1b);
|
||||||
|
|
||||||
@@ -48,9 +50,10 @@ namespace SnapshotUtils
|
|||||||
virtual HRESULT STDMETHODCALLTYPE GetAppIDForProcess(DWORD dwProcessId, WCHAR** pszAppId, void* pUnknown1, void* pUnknown2, void* pUnknown3) = 0;
|
virtual HRESULT STDMETHODCALLTYPE GetAppIDForProcess(DWORD dwProcessId, WCHAR** pszAppId, void* pUnknown1, void* pUnknown2, void* pUnknown3) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
BOOL GetAppId_7(HWND hWnd, std::wstring* result)
|
std::optional<std::wstring> PwaHelper::GetAppId_7(HWND hWnd) const
|
||||||
{
|
{
|
||||||
HRESULT hr;
|
HRESULT hr;
|
||||||
|
std::optional<std::wstring> result = std::nullopt;
|
||||||
|
|
||||||
wil::com_ptr<IAppResolver_7> appResolver;
|
wil::com_ptr<IAppResolver_7> appResolver;
|
||||||
hr = CoCreateInstance(CLSID_StartMenuCacheAndAppResolver, NULL, CLSCTX_INPROC_SERVER | CLSCTX_INPROC_HANDLER, IID_IAppResolver_7, reinterpret_cast<void**>(appResolver.put()));
|
hr = CoCreateInstance(CLSID_StartMenuCacheAndAppResolver, NULL, CLSCTX_INPROC_SERVER | CLSCTX_INPROC_HANDLER, IID_IAppResolver_7, reinterpret_cast<void**>(appResolver.put()));
|
||||||
@@ -60,19 +63,19 @@ namespace SnapshotUtils
|
|||||||
hr = appResolver->GetAppIDForWindow(hWnd, &pszAppId, NULL, NULL, NULL);
|
hr = appResolver->GetAppIDForWindow(hWnd, &pszAppId, NULL, NULL, NULL);
|
||||||
if (SUCCEEDED(hr))
|
if (SUCCEEDED(hr))
|
||||||
{
|
{
|
||||||
*result = std::wstring(pszAppId.get());
|
result = std::wstring(pszAppId.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
appResolver->Release();
|
appResolver->Release();
|
||||||
}
|
}
|
||||||
|
|
||||||
return SUCCEEDED(hr);
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOL GetAppId_8(HWND hWnd, std::wstring* result)
|
std::optional<std::wstring> PwaHelper::GetAppId_8(HWND hWnd) const
|
||||||
{
|
{
|
||||||
HRESULT hr;
|
HRESULT hr;
|
||||||
*result = L"";
|
std::optional<std::wstring> result = std::nullopt;
|
||||||
|
|
||||||
wil::com_ptr<IAppResolver_8> appResolver;
|
wil::com_ptr<IAppResolver_8> appResolver;
|
||||||
hr = CoCreateInstance(CLSID_StartMenuCacheAndAppResolver, NULL, CLSCTX_INPROC_SERVER | CLSCTX_INPROC_HANDLER, IID_IAppResolver_8, reinterpret_cast<void**>(appResolver.put()));
|
hr = CoCreateInstance(CLSID_StartMenuCacheAndAppResolver, NULL, CLSCTX_INPROC_SERVER | CLSCTX_INPROC_HANDLER, IID_IAppResolver_8, reinterpret_cast<void**>(appResolver.put()));
|
||||||
@@ -82,29 +85,29 @@ namespace SnapshotUtils
|
|||||||
hr = appResolver->GetAppIDForWindow(hWnd, &pszAppId, NULL, NULL, NULL);
|
hr = appResolver->GetAppIDForWindow(hWnd, &pszAppId, NULL, NULL, NULL);
|
||||||
if (SUCCEEDED(hr))
|
if (SUCCEEDED(hr))
|
||||||
{
|
{
|
||||||
*result = std::wstring(pszAppId.get());
|
result = std::wstring(pszAppId.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
appResolver->Release();
|
appResolver->Release();
|
||||||
}
|
}
|
||||||
|
|
||||||
return SUCCEEDED(hr);
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOL PwaHelper::GetAppId(HWND hWnd, std::wstring* result)
|
std::wstring PwaHelper::GetAppId(HWND hWnd) const
|
||||||
{
|
{
|
||||||
HRESULT hr = GetAppId_8(hWnd, result);
|
std::optional<std::wstring> result = GetAppId_8(hWnd);
|
||||||
if (!SUCCEEDED(hr))
|
if (result == std::nullopt)
|
||||||
{
|
{
|
||||||
hr = GetAppId_7(hWnd, result);
|
result = GetAppId_7(hWnd);
|
||||||
}
|
}
|
||||||
return SUCCEEDED(hr);
|
return result.has_value() ? result.value() : L"";
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOL GetProcessId_7(DWORD dwProcessId, std::wstring* result)
|
std::optional<std::wstring> PwaHelper::GetProcessId_7(DWORD dwProcessId) const
|
||||||
{
|
{
|
||||||
HRESULT hr;
|
HRESULT hr;
|
||||||
*result = L"";
|
std::optional<std::wstring> result = std::nullopt;
|
||||||
|
|
||||||
wil::com_ptr<IAppResolver_7> appResolver;
|
wil::com_ptr<IAppResolver_7> appResolver;
|
||||||
hr = CoCreateInstance(CLSID_StartMenuCacheAndAppResolver, NULL, CLSCTX_INPROC_SERVER | CLSCTX_INPROC_HANDLER, IID_IAppResolver_7, reinterpret_cast<void**>(appResolver.put()));
|
hr = CoCreateInstance(CLSID_StartMenuCacheAndAppResolver, NULL, CLSCTX_INPROC_SERVER | CLSCTX_INPROC_HANDLER, IID_IAppResolver_7, reinterpret_cast<void**>(appResolver.put()));
|
||||||
@@ -114,19 +117,19 @@ namespace SnapshotUtils
|
|||||||
hr = appResolver->GetAppIDForProcess(dwProcessId, &pszAppId, NULL, NULL, NULL);
|
hr = appResolver->GetAppIDForProcess(dwProcessId, &pszAppId, NULL, NULL, NULL);
|
||||||
if (SUCCEEDED(hr))
|
if (SUCCEEDED(hr))
|
||||||
{
|
{
|
||||||
*result = std::wstring(pszAppId.get());
|
result = std::wstring(pszAppId.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
appResolver->Release();
|
appResolver->Release();
|
||||||
}
|
}
|
||||||
|
|
||||||
return SUCCEEDED(hr);
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOL GetProcessId_8(DWORD dwProcessId, std::wstring* result)
|
std::optional<std::wstring> PwaHelper::GetProcessId_8(DWORD dwProcessId) const
|
||||||
{
|
{
|
||||||
HRESULT hr;
|
HRESULT hr;
|
||||||
*result = L"";
|
std::optional<std::wstring> result = std::nullopt;
|
||||||
|
|
||||||
wil::com_ptr<IAppResolver_8> appResolver;
|
wil::com_ptr<IAppResolver_8> appResolver;
|
||||||
hr = CoCreateInstance(CLSID_StartMenuCacheAndAppResolver, NULL, CLSCTX_INPROC_SERVER | CLSCTX_INPROC_HANDLER, IID_IAppResolver_8, reinterpret_cast<void**>(appResolver.put()));
|
hr = CoCreateInstance(CLSID_StartMenuCacheAndAppResolver, NULL, CLSCTX_INPROC_SERVER | CLSCTX_INPROC_HANDLER, IID_IAppResolver_8, reinterpret_cast<void**>(appResolver.put()));
|
||||||
@@ -136,23 +139,23 @@ namespace SnapshotUtils
|
|||||||
hr = appResolver->GetAppIDForProcess(dwProcessId, &pszAppId, NULL, NULL, NULL);
|
hr = appResolver->GetAppIDForProcess(dwProcessId, &pszAppId, NULL, NULL, NULL);
|
||||||
if (SUCCEEDED(hr))
|
if (SUCCEEDED(hr))
|
||||||
{
|
{
|
||||||
*result = std::wstring(pszAppId.get());
|
result = std::wstring(pszAppId.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
appResolver->Release();
|
appResolver->Release();
|
||||||
}
|
}
|
||||||
|
|
||||||
return SUCCEEDED(hr);
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOL GetProcessId(DWORD dwProcessId, std::wstring* result)
|
std::wstring PwaHelper::GetProcessId(DWORD dwProcessId) const
|
||||||
{
|
{
|
||||||
HRESULT hr = GetProcessId_8(dwProcessId, result);
|
std::optional<std::wstring> result = GetProcessId_8(dwProcessId);
|
||||||
if (!SUCCEEDED(hr))
|
if (result == std::nullopt)
|
||||||
{
|
{
|
||||||
hr = GetProcessId_7(dwProcessId, result);
|
result = GetProcessId_7(dwProcessId);
|
||||||
}
|
}
|
||||||
return SUCCEEDED(hr);
|
return result.has_value() ? result.value() : L"";
|
||||||
}
|
}
|
||||||
|
|
||||||
std::wstring GetProcCommandLine(DWORD pid)
|
std::wstring GetProcCommandLine(DWORD pid)
|
||||||
@@ -244,7 +247,7 @@ namespace SnapshotUtils
|
|||||||
|
|
||||||
void PwaHelper::InitAumidToAppId()
|
void PwaHelper::InitAumidToAppId()
|
||||||
{
|
{
|
||||||
if (pwaAumidToAppId.size() > 0)
|
if (m_pwaAumidToAppId.size() > 0)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -254,7 +257,7 @@ namespace SnapshotUtils
|
|||||||
for (const auto subProcessID : pwaHelperProcessIds)
|
for (const auto subProcessID : pwaHelperProcessIds)
|
||||||
{
|
{
|
||||||
std::wstring aumidID;
|
std::wstring aumidID;
|
||||||
GetProcessId(subProcessID, &aumidID);
|
aumidID = GetProcessId(subProcessID);
|
||||||
std::wstring commandLineArg = GetProcCommandLine(subProcessID);
|
std::wstring commandLineArg = GetProcCommandLine(subProcessID);
|
||||||
auto appIdIndexStart = commandLineArg.find(NonLocalizable::EdgeAppIdIdentifier);
|
auto appIdIndexStart = commandLineArg.find(NonLocalizable::EdgeAppIdIdentifier);
|
||||||
if (appIdIndexStart != std::wstring::npos)
|
if (appIdIndexStart != std::wstring::npos)
|
||||||
@@ -267,7 +270,7 @@ namespace SnapshotUtils
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
std::wstring appId{ commandLineArg };
|
std::wstring appId{ commandLineArg };
|
||||||
pwaAumidToAppId.insert(std::map<std::wstring, std::wstring>::value_type(aumidID, appId));
|
m_pwaAumidToAppId.insert(std::map<std::wstring, std::wstring>::value_type(aumidID, appId));
|
||||||
Logger::info(L"Found an edge Pwa helper process with AumidID {} and PwaAppId {}", aumidID, appId);
|
Logger::info(L"Found an edge Pwa helper process with AumidID {} and PwaAppId {}", aumidID, appId);
|
||||||
|
|
||||||
PWSTR path = NULL;
|
PWSTR path = NULL;
|
||||||
@@ -293,7 +296,7 @@ namespace SnapshotUtils
|
|||||||
const std::filesystem::path filenameString = filename.path().filename();
|
const std::filesystem::path filenameString = filename.path().filename();
|
||||||
if (filenameString.extension().wstring() == L".ico")
|
if (filenameString.extension().wstring() == L".ico")
|
||||||
{
|
{
|
||||||
pwaAppIdsToAppNames.insert(std::map<std::wstring, std::wstring>::value_type(appId, filenameString.stem().wstring()));
|
m_pwaAppIdsToAppNames.insert(std::map<std::wstring, std::wstring>::value_type(appId, filenameString.stem().wstring()));
|
||||||
Logger::info(L"Storing an edge Pwa app name {} for PwaAppId {}", filenameString.stem().wstring(), appId);
|
Logger::info(L"Storing an edge Pwa app name {} for PwaAppId {}", filenameString.stem().wstring(), appId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -307,41 +310,39 @@ namespace SnapshotUtils
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOL PwaHelper::GetPwaAppId(std::wstring windowAumid, std::wstring* result)
|
std::optional<std::wstring> PwaHelper::GetPwaAppId(const std::wstring& windowAumid) const
|
||||||
{
|
{
|
||||||
const auto pwaIndex = pwaAumidToAppId.find(windowAumid);
|
const auto pwaIndex = m_pwaAumidToAppId.find(windowAumid);
|
||||||
if (pwaIndex != pwaAumidToAppId.end())
|
if (pwaIndex != m_pwaAumidToAppId.end())
|
||||||
{
|
{
|
||||||
*result = pwaIndex->second;
|
return pwaIndex->second;
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return std::nullopt;
|
||||||
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOL PwaHelper::SearchPwaName(std::wstring pwaAppId, std::wstring windowAumid, std::wstring* pwaName)
|
std::wstring PwaHelper::SearchPwaName(const std::wstring& pwaAppId, const std::wstring& windowAumid) const
|
||||||
{
|
{
|
||||||
const auto index = pwaAppIdsToAppNames.find(pwaAppId);
|
const auto index = m_pwaAppIdsToAppNames.find(pwaAppId);
|
||||||
if (index != pwaAppIdsToAppNames.end())
|
if (index != m_pwaAppIdsToAppNames.end())
|
||||||
{
|
{
|
||||||
*pwaName = index->second;
|
return index->second;
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::wstring nameFromAumid{ windowAumid };
|
std::wstring nameFromAumid{ windowAumid };
|
||||||
const std::size_t delimiterPos = nameFromAumid.find(L"-");
|
const std::size_t delimiterPos = nameFromAumid.find(L"-");
|
||||||
if (delimiterPos != std::string::npos)
|
if (delimiterPos != std::string::npos)
|
||||||
{
|
{
|
||||||
nameFromAumid = nameFromAumid.substr(0, delimiterPos);
|
return nameFromAumid.substr(0, delimiterPos);
|
||||||
}
|
}
|
||||||
|
|
||||||
*pwaName = nameFromAumid;
|
return nameFromAumid;
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PwaHelper::InitChromeAppIds()
|
void PwaHelper::InitChromeAppIds()
|
||||||
{
|
{
|
||||||
if (chromeAppIds.size() > 0)
|
if (m_chromeAppIds.size() > 0)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -360,7 +361,7 @@ namespace SnapshotUtils
|
|||||||
if (directoryName.wstring().find(NonLocalizable::ChromeDirPrefix) == 0)
|
if (directoryName.wstring().find(NonLocalizable::ChromeDirPrefix) == 0)
|
||||||
{
|
{
|
||||||
const std::wstring appId = directoryName.wstring().substr(NonLocalizable::ChromeDirPrefix.size());
|
const std::wstring appId = directoryName.wstring().substr(NonLocalizable::ChromeDirPrefix.size());
|
||||||
chromeAppIds.push_back(appId);
|
m_chromeAppIds.push_back(appId);
|
||||||
for (const auto& filename : std::filesystem::directory_iterator(directory))
|
for (const auto& filename : std::filesystem::directory_iterator(directory))
|
||||||
{
|
{
|
||||||
if (!filename.is_directory())
|
if (!filename.is_directory())
|
||||||
@@ -368,7 +369,7 @@ namespace SnapshotUtils
|
|||||||
const std::filesystem::path filenameString = filename.path().filename();
|
const std::filesystem::path filenameString = filename.path().filename();
|
||||||
if (filenameString.extension().wstring() == L".ico")
|
if (filenameString.extension().wstring() == L".ico")
|
||||||
{
|
{
|
||||||
pwaAppIdsToAppNames.insert(std::map<std::wstring, std::wstring>::value_type(appId, filenameString.stem().wstring()));
|
m_pwaAppIdsToAppNames.insert(std::map<std::wstring, std::wstring>::value_type(appId, filenameString.stem().wstring()));
|
||||||
Logger::info(L"Found an installed chrome Pwa app {} with PwaAppId {}", filenameString.stem().wstring(), appId);
|
Logger::info(L"Found an installed chrome Pwa app {} with PwaAppId {}", filenameString.stem().wstring(), appId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -380,30 +381,73 @@ namespace SnapshotUtils
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOL PwaHelper::SearchPwaAppId(std::wstring windowAumid, std::wstring* pwaAppId)
|
std::optional<std::wstring> PwaHelper::SearchPwaAppId(const std::wstring& windowAumid) const
|
||||||
{
|
{
|
||||||
const auto appIdIndexStart = windowAumid.find(NonLocalizable::ChromeAppIdIdentifier);
|
const auto appIdIndexStart = windowAumid.find(NonLocalizable::ChromeAppIdIdentifier);
|
||||||
if (appIdIndexStart != std::wstring::npos)
|
if (appIdIndexStart != std::wstring::npos)
|
||||||
{
|
{
|
||||||
windowAumid = windowAumid.substr(appIdIndexStart + NonLocalizable::ChromeAppIdIdentifier.size());
|
std::wstring windowAumidSub = windowAumid.substr(appIdIndexStart + NonLocalizable::ChromeAppIdIdentifier.size());
|
||||||
const auto appIdIndexEnd = windowAumid.find(L" ");
|
const auto appIdIndexEnd = windowAumidSub.find(L" ");
|
||||||
if (appIdIndexEnd != std::wstring::npos)
|
if (appIdIndexEnd != std::wstring::npos)
|
||||||
{
|
{
|
||||||
windowAumid = windowAumid.substr(0, appIdIndexEnd);
|
windowAumidSub = windowAumidSub.substr(0, appIdIndexEnd);
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::wstring windowAumidBegin = windowAumid.substr(0, 10);
|
const std::wstring windowAumidBegin = windowAumidSub.substr(0, 10);
|
||||||
for (const auto chromeAppId : chromeAppIds)
|
for (const auto chromeAppId : m_chromeAppIds)
|
||||||
{
|
{
|
||||||
if (chromeAppId.find(windowAumidBegin) == 0)
|
if (chromeAppId.find(windowAumidBegin) == 0)
|
||||||
{
|
{
|
||||||
*pwaAppId = chromeAppId;
|
return chromeAppId;
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
*pwaAppId = L"";
|
return std::nullopt;
|
||||||
return false;
|
}
|
||||||
|
|
||||||
|
void PwaHelper::UpdatePwaApp(Utils::Apps::AppData* appData, HWND window)
|
||||||
|
{
|
||||||
|
std::optional<std::wstring> pwaAppId = std::nullopt;
|
||||||
|
std::wstring finalName = appData->name;
|
||||||
|
std::wstring pwaName = L"";
|
||||||
|
if (appData->IsEdge())
|
||||||
|
{
|
||||||
|
InitAumidToAppId();
|
||||||
|
|
||||||
|
std::wstring windowAumid = GetAppId(window);
|
||||||
|
|
||||||
|
Logger::info(L"Found an edge window with aumid {}", windowAumid);
|
||||||
|
|
||||||
|
pwaAppId = GetPwaAppId(windowAumid);
|
||||||
|
if (pwaAppId.has_value())
|
||||||
|
{
|
||||||
|
Logger::info(L"The found edge window is a PWA app with appId {}", pwaAppId.value());
|
||||||
|
pwaName = SearchPwaName(pwaAppId.value(), windowAumid);
|
||||||
|
Logger::info(L"The found edge window is a PWA app with name {}", pwaName);
|
||||||
|
finalName = pwaName + L" (" + finalName + L")";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Logger::info(L"The found edge window does not contain a PWA app");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (appData->IsChrome())
|
||||||
|
{
|
||||||
|
InitChromeAppIds();
|
||||||
|
|
||||||
|
std::wstring windowAumid = GetAppId(window);
|
||||||
|
Logger::info(L"Found a chrome window with aumid {}", windowAumid);
|
||||||
|
|
||||||
|
pwaAppId = SearchPwaAppId(windowAumid);
|
||||||
|
if (pwaAppId.has_value())
|
||||||
|
{
|
||||||
|
pwaName = SearchPwaName(pwaAppId.value(), windowAumid);
|
||||||
|
finalName = pwaName + L" (" + finalName + L")";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
appData->name = finalName;
|
||||||
|
appData->pwaAppId = pwaAppId.has_value() ? pwaAppId.value() : L"";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
29
src/modules/Workspaces/WorkspacesLib/PwaHelper.h
Normal file
29
src/modules/Workspaces/WorkspacesLib/PwaHelper.h
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <WorkspacesLib/AppUtils.h>
|
||||||
|
|
||||||
|
namespace Utils
|
||||||
|
{
|
||||||
|
class PwaHelper
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
void UpdatePwaApp(Apps::AppData* appData, HWND window);
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::map<std::wstring, std::wstring> m_pwaAumidToAppId;
|
||||||
|
std::vector<std::wstring> m_chromeAppIds;
|
||||||
|
std::map<std::wstring, std::wstring> m_pwaAppIdsToAppNames;
|
||||||
|
|
||||||
|
void InitAumidToAppId();
|
||||||
|
void InitChromeAppIds();
|
||||||
|
std::optional<std::wstring> GetAppId_7(HWND hWnd) const;
|
||||||
|
std::optional<std::wstring> GetAppId_8(HWND hWnd) const;
|
||||||
|
std::wstring GetAppId(HWND hWnd) const;
|
||||||
|
std::optional<std::wstring> GetProcessId_7(DWORD dwProcessId) const;
|
||||||
|
std::optional<std::wstring> GetProcessId_8(DWORD dwProcessId) const;
|
||||||
|
std::wstring GetProcessId(DWORD dwProcessId) const;
|
||||||
|
std::optional<std::wstring> GetPwaAppId(const std::wstring& windowAumid) const;
|
||||||
|
std::wstring SearchPwaName(const std::wstring& pwaAppId, const std::wstring& windowAumid) const;
|
||||||
|
std::optional<std::wstring> SearchPwaAppId(const std::wstring& windowAumid) const;
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
#include "pch.h"
|
#include "pch.h"
|
||||||
#include "WorkspacesData.h"
|
#include "WorkspacesData.h"
|
||||||
|
|
||||||
#include <common/SettingsAPI/settings_helpers.h>
|
#include <common/SettingsAPI/settings_helpers.h>
|
||||||
|
|
||||||
#include <workspaces-common/GuidUtils.h>
|
#include <workspaces-common/GuidUtils.h>
|
||||||
@@ -157,6 +156,7 @@ namespace WorkspacesData
|
|||||||
|
|
||||||
result.isMaximized = json.GetNamedBoolean(NonLocalizable::MaximizedID);
|
result.isMaximized = json.GetNamedBoolean(NonLocalizable::MaximizedID);
|
||||||
result.isMinimized = json.GetNamedBoolean(NonLocalizable::MinimizedID);
|
result.isMinimized = json.GetNamedBoolean(NonLocalizable::MinimizedID);
|
||||||
|
|
||||||
result.monitor = static_cast<int>(json.GetNamedNumber(NonLocalizable::MonitorID));
|
result.monitor = static_cast<int>(json.GetNamedNumber(NonLocalizable::MonitorID));
|
||||||
if (json.HasKey(NonLocalizable::PositionID))
|
if (json.HasKey(NonLocalizable::PositionID))
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -38,6 +38,7 @@
|
|||||||
<ClInclude Include="LaunchingStateEnum.h" />
|
<ClInclude Include="LaunchingStateEnum.h" />
|
||||||
<ClInclude Include="LaunchingStatus.h" />
|
<ClInclude Include="LaunchingStatus.h" />
|
||||||
<ClInclude Include="pch.h" />
|
<ClInclude Include="pch.h" />
|
||||||
|
<ClInclude Include="PwaHelper.h" />
|
||||||
<ClInclude Include="Result.h" />
|
<ClInclude Include="Result.h" />
|
||||||
<ClInclude Include="utils.h" />
|
<ClInclude Include="utils.h" />
|
||||||
<ClInclude Include="WorkspacesData.h" />
|
<ClInclude Include="WorkspacesData.h" />
|
||||||
@@ -51,6 +52,7 @@
|
|||||||
<ClCompile Include="pch.cpp">
|
<ClCompile Include="pch.cpp">
|
||||||
<PrecompiledHeader Condition="'$(UsePrecompiledHeaders)' != 'false'">Create</PrecompiledHeader>
|
<PrecompiledHeader Condition="'$(UsePrecompiledHeaders)' != 'false'">Create</PrecompiledHeader>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="PwaHelper.cpp" />
|
||||||
<ClCompile Include="two_way_pipe_message_ipc.cpp" />
|
<ClCompile Include="two_way_pipe_message_ipc.cpp" />
|
||||||
<ClCompile Include="WorkspacesData.cpp" />
|
<ClCompile Include="WorkspacesData.cpp" />
|
||||||
<ClCompile Include="trace.cpp" />
|
<ClCompile Include="trace.cpp" />
|
||||||
@@ -70,6 +72,7 @@
|
|||||||
<Import Project="..\..\..\..\deps\spdlog.props" />
|
<Import Project="..\..\..\..\deps\spdlog.props" />
|
||||||
<ImportGroup Label="ExtensionTargets">
|
<ImportGroup Label="ExtensionTargets">
|
||||||
<Import Project="..\..\..\..\packages\Microsoft.Windows.CppWinRT.2.0.240111.5\build\native\Microsoft.Windows.CppWinRT.targets" Condition="Exists('..\..\..\..\packages\Microsoft.Windows.CppWinRT.2.0.240111.5\build\native\Microsoft.Windows.CppWinRT.targets')" />
|
<Import Project="..\..\..\..\packages\Microsoft.Windows.CppWinRT.2.0.240111.5\build\native\Microsoft.Windows.CppWinRT.targets" Condition="Exists('..\..\..\..\packages\Microsoft.Windows.CppWinRT.2.0.240111.5\build\native\Microsoft.Windows.CppWinRT.targets')" />
|
||||||
|
<Import Project="..\..\..\..\packages\Microsoft.Windows.ImplementationLibrary.1.0.231216.1\build\native\Microsoft.Windows.ImplementationLibrary.targets" Condition="Exists('..\..\..\..\packages\Microsoft.Windows.ImplementationLibrary.1.0.231216.1\build\native\Microsoft.Windows.ImplementationLibrary.targets')" />
|
||||||
</ImportGroup>
|
</ImportGroup>
|
||||||
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
|
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
@@ -77,5 +80,6 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<Error Condition="!Exists('..\..\..\..\packages\Microsoft.Windows.CppWinRT.2.0.240111.5\build\native\Microsoft.Windows.CppWinRT.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\..\packages\Microsoft.Windows.CppWinRT.2.0.240111.5\build\native\Microsoft.Windows.CppWinRT.props'))" />
|
<Error Condition="!Exists('..\..\..\..\packages\Microsoft.Windows.CppWinRT.2.0.240111.5\build\native\Microsoft.Windows.CppWinRT.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\..\packages\Microsoft.Windows.CppWinRT.2.0.240111.5\build\native\Microsoft.Windows.CppWinRT.props'))" />
|
||||||
<Error Condition="!Exists('..\..\..\..\packages\Microsoft.Windows.CppWinRT.2.0.240111.5\build\native\Microsoft.Windows.CppWinRT.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\..\packages\Microsoft.Windows.CppWinRT.2.0.240111.5\build\native\Microsoft.Windows.CppWinRT.targets'))" />
|
<Error Condition="!Exists('..\..\..\..\packages\Microsoft.Windows.CppWinRT.2.0.240111.5\build\native\Microsoft.Windows.CppWinRT.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\..\packages\Microsoft.Windows.CppWinRT.2.0.240111.5\build\native\Microsoft.Windows.CppWinRT.targets'))" />
|
||||||
|
<Error Condition="!Exists('..\..\..\..\packages\Microsoft.Windows.ImplementationLibrary.1.0.231216.1\build\native\Microsoft.Windows.ImplementationLibrary.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\..\packages\Microsoft.Windows.ImplementationLibrary.1.0.231216.1\build\native\Microsoft.Windows.ImplementationLibrary.targets'))" />
|
||||||
</Target>
|
</Target>
|
||||||
</Project>
|
</Project>
|
||||||
@@ -41,6 +41,9 @@
|
|||||||
<ClInclude Include="LaunchingStatus.h">
|
<ClInclude Include="LaunchingStatus.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="PwaHelper.h">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="pch.cpp">
|
<ClCompile Include="pch.cpp">
|
||||||
@@ -67,6 +70,9 @@
|
|||||||
<ClCompile Include="LaunchingStatus.cpp">
|
<ClCompile Include="LaunchingStatus.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="PwaHelper.cpp">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="packages.config" />
|
<None Include="packages.config" />
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<packages>
|
<packages>
|
||||||
<package id="Microsoft.Windows.CppWinRT" version="2.0.240111.5" targetFramework="native" />
|
<package id="Microsoft.Windows.CppWinRT" version="2.0.240111.5" targetFramework="native" />
|
||||||
|
<package id="Microsoft.Windows.ImplementationLibrary" version="1.0.231216.1" targetFramework="native" />
|
||||||
</packages>
|
</packages>
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
namespace SnapshotUtils
|
|
||||||
{
|
|
||||||
class PwaHelper
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
void InitAumidToAppId();
|
|
||||||
BOOL GetAppId(HWND hWnd, std::wstring* result);
|
|
||||||
BOOL GetPwaAppId(std::wstring windowAumid, std::wstring* result);
|
|
||||||
BOOL SearchPwaName(std::wstring pwaAppId, std::wstring windowAumid, std::wstring* pwaName);
|
|
||||||
void InitChromeAppIds();
|
|
||||||
BOOL SearchPwaAppId(std::wstring windowAumid, std::wstring* pwaAppId);
|
|
||||||
|
|
||||||
private:
|
|
||||||
std::map<std::wstring, std::wstring> pwaAumidToAppId;
|
|
||||||
std::vector<std::wstring> chromeAppIds;
|
|
||||||
std::map<std::wstring, std::wstring> pwaAppIdsToAppNames;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@@ -9,7 +9,7 @@
|
|||||||
#include <workspaces-common/WindowFilter.h>
|
#include <workspaces-common/WindowFilter.h>
|
||||||
|
|
||||||
#include <WorkspacesLib/AppUtils.h>
|
#include <WorkspacesLib/AppUtils.h>
|
||||||
#include <PwaHelper.h>
|
#include <WorkspacesLib/PwaHelper.h>
|
||||||
|
|
||||||
#pragma comment(lib, "ntdll.lib")
|
#pragma comment(lib, "ntdll.lib")
|
||||||
|
|
||||||
@@ -18,8 +18,6 @@ namespace SnapshotUtils
|
|||||||
namespace NonLocalizable
|
namespace NonLocalizable
|
||||||
{
|
{
|
||||||
const std::wstring ApplicationFrameHost = L"ApplicationFrameHost.exe";
|
const std::wstring ApplicationFrameHost = L"ApplicationFrameHost.exe";
|
||||||
const std::wstring EdgeFilename = L"msedge.exe";
|
|
||||||
const std::wstring ChromeFilename = L"chrome.exe";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsProcessElevated(DWORD processID)
|
bool IsProcessElevated(DWORD processID)
|
||||||
@@ -40,19 +38,9 @@ namespace SnapshotUtils
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsEdge(Utils::Apps::AppData appData)
|
|
||||||
{
|
|
||||||
return appData.installPath.ends_with(NonLocalizable::EdgeFilename);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool IsChrome(Utils::Apps::AppData appData)
|
|
||||||
{
|
|
||||||
return appData.installPath.ends_with(NonLocalizable::ChromeFilename);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<WorkspacesData::WorkspacesProject::Application> GetApps(const std::function<unsigned int(HWND)> getMonitorNumberFromWindowHandle, const std::function<WorkspacesData::WorkspacesProject::Monitor::MonitorRect(unsigned int)> getMonitorRect)
|
std::vector<WorkspacesData::WorkspacesProject::Application> GetApps(const std::function<unsigned int(HWND)> getMonitorNumberFromWindowHandle, const std::function<WorkspacesData::WorkspacesProject::Monitor::MonitorRect(unsigned int)> getMonitorRect)
|
||||||
{
|
{
|
||||||
PwaHelper pwaHelper{};
|
Utils::PwaHelper pwaHelper{};
|
||||||
std::vector<WorkspacesData::WorkspacesProject::Application> apps{};
|
std::vector<WorkspacesData::WorkspacesProject::Application> apps{};
|
||||||
|
|
||||||
auto installedApps = Utils::Apps::GetAppsList();
|
auto installedApps = Utils::Apps::GetAppsList();
|
||||||
@@ -128,47 +116,7 @@ namespace SnapshotUtils
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::wstring pwaAppId = L"";
|
pwaHelper.UpdatePwaApp(&data.value(), window);
|
||||||
std::wstring finalName = data.value().name;
|
|
||||||
std::wstring pwaName = L"";
|
|
||||||
if (IsEdge(data.value()))
|
|
||||||
{
|
|
||||||
pwaHelper.InitAumidToAppId();
|
|
||||||
|
|
||||||
std::wstring windowAumid;
|
|
||||||
pwaHelper.GetAppId(window, &windowAumid);
|
|
||||||
Logger::info(L"Found an edge window with aumid {}", windowAumid);
|
|
||||||
|
|
||||||
if (pwaHelper.GetPwaAppId(windowAumid, &pwaAppId))
|
|
||||||
{
|
|
||||||
Logger::info(L"The found edge window is a PWA app with appId {}", pwaAppId);
|
|
||||||
if (pwaHelper.SearchPwaName(pwaAppId, windowAumid ,& pwaName))
|
|
||||||
{
|
|
||||||
Logger::info(L"The found edge window is a PWA app with name {}", finalName);
|
|
||||||
}
|
|
||||||
finalName = pwaName + L" (" + finalName + L")";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Logger::info(L"The found edge window does not contain a PWA app", pwaAppId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (IsChrome(data.value()))
|
|
||||||
{
|
|
||||||
pwaHelper.InitChromeAppIds();
|
|
||||||
|
|
||||||
std::wstring windowAumid;
|
|
||||||
pwaHelper.GetAppId(window, &windowAumid);
|
|
||||||
Logger::info(L"Found a chrome window with aumid {}", windowAumid);
|
|
||||||
|
|
||||||
if (pwaHelper.SearchPwaAppId(windowAumid, &pwaAppId))
|
|
||||||
{
|
|
||||||
if (pwaHelper.SearchPwaName(pwaAppId, windowAumid, &pwaName))
|
|
||||||
{
|
|
||||||
finalName = pwaName + L" (" + finalName + L")";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool isMinimized = WindowUtils::IsMinimized(window);
|
bool isMinimized = WindowUtils::IsMinimized(window);
|
||||||
unsigned int monitorNumber = getMonitorNumberFromWindowHandle(window);
|
unsigned int monitorNumber = getMonitorNumberFromWindowHandle(window);
|
||||||
@@ -184,12 +132,12 @@ namespace SnapshotUtils
|
|||||||
}
|
}
|
||||||
|
|
||||||
WorkspacesData::WorkspacesProject::Application app{
|
WorkspacesData::WorkspacesProject::Application app{
|
||||||
.name = finalName,
|
.name = data.value().name,
|
||||||
.title = title,
|
.title = title,
|
||||||
.path = data.value().installPath,
|
.path = data.value().installPath,
|
||||||
.packageFullName = data.value().packageFullName,
|
.packageFullName = data.value().packageFullName,
|
||||||
.appUserModelId = data.value().appUserModelId,
|
.appUserModelId = data.value().appUserModelId,
|
||||||
.pwaAppId = pwaAppId,
|
.pwaAppId = data.value().pwaAppId,
|
||||||
.commandLineArgs = L"",
|
.commandLineArgs = L"",
|
||||||
.isElevated = IsProcessElevated(pid),
|
.isElevated = IsProcessElevated(pid),
|
||||||
.canLaunchElevated = data.value().canLaunchElevated,
|
.canLaunchElevated = data.value().canLaunchElevated,
|
||||||
|
|||||||
@@ -130,12 +130,10 @@
|
|||||||
<ClCompile Include="pch.cpp">
|
<ClCompile Include="pch.cpp">
|
||||||
<PrecompiledHeader Condition="'$(UsePrecompiledHeaders)' != 'false'">Create</PrecompiledHeader>
|
<PrecompiledHeader Condition="'$(UsePrecompiledHeaders)' != 'false'">Create</PrecompiledHeader>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="PwaHelper.cpp" />
|
|
||||||
<ClCompile Include="SnapshotUtils.cpp" />
|
<ClCompile Include="SnapshotUtils.cpp" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="pch.h" />
|
<ClInclude Include="pch.h" />
|
||||||
<ClInclude Include="PwaHelper.h" />
|
|
||||||
<ClInclude Include="resource.base.h" />
|
<ClInclude Include="resource.base.h" />
|
||||||
<ClInclude Include="SnapshotUtils.h" />
|
<ClInclude Include="SnapshotUtils.h" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|||||||
@@ -24,9 +24,6 @@
|
|||||||
<ClInclude Include="resource.base.h">
|
<ClInclude Include="resource.base.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="PwaHelper.h">
|
|
||||||
<Filter>Header Files</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="pch.cpp">
|
<ClCompile Include="pch.cpp">
|
||||||
@@ -38,9 +35,6 @@
|
|||||||
<ClCompile Include="SnapshotUtils.cpp">
|
<ClCompile Include="SnapshotUtils.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="PwaHelper.cpp">
|
|
||||||
<Filter>Source Files</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="packages.config" />
|
<None Include="packages.config" />
|
||||||
|
|||||||
@@ -12,9 +12,18 @@
|
|||||||
#include <workspaces-common/WindowUtils.h>
|
#include <workspaces-common/WindowUtils.h>
|
||||||
|
|
||||||
#include <WindowProperties/WorkspacesWindowPropertyUtils.h>
|
#include <WindowProperties/WorkspacesWindowPropertyUtils.h>
|
||||||
|
#include <WorkspacesLib/PwaHelper.h>
|
||||||
|
|
||||||
namespace FancyZones
|
namespace PlacementHelper
|
||||||
{
|
{
|
||||||
|
// When calculating the coordinates difference (== 'distance') between 2 windows, there are additional values added to the real distance
|
||||||
|
// if both windows are minimized, the 'distance' is 0, the minimal value, this is the best match, we prefer this 'pairing'
|
||||||
|
// if both are in normal state (non-minimized), we add 1 to the calculated 'distance', this is the 2nd best match
|
||||||
|
// if one window is minimized and the other is maximized, we add a high value (10.000) to the result as
|
||||||
|
// this case is the least desired match, we want this pairing (matching) only if there is no other possibility left
|
||||||
|
const int PlacementDistanceAdditionBothNormal = 1;
|
||||||
|
const int PlacementDistanceAdditionNormalAndMinimized = 10000;
|
||||||
|
|
||||||
inline void ScreenToWorkAreaCoords(HWND window, HMONITOR monitor, RECT& rect)
|
inline void ScreenToWorkAreaCoords(HWND window, HMONITOR monitor, RECT& rect)
|
||||||
{
|
{
|
||||||
MONITORINFOEXW monitorInfo{ sizeof(MONITORINFOEXW) };
|
MONITORINFOEXW monitorInfo{ sizeof(MONITORINFOEXW) };
|
||||||
@@ -52,14 +61,7 @@ namespace FancyZones
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if ((placement.showCmd != SW_SHOWMINIMIZED) &&
|
|
||||||
(placement.showCmd != SW_MINIMIZE))
|
|
||||||
{
|
|
||||||
if (placement.showCmd == SW_SHOWMAXIMIZED)
|
|
||||||
placement.flags &= ~WPF_RESTORETOMAXIMIZED;
|
|
||||||
|
|
||||||
placement.showCmd = SW_RESTORE;
|
placement.showCmd = SW_RESTORE;
|
||||||
}
|
|
||||||
|
|
||||||
ScreenToWorkAreaCoords(window, monitor, rect);
|
ScreenToWorkAreaCoords(window, monitor, rect);
|
||||||
placement.rcNormalPosition = rect;
|
placement.rcNormalPosition = rect;
|
||||||
@@ -91,18 +93,191 @@ namespace FancyZones
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int CalculateDistance(const WorkspacesData::WorkspacesProject::Application& app, HWND window)
|
||||||
|
{
|
||||||
|
WINDOWPLACEMENT placement{};
|
||||||
|
::GetWindowPlacement(window, &placement);
|
||||||
|
|
||||||
|
if (app.isMinimized && (placement.showCmd == SW_SHOWMINIMIZED))
|
||||||
|
{
|
||||||
|
// The most preferred case: both windows are minimized. The 'distance' between these 2 windows is 0, the lowest value
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int placementDiffPenalty = PlacementDistanceAdditionBothNormal;
|
||||||
|
if (app.isMinimized || (placement.showCmd == SW_SHOWMINIMIZED))
|
||||||
|
{
|
||||||
|
// The least preferred case: one window is minimized the other one isn't.
|
||||||
|
// We add a high number to the real distance, as we want this 2 windows be matched only if there is no other match
|
||||||
|
placementDiffPenalty = PlacementDistanceAdditionNormalAndMinimized;
|
||||||
|
}
|
||||||
|
|
||||||
|
RECT windowPosition;
|
||||||
|
GetWindowRect(window, &windowPosition);
|
||||||
|
DPIAware::InverseConvert(MonitorFromWindow(window, MONITOR_DEFAULTTOPRIMARY), windowPosition);
|
||||||
|
|
||||||
|
return placementDiffPenalty + abs(app.position.x - windowPosition.left) + abs(app.position.y - windowPosition.top) + abs(app.position.x + app.position.width - windowPosition.right) + abs(app.position.y + app.position.height - windowPosition.bottom);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool WindowArranger::TryMoveWindow(const WorkspacesData::WorkspacesProject::Application& app, HWND windowToMove)
|
||||||
|
{
|
||||||
|
Logger::info(L"The app {} is found at launch, moving it", app.name);
|
||||||
|
auto appState = m_launchingStatus.Get(app);
|
||||||
|
if (!appState.has_value())
|
||||||
|
{
|
||||||
|
Logger::info(L"The app {} is not found in the map of apps", app.name);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool success = moveWindow(windowToMove, app);
|
||||||
|
if (success)
|
||||||
|
{
|
||||||
|
m_launchingStatus.Update(appState.value().application, windowToMove, LaunchingState::LaunchedAndMoved);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Logger::info(L"Failed to move the existing app {} ", app.name);
|
||||||
|
m_launchingStatus.Update(appState.value().application, windowToMove, LaunchingState::Failed);
|
||||||
|
}
|
||||||
|
|
||||||
|
auto updatedState = m_launchingStatus.Get(app);
|
||||||
|
if (updatedState.has_value())
|
||||||
|
{
|
||||||
|
m_ipcHelper.send(WorkspacesData::AppLaunchInfoJSON::ToJson(updatedState.value()).ToString().c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
return success;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::optional<WindowWithDistance> WindowArranger::GetNearestWindow(const WorkspacesData::WorkspacesProject::Application& app, const std::vector<HWND>& movedWindows, Utils::PwaHelper& pwaHelper)
|
||||||
|
{
|
||||||
|
std::optional<Utils::Apps::AppData> appDataNearest = std::nullopt;
|
||||||
|
WindowWithDistance nearestWindowWithDistance{};
|
||||||
|
|
||||||
|
for (HWND window : m_windowsBefore)
|
||||||
|
{
|
||||||
|
if (std::find(movedWindows.begin(), movedWindows.end(), window) != movedWindows.end())
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::wstring processPath = get_process_path(window);
|
||||||
|
if (processPath.empty())
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
DWORD pid{};
|
||||||
|
GetWindowThreadProcessId(window, &pid);
|
||||||
|
|
||||||
|
auto data = Utils::Apps::GetApp(processPath, pid, m_installedApps);
|
||||||
|
if (!data.has_value())
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
pwaHelper.UpdatePwaApp(&data.value(), window);
|
||||||
|
|
||||||
|
if ((app.name == data.value().name || app.path == data.value().installPath) && (app.pwaAppId == data.value().pwaAppId))
|
||||||
|
{
|
||||||
|
if (!appDataNearest.has_value())
|
||||||
|
{
|
||||||
|
appDataNearest = data;
|
||||||
|
nearestWindowWithDistance.distance = PlacementHelper::CalculateDistance(app, window);
|
||||||
|
nearestWindowWithDistance.window = window;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
int currentDistance = PlacementHelper::CalculateDistance(app, window);
|
||||||
|
if (currentDistance < nearestWindowWithDistance.distance)
|
||||||
|
{
|
||||||
|
appDataNearest = data;
|
||||||
|
nearestWindowWithDistance.distance = currentDistance;
|
||||||
|
nearestWindowWithDistance.window = window;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (appDataNearest.has_value())
|
||||||
|
{
|
||||||
|
return nearestWindowWithDistance;
|
||||||
|
}
|
||||||
|
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
WindowArranger::WindowArranger(WorkspacesData::WorkspacesProject project) :
|
WindowArranger::WindowArranger(WorkspacesData::WorkspacesProject project) :
|
||||||
m_project(project),
|
m_project(project),
|
||||||
m_windowsBefore(WindowEnumerator::Enumerate(WindowFilter::Filter)),
|
m_windowsBefore(WindowEnumerator::Enumerate(WindowFilter::Filter)),
|
||||||
m_monitors(MonitorUtils::IdentifyMonitors()),
|
m_monitors(MonitorUtils::IdentifyMonitors()),
|
||||||
m_installedApps(Utils::Apps::GetAppsList()),
|
m_installedApps(Utils::Apps::GetAppsList()),
|
||||||
//m_windowCreationHandler(std::bind(&WindowArranger::onWindowCreated, this, std::placeholders::_1)),
|
|
||||||
m_ipcHelper(IPCHelperStrings::WindowArrangerPipeName, IPCHelperStrings::LauncherArrangerPipeName, std::bind(&WindowArranger::receiveIpcMessage, this, std::placeholders::_1)),
|
m_ipcHelper(IPCHelperStrings::WindowArrangerPipeName, IPCHelperStrings::LauncherArrangerPipeName, std::bind(&WindowArranger::receiveIpcMessage, this, std::placeholders::_1)),
|
||||||
m_launchingStatus(m_project)
|
m_launchingStatus(m_project)
|
||||||
{
|
{
|
||||||
|
if (project.moveExistingWindows)
|
||||||
|
{
|
||||||
|
Logger::info(L"Moving existing windows");
|
||||||
|
bool isMovePhase = true;
|
||||||
|
bool movedAny = false;
|
||||||
|
std::vector<HWND> movedWindows;
|
||||||
|
std::vector<WorkspacesData::WorkspacesProject::Application> movedApps;
|
||||||
|
Utils::PwaHelper pwaHelper{};
|
||||||
|
|
||||||
|
while (isMovePhase)
|
||||||
|
{
|
||||||
|
isMovePhase = false;
|
||||||
|
int minDistance = INT_MAX;
|
||||||
|
WorkspacesData::WorkspacesProject::Application appToMove;
|
||||||
|
HWND windowToMove = NULL;
|
||||||
|
for (auto& app : project.apps)
|
||||||
|
{
|
||||||
|
// move the apps which are set to "Move-If-Exists" and are already present (launched, running)
|
||||||
|
if (std::find(movedApps.begin(), movedApps.end(), app) != movedApps.end())
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::optional<WindowWithDistance> nearestWindowWithDistance;
|
||||||
|
nearestWindowWithDistance = GetNearestWindow(app, movedWindows, pwaHelper);
|
||||||
|
if (nearestWindowWithDistance.has_value())
|
||||||
|
{
|
||||||
|
if (nearestWindowWithDistance.value().distance < minDistance)
|
||||||
|
{
|
||||||
|
minDistance = nearestWindowWithDistance.value().distance;
|
||||||
|
appToMove = app;
|
||||||
|
windowToMove = nearestWindowWithDistance.value().window;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Logger::info(L"The app {} is not found at launch, cannot be moved, has to be started", app.name);
|
||||||
|
movedApps.push_back(app);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (minDistance < INT_MAX)
|
||||||
|
{
|
||||||
|
isMovePhase = true;
|
||||||
|
movedAny = true;
|
||||||
|
bool success = TryMoveWindow(appToMove, windowToMove);
|
||||||
|
movedApps.push_back(appToMove);
|
||||||
|
if (success)
|
||||||
|
{
|
||||||
|
movedWindows.push_back(windowToMove);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (movedAny)
|
||||||
|
{
|
||||||
|
// Wait if there were moved windows. This message might not arrive if sending immediately after the last "moved" message (status update)
|
||||||
|
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||||
|
}
|
||||||
|
|
||||||
|
Logger::info(L"Finished moving existing windows");
|
||||||
|
}
|
||||||
|
|
||||||
m_ipcHelper.send(L"ready");
|
m_ipcHelper.send(L"ready");
|
||||||
|
|
||||||
const long maxLaunchingWaitingTime = 10000, maxRepositionWaitingTime = 3000, ms = 300;
|
const long maxLaunchingWaitingTime = 10000, maxRepositionWaitingTime = 3000, ms = 300;
|
||||||
@@ -138,16 +313,6 @@ WindowArranger::WindowArranger(WorkspacesData::WorkspacesProject project) :
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//void WindowArranger::onWindowCreated(HWND window)
|
|
||||||
//{
|
|
||||||
// if (!WindowFilter::Filter(window))
|
|
||||||
// {
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// processWindow(window);
|
|
||||||
//}
|
|
||||||
|
|
||||||
void WindowArranger::processWindows(bool processAll)
|
void WindowArranger::processWindows(bool processAll)
|
||||||
{
|
{
|
||||||
std::vector<HWND> windows = WindowEnumerator::Enumerate(WindowFilter::Filter);
|
std::vector<HWND> windows = WindowEnumerator::Enumerate(WindowFilter::Filter);
|
||||||
@@ -194,8 +359,7 @@ void WindowArranger::processWindow(HWND window)
|
|||||||
}
|
}
|
||||||
|
|
||||||
const auto& apps = m_launchingStatus.Get();
|
const auto& apps = m_launchingStatus.Get();
|
||||||
auto iter = std::find_if(apps.begin(), apps.end(), [&](const auto& val)
|
auto iter = std::find_if(apps.begin(), apps.end(), [&](const auto& val) {
|
||||||
{
|
|
||||||
return val.second.state == LaunchingState::Launched &&
|
return val.second.state == LaunchingState::Launched &&
|
||||||
!val.second.window &&
|
!val.second.window &&
|
||||||
(val.first.name == data.value().name || val.first.path == data.value().installPath);
|
(val.first.name == data.value().name || val.first.path == data.value().installPath);
|
||||||
@@ -258,7 +422,7 @@ bool WindowArranger::moveWindow(HWND window, const WorkspacesData::WorkspacesPro
|
|||||||
rect.top = static_cast<long>(std::round(rect.top * mult));
|
rect.top = static_cast<long>(std::round(rect.top * mult));
|
||||||
rect.bottom = static_cast<long>(std::round(rect.bottom * mult));
|
rect.bottom = static_cast<long>(std::round(rect.bottom * mult));
|
||||||
|
|
||||||
if (FancyZones::SizeWindowToRect(window, currentMonitor, launchMinimized, launchMaximized, rect))
|
if (PlacementHelper::SizeWindowToRect(window, currentMonitor, launchMinimized, launchMaximized, rect))
|
||||||
{
|
{
|
||||||
WorkspacesWindowProperties::StampWorkspacesLaunchedProperty(window);
|
WorkspacesWindowProperties::StampWorkspacesLaunchedProperty(window);
|
||||||
Logger::trace(L"Placed {} to ({},{}) [{}x{}]", app.name, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top);
|
Logger::trace(L"Placed {} to ({},{}) [{}x{}]", app.name, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top);
|
||||||
|
|||||||
@@ -5,8 +5,15 @@
|
|||||||
#include <WorkspacesLib/AppUtils.h>
|
#include <WorkspacesLib/AppUtils.h>
|
||||||
#include <WorkspacesLib/IPCHelper.h>
|
#include <WorkspacesLib/IPCHelper.h>
|
||||||
#include <WorkspacesLib/LaunchingStatus.h>
|
#include <WorkspacesLib/LaunchingStatus.h>
|
||||||
|
#include <WorkspacesLib/PwaHelper.h>
|
||||||
#include <WorkspacesLib/WorkspacesData.h>
|
#include <WorkspacesLib/WorkspacesData.h>
|
||||||
|
|
||||||
|
struct WindowWithDistance
|
||||||
|
{
|
||||||
|
int distance;
|
||||||
|
HWND window;
|
||||||
|
};
|
||||||
|
|
||||||
class WindowArranger
|
class WindowArranger
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -21,6 +28,8 @@ private:
|
|||||||
//const WindowCreationHandler m_windowCreationHandler;
|
//const WindowCreationHandler m_windowCreationHandler;
|
||||||
IPCHelper m_ipcHelper;
|
IPCHelper m_ipcHelper;
|
||||||
LaunchingStatus m_launchingStatus;
|
LaunchingStatus m_launchingStatus;
|
||||||
|
std::optional<WindowWithDistance> GetNearestWindow(const WorkspacesData::WorkspacesProject::Application& app, const std::vector<HWND>& movedWindows, Utils::PwaHelper& pwaHelper);
|
||||||
|
bool TryMoveWindow(const WorkspacesData::WorkspacesProject::Application& app, HWND windowToMove);
|
||||||
|
|
||||||
//void onWindowCreated(HWND window);
|
//void onWindowCreated(HWND window);
|
||||||
void processWindows(bool processAll);
|
void processWindows(bool processAll);
|
||||||
|
|||||||
Reference in New Issue
Block a user