Skip to content

Remove WindowDecorationsHelper, fix theme in properties window #9966

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Sep 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions src/Files.App/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,6 @@ protected override async void OnLaunched(LaunchActivatedEventArgs e)
_ = InitializeAppComponentsAsync().ContinueWith(t => Logger.Warn(t.Exception, "Error during InitializeAppComponentsAsync()"), TaskContinuationOptions.OnlyOnFaulted);

await Window.InitializeApplication(activatedEventArgs);

WindowDecorationsHelper.RequestWindowDecorationsAccess();
}

private void EnsureWindowIsInitialized()
Expand Down
88 changes: 40 additions & 48 deletions src/Files.App/Helpers/FilePropertiesHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,65 +47,57 @@ public static async Task OpenPropertiesWindowAsync(object item, IShellPage assoc

if (ApiInformation.IsApiContractPresent("Windows.Foundation.UniversalApiContract", 8))
{
if (WindowDecorationsHelper.IsWindowDecorationsAllowed)
var frame = new Frame();
frame.RequestedTheme = ThemeHelper.RootTheme;
frame.Navigate(typeof(Properties), new PropertiesPageNavigationArguments()
{
var frame = new Frame();
frame.RequestedTheme = ThemeHelper.RootTheme;
frame.Navigate(typeof(Properties), new PropertiesPageNavigationArguments()
{
Item = item,
AppInstanceArgument = associatedInstance
}, new SuppressNavigationTransitionInfo());
Item = item,
AppInstanceArgument = associatedInstance
}, new SuppressNavigationTransitionInfo());

// Initialize window
var propertiesWindow = new WinUIEx.WindowEx()
{
IsMaximizable = false,
IsMinimizable = false
};
var appWindow = propertiesWindow.AppWindow;
// Initialize window
var propertiesWindow = new WinUIEx.WindowEx()
{
IsMaximizable = false,
IsMinimizable = false
};
var appWindow = propertiesWindow.AppWindow;

// Set icon
appWindow.SetIcon(Path.Combine(Package.Current.InstalledLocation.Path, "Assets/AppTiles/Dev/Logo.ico"));
// Set icon
appWindow.SetIcon(Path.Combine(Package.Current.InstalledLocation.Path, "Assets/AppTiles/Dev/Logo.ico"));

// Set content
propertiesWindow.Content = frame;
if (frame.Content is Properties properties)
properties.appWindow = appWindow;
// Set content
propertiesWindow.Content = frame;
if (frame.Content is Properties properties)
properties.appWindow = appWindow;

// Set min size
propertiesWindow.MinWidth = 460;
propertiesWindow.MinHeight = 550;
// Set min size
propertiesWindow.MinWidth = 460;
propertiesWindow.MinHeight = 550;

// Set backdrop
propertiesWindow.Backdrop = new WinUIEx.MicaSystemBackdrop() { DarkTintOpacity = 0.8 };
// Set backdrop
propertiesWindow.Backdrop = new WinUIEx.MicaSystemBackdrop() { DarkTintOpacity = 0.8 };

if (AppWindowTitleBar.IsCustomizationSupported())
{
appWindow.TitleBar.ExtendsContentIntoTitleBar = true;
appWindow.TitleBar.ExtendsContentIntoTitleBar = true;

// Set window buttons background to transparent
appWindow.TitleBar.ButtonBackgroundColor = Colors.Transparent;
appWindow.TitleBar.ButtonInactiveBackgroundColor = Colors.Transparent;
}
else
{
propertiesWindow.ExtendsContentIntoTitleBar = true;
}
// Set window buttons background to transparent
appWindow.TitleBar.ButtonBackgroundColor = Colors.Transparent;
appWindow.TitleBar.ButtonInactiveBackgroundColor = Colors.Transparent;

appWindow.Title = "PropertiesTitle".GetLocalizedResource();
appWindow.Resize(new SizeInt32(460, 550));
appWindow.Show();
appWindow.Title = "PropertiesTitle".GetLocalizedResource();
appWindow.Resize(new SizeInt32(460, 550));
appWindow.Show();

if (true) // WINUI3: move window to cursor position, todo better
{
UWPToWinAppSDKUpgradeHelpers.InteropHelpers.GetCursorPos(out var pointerPosition);
appWindow.Move(new PointInt32(pointerPosition.X, pointerPosition.Y));
}
}
else
if (true) // WINUI3: move window to cursor position
{
//WINUI3: no CoreApplicationView
UWPToWinAppSDKUpgradeHelpers.InteropHelpers.GetCursorPos(out var pointerPosition);
var displayArea = DisplayArea.GetFromPoint(new PointInt32(pointerPosition.X, pointerPosition.Y), DisplayAreaFallback.Nearest);
var appWindowPos = new PointInt32()
{
X = displayArea.WorkArea.X + Math.Max(0, Math.Min(displayArea.WorkArea.Width - appWindow.Size.Width, pointerPosition.X - displayArea.WorkArea.X)),
Y = displayArea.WorkArea.Y + Math.Max(0, Math.Min(displayArea.WorkArea.Height - appWindow.Size.Height, pointerPosition.Y - displayArea.WorkArea.Y))
};
appWindow.Move(appWindowPos);
}
}
else
Expand Down
5 changes: 1 addition & 4 deletions src/Files.App/Helpers/ThemeHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,7 @@ public static void Initialize()
currentApplicationWindow = App.Window;

// Set TitleBar background color
if (AppWindowTitleBar.IsCustomizationSupported())
{
titleBar = App.GetAppWindow(currentApplicationWindow).TitleBar;
}
titleBar = App.GetAppWindow(currentApplicationWindow).TitleBar;

// Apply the desired theme based on what is set in the application settings
ApplyTheme();
Expand Down
44 changes: 0 additions & 44 deletions src/Files.App/Helpers/WindowDecorationsHelper.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -337,10 +337,12 @@ public virtual async void OpenDirectoryInDefaultTerminal(RoutedEventArgs e)

public virtual void ShareItem(RoutedEventArgs e)
{
DataTransferManager manager = DataTransferManager.GetForCurrentView();
var interop = DataTransferManager.As<UWPToWinAppSDKUpgradeHelpers.IDataTransferManagerInterop>();
IntPtr result = interop.GetForWindow(App.WindowHandle, UWPToWinAppSDKUpgradeHelpers.InteropHelpers.DataTransferManagerInteropIID);
var manager = WinRT.MarshalInterface<DataTransferManager>.FromAbi(result);
manager.DataRequested += new TypedEventHandler<DataTransferManager, DataRequestedEventArgs>(Manager_DataRequested);

DataTransferManager.As<UWPToWinAppSDKUpgradeHelpers.IDataTransferManagerInterop>().ShowShareUIForWindow(App.WindowHandle);
interop.ShowShareUIForWindow(App.WindowHandle);

async void Manager_DataRequested(DataTransferManager sender, DataRequestedEventArgs args)
{
Expand Down
17 changes: 5 additions & 12 deletions src/Files.App/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,12 @@ private void EnsureEarlyWindow()
// Set icon
AppWindow.SetIcon(Path.Combine(Package.Current.InstalledLocation.Path, "Assets/AppTiles/Dev/Logo.ico"));

if (AppWindowTitleBar.IsCustomizationSupported())
{
// Extend title bar
AppWindow.TitleBar.ExtendsContentIntoTitleBar = true;
// Extend title bar
AppWindow.TitleBar.ExtendsContentIntoTitleBar = true;

// Set window buttons background to transparent
AppWindow.TitleBar.ButtonBackgroundColor = Colors.Transparent;
AppWindow.TitleBar.ButtonInactiveBackgroundColor = Colors.Transparent;
}
else
{
this.ExtendsContentIntoTitleBar = true;
}
// Set window buttons background to transparent
AppWindow.TitleBar.ButtonBackgroundColor = Colors.Transparent;
AppWindow.TitleBar.ButtonInactiveBackgroundColor = Colors.Transparent;

// Set min size
base.MinHeight = 328;
Expand Down
3 changes: 3 additions & 0 deletions src/Files.App/UWPToWinAppSDKUpgradeHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ IntPtr GetForWindow([In] IntPtr appWindow,

public static class InteropHelpers
{
public static readonly Guid DataTransferManagerInteropIID =
new Guid(0xa5caee9b, 0x8708, 0x49d1, 0x8d, 0x36, 0x67, 0xd2, 0x5a, 0x8d, 0xa0, 0x0c);

[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool GetCursorPos(out POINT point);
Expand Down
2 changes: 0 additions & 2 deletions src/Files.App/Views/MainPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
NavigationCacheMode="Required"
SizeChanged="Page_SizeChanged"
mc:Ignorable="d">
<!-- WINUI3 -->
<!-- BackdropMaterial.ApplyToRootOrPageBackground="False" -->

<Page.DataContext>
<viewmodels:MainPageViewModel />
Expand Down
33 changes: 0 additions & 33 deletions src/Files.App/Views/Pages/Properties.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,39 +36,6 @@
VerticalAlignment="Top"
Background="Transparent" />

<!-- WINUI3 -->
<!--<Grid
x:Name="AppWindowTitleBarCaptionButtonsGrid"
Grid.Row="0"
Height="32"
HorizontalAlignment="Right"
VerticalAlignment="Top"
x:Load="{x:Bind helpers:WindowDecorationsHelper.IsWindowDecorationsAllowed}"
Background="Transparent">
<Rectangle
x:Name="CloseRect"
Width="46"
VerticalAlignment="Stretch"
AutomationProperties.Name="{helpers:ResourceString Name=Close}"
Fill="Transparent"
PointerEntered="CloseRect_PointerEntered"
PointerExited="CloseRect_PointerExited"
PointerPressed="CloseRect_PointerPressed"
ToolTipService.ToolTip="{helpers:ResourceString Name=Close}" />
<Viewbox
Width="10"
Height="10"
IsHitTestVisible="False">
<PathIcon
x:Name="crossIcon"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Data="F1 M 11.416016 10 L 20 18.583984 L 18.583984 20 L 10 11.416016 L 1.416016 20 L 0 18.583984 L 8.583984 10 L 0 1.416016 L 1.416016 0 L 10 8.583984 L 18.583984 0 L 20 1.416016 Z "
Foreground="Black"
IsHitTestVisible="False" />
</Viewbox>
</Grid>-->

<NavigationView
x:Name="NavigationView"
Grid.Row="0"
Expand Down
Loading