mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-03 09:46:54 +02:00
FancyZones: improve windows and apps filtering (#673)
Unifies the way windows are considered "interesting" by FancyZone. Berfore the change WinKey + arrows would use different method than dragging. This PR makes both use the WinKey + arrows method. Cleans up FancyZones Settings.cpp by removing m_configStrings variable. Contrary to its name it was used to create color picker control. Adds a multiline option to the text input to settings. Uses this to provide the user with a way to exclude certain apps from snapping to zones.
This commit is contained in:
committed by
GitHub
parent
4df1d2093f
commit
03438f9192
@@ -1,5 +1,6 @@
|
||||
#include "pch.h"
|
||||
#include <common/settings_objects.h>
|
||||
#include <common/common.h>
|
||||
#include <interface/powertoy_module_interface.h>
|
||||
#include <interface/lowlevel_keyboard_event_data.h>
|
||||
#include <interface/win_hook_event_data.h>
|
||||
@@ -198,11 +199,25 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
static bool IsInterestingWindow(HWND window)
|
||||
bool IsInterestingWindow(HWND window)
|
||||
{
|
||||
auto style = GetWindowLongPtr(window, GWL_STYLE);
|
||||
auto exStyle = GetWindowLongPtr(window, GWL_EXSTYLE);
|
||||
return IsWindowVisible(window) && WI_IsFlagSet(style, WS_MAXIMIZEBOX) && WI_IsFlagClear(style, WS_CHILD) && WI_IsFlagClear(exStyle, WS_EX_TOOLWINDOW);
|
||||
auto windowAndPath = get_filtered_base_window_and_path(window);
|
||||
if (windowAndPath.hwnd == nullptr)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
CharUpperBuffW(windowAndPath.process_path.data(), (DWORD)windowAndPath.process_path.length());
|
||||
if (m_settings)
|
||||
{
|
||||
for (const auto& excluded : m_settings->GetSettings().excludedAppsArray)
|
||||
{
|
||||
if (windowAndPath.process_path.find(excluded) != std::wstring::npos)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void Disable(bool const traceEvent)
|
||||
|
||||
@@ -44,15 +44,9 @@ private:
|
||||
{ L"use_cursorpos_editor_startupscreen", &m_settings.use_cursorpos_editor_startupscreen, IDS_SETTING_DESCRIPTION_USE_CURSORPOS_EDITOR_STARTUPSCREEN },
|
||||
};
|
||||
|
||||
struct
|
||||
{
|
||||
PCWSTR name;
|
||||
std::wstring* value;
|
||||
int resourceId;
|
||||
} m_configStrings[1] = {
|
||||
{ L"fancyzones_zoneHighlightColor", &m_settings.zoneHightlightColor, IDS_SETTING_DESCRIPTION_ZONEHIGHLIGHTCOLOR },
|
||||
};
|
||||
const std::wstring m_editor_hotkey_name = L"fancyzones_editor_hotkey";
|
||||
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";
|
||||
};
|
||||
|
||||
IFACEMETHODIMP_(bool) FancyZonesSettings::GetConfig(_Out_ PWSTR buffer, _Out_ int *buffer_size) noexcept
|
||||
@@ -73,17 +67,15 @@ IFACEMETHODIMP_(bool) FancyZonesSettings::GetConfig(_Out_ PWSTR buffer, _Out_ in
|
||||
IDS_SETTING_LAUNCH_EDITOR_BUTTON,
|
||||
IDS_SETTING_LAUNCH_EDITOR_DESCRIPTION
|
||||
);
|
||||
settings.add_hotkey(m_editor_hotkey_name, IDS_SETTING_LAUNCH_EDITOR_HOTKEY_LABEL, m_settings.editorHotkey);
|
||||
settings.add_hotkey(m_editorHotkeyName, IDS_SETTING_LAUNCH_EDITOR_HOTKEY_LABEL, m_settings.editorHotkey);
|
||||
|
||||
for (auto const& setting : m_configBools)
|
||||
{
|
||||
settings.add_bool_toogle(setting.name, setting.resourceId, *setting.value);
|
||||
}
|
||||
|
||||
for (auto const& setting : m_configStrings)
|
||||
{
|
||||
settings.add_color_picker(setting.name, setting.resourceId, *setting.value);
|
||||
}
|
||||
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);
|
||||
|
||||
return settings.serialize_to_buffer(buffer, buffer_size);
|
||||
}
|
||||
@@ -127,17 +119,37 @@ void FancyZonesSettings::LoadSettings(PCWSTR config, bool fromFile) noexcept try
|
||||
}
|
||||
}
|
||||
|
||||
for (auto const& setting : m_configStrings)
|
||||
if (values.is_string_value(m_zoneHiglightName))
|
||||
{
|
||||
if (values.is_string_value(setting.name))
|
||||
{
|
||||
*setting.value = values.get_string_value(setting.name);
|
||||
}
|
||||
m_settings.zoneHightlightColor = values.get_string_value(m_zoneHiglightName);
|
||||
}
|
||||
|
||||
if (values.is_object_value(m_editor_hotkey_name))
|
||||
if (values.is_object_value(m_editorHotkeyName))
|
||||
{
|
||||
m_settings.editorHotkey = PowerToysSettings::HotkeyObject::from_json(values.get_json(m_editor_hotkey_name));
|
||||
m_settings.editorHotkey = PowerToysSettings::HotkeyObject::from_json(values.get_json(m_editorHotkeyName));
|
||||
}
|
||||
|
||||
if (values.is_string_value(m_excludedAppsName))
|
||||
{
|
||||
m_settings.excludedApps = values.get_string_value(m_excludedAppsName);
|
||||
m_settings.excludedAppsArray.clear();
|
||||
auto excludedUppercase = m_settings.excludedApps;
|
||||
CharUpperBuffW(excludedUppercase.data(), (DWORD)excludedUppercase.length());
|
||||
std::wstring_view view(excludedUppercase);
|
||||
while (view.starts_with('\n') || view.starts_with('\r'))
|
||||
{
|
||||
view.remove_prefix(1);
|
||||
}
|
||||
while (!view.empty())
|
||||
{
|
||||
auto pos = (std::min)(view.find_first_of(L"\r\n"), view.length());
|
||||
m_settings.excludedAppsArray.emplace_back(view.substr(0, pos));
|
||||
view.remove_prefix(pos);
|
||||
while (view.starts_with('\n') || view.starts_with('\r'))
|
||||
{
|
||||
view.remove_prefix(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
CATCH_LOG();
|
||||
@@ -151,12 +163,9 @@ void FancyZonesSettings::SaveSettings() noexcept try
|
||||
values.add_property(setting.name, *setting.value);
|
||||
}
|
||||
|
||||
for (auto const& setting : m_configStrings)
|
||||
{
|
||||
values.add_property(setting.name, *setting.value);
|
||||
}
|
||||
|
||||
values.add_property(m_editor_hotkey_name, m_settings.editorHotkey);
|
||||
values.add_property(m_zoneHiglightName, m_settings.zoneHightlightColor);
|
||||
values.add_property(m_editorHotkeyName, m_settings.editorHotkey);
|
||||
values.add_property(m_excludedAppsName, m_settings.excludedApps);
|
||||
|
||||
values.save_to_settings_file();
|
||||
}
|
||||
|
||||
@@ -17,6 +17,8 @@ struct Settings
|
||||
bool use_cursorpos_editor_startupscreen = true;
|
||||
std::wstring zoneHightlightColor = L"#0078D7";
|
||||
PowerToysSettings::HotkeyObject editorHotkey = PowerToysSettings::HotkeyObject::from_settings(true, false, false, false, VK_OEM_3, L"~");
|
||||
std::wstring excludedApps = L"";
|
||||
std::vector<std::wstring> excludedAppsArray;
|
||||
};
|
||||
|
||||
interface __declspec(uuid("{BA4E77C4-6F44-4C5D-93D3-CBDE880495C2}")) IFancyZonesSettings : public IUnknown
|
||||
|
||||
Binary file not shown.
@@ -13,3 +13,4 @@
|
||||
#define IDS_SETTING_LAUNCH_EDITOR_BUTTON 113
|
||||
#define IDS_SETTING_LAUNCH_EDITOR_DESCRIPTION 114
|
||||
#define IDS_SETTING_LAUNCH_EDITOR_HOTKEY_LABEL 115
|
||||
#define IDS_SETTING_EXCLCUDED_APPS_DESCRIPTION 116
|
||||
|
||||
Reference in New Issue
Block a user