Skip to content

Commit

Permalink
Sync dev/imageResizer with master (#1105)
Browse files Browse the repository at this point in the history
* tweaking language

* adjusting elevated permission verbiage to match Windows

* npm audit fix to update stuff

* slight bump for fabric ui

* Remove unwanted files (#1037)

Add temp build files to gitignore

* Ensure previous search and replace texts are evaluated and updated in the UI at startup (#1043)

Ensure stored settings get evaluated after initial enumeration

There was a bug where the list view was not getting updated with the results of the search and replace on launch when we are using a stored search or replace text from a previous session.

* adding fancy zone opacity setting, enhancement #631 (#1008)

* adding fancy zone opacity setting, enhancement #631

* applying zone opacity setting to all zones during zone selection

* changing opacity setting to percentage

* runner: show message box when restarting with different elevation fails (#1061)

Also make the message box appear on top of the settings window.

* Fix misaligned display of zones in layout priview and grid editor (#1010)

Fix misaligned display of zones in layout preview and grid editor

* MSIX: Extract MSIX building functionality from msix_reinstall.ps1 to a separate script (#1068)

* MSIX: label PowerToys as Preview (#1090)

* MSIX: Code sign msixbundle (#1093)

* Update to MSIX README.md (#1095)

* Update README.md

few adjustments

* Update README.md

* Update README.md

* adding in privacy statement, removing About in dialog (#1087)

* adding in privacy statement, removing About in dialog

* added Preview

* Revert "Fix misaligned display of zones in layout priview and grid editor (#1010)" (#1097)

This reverts commit d03690c.

* Fix reversed order of zones in layout (#1071)

* Shifted three functions to common (#1101)

Co-authored-by: Clint Rutkas <[email protected]>
Co-authored-by: Enrico Giordani <[email protected]>
Co-authored-by: Chris Davis <[email protected]>
Co-authored-by: Yosef Durr <[email protected]>
Co-authored-by: Bartosz Sosnowski <[email protected]>
Co-authored-by: vldmr11080 <[email protected]>
Co-authored-by: yuyoyuppe <[email protected]>
  • Loading branch information
8 people committed Jan 18, 2020
1 parent f65b9fd commit db7f155
Show file tree
Hide file tree
Showing 41 changed files with 420 additions and 263 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -330,3 +330,7 @@ ASALocalRun/

# MFractors (Xamarin productivity tool) working folder
.mfractor/

# Temp build files
src/settings/settings-html/200.html
src/settings/settings-html/404.html
2 changes: 1 addition & 1 deletion installer/MSIX/appxmanifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
</Capabilities>
<Applications>
<Application Id="PowerToys" Executable="PowerToys.exe" EntryPoint="Windows.FullTrustApplication">
<uap:VisualElements DisplayName="PowerToys" Description="Windows system utilities to maximize productivity" Square150x150Logo="Images\logo150.png" Square44x44Logo="Images\logo44.png" BackgroundColor="transparent" />
<uap:VisualElements DisplayName="PowerToys (Preview)" Description="Windows system utilities to maximize productivity" Square150x150Logo="Images\logo150.png" Square44x44Logo="Images\logo44.png" BackgroundColor="transparent" />
<Extensions>
<uap5:Extension Category="windows.startupTask" Executable="PowerToys.exe" EntryPoint="Windows.FullTrustApplication">
<uap5:StartupTask TaskId="PowerToysStartupTaskID" Enabled="true" DisplayName="PowerToys" />
Expand Down
1 change: 1 addition & 0 deletions installer/MSIX/build_msix.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
makeappx build /v /overwrite /f PackagingLayout.xml /id "PowerToys-x64" /op bin\
7 changes: 6 additions & 1 deletion installer/MSIX/msix_reinstall.ps1
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
taskkill /f /im explorer.exe

Get-AppxPackage -Name 'PowerToys' | select -ExpandProperty "PackageFullName" | Remove-AppxPackage
makeappx build /v /overwrite /f PackagingLayout.xml /id "PowerToys-x64" /op bin\

.\build_msix.ps1
signtool sign /debug /a /fd SHA256 /f PowerToys_TemporaryKey.pfx /p 12345 bin\PowerToys-x64.msix
signtool sign /debug /a /fd SHA256 /f PowerToys_TemporaryKey.pfx /p 12345 bin\PowerToys.msixbundle

Add-AppxPackage .\bin\PowerToys-x64.msix

start $Env:windir\explorer.exe
17 changes: 12 additions & 5 deletions installer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,21 @@
* The resulting installer will be built to `PowerToysSetup\bin\Release\PowerToysSetup.msi`.

## Building and installing self-signed PowerToys MSIX package
For the first-time installation, you should generate a self-signed certificate and add it to the [TRCA store](https://docs.microsoft.com/en-us/windows-hardware/drivers/install/trusted-root-certification-authorities-certificate-store). That could be done by simply running `
generate_self_sign_cert.ps1` from a powershell admin. After that:
For the first-time installation, you'll need to generate a self-signed certificate. The script below will generate and add a cert to your [TRCA store](https://docs.microsoft.com/en-us/windows-hardware/drivers/install/trusted-root-certification-authorities-certificate-store).
1. Open `Developer PowerShell for VS` as an Admin
2. Navigate to your repo's `installer\MSIX`
3. Run `.\generate_self_sign_cert.ps1`

* Make sure you've built the `Release` configuration of `powertoys.sln`
* Launch `msix_reinstall.ps1` from the devenv powershell
## To Build
1. Make sure you've built the `Release` configuration of `powertoys.sln`
2. Open `Developer PowerShell for VS`
3. Navigate to your repo's `installer\MSIX`
4. Run `.\msix_reinstall.ps1` from the devenv powershell

### What msix_reinstall.ps1 does
`msix_reinstall.ps1` removes the current PowerToys installation, restarts explorer.exe (to update PowerRename shell extension), builds `PowerToys-x64.msix` package, signs it with a PowerToys_TemporaryKey.pfx, and finally installs it.
## Removing all .msi/.msix PowerToys installations

#### Removing all .msi/.msix PowerToys installations
```ps
$name='PowerToys'
Get-AppxPackage -Name $name | select -ExpandProperty "PackageFullName" | Remove-AppxPackage
Expand Down
27 changes: 27 additions & 0 deletions src/common/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,33 @@ bool run_non_elevated(const std::wstring& file, const std::wstring& params) {
return succedded;
}

bool run_same_elevation(const std::wstring& file, const std::wstring& params) {
auto executable_args = file;
if (!params.empty()) {
executable_args += L" " + params;
}
STARTUPINFO si = { 0 };
PROCESS_INFORMATION pi = { 0 };
auto succedded = CreateProcessW(file.c_str(),
const_cast<LPWSTR>(executable_args.c_str()),
nullptr,
nullptr,
FALSE,
0,
nullptr,
nullptr,
&si,
&pi);
if (pi.hProcess) {
CloseHandle(pi.hProcess);
}
if (pi.hThread) {
CloseHandle(pi.hThread);
}
return succedded;
}


std::wstring get_process_path(HWND window) noexcept {
const static std::wstring app_frame_host = L"ApplicationFrameHost.exe";
DWORD pid{};
Expand Down
3 changes: 3 additions & 0 deletions src/common/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ bool run_elevated(const std::wstring& file, const std::wstring& params);
// Run command as non-elevated user, returns true if succeeded
bool run_non_elevated(const std::wstring& file, const std::wstring& params);

// Run command with the same elevation, returns true if succedded
bool run_same_elevation(const std::wstring& file, const std::wstring& params);

// Get the executable path or module name for modern apps
std::wstring get_process_path(DWORD pid) noexcept;
// Get the executable path or module name for modern apps
Expand Down
4 changes: 4 additions & 0 deletions src/common/common.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@
<ClInclude Include="d2d_text.h" />
<ClInclude Include="d2d_window.h" />
<ClInclude Include="dpi_aware.h" />
<ClInclude Include="window_helpers.h" />
<ClInclude Include="icon_helpers.h" />
<ClInclude Include="hwnd_data_cache.h" />
<ClInclude Include="json.h" />
<ClInclude Include="monitors.h" />
Expand Down Expand Up @@ -130,10 +132,12 @@
</ClCompile>
<ClCompile Include="settings_helpers.cpp" />
<ClCompile Include="settings_objects.cpp" />
<ClCompile Include="icon_helpers.cpp" />
<ClCompile Include="start_visible.cpp" />
<ClCompile Include="tasklist_positions.cpp" />
<ClCompile Include="common.cpp" />
<ClCompile Include="windows_colors.cpp" />
<ClCompile Include="window_helpers.cpp" />
<ClCompile Include="winstore.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
Expand Down
12 changes: 12 additions & 0 deletions src/common/common.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@
<ClInclude Include="winstore.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="icon_helpers.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="window_helpers.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="d2d_svg.cpp">
Expand Down Expand Up @@ -132,5 +138,11 @@
<ClCompile Include="winstore.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="icon_helpers.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="window_helpers.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
</Project>
90 changes: 90 additions & 0 deletions src/common/icon_helpers.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#include "icon_helpers.h"
#include "pch.h"

HRESULT GetIconIndexFromPath(_In_ PCWSTR path, _Out_ int* index)
{
*index = 0;

HRESULT hr = E_FAIL;

SHFILEINFO shFileInfo = { 0 };

if (!PathIsRelative(path))
{
DWORD attrib = GetFileAttributes(path);
HIMAGELIST himl = (HIMAGELIST)SHGetFileInfo(path, attrib, &shFileInfo, sizeof(shFileInfo), (SHGFI_SYSICONINDEX | SHGFI_SMALLICON | SHGFI_USEFILEATTRIBUTES));
if (himl)
{
*index = shFileInfo.iIcon;
// We shouldn't free the HIMAGELIST.
hr = S_OK;
}
}

return hr;
}

HBITMAP CreateBitmapFromIcon(_In_ HICON hIcon, _In_opt_ UINT width, _In_opt_ UINT height)
{
HBITMAP hBitmapResult = NULL;

// Create compatible DC
HDC hDC = CreateCompatibleDC(NULL);
if (hDC != NULL)
{
// Get bitmap rectangle size
RECT rc = { 0 };
rc.left = 0;
rc.right = (width != 0) ? width : GetSystemMetrics(SM_CXSMICON);
rc.top = 0;
rc.bottom = (height != 0) ? height : GetSystemMetrics(SM_CYSMICON);

// Create bitmap compatible with DC
BITMAPINFO BitmapInfo;
ZeroMemory(&BitmapInfo, sizeof(BITMAPINFO));

BitmapInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
BitmapInfo.bmiHeader.biWidth = rc.right;
BitmapInfo.bmiHeader.biHeight = rc.bottom;
BitmapInfo.bmiHeader.biPlanes = 1;
BitmapInfo.bmiHeader.biBitCount = 32;
BitmapInfo.bmiHeader.biCompression = BI_RGB;

HDC hDCBitmap = GetDC(NULL);

HBITMAP hBitmap = CreateDIBSection(hDCBitmap, &BitmapInfo, DIB_RGB_COLORS, NULL, NULL, 0);

ReleaseDC(NULL, hDCBitmap);

if (hBitmap != NULL)
{
// Select bitmap into DC
HBITMAP hBitmapOld = (HBITMAP)SelectObject(hDC, hBitmap);
if (hBitmapOld != NULL)
{
// Draw icon into DC
if (DrawIconEx(hDC, 0, 0, hIcon, rc.right, rc.bottom, 0, NULL, DI_NORMAL))
{
// Restore original bitmap in DC
hBitmapResult = (HBITMAP)SelectObject(hDC, hBitmapOld);
hBitmapOld = NULL;
hBitmap = NULL;
}

if (hBitmapOld != NULL)
{
SelectObject(hDC, hBitmapOld);
}
}

if (hBitmap != NULL)
{
DeleteObject(hBitmap);
}
}

DeleteDC(hDC);
}

return hBitmapResult;
}
5 changes: 5 additions & 0 deletions src/common/icon_helpers.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#pragma once
#include "common.h"

HRESULT GetIconIndexFromPath(_In_ PCWSTR path, _Out_ int* index);
HBITMAP CreateBitmapFromIcon(_In_ HICON hIcon, _In_opt_ UINT width = 0, _In_opt_ UINT height = 0);
30 changes: 30 additions & 0 deletions src/common/window_helpers.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include "window_helpers.h"
#include "pch.h"

HWND CreateMsgWindow(_In_ HINSTANCE hInst, _In_ WNDPROC pfnWndProc, _In_ void* p)
{
WNDCLASS wc = { 0 };

PCWSTR wndClassName = L"MsgWindow";

wc.lpfnWndProc = DefWindowProc;
wc.cbWndExtra = sizeof(void*);
wc.hInstance = hInst;
wc.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
wc.lpszClassName = wndClassName;

RegisterClass(&wc);

HWND hwnd = CreateWindowEx(
0, wndClassName, nullptr, 0, 0, 0, 0, 0, HWND_MESSAGE, 0, hInst, nullptr);
if (hwnd)
{
SetWindowLongPtr(hwnd, 0, (LONG_PTR)p);
if (pfnWndProc)
{
SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR)pfnWndProc);
}
}

return hwnd;
}
4 changes: 4 additions & 0 deletions src/common/window_helpers.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#pragma once
#include "common.h"

HWND CreateMsgWindow(_In_ HINSTANCE hInst, _In_ WNDPROC pfnWndProc, _In_ void* p);
7 changes: 5 additions & 2 deletions src/modules/fancyzones/lib/FancyZones.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ struct FancyZones : public winrt::implements<FancyZones, IFancyZones, IFancyZone
}
return GUID_NULL;
}
IFACEMETHODIMP_(int) GetZoneHighlightOpacity() noexcept
{
return m_settings->GetSettings().zoneHighlightOpacity;
}

LRESULT WndProc(HWND, UINT, WPARAM, LPARAM) noexcept;
void OnDisplayChange(DisplayChangeType changeType) noexcept;
Expand Down Expand Up @@ -321,7 +325,6 @@ void FancyZones::ToggleEditor() noexcept
monitor = MonitorFromWindow(foregroundWindow, MONITOR_DEFAULTTOPRIMARY);
}


if (!monitor)
{
return;
Expand Down Expand Up @@ -352,7 +355,7 @@ void FancyZones::ToggleEditor() noexcept

const auto taskbar_x_offset = MulDiv(mi.rcWork.left - mi.rcMonitor.left, DPIAware::DEFAULT_DPI, dpi_x);
const auto taskbar_y_offset = MulDiv(mi.rcWork.top - mi.rcMonitor.top, DPIAware::DEFAULT_DPI, dpi_y);

// Do not scale window params by the dpi, that will be done in the editor - see LayoutModel.Apply
const auto x = mi.rcMonitor.left + taskbar_x_offset;
const auto y = mi.rcMonitor.top + taskbar_y_offset;
Expand Down
1 change: 1 addition & 0 deletions src/modules/fancyzones/lib/FancyZones.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ interface __declspec(uuid("{5C8D99D6-34B2-4F4A-A8E5-7483F6869775}")) IZoneWindow
IFACEMETHOD_(void, MoveWindowsOnActiveZoneSetChange)() = 0;
IFACEMETHOD_(COLORREF, GetZoneHighlightColor)() = 0;
IFACEMETHOD_(GUID, GetCurrentMonitorZoneSetId)(HMONITOR monitor) = 0;
IFACEMETHOD_(int, GetZoneHighlightOpacity)() = 0;
};

winrt::com_ptr<IFancyZones> MakeFancyZones(HINSTANCE hinstance, IFancyZonesSettings* settings) noexcept;
8 changes: 8 additions & 0 deletions src/modules/fancyzones/lib/Settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ struct FancyZonesSettings : winrt::implements<FancyZonesSettings, IFancyZonesSet
const std::wstring m_zoneHiglightName = L"fancyzones_zoneHighlightColor";
const std::wstring m_editorHotkeyName = L"fancyzones_editor_hotkey";
const std::wstring m_excludedAppsName = L"fancyzones_excluded_apps";
const std::wstring m_zoneHighlightOpacity = L"fancyzones_highlight_opacity";
};

IFACEMETHODIMP_(bool) FancyZonesSettings::GetConfig(_Out_ PWSTR buffer, _Out_ int *buffer_size) noexcept
Expand Down Expand Up @@ -76,6 +77,7 @@ IFACEMETHODIMP_(bool) FancyZonesSettings::GetConfig(_Out_ PWSTR buffer, _Out_ in
settings.add_bool_toogle(setting.name, setting.resourceId, *setting.value);
}

settings.add_int_spinner(m_zoneHighlightOpacity, IDS_SETTINGS_HIGHLIGHT_OPACITY, m_settings.zoneHighlightOpacity, 0, 100, 1);
settings.add_color_picker(m_zoneHiglightName, IDS_SETTING_DESCRIPTION_ZONEHIGHLIGHTCOLOR, m_settings.zoneHightlightColor);
settings.add_multiline_string(m_excludedAppsName, IDS_SETTING_EXCLCUDED_APPS_DESCRIPTION, m_settings.excludedApps);

Expand Down Expand Up @@ -153,6 +155,11 @@ void FancyZonesSettings::LoadSettings(PCWSTR config, bool fromFile) noexcept try
}
}
}

if (auto val = values.get_int_value(m_zoneHighlightOpacity))
{
m_settings.zoneHighlightOpacity = *val;
}
}
CATCH_LOG();

Expand All @@ -166,6 +173,7 @@ void FancyZonesSettings::SaveSettings() noexcept try
}

values.add_property(m_zoneHiglightName, m_settings.zoneHightlightColor);
values.add_property(m_zoneHighlightOpacity, m_settings.zoneHighlightOpacity);
values.add_property(m_editorHotkeyName, m_settings.editorHotkey.get_json());
values.add_property(m_excludedAppsName, m_settings.excludedApps);

Expand Down
1 change: 1 addition & 0 deletions src/modules/fancyzones/lib/Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ struct Settings
bool appLastZone_moveWindows = false;
bool use_cursorpos_editor_startupscreen = true;
std::wstring zoneHightlightColor = L"#0078D7";
int zoneHighlightOpacity = 90;
PowerToysSettings::HotkeyObject editorHotkey = PowerToysSettings::HotkeyObject::from_settings(true, false, false, false, VK_OEM_3);
std::wstring excludedApps = L"";
std::vector<std::wstring> excludedAppsArray;
Expand Down
2 changes: 1 addition & 1 deletion src/modules/fancyzones/lib/ZoneSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ IFACEMETHODIMP_(winrt::com_ptr<IZone>) ZoneSet::ZoneFromPoint(POINT pt) noexcept
winrt::com_ptr<IZone> smallestKnownZone = nullptr;
// To reduce redundant calculations, we will store the last known zones area.
int smallestKnownZoneArea = INT32_MAX;
for (auto iter = m_zones.begin(); iter != m_zones.end(); iter++)
for (auto iter = m_zones.rbegin(); iter != m_zones.rend(); iter++)
{
if (winrt::com_ptr<IZone> zone = iter->try_as<IZone>())
{
Expand Down
6 changes: 3 additions & 3 deletions src/modules/fancyzones/lib/ZoneWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -546,14 +546,14 @@ void ZoneWindow::DrawActiveZoneSet(wil::unique_hdc& hdc, RECT const& clientRect)

// { fillAlpha, fill, borderAlpha, border, thickness }
ColorSetting const colorHints { 225, RGB(81, 92, 107), 255, RGB(104, 118, 138), -2 };
ColorSetting colorViewer { 225, 0, 255, RGB(40, 50, 60), -2 };
ColorSetting colorHighlight { 225, 0, 255, 0, -2 };
ColorSetting colorViewer { OpacitySettingToAlpha(m_host->GetZoneHighlightOpacity()), 0, 255, RGB(40, 50, 60), -2 };
ColorSetting colorHighlight { OpacitySettingToAlpha(m_host->GetZoneHighlightOpacity()), 0, 255, 0, -2 };
ColorSetting const colorFlash { 200, RGB(81, 92, 107), 200, RGB(104, 118, 138), -2 };

auto zones = m_activeZoneSet->GetZones();
const size_t maxColorIndex = min(size(zones) - 1, size(colors) - 1);
size_t colorIndex = maxColorIndex;
for (auto iter = zones.rbegin(); iter != zones.rend(); iter++)
for (auto iter = zones.begin(); iter != zones.end(); iter++)
{
winrt::com_ptr<IZone> zone = iter->try_as<IZone>();
if (!zone)
Expand Down
Binary file modified src/modules/fancyzones/lib/fancyzones.rc
Binary file not shown.
Loading

0 comments on commit db7f155

Please sign in to comment.