Skip to content

Commit

Permalink
User/bretan/fz remove legacy editor (#1)
Browse files Browse the repository at this point in the history
* Removed and runs
Still needs some extra cleanup and addressing open issues

* Removed and runs
Still needs some extra cleanup and addressing open issues

* Clean

* Update
  • Loading branch information
TheMrJukes committed Nov 18, 2019
1 parent 03438f9 commit 28d7835
Show file tree
Hide file tree
Showing 14 changed files with 164 additions and 1,179 deletions.
8 changes: 3 additions & 5 deletions src/modules/fancyzones/dll/dllmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,8 @@ STDAPI PersistZoneSet(
ZoneSetConfig(
id,
layoutId,
reinterpret_cast<HMONITOR>(monitor),
resolutionKey,
ZoneSetLayout::Custom,
0, 0, 0));
MonitorFromPoint({}, MONITOR_DEFAULTTOPRIMARY),
resolutionKey));

for (int i = 0; i < zoneCount; i++)
{
Expand All @@ -85,7 +83,7 @@ STDAPI PersistZoneSet(
const int top = zones[baseIndex+1];
const int right = zones[baseIndex+2];
const int bottom = zones[baseIndex+3];
zoneSet->AddZone(MakeZone({ left, top, right, bottom }), false);
zoneSet->AddZone(MakeZone({ left, top, right, bottom }));
}
zoneSet->Save();

Expand Down
87 changes: 18 additions & 69 deletions src/modules/fancyzones/lib/FancyZones.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ struct FancyZones : public winrt::implements<FancyZones, IFancyZones, IFancyZone
IFACEMETHODIMP_(void) SettingsChanged() noexcept;

// IZoneWindowHost
IFACEMETHODIMP_(void) ToggleZoneViewers() noexcept;
IFACEMETHODIMP_(void) MoveWindowsOnActiveZoneSetChange() noexcept;
IFACEMETHODIMP_(COLORREF) GetZoneHighlightColor() noexcept
{
Expand All @@ -43,7 +42,6 @@ struct FancyZones : public winrt::implements<FancyZones, IFancyZones, IFancyZone

LRESULT WndProc(HWND, UINT, WPARAM, LPARAM) noexcept;
void OnDisplayChange(DisplayChangeType changeType) noexcept;
void ShowZoneEditorForMonitor(HMONITOR monitor) noexcept;
void AddZoneWindow(HMONITOR monitor, PCWSTR deviceId) noexcept;
void MoveWindowIntoZoneByIndex(HWND window, int index) noexcept;

Expand Down Expand Up @@ -80,20 +78,20 @@ struct FancyZones : public winrt::implements<FancyZones, IFancyZones, IFancyZone
mutable std::shared_mutex m_lock;
HWND m_window{};
HWND m_windowMoveSize{}; // The window that is being moved/sized
bool m_editorsVisible{}; // Are we showing the zone editors?
bool m_inMoveSize{}; // Whether or not a move/size operation is currently active
bool m_dragEnabled{}; // True if we should be showing zone hints while dragging
std::map<HMONITOR, winrt::com_ptr<IZoneWindow>> m_zoneWindowMap; // Map of monitor to ZoneWindow (one per monitor)
winrt::com_ptr<IZoneWindow> m_zoneWindowMoveSize; // "Active" ZoneWindow, where the move/size is happening. Will update as drag moves between monitors.
IFancyZonesSettings* m_settings{};
GUID m_currentVirtualDesktopId{};
wil::unique_handle m_terminateEditorEvent;
GUID m_currentVirtualDesktopId{}; // UUID of the current virtual desktop. Is GUID_NULL until first VD switch per session.
wil::unique_handle m_terminateEditorEvent; // Handle of FancyZonesEditor.exe we launch and wait on

OnThreadExecutor m_dpiUnawareThread;

static UINT WM_PRIV_VDCHANGED;
static UINT WM_PRIV_EDITOR;
static UINT WM_PRIV_VDCHANGED; // Message to get back on to the UI thread when virtual desktop changes
static UINT WM_PRIV_EDITOR; // Message to get back on to the UI thread when the editor exits

// Did we terminate the editor or was it closed cleanly?
enum class EditorExitKind : byte
{
Exit,
Expand Down Expand Up @@ -122,6 +120,7 @@ IFACEMETHODIMP_(void) FancyZones::Run() noexcept
if (!m_window) return;

RegisterHotKey(m_window, 1, m_settings->GetSettings().editorHotkey.get_modifiers(), m_settings->GetSettings().editorHotkey.get_code());

VirtualDesktopChanged();

m_dpiUnawareThread.submit(OnThreadExecutor::task_t{[]{
Expand Down Expand Up @@ -198,31 +197,32 @@ IFACEMETHODIMP_(bool) FancyZones::OnKeyDown(PKBDLLHOOKSTRUCT info) noexcept
bool const win = GetAsyncKeyState(VK_LWIN) & 0x8000;
if (win && !shift)
{
if (!m_settings->GetSettings().overrideSnapHotkeys)
{
return false;
}

bool const ctrl = GetAsyncKeyState(VK_CONTROL) & 0x8000;
if (ctrl)
{
if ((info->vkCode >= '0') && (info->vkCode <= '9'))
{
Trace::FancyZones::OnKeyDown(info->vkCode, win, ctrl, false /* inMoveSize */);
// Win+Ctrl+Number will cycle through ZoneSets
Trace::FancyZones::OnKeyDown(info->vkCode, win, ctrl, false /*inMoveSize*/);
CycleActiveZoneSet(info->vkCode);
return true;
}
}
else if ((info->vkCode == VK_RIGHT) || (info->vkCode == VK_LEFT))
{
Trace::FancyZones::OnKeyDown(info->vkCode, win, ctrl, false /* inMoveSize */);
OnSnapHotkey(info->vkCode);
return true;
if (!m_settings->GetSettings().overrideSnapHotkeys)
{
// Win+Left, Win+Right will cycle through Zones in the active ZoneSet
Trace::FancyZones::OnKeyDown(info->vkCode, win, ctrl, false /*inMoveSize*/);
OnSnapHotkey(info->vkCode);
return true;
}
}
}
else if (m_inMoveSize && (info->vkCode >= '0') && (info->vkCode <= '9'))
{
Trace::FancyZones::OnKeyDown(info->vkCode, win, false /* control */, true/* inMoveSize */);
// This allows you to cycle through ZoneSets while dragging a window
Trace::FancyZones::OnKeyDown(info->vkCode, win, false /*control*/, true /*inMoveSize*/);
CycleActiveZoneSet(info->vkCode);
return true;
}
Expand Down Expand Up @@ -356,38 +356,6 @@ void FancyZones::SettingsChanged() noexcept
RegisterHotKey(m_window, 1, m_settings->GetSettings().editorHotkey.get_modifiers(), m_settings->GetSettings().editorHotkey.get_code());
}

// IZoneWindowHost
IFACEMETHODIMP_(void) FancyZones::ToggleZoneViewers() noexcept
{
bool alreadyVisible{};

{
std::unique_lock writeLock(m_lock);
alreadyVisible = m_editorsVisible;
m_editorsVisible = !alreadyVisible;
}
Trace::FancyZones::ToggleZoneViewers(!alreadyVisible);

if (!alreadyVisible)
{
auto callback = [](HMONITOR monitor, HDC, RECT *, LPARAM data) -> BOOL
{
auto strongThis = reinterpret_cast<FancyZones*>(data);
strongThis->ShowZoneEditorForMonitor(monitor);
return TRUE;
};
EnumDisplayMonitors(nullptr, nullptr, callback, reinterpret_cast<LPARAM>(this));
}
else
{
std::shared_lock readLock(m_lock);
for (auto iter : m_zoneWindowMap)
{
iter.second->HideZoneWindow();
}
}
}

// IZoneWindowHost
IFACEMETHODIMP_(void) FancyZones::MoveWindowsOnActiveZoneSetChange() noexcept
{
Expand All @@ -405,14 +373,7 @@ LRESULT FancyZones::WndProc(HWND window, UINT message, WPARAM wparam, LPARAM lpa
{
if (wparam == 1)
{
if (m_settings->GetSettings().use_standalone_editor)
{
ToggleEditor();
}
else
{
ToggleZoneViewers();
}
ToggleEditor();
}
}
break;
Expand Down Expand Up @@ -508,18 +469,6 @@ void FancyZones::OnDisplayChange(DisplayChangeType changeType) noexcept
}
}

void FancyZones::ShowZoneEditorForMonitor(HMONITOR monitor) noexcept
{
std::shared_lock readLock(m_lock);

auto iter = m_zoneWindowMap.find(monitor);
if (iter != m_zoneWindowMap.end())
{
bool const activate = MonitorFromPoint(POINT(), MONITOR_DEFAULTTOPRIMARY) == monitor;
iter->second->ShowZoneWindow(activate, false /*fadeIn*/);
}
}

void FancyZones::AddZoneWindow(HMONITOR monitor, PCWSTR deviceId) noexcept
{
std::unique_lock writeLock(m_lock);
Expand Down
1 change: 0 additions & 1 deletion src/modules/fancyzones/lib/FancyZones.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ interface __declspec(uuid("{2CB37E8F-87E6-4AEC-B4B2-E0FDC873343F}")) IFancyZones

interface __declspec(uuid("{5C8D99D6-34B2-4F4A-A8E5-7483F6869775}")) IZoneWindowHost : public IUnknown
{
IFACEMETHOD_(void, ToggleZoneViewers)() = 0;
IFACEMETHOD_(void, MoveWindowsOnActiveZoneSetChange)() = 0;
IFACEMETHOD_(COLORREF, GetZoneHighlightColor)() = 0;
};
Expand Down
3 changes: 1 addition & 2 deletions src/modules/fancyzones/lib/Settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,14 @@ struct FancyZonesSettings : winrt::implements<FancyZonesSettings, IFancyZonesSet
PCWSTR name;
bool* value;
int resourceId;
} m_configBools[9] = {
} m_configBools[8] = {
{ L"fancyzones_shiftDrag", &m_settings.shiftDrag, IDS_SETTING_DESCRIPTION_SHIFTDRAG },
{ L"fancyzones_overrideSnapHotkeys", &m_settings.overrideSnapHotkeys, IDS_SETTING_DESCRIPTION_OVERRIDE_SNAP_HOTKEYS },
{ L"fancyzones_zoneSetChange_flashZones", &m_settings.zoneSetChange_flashZones, IDS_SETTING_DESCRIPTION_ZONESETCHANGE_FLASHZONES },
{ L"fancyzones_displayChange_moveWindows", &m_settings.displayChange_moveWindows, IDS_SETTING_DESCRIPTION_DISPLAYCHANGE_MOVEWINDOWS },
{ L"fancyzones_zoneSetChange_moveWindows", &m_settings.zoneSetChange_moveWindows, IDS_SETTING_DESCRIPTION_ZONESETCHANGE_MOVEWINDOWS },
{ L"fancyzones_virtualDesktopChange_moveWindows", &m_settings.virtualDesktopChange_moveWindows, IDS_SETTING_DESCRIPTION_VIRTUALDESKTOPCHANGE_MOVEWINDOWS },
{ L"fancyzones_appLastZone_moveWindows", &m_settings.appLastZone_moveWindows, IDS_SETTING_DESCRIPTION_APPLASTZONE_MOVEWINDOWS },
{ L"fancyzones_use_standalone_editor", &m_settings.use_standalone_editor, IDS_SETTING_DESCRIPTION_USE_STANDALONE_EDITOR },
{ L"use_cursorpos_editor_startupscreen", &m_settings.use_cursorpos_editor_startupscreen, IDS_SETTING_DESCRIPTION_USE_CURSORPOS_EDITOR_STARTUPSCREEN },
};

Expand Down
1 change: 0 additions & 1 deletion src/modules/fancyzones/lib/Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ struct Settings
bool zoneSetChange_moveWindows = false;
bool overrideSnapHotkeys = false;
bool appLastZone_moveWindows = false;
bool use_standalone_editor = true;
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"~");
Expand Down

0 comments on commit 28d7835

Please sign in to comment.