Skip to content

Commit

Permalink
[Workspaces] implement the move feature (#35480)
Browse files Browse the repository at this point in the history
* [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 <[email protected]>
Co-authored-by: donlaci <[email protected]>
  • Loading branch information
3 people authored Dec 4, 2024
1 parent e0949cb commit 89be43e
Show file tree
Hide file tree
Showing 38 changed files with 668 additions and 556 deletions.
18 changes: 18 additions & 0 deletions src/common/Display/dpi_aware.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
SetProcessDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2);
Expand Down
1 change: 1 addition & 0 deletions src/common/Display/dpi_aware.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ namespace DPIAware
void Convert(HMONITOR monitor_handle, RECT& rect);
void ConvertByCursorPosition(float& width, float& height);
void InverseConvert(HMONITOR monitor_handle, float& width, float& height);
void InverseConvert(HMONITOR monitor_handle, RECT& rect);
void EnableDPIAwarenessForThisProcess();

enum AwarenessLevel
Expand Down
3 changes: 0 additions & 3 deletions src/modules/Workspaces/WorkspacesEditor/Data/ProjectData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
// See the LICENSE file in the project root for more information.

using System.Collections.Generic;

using Workspaces.Data;

using static WorkspacesEditor.Data.ProjectData;

namespace WorkspacesEditor.Data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,7 @@ namespace WorkspacesEditor.Data
{
public class TempProjectData : ProjectData
{
public static string File
{
get
{
return FolderUtils.DataFolder() + "\\temp-workspaces.json";
}
}
public static string File => FolderUtils.DataFolder() + "\\temp-workspaces.json";

public static void DeleteTempFile()
{
Expand Down
10 changes: 1 addition & 9 deletions src/modules/Workspaces/WorkspacesEditor/Data/WorkspacesData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
// See the LICENSE file in the project root for more information.

using System.Collections.Generic;

using Workspaces.Data;
using WorkspacesEditor.Utils;

using static WorkspacesEditor.Data.ProjectData;
Expand All @@ -14,13 +12,7 @@ namespace WorkspacesEditor.Data
{
public class WorkspacesData : WorkspacesEditorData<WorkspacesListWrapper>
{
public string File
{
get
{
return FolderUtils.DataFolder() + "\\workspaces.json";
}
}
public string File => FolderUtils.DataFolder() + "\\workspaces.json";

public struct WorkspacesListWrapper
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,24 @@
// See the LICENSE file in the project root for more information.

using System.Text.Json;

using WorkspacesEditor.Utils;

namespace Workspaces.Data
namespace WorkspacesEditor.Data
{
public class WorkspacesEditorData<T>
{
protected JsonSerializerOptions JsonOptions
{
get
get => new()
{
return new JsonSerializerOptions
{
PropertyNamingPolicy = new DashCaseNamingPolicy(),
WriteIndented = true,
};
}
PropertyNamingPolicy = new DashCaseNamingPolicy(),
WriteIndented = true,
};
}

public T Read(string file)
{
IOUtils ioUtils = new IOUtils();
IOUtils ioUtils = new();
string data = ioUtils.ReadFile(file);
return JsonSerializer.Deserialize<T>(data, JsonOptions);
}
Expand Down
2 changes: 1 addition & 1 deletion src/modules/Workspaces/WorkspacesEditor/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
xmlns:ui="http://schemas.modernwpf.com/2019"
x:Name="WorkspacesMainWindow"
Title="{x:Static props:Resources.MainTitle}"
MinWidth="700"
MinWidth="750"
MinHeight="680"
ui:TitleBar.Background="{DynamicResource PrimaryBackgroundBrush}"
ui:TitleBar.InactiveBackground="{DynamicResource TertiaryBackgroundBrush}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,7 @@ public AppListDataTemplateSelector()

public override System.Windows.DataTemplate SelectTemplate(object item, System.Windows.DependencyObject container)
{
if (item is MonitorHeaderRow)
{
return HeaderTemplate;
}
else
{
return AppTemplate;
}
return item is MonitorHeaderRow ? HeaderTemplate : AppTemplate;
}
}
}
76 changes: 21 additions & 55 deletions src/modules/Workspaces/WorkspacesEditor/Models/Application.cs
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
// Copyright (c) Microsoft Corporation
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Globalization;
using System.IO;
using System.Linq;
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;

namespace WorkspacesEditor.Models
{
public enum WindowPositionKind
{
Custom = 0,
Maximized = 1,
Minimized = 2,
}

public class Application : BaseApplication, IDisposable
{
private bool _isInitialized;
Expand Down Expand Up @@ -79,7 +76,7 @@ public struct WindowPosition
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())
{
Expand All @@ -90,7 +87,7 @@ public override bool Equals(object obj)
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();
}
Expand Down Expand Up @@ -136,36 +133,24 @@ private void RedrawPreviewImage()
}
}

private bool _minimized;
public bool Minimized { get; set; }

public bool Minimized
{
get => _minimized;
set
{
_minimized = value;
OnPropertyChanged(new PropertyChangedEventArgs(nameof(Minimized)));
OnPropertyChanged(new PropertyChangedEventArgs(nameof(EditPositionEnabled)));
RedrawPreviewImage();
}
}
public bool Maximized { get; set; }

private bool _maximized;
public bool EditPositionEnabled => !Minimized && !Maximized;

public bool Maximized
public int PositionComboboxIndex
{
get => _maximized;
get => Maximized ? (int)WindowPositionKind.Maximized : Minimized ? (int)WindowPositionKind.Minimized : (int)WindowPositionKind.Custom;
set
{
_maximized = value;
OnPropertyChanged(new PropertyChangedEventArgs(nameof(Maximized)));
Maximized = value == (int)WindowPositionKind.Maximized;
Minimized = value == (int)WindowPositionKind.Minimized;
OnPropertyChanged(new PropertyChangedEventArgs(nameof(EditPositionEnabled)));
RedrawPreviewImage();
}
}

public bool EditPositionEnabled { get => !Minimized && !Maximized; }

private string _appMainParams;

public string AppMainParams
Expand All @@ -183,7 +168,7 @@ public string AppMainParams
}
}

public bool IsAppMainParamVisible { get => !string.IsNullOrWhiteSpace(_appMainParams); }
public bool IsAppMainParamVisible => !string.IsNullOrWhiteSpace(_appMainParams);

[JsonIgnore]
public bool IsHighlighted { get; set; }
Expand All @@ -192,13 +177,7 @@ public string AppMainParams
public int RepeatIndex { get; set; }

[JsonIgnore]
public string RepeatIndexString
{
get
{
return RepeatIndex <= 1 ? string.Empty : RepeatIndex.ToString(CultureInfo.InvariantCulture);
}
}
public string RepeatIndexString => RepeatIndex <= 1 ? string.Empty : RepeatIndex.ToString(CultureInfo.InvariantCulture);

private WindowPosition _position;

Expand Down Expand Up @@ -242,10 +221,7 @@ public MonitorSetup MonitorSetup
{
get
{
if (_monitorSetup == null)
{
_monitorSetup = Parent.GetMonitorForApp(this);
}
_monitorSetup ??= Parent.GetMonitorForApp(this);

return _monitorSetup;
}
Expand All @@ -271,7 +247,7 @@ public bool IsExpanded
}
}

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;

Expand All @@ -298,15 +274,5 @@ internal void CommandLineTextChanged(string newCommandLineValue)
CommandLineArguments = newCommandLineValue;
OnPropertyChanged(new PropertyChangedEventArgs(nameof(AppMainParams)));
}

internal void MaximizedChecked()
{
Minimized = false;
}

internal void MinimizedChecked()
{
Maximized = false;
}
}
}
24 changes: 7 additions & 17 deletions src/modules/Workspaces/WorkspacesEditor/Models/Monitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,18 @@

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 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;
}
public Rect MonitorDpiAwareBounds { get; private set; } = dpiAwareBounds;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ public void OnPropertyChanged(PropertyChangedEventArgs 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)
: base(monitorName, monitorInstanceId, number, dpi, dpiAwareBounds, dpiUnawareBounds)
Expand Down
Loading

0 comments on commit 89be43e

Please sign in to comment.