From 5ab83c6ad20652d416459bf88bd095a75316bbbb Mon Sep 17 00:00:00 2001 From: Andrey Nekrasov Date: Wed, 15 Nov 2023 17:38:44 +0100 Subject: [PATCH 1/6] [CodeQuality]Fix C++ static analyzer findings (#29745) * [PVS] Fix static analyzer findings * f: fix error handling * f: more improvements * Update src/modules/FileLocksmith/FileLocksmithLibInterop/NtdllExtensions.cpp --- src/common/updating/pch.h | 3 ++- src/modules/CropAndLock/CropAndLock/main.cpp | 2 +- .../NtdllExtensions.cpp | 5 ++--- .../MeasureToolCore/MeasureToolOverlayUI.cpp | 2 -- .../fancyzones/FancyZonesLib/Settings.cpp | 2 +- .../fancyzones/FancyZonesLib/WindowUtils.cpp | 19 ++++++++----------- .../common/KeyboardEventHandlers.cpp | 3 +-- .../VideoConferenceModule/Toolbar.cpp | 2 +- .../VideoConferenceShared/Logging.cpp | 2 -- src/runner/settings_window.cpp | 6 +++--- 10 files changed, 19 insertions(+), 27 deletions(-) diff --git a/src/common/updating/pch.h b/src/common/updating/pch.h index 824630e52a..41408474c9 100644 --- a/src/common/updating/pch.h +++ b/src/common/updating/pch.h @@ -3,9 +3,10 @@ #ifndef PCH_H #define PCH_H +#pragma warning(push) #pragma warning(disable : 5205) #include -#pragma warning(default : 5205) +#pragma warning(pop) #define WIN32_LEAN_AND_MEAN #define NOMINMAX #include diff --git a/src/modules/CropAndLock/CropAndLock/main.cpp b/src/modules/CropAndLock/CropAndLock/main.cpp index 5945cd63ed..dc530b7769 100644 --- a/src/modules/CropAndLock/CropAndLock/main.cpp +++ b/src/modules/CropAndLock/CropAndLock/main.cpp @@ -188,7 +188,7 @@ int WINAPI wWinMain(_In_ HINSTANCE, _In_opt_ HINSTANCE, _In_ PWSTR lpCmdLine, _I m_reparent_event_handle = CreateEventW(nullptr, false, false, CommonSharedConstants::CROP_AND_LOCK_REPARENT_EVENT); m_thumbnail_event_handle = CreateEventW(nullptr, false, false, CommonSharedConstants::CROP_AND_LOCK_THUMBNAIL_EVENT); m_exit_event_handle = CreateEventW(nullptr, false, false, CommonSharedConstants::CROP_AND_LOCK_EXIT_EVENT); - if (!m_reparent_event_handle || !m_reparent_event_handle || !m_exit_event_handle) + if (!m_reparent_event_handle || !m_thumbnail_event_handle || !m_exit_event_handle) { Logger::warn(L"Failed to create events. {}", get_last_error_or_default(GetLastError())); return 1; diff --git a/src/modules/FileLocksmith/FileLocksmithLibInterop/NtdllExtensions.cpp b/src/modules/FileLocksmith/FileLocksmithLibInterop/NtdllExtensions.cpp index b85c512ee6..f731cfbee1 100644 --- a/src/modules/FileLocksmith/FileLocksmithLibInterop/NtdllExtensions.cpp +++ b/src/modules/FileLocksmith/FileLocksmithLibInterop/NtdllExtensions.cpp @@ -309,9 +309,8 @@ std::wstring NtdllExtensions::pid_to_user(DWORD pid) } DWORD token_size = 0; - GetTokenInformation(token, TokenUser, nullptr, 0, &token_size); - - if (token_size < 0) + const bool ok = GetTokenInformation(token, TokenUser, nullptr, 0, &token_size); + if ((!ok && GetLastError() != ERROR_INSUFFICIENT_BUFFER) || !token_size) { return user; } diff --git a/src/modules/MeasureTool/MeasureToolCore/MeasureToolOverlayUI.cpp b/src/modules/MeasureTool/MeasureToolCore/MeasureToolOverlayUI.cpp index 679234a77c..e44bdaf268 100644 --- a/src/modules/MeasureTool/MeasureToolCore/MeasureToolOverlayUI.cpp +++ b/src/modules/MeasureTool/MeasureToolCore/MeasureToolOverlayUI.cpp @@ -32,8 +32,6 @@ namespace winrt::com_ptr ConvertID3D11Texture2DToD2D1Bitmap(winrt::com_ptr rt, const MappedTextureView* capturedScreenTexture) { - capturedScreenTexture->view.pixels; - D2D1_BITMAP_PROPERTIES props = { .pixelFormat = rt->GetPixelFormat() }; rt->GetDpi(&props.dpiX, &props.dpiY); const auto sizeF = rt->GetSize(); diff --git a/src/modules/fancyzones/FancyZonesLib/Settings.cpp b/src/modules/fancyzones/FancyZonesLib/Settings.cpp index c794bc116e..51d9b52846 100644 --- a/src/modules/fancyzones/FancyZonesLib/Settings.cpp +++ b/src/modules/fancyzones/FancyZonesLib/Settings.cpp @@ -238,7 +238,7 @@ void FancyZonesSettings::LoadSettings() if (auto val = values.get_int_value(NonLocalizable::OverlappingZonesAlgorithmID)) { // Avoid undefined behavior - if (*val >= 0 || *val < static_cast(OverlappingZonesAlgorithm::EnumElements)) + if (*val >= 0 && *val < static_cast(OverlappingZonesAlgorithm::EnumElements)) { auto algorithm = (OverlappingZonesAlgorithm)*val; if (m_settings.overlappingZonesAlgorithm != algorithm) diff --git a/src/modules/fancyzones/FancyZonesLib/WindowUtils.cpp b/src/modules/fancyzones/FancyZonesLib/WindowUtils.cpp index ec246180fd..8d83a7cab7 100644 --- a/src/modules/fancyzones/FancyZonesLib/WindowUtils.cpp +++ b/src/modules/fancyzones/FancyZonesLib/WindowUtils.cpp @@ -306,26 +306,23 @@ void FancyZonesWindowUtils::SizeWindowToRect(HWND window, RECT rect) noexcept ::GetWindowPlacement(window, &placement); } - if (!IsWindowVisible(window)) - { - placement.showCmd = SW_HIDE; - } - else + if (IsWindowVisible(window)) { // Do not restore minimized windows. We change their placement though so they restore to the correct zone. if ((placement.showCmd != SW_SHOWMINIMIZED) && (placement.showCmd != SW_MINIMIZE)) { - placement.showCmd = SW_RESTORE; - } + // Remove maximized show command to make sure window is moved to the correct zone. + if (placement.showCmd == SW_SHOWMAXIMIZED) + placement.flags &= ~WPF_RESTORETOMAXIMIZED; - // Remove maximized show command to make sure window is moved to the correct zone. - if (placement.showCmd == SW_SHOWMAXIMIZED) - { placement.showCmd = SW_RESTORE; - placement.flags &= ~WPF_RESTORETOMAXIMIZED; } } + else + { + placement.showCmd = SW_HIDE; + } ScreenToWorkAreaCoords(window, rect); diff --git a/src/modules/keyboardmanager/common/KeyboardEventHandlers.cpp b/src/modules/keyboardmanager/common/KeyboardEventHandlers.cpp index 97487106ca..be965cab7a 100644 --- a/src/modules/keyboardmanager/common/KeyboardEventHandlers.cpp +++ b/src/modules/keyboardmanager/common/KeyboardEventHandlers.cpp @@ -12,8 +12,7 @@ namespace KeyboardEventHandlers // Num Lock's key state is applied before it is intercepted by low level keyboard hooks, so we have to manually set back the state when we suppress the key. This is done by sending an additional key up, key down set of messages. // We need 2 key events because after Num Lock is suppressed, key up to release num lock key and key down to revert the num lock state int key_count = 2; - LPINPUT keyEventList = new INPUT[size_t(key_count)](); - memset(keyEventList, 0, sizeof(keyEventList)); + LPINPUT keyEventList = new INPUT[size_t(key_count)]{}; // Use the suppress flag to ensure these are not intercepted by any remapped keys or shortcuts Helpers::SetKeyEvent(keyEventList, 0, INPUT_KEYBOARD, VK_NUMLOCK, KEYEVENTF_KEYUP, KeyboardManagerConstants::KEYBOARDMANAGER_SUPPRESS_FLAG); diff --git a/src/modules/videoconference/VideoConferenceModule/Toolbar.cpp b/src/modules/videoconference/VideoConferenceModule/Toolbar.cpp index aac13b3dec..0dabd58d9c 100644 --- a/src/modules/videoconference/VideoConferenceModule/Toolbar.cpp +++ b/src/modules/videoconference/VideoConferenceModule/Toolbar.cpp @@ -109,7 +109,7 @@ LRESULT Toolbar::WindowProcessMessages(HWND hwnd, UINT msg, WPARAM wparam, LPARA } case WM_DPICHANGED: { - UINT dpi = LOWORD(dpi); + UINT dpi = LOWORD(wparam); RECT* prcNewWindow = reinterpret_cast(lparam); POINT suggestedPosition; diff --git a/src/modules/videoconference/VideoConferenceShared/Logging.cpp b/src/modules/videoconference/VideoConferenceShared/Logging.cpp index 45f643fa12..faeab04bb5 100644 --- a/src/modules/videoconference/VideoConferenceShared/Logging.cpp +++ b/src/modules/videoconference/VideoConferenceShared/Logging.cpp @@ -99,8 +99,6 @@ std::string toMediaTypeString(GUID subtype) return "MFVideoFormat_D16"; else if (subtype == MFVideoFormat_AYUV) return "MFVideoFormat_AYUV"; - else if (subtype == MFVideoFormat_YUY2) - return "MFVideoFormat_YUY2"; else if (subtype == MFVideoFormat_YVYU) return "MFVideoFormat_YVYU"; else if (subtype == MFVideoFormat_YVU9) diff --git a/src/runner/settings_window.cpp b/src/runner/settings_window.cpp index 86a6f25c13..a834748986 100644 --- a/src/runner/settings_window.cpp +++ b/src/runner/settings_window.cpp @@ -616,10 +616,10 @@ void close_settings_window() { if (g_settings_process_id != 0) { - HANDLE proc = OpenProcess(PROCESS_TERMINATE, false, g_settings_process_id); - if (proc != INVALID_HANDLE_VALUE) + wil::unique_handle proc{ OpenProcess(PROCESS_TERMINATE, false, g_settings_process_id) }; + if (proc) { - TerminateProcess(proc, 0); + TerminateProcess(proc.get(), 0); } } } From 1f4eff4a5df524d83de9c0bd8460b22c964ff3ab Mon Sep 17 00:00:00 2001 From: Aaron Junker Date: Thu, 16 Nov 2023 00:46:52 +0100 Subject: [PATCH 2/6] Add bot trigger for contribution thread (#28221) --- .github/policies/resourceManagement.yml | 9 +++++++++ CONTRIBUTING.md | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/.github/policies/resourceManagement.yml b/.github/policies/resourceManagement.yml index 0a9e925b94..f41817bbf6 100644 --- a/.github/policies/resourceManagement.yml +++ b/.github/policies/resourceManagement.yml @@ -233,5 +233,14 @@ configuration: - addReply: reply: Hi! Thanks for making us aware of the problem. We raised the issue with our internal localization team. This issue should be fixed hopefully in the next version of PowerToys. description: + - if: + - payloadType: Issue_Comment + - commentContains: + pattern: 'I would [like|love] [to help|helping|to contribute|contributing|to implement|implementing|to fix|fixing]' + isRegex: True + then: + - addReply: + reply: Hi! Your last comment indicates to our system, that you might want to contribute to this feature/fix this bug. Thank you! Please make us aware on our ["Would you like to contribute to PowerToys?" thread](https://github.com/microsoft/PowerToys/issues/28769), as we don't see all the comments.

_I'm a bot (beep!) so please excuse any mistakes I may make_ + description: onFailure: onSuccess: diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 01d1400264..43eb58e7e0 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -31,7 +31,7 @@ Upvote the original issue by clicking its [+😊] button and hitting 👍 (+1) i ## Contributing fixes / features -Please comment on an issue to let us know you're interested in working on something before you start the work. Not only does this avoid multiple people unexpectedly working on the same thing at the same time but it enables us to make sure everyone is clear on what should be done to implement any new functionality. It's less work for everyone, in the long run, to establish this up front. +Please comment on [our "Would you like to contribute to PowerToys?" thread](https://github.com/microsoft/PowerToys/issues/28769) to let us know you're interested in working on something before you start the work. Not only does this avoid multiple people unexpectedly working on the same thing at the same time but it enables us to make sure everyone is clear on what should be done to implement any new functionality. It's less work for everyone, in the long run, to establish this up front. ### Localization issues From 468e55c7e1b08b0e29f2ab184c708c4c582f1c84 Mon Sep 17 00:00:00 2001 From: Clint Rutkas Date: Thu, 16 Nov 2023 07:14:13 -0800 Subject: [PATCH 3/6] [Spellcheck] Remove unneeded entries from expect.txt (#29872) --- .github/actions/spell-check/expect.txt | 6 ------ 1 file changed, 6 deletions(-) diff --git a/.github/actions/spell-check/expect.txt b/.github/actions/spell-check/expect.txt index f27fd385b4..2965a4f3d8 100644 --- a/.github/actions/spell-check/expect.txt +++ b/.github/actions/spell-check/expect.txt @@ -610,7 +610,6 @@ findfast firefox FIXEDFILEINFO flyout -flyouts FOF FOFX FOLDERID @@ -985,7 +984,6 @@ lmcons LMEM LMENU lnk -lnks LOADFROMFILE LOBYTE LOCALAPPDATA @@ -1628,7 +1626,6 @@ renamable RENAMEONCOLLISION Renamer reparent -reparented reparenting reparse reportbug @@ -1722,7 +1719,6 @@ Scode scoobe SCOPEID screenshot -screenshots scrollviewer sddl SDKDDK @@ -1805,7 +1801,6 @@ sia SIATTRIBFLAGS SICHINT sid -SIDs siex sigdn SIGNINGSCENARIO @@ -2176,7 +2171,6 @@ webpage websearch webserver website -websites wekyb Wevtapi wgpocpl From 412550abcd2f42bf8682588d75b190eb5ba2cfc7 Mon Sep 17 00:00:00 2001 From: Niels Laute Date: Thu, 16 Nov 2023 17:37:21 +0100 Subject: [PATCH 4/6] [Deps]Upgrade WpfUI to preview.9 and fix Windows 10 background issue (#29884) * Bumping to preview9 --- Directory.Packages.props | 2 +- NOTICE.md | 2 +- src/common/Common.UI/OSVersionHelper.cs | 16 ++++++++++++++++ .../imageresizer/ui/Views/MainWindow.xaml | 1 - .../imageresizer/ui/Views/MainWindow.xaml.cs | 13 ++++++++++++- .../Settings.UI.Library/Utilities/Helper.cs | 5 ----- .../ViewModels/AlwaysOnTopViewModel.cs | 3 ++- .../ViewModels/FancyZonesViewModel.cs | 3 ++- .../ViewModels/Flyout/FlyoutViewModel.cs | 3 ++- 9 files changed, 36 insertions(+), 12 deletions(-) create mode 100644 src/common/Common.UI/OSVersionHelper.cs diff --git a/Directory.Packages.props b/Directory.Packages.props index 97db311ce0..185b6c2159 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -74,7 +74,7 @@ - + diff --git a/NOTICE.md b/NOTICE.md index b55b8c9f0f..0396e96d8c 100644 --- a/NOTICE.md +++ b/NOTICE.md @@ -1332,5 +1332,5 @@ EXHIBIT A -Mozilla Public License. - Vanara.PInvoke.Shell32 3.4.11 - Vanara.PInvoke.User32 3.4.11 - WinUIEx 2.2.0 -- WPF-UI 3.0.0-preview.4 +- WPF-UI 3.0.0-preview.9 diff --git a/src/common/Common.UI/OSVersionHelper.cs b/src/common/Common.UI/OSVersionHelper.cs new file mode 100644 index 0000000000..8823ceaf85 --- /dev/null +++ b/src/common/Common.UI/OSVersionHelper.cs @@ -0,0 +1,16 @@ +// 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; + +namespace Common.UI +{ + public static class OSVersionHelper + { + public static bool IsWindows11() + { + return Environment.OSVersion.Version.Major >= 10 && Environment.OSVersion.Version.Build >= 22000; + } + } +} diff --git a/src/modules/imageresizer/ui/Views/MainWindow.xaml b/src/modules/imageresizer/ui/Views/MainWindow.xaml index 3627e68d4a..72a5120710 100644 --- a/src/modules/imageresizer/ui/Views/MainWindow.xaml +++ b/src/modules/imageresizer/ui/Views/MainWindow.xaml @@ -16,7 +16,6 @@ ExtendsContentIntoTitleBar="True" Icon="/PowerToys.ImageResizer;component/Resources/ImageResizer.ico" ResizeMode="NoResize" - WindowBackdropType="Mica" WindowCornerPreference="Default" WindowStartupLocation="CenterScreen"> diff --git a/src/modules/imageresizer/ui/Views/MainWindow.xaml.cs b/src/modules/imageresizer/ui/Views/MainWindow.xaml.cs index 0c96ed12a7..9a6dfc15b1 100644 --- a/src/modules/imageresizer/ui/Views/MainWindow.xaml.cs +++ b/src/modules/imageresizer/ui/Views/MainWindow.xaml.cs @@ -5,6 +5,7 @@ using System; using System.Collections.Generic; using System.Linq; +using Common.UI; using ImageResizer.ViewModels; using Microsoft.Win32; using Wpf.Ui.Controls; @@ -17,7 +18,17 @@ namespace ImageResizer.Views public MainWindow(MainViewModel viewModel) { DataContext = viewModel; - Wpf.Ui.Appearance.Watcher.Watch(this); + Wpf.Ui.Appearance.SystemThemeWatcher.Watch(this); + + if (OSVersionHelper.IsWindows11()) + { + WindowBackdropType = WindowBackdropType.Mica; + } + else + { + WindowBackdropType = WindowBackdropType.None; + } + InitializeComponent(); } diff --git a/src/settings-ui/Settings.UI.Library/Utilities/Helper.cs b/src/settings-ui/Settings.UI.Library/Utilities/Helper.cs index 7c4070b209..4f75ae6a25 100644 --- a/src/settings-ui/Settings.UI.Library/Utilities/Helper.cs +++ b/src/settings-ui/Settings.UI.Library/Utilities/Helper.cs @@ -150,10 +150,5 @@ namespace Microsoft.PowerToys.Settings.UI.Library.Utilities } public const uint VirtualKeyWindows = interop.Constants.VK_WIN_BOTH; - - public static bool Windows11() - { - return Environment.OSVersion.Version.Major >= 10 && Environment.OSVersion.Version.Build >= 22000; - } } } diff --git a/src/settings-ui/Settings.UI/ViewModels/AlwaysOnTopViewModel.cs b/src/settings-ui/Settings.UI/ViewModels/AlwaysOnTopViewModel.cs index 184ef0d600..8df6bfa896 100644 --- a/src/settings-ui/Settings.UI/ViewModels/AlwaysOnTopViewModel.cs +++ b/src/settings-ui/Settings.UI/ViewModels/AlwaysOnTopViewModel.cs @@ -6,6 +6,7 @@ using System; using System.Globalization; using System.Runtime.CompilerServices; using System.Text.Json; +using Common.UI; using global::PowerToys.GPOWrapper; using Microsoft.PowerToys.Settings.UI.Library; using Microsoft.PowerToys.Settings.UI.Library.Helpers; @@ -61,7 +62,7 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels _doNotActivateOnGameMode = Settings.Properties.DoNotActivateOnGameMode.Value; _roundCornersEnabled = Settings.Properties.RoundCornersEnabled.Value; _excludedApps = Settings.Properties.ExcludedApps.Value; - _windows11 = Helper.Windows11(); + _windows11 = OSVersionHelper.IsWindows11(); // set the callback functions value to handle outgoing IPC message. SendConfigMSG = ipcMSGCallBackFunc; diff --git a/src/settings-ui/Settings.UI/ViewModels/FancyZonesViewModel.cs b/src/settings-ui/Settings.UI/ViewModels/FancyZonesViewModel.cs index 428730370c..2ce6a47b52 100644 --- a/src/settings-ui/Settings.UI/ViewModels/FancyZonesViewModel.cs +++ b/src/settings-ui/Settings.UI/ViewModels/FancyZonesViewModel.cs @@ -4,6 +4,7 @@ using System; using System.Runtime.CompilerServices; +using Common.UI; using global::PowerToys.GPOWrapper; using Microsoft.PowerToys.Settings.UI.Library; using Microsoft.PowerToys.Settings.UI.Library.Helpers; @@ -119,7 +120,7 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels InitializeEnabledValue(); - _windows11 = Helper.Windows11(); + _windows11 = OSVersionHelper.IsWindows11(); // Disable setting on windows 10 if (!_windows11 && DisableRoundCornersOnWindowSnap) diff --git a/src/settings-ui/Settings.UI/ViewModels/Flyout/FlyoutViewModel.cs b/src/settings-ui/Settings.UI/ViewModels/Flyout/FlyoutViewModel.cs index d97237c43f..4b77b1dce6 100644 --- a/src/settings-ui/Settings.UI/ViewModels/Flyout/FlyoutViewModel.cs +++ b/src/settings-ui/Settings.UI/ViewModels/Flyout/FlyoutViewModel.cs @@ -6,6 +6,7 @@ using System; using System.ComponentModel; using System.Runtime.CompilerServices; using System.Timers; +using Common.UI; using Microsoft.PowerToys.Settings.UI.Library.Utilities; namespace Microsoft.PowerToys.Settings.UI.ViewModels.Flyout @@ -39,7 +40,7 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels.Flyout _hideTimer.Elapsed += HideTimer_Elapsed; _hideTimer.Interval = 1000; _hideTimer.Enabled = false; - _windows10 = !Helper.Windows11(); + _windows10 = !OSVersionHelper.IsWindows11(); } private void HideTimer_Elapsed(object sender, ElapsedEventArgs e) From 7e0f69f7d4f8a018b7fff0f0bd1babb063800b40 Mon Sep 17 00:00:00 2001 From: Niels Laute Date: Thu, 16 Nov 2023 18:06:22 +0100 Subject: [PATCH 5/6] [TextExtractor]WpfUI, Localization and light theme support (#29861) * Remove custom styles * Update OCROverlay.xaml * Bump WPfUI version number * Adding localization and improved toolbar styling * Updating icons * XAML styler * Update MainWindow.xaml.cs * Fix NOTICE.md --- src/modules/PowerOCR/PowerOCR/App.xaml | 2 - src/modules/PowerOCR/PowerOCR/OCROverlay.xaml | 90 +-- .../PowerOCR/PowerOCR/OCROverlay.xaml.cs | 2 +- src/modules/PowerOCR/PowerOCR/PowerOCR.csproj | 16 + .../PowerOCR/Properties/Resources.Designer.cs | 135 ++++ .../PowerOCR/Properties/Resources.resx | 147 ++++ .../PowerOCR/Styles/ButtonStyles.xaml | 695 ------------------ .../PowerOCR/PowerOCR/Styles/Colors.xaml | 6 - 8 files changed, 338 insertions(+), 755 deletions(-) create mode 100644 src/modules/PowerOCR/PowerOCR/Properties/Resources.Designer.cs create mode 100644 src/modules/PowerOCR/PowerOCR/Properties/Resources.resx delete mode 100644 src/modules/PowerOCR/PowerOCR/Styles/ButtonStyles.xaml delete mode 100644 src/modules/PowerOCR/PowerOCR/Styles/Colors.xaml diff --git a/src/modules/PowerOCR/PowerOCR/App.xaml b/src/modules/PowerOCR/PowerOCR/App.xaml index a8dcd7c7a0..2831d1d4f3 100644 --- a/src/modules/PowerOCR/PowerOCR/App.xaml +++ b/src/modules/PowerOCR/PowerOCR/App.xaml @@ -12,8 +12,6 @@ - - diff --git a/src/modules/PowerOCR/PowerOCR/OCROverlay.xaml b/src/modules/PowerOCR/PowerOCR/OCROverlay.xaml index c22453aae1..100b5de9ef 100644 --- a/src/modules/PowerOCR/PowerOCR/OCROverlay.xaml +++ b/src/modules/PowerOCR/PowerOCR/OCROverlay.xaml @@ -3,12 +3,13 @@ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" - xmlns:local="clr-namespace:PowerOCR" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + xmlns:p="clr-namespace:PowerOCR.Properties" xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml" Title="TextExtractor" Width="200" Height="200" + ui:Design.Background="Transparent" AllowsTransparency="True" Background="Transparent" Loaded="Window_Loaded" @@ -23,19 +24,22 @@ mc:Ignorable="d"> - - @@ -70,23 +74,23 @@ + Header="{x:Static p:Resources.Settings}" /> + Header="{x:Static p:Resources.Cancel}" /> @@ -96,7 +100,6 @@ Padding="4,8,12,8" HorizontalAlignment="Center" VerticalAlignment="Top" - d:Background="White" d:Visibility="Visible" Background="{DynamicResource ApplicationBackgroundBrush}" CornerRadius="8" @@ -104,75 +107,60 @@ + Opacity="0.28" + RenderingBias="Performance" + ShadowDepth="1" /> + - + ToolTip="{x:Static p:Resources.ResultTextSingleLineShortcut}"> + - + ToolTip="{x:Static p:Resources.ResultTextTableShortcut}"> + diff --git a/src/modules/PowerOCR/PowerOCR/OCROverlay.xaml.cs b/src/modules/PowerOCR/PowerOCR/OCROverlay.xaml.cs index e79d0d3ea4..60ec8b3a3a 100644 --- a/src/modules/PowerOCR/PowerOCR/OCROverlay.xaml.cs +++ b/src/modules/PowerOCR/PowerOCR/OCROverlay.xaml.cs @@ -49,7 +49,7 @@ public partial class OCROverlay : Window Top = screenRectangle.Top >= 0 ? screenRectangle.Top : screenRectangle.Top + (screenRectangle.Height / 2); InitializeComponent(); - + Wpf.Ui.Appearance.SystemThemeWatcher.Watch(this, Wpf.Ui.Controls.WindowBackdropType.None); PopulateLanguageMenu(); } diff --git a/src/modules/PowerOCR/PowerOCR/PowerOCR.csproj b/src/modules/PowerOCR/PowerOCR/PowerOCR.csproj index 5b59ab9ef8..4116b0889c 100644 --- a/src/modules/PowerOCR/PowerOCR/PowerOCR.csproj +++ b/src/modules/PowerOCR/PowerOCR/PowerOCR.csproj @@ -61,4 +61,20 @@ + + + + True + True + Resources.resx + + + + + + PublicResXFileCodeGenerator + Resources.Designer.cs + Designer + + diff --git a/src/modules/PowerOCR/PowerOCR/Properties/Resources.Designer.cs b/src/modules/PowerOCR/PowerOCR/Properties/Resources.Designer.cs new file mode 100644 index 0000000000..f50fd9ff68 --- /dev/null +++ b/src/modules/PowerOCR/PowerOCR/Properties/Resources.Designer.cs @@ -0,0 +1,135 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace PowerOCR.Properties { + using System; + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + public class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + public static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("PowerOCR.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + public static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// + /// Looks up a localized string similar to Cancel. + /// + public static string Cancel { + get { + return ResourceManager.GetString("Cancel", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Cancel (Esc). + /// + public static string CancelShortcut { + get { + return ResourceManager.GetString("CancelShortcut", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Format result as a single line. + /// + public static string ResultTextSingleLine { + get { + return ResourceManager.GetString("ResultTextSingleLine", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Format result as a single line (S). + /// + public static string ResultTextSingleLineShortcut { + get { + return ResourceManager.GetString("ResultTextSingleLineShortcut", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Format result as a table. + /// + public static string ResultTextTable { + get { + return ResourceManager.GetString("ResultTextTable", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Format result as a table (T). + /// + public static string ResultTextTableShortcut { + get { + return ResourceManager.GetString("ResultTextTableShortcut", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Selected language. + /// + public static string SelectedLang { + get { + return ResourceManager.GetString("SelectedLang", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Settings. + /// + public static string Settings { + get { + return ResourceManager.GetString("Settings", resourceCulture); + } + } + } +} diff --git a/src/modules/PowerOCR/PowerOCR/Properties/Resources.resx b/src/modules/PowerOCR/PowerOCR/Properties/Resources.resx new file mode 100644 index 0000000000..df6947f018 --- /dev/null +++ b/src/modules/PowerOCR/PowerOCR/Properties/Resources.resx @@ -0,0 +1,147 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Cancel + + + Cancel (Esc) + (Esc) indicates the keyboard shortcut + + + Format result as a single line + + + Format result as a single line (S) + (S) indicates the keyboard shortcut + + + Format result as a table + + + Format result as a table (T) + (T) indicates the keyboard shortcut + + + Selected language + + + Settings + + \ No newline at end of file diff --git a/src/modules/PowerOCR/PowerOCR/Styles/ButtonStyles.xaml b/src/modules/PowerOCR/PowerOCR/Styles/ButtonStyles.xaml deleted file mode 100644 index fab21fb3ee..0000000000 --- a/src/modules/PowerOCR/PowerOCR/Styles/ButtonStyles.xaml +++ /dev/null @@ -1,695 +0,0 @@ - - - - - - - - - - - - - - M 0,0 L 3.5,4 L 7,0 Z - M 0,4 L 3.5,0 L 7,4 Z - M 0,0 L 4,3.5 L 0,7 Z - F1 M 10.0,1.2 L 4.7,9.1 L 4.5,9.1 L 0,5.2 L 1.3,3.5 L 4.3,6.1L 8.3,0 L 10.0,1.2 Z - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/modules/PowerOCR/PowerOCR/Styles/Colors.xaml b/src/modules/PowerOCR/PowerOCR/Styles/Colors.xaml deleted file mode 100644 index 97fa005753..0000000000 --- a/src/modules/PowerOCR/PowerOCR/Styles/Colors.xaml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file From 7d9681ecd2533e63a13ac3a88257e698b9c7b5a9 Mon Sep 17 00:00:00 2001 From: Niels Laute Date: Thu, 16 Nov 2023 18:40:04 +0100 Subject: [PATCH 6/6] [QuickAccent]Move from ModernWPF to WpfUi (#29863) * Updating to WpfUI * XAML styler * Removing unused namespaces * Updating ImageResizer watcher --- .../poweraccent/PowerAccent.UI/App.xaml | 7 +- .../poweraccent/PowerAccent.UI/App.xaml.cs | 5 - .../PowerAccent.UI/PowerAccent.UI.csproj | 2 +- .../poweraccent/PowerAccent.UI/Program.cs | 1 - .../poweraccent/PowerAccent.UI/Selector.xaml | 180 ++++++++---------- .../PowerAccent.UI/Selector.xaml.cs | 17 +- .../PowerAccent.UI/Themes/Dark.xaml | 32 ---- .../PowerAccent.UI/Themes/HighContrast1.xaml | 26 --- .../PowerAccent.UI/Themes/HighContrast2.xaml | 26 --- .../Themes/HighContrastBlack.xaml | 26 --- .../Themes/HighContrastWhite.xaml | 26 --- .../PowerAccent.UI/Themes/Light.xaml | 35 ---- 12 files changed, 91 insertions(+), 292 deletions(-) delete mode 100644 src/modules/poweraccent/PowerAccent.UI/Themes/Dark.xaml delete mode 100644 src/modules/poweraccent/PowerAccent.UI/Themes/HighContrast1.xaml delete mode 100644 src/modules/poweraccent/PowerAccent.UI/Themes/HighContrast2.xaml delete mode 100644 src/modules/poweraccent/PowerAccent.UI/Themes/HighContrastBlack.xaml delete mode 100644 src/modules/poweraccent/PowerAccent.UI/Themes/HighContrastWhite.xaml delete mode 100644 src/modules/poweraccent/PowerAccent.UI/Themes/Light.xaml diff --git a/src/modules/poweraccent/PowerAccent.UI/App.xaml b/src/modules/poweraccent/PowerAccent.UI/App.xaml index abc58f7b3e..aabf3459af 100644 --- a/src/modules/poweraccent/PowerAccent.UI/App.xaml +++ b/src/modules/poweraccent/PowerAccent.UI/App.xaml @@ -2,15 +2,14 @@ x:Class="PowerAccent.UI.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" - xmlns:local="clr-namespace:PowerAccent" - xmlns:ui="http://schemas.modernwpf.com/2019" + xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml" StartupUri="Selector.xaml"> - - + + diff --git a/src/modules/poweraccent/PowerAccent.UI/App.xaml.cs b/src/modules/poweraccent/PowerAccent.UI/App.xaml.cs index af3ff38db9..1ae590ce88 100644 --- a/src/modules/poweraccent/PowerAccent.UI/App.xaml.cs +++ b/src/modules/poweraccent/PowerAccent.UI/App.xaml.cs @@ -5,9 +5,7 @@ using System; using System.Threading; using System.Windows; -using Common.UI; using ManagedCommon; -using PowerAccent.Core.Tools; namespace PowerAccent.UI { @@ -18,7 +16,6 @@ namespace PowerAccent.UI { private static Mutex _mutex; private bool _disposed; - private ThemeManager _themeManager; protected override void OnStartup(StartupEventArgs e) { @@ -30,7 +27,6 @@ namespace PowerAccent.UI Application.Current.Shutdown(); } - _themeManager = new ThemeManager(this); base.OnStartup(e); } @@ -50,7 +46,6 @@ namespace PowerAccent.UI if (disposing) { _mutex?.Dispose(); - _themeManager?.Dispose(); } _disposed = true; diff --git a/src/modules/poweraccent/PowerAccent.UI/PowerAccent.UI.csproj b/src/modules/poweraccent/PowerAccent.UI/PowerAccent.UI.csproj index b459272213..be88b83789 100644 --- a/src/modules/poweraccent/PowerAccent.UI/PowerAccent.UI.csproj +++ b/src/modules/poweraccent/PowerAccent.UI/PowerAccent.UI.csproj @@ -35,7 +35,7 @@ - + diff --git a/src/modules/poweraccent/PowerAccent.UI/Program.cs b/src/modules/poweraccent/PowerAccent.UI/Program.cs index 9ca3de95be..d45b7c601c 100644 --- a/src/modules/poweraccent/PowerAccent.UI/Program.cs +++ b/src/modules/poweraccent/PowerAccent.UI/Program.cs @@ -9,7 +9,6 @@ using System.Threading.Tasks; using System.Windows; using interop; using ManagedCommon; -using PowerAccent.Core.Tools; namespace PowerAccent.UI; diff --git a/src/modules/poweraccent/PowerAccent.UI/Selector.xaml b/src/modules/poweraccent/PowerAccent.UI/Selector.xaml index 1f30d628e2..1396528383 100644 --- a/src/modules/poweraccent/PowerAccent.UI/Selector.xaml +++ b/src/modules/poweraccent/PowerAccent.UI/Selector.xaml @@ -1,30 +1,30 @@ - - + @@ -33,101 +33,89 @@ - + - + + + + - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + - - - - - - + + + + - + \ No newline at end of file diff --git a/src/modules/poweraccent/PowerAccent.UI/Selector.xaml.cs b/src/modules/poweraccent/PowerAccent.UI/Selector.xaml.cs index f83e20c037..14df70a72f 100644 --- a/src/modules/poweraccent/PowerAccent.UI/Selector.xaml.cs +++ b/src/modules/poweraccent/PowerAccent.UI/Selector.xaml.cs @@ -5,13 +5,13 @@ using System; using System.ComponentModel; using System.Windows; -using PowerAccent.Core.Services; +using Wpf.Ui.Controls; using Point = PowerAccent.Core.Point; using Size = PowerAccent.Core.Size; namespace PowerAccent.UI; -public partial class Selector : Window, IDisposable, INotifyPropertyChanged +public partial class Selector : FluentWindow, IDisposable, INotifyPropertyChanged { private readonly Core.PowerAccent _powerAccent = new(); @@ -38,6 +38,7 @@ public partial class Selector : Window, IDisposable, INotifyPropertyChanged public Selector() { InitializeComponent(); + Wpf.Ui.Appearance.SystemThemeWatcher.Watch(this); Application.Current.MainWindow.ShowActivated = false; Application.Current.MainWindow.Topmost = true; } @@ -67,7 +68,6 @@ public partial class Selector : Window, IDisposable, INotifyPropertyChanged characters.SelectedIndex = _selectedIndex; this.UpdateLayout(); // Required for filling the actual width/height before positioning. SetWindowPosition(); - SetWindowAlignment(); Show(); Microsoft.PowerToys.Telemetry.PowerToysTelemetry.Log.WriteEvent(new PowerAccent.Core.Telemetry.PowerAccentShowAccentMenuEvent()); } @@ -90,17 +90,6 @@ public partial class Selector : Window, IDisposable, INotifyPropertyChanged this.Top = position.Y; } - private void SetWindowAlignment() - { - gridBorder.HorizontalAlignment = _powerAccent.GetToolbarPosition() switch - { - Position.Left or Position.TopLeft or Position.BottomLeft => HorizontalAlignment.Left, - Position.Right or Position.TopRight or Position.BottomRight => HorizontalAlignment.Right, - Position.Center or Position.Top or Position.Bottom => HorizontalAlignment.Center, - _ => HorizontalAlignment.Center, - }; - } - protected override void OnClosed(EventArgs e) { _powerAccent.Dispose(); diff --git a/src/modules/poweraccent/PowerAccent.UI/Themes/Dark.xaml b/src/modules/poweraccent/PowerAccent.UI/Themes/Dark.xaml deleted file mode 100644 index 07ed9f95ce..0000000000 --- a/src/modules/poweraccent/PowerAccent.UI/Themes/Dark.xaml +++ /dev/null @@ -1,32 +0,0 @@ - - - - Dark.Accent1 - PowerToysRun - Accent1 (Dark) - Dark - Accent1 - Black - - - - - - - - \ No newline at end of file diff --git a/src/modules/poweraccent/PowerAccent.UI/Themes/HighContrast1.xaml b/src/modules/poweraccent/PowerAccent.UI/Themes/HighContrast1.xaml deleted file mode 100644 index 42d269d7fe..0000000000 --- a/src/modules/poweraccent/PowerAccent.UI/Themes/HighContrast1.xaml +++ /dev/null @@ -1,26 +0,0 @@ - - - - HighContrast.Accent2 - PowerToysRun - Accent2 (HighContrast) - HighContrast - Accent2 - White - - - - - - - - \ No newline at end of file diff --git a/src/modules/poweraccent/PowerAccent.UI/Themes/HighContrast2.xaml b/src/modules/poweraccent/PowerAccent.UI/Themes/HighContrast2.xaml deleted file mode 100644 index 825f0267bf..0000000000 --- a/src/modules/poweraccent/PowerAccent.UI/Themes/HighContrast2.xaml +++ /dev/null @@ -1,26 +0,0 @@ - - - - HighContrast.Accent3 - PowerToysRun - Accent3 (HighContrast) - HighContrast - Accent3 - White - - - - - - - - \ No newline at end of file diff --git a/src/modules/poweraccent/PowerAccent.UI/Themes/HighContrastBlack.xaml b/src/modules/poweraccent/PowerAccent.UI/Themes/HighContrastBlack.xaml deleted file mode 100644 index eee95d5823..0000000000 --- a/src/modules/poweraccent/PowerAccent.UI/Themes/HighContrastBlack.xaml +++ /dev/null @@ -1,26 +0,0 @@ - - - - HighContrast.Accent4 - PowerToysRun - Accent4 (HighContrast) - HighContrast - Accent4 - White - - - - - - - - \ No newline at end of file diff --git a/src/modules/poweraccent/PowerAccent.UI/Themes/HighContrastWhite.xaml b/src/modules/poweraccent/PowerAccent.UI/Themes/HighContrastWhite.xaml deleted file mode 100644 index 5a9f6df8ab..0000000000 --- a/src/modules/poweraccent/PowerAccent.UI/Themes/HighContrastWhite.xaml +++ /dev/null @@ -1,26 +0,0 @@ - - - - HighContrast.Accent5 - PowerToysRun - Accent5 (HighContrast) - HighContrast - Accent5 - White - - - - - - - - \ No newline at end of file diff --git a/src/modules/poweraccent/PowerAccent.UI/Themes/Light.xaml b/src/modules/poweraccent/PowerAccent.UI/Themes/Light.xaml deleted file mode 100644 index 22f8213eee..0000000000 --- a/src/modules/poweraccent/PowerAccent.UI/Themes/Light.xaml +++ /dev/null @@ -1,35 +0,0 @@ - - - - Light.Accent1 - PowerToysRun - Accent1 (Light) - Light - Accent1 - White - - - - - - - - \ No newline at end of file