Skip to content

Commit

Permalink
Document fancy zones (#1496)
Browse files Browse the repository at this point in the history
  • Loading branch information
vldmr11080 authored Mar 9, 2020
1 parent 7e1f7bd commit 7653d5f
Show file tree
Hide file tree
Showing 5 changed files with 237 additions and 2 deletions.
72 changes: 72 additions & 0 deletions src/modules/fancyzones/lib/FancyZones.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,100 @@ interface IZoneSet;

interface __declspec(uuid("{50D3F0F5-736E-4186-BDF4-3D6BEE150C3A}")) IFancyZones : public IUnknown
{
/**
* Start and initialize FancyZones.
*/
IFACEMETHOD_(void, Run)() = 0;
/**
* Stop FancyZones and do the clean up.
*/
IFACEMETHOD_(void, Destroy)() = 0;
};

/**
* Core FancyZones functionality.
*/
interface __declspec(uuid("{2CB37E8F-87E6-4AEC-B4B2-E0FDC873343F}")) IFancyZonesCallback : public IUnknown
{
/**
* @returns Boolean indicating whether a move/size operation is currently active.
*/
IFACEMETHOD_(bool, InMoveSize)() = 0;
/**
* A window is being moved or resized. Track down window position and give zone layout
* hints if dragging functionality is enabled.
*
* @param window Handle of window being moved or resized.
* @param monitor Handle of monitor on which windows is moving / resizing.
* @param ptScreen Cursor coordinates.
*/
IFACEMETHOD_(void, MoveSizeStart)(HWND window, HMONITOR monitor, POINT const& ptScreen) = 0;
/**
* A window has changed location, shape, or size. Track down window position and give zone layout
* hints if dragging functionality is enabled.
*
* @param monitor Handle of monitor on which windows is moving / resizing.
* @param ptScreen Cursor coordinates.
*/
IFACEMETHOD_(void, MoveSizeUpdate)(HMONITOR monitor, POINT const& ptScreen) = 0;
/**
* The movement or resizing of a window has finished. Assign window to the zone if it
* is dropped within zone borders.
*
* @param window Handle of window being moved or resized.
* @param ptScreen Cursor coordinates where window is droped.
*/
IFACEMETHOD_(void, MoveSizeEnd)(HWND window, POINT const& ptScreen) = 0;
/**
* Inform FancyZones that user has switched between virtual desktops.
*/
IFACEMETHOD_(void, VirtualDesktopChanged)() = 0;
/**
* Inform FancyZones that new window is created. FancyZones will try to assign it to the
* zone insde active zone layout (if information about last zone, in which window was located
* before being closed, is available).
*
* @param window Handle of newly created window.
*/
IFACEMETHOD_(void, WindowCreated)(HWND window) = 0;
/**
* Process keyboard event.
*
* @param info Information about low level keyboard event.
* @returns Boolean indicating if this event should be passed on further to other applications
* in event chain, or should it be suppressed.
*/
IFACEMETHOD_(bool, OnKeyDown)(PKBDLLHOOKSTRUCT info) = 0;
/**
* Toggle FancyZones editor application.
*/
IFACEMETHOD_(void, ToggleEditor)() = 0;
/**
* Callback triggered when user changes FancyZones settings.
*/
IFACEMETHOD_(void, SettingsChanged)() = 0;
};

/**
* Helper functions used by each ZoneWindow (representing work area).
*/
interface __declspec(uuid("{5C8D99D6-34B2-4F4A-A8E5-7483F6869775}")) IZoneWindowHost : public IUnknown
{
/**
* Assign window to appropriate zone inside new zone layout.
*/
IFACEMETHOD_(void, MoveWindowsOnActiveZoneSetChange)() = 0;
/**
* @returns Color used to highlight zone while giving zone layout hints.
*/
IFACEMETHOD_(COLORREF, GetZoneHighlightColor)() = 0;
/**
* @returns ZoneWindow (representing work area) currently being processed.
*/
IFACEMETHOD_(IZoneWindow*, GetParentZoneWindow) (HMONITOR monitor) = 0;
/**
* @returns Integer in range [0, 100] indicating opacity of highlited zone (while giving zone layout hints).
*/
IFACEMETHOD_(int, GetZoneHighlightOpacity)() = 0;
};

Expand Down
36 changes: 36 additions & 0 deletions src/modules/fancyzones/lib/Zone.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,49 @@
#pragma once

/**
* Class representing one zone inside applied zone layout, which is basically wrapper around rectangle structure.
*/
interface __declspec(uuid("{8228E934-B6EF-402A-9892-15A1441BF8B0}")) IZone : public IUnknown
{
/**
* @returns Zone coordinates (top-left and bottom-right corner) represented as RECT structure.
*/
IFACEMETHOD_(RECT, GetZoneRect)() = 0;
/**
* @returns Boolean indicating if zone is empty or there are windows assigned to it.
*/
IFACEMETHOD_(bool, IsEmpty)() = 0;
/**
* @param window Window handle.
* @returns Boolean indicating if specified window is assigned to the zone.
*/
IFACEMETHOD_(bool, ContainsWindow)(HWND window) = 0;
/**
* Assign single window to this zone.
*
* @param window Handle of window which should be assigned to zone.
* @param zoneWindow The m_window of a ZoneWindow, it's a hidden window representing the
* current monitor desktop work area.
* @param stampZone Boolean indicating weather we should add special property on the
* window. This property is used on display change to rearrange windows
* to corresponding zones.
*/
IFACEMETHOD_(void, AddWindowToZone)(HWND window, HWND zoneWindow, bool stampZone) = 0;
/**
* Remove window from this zone (if it is assigned to it).
*
* @param window Handle of window to be removed from this zone.
* @param restoreSize Boolean indicating that window should fall back to dimensions
* before assigning to this zone.
*/
IFACEMETHOD_(void, RemoveWindowFromZone)(HWND window, bool restoreSize) = 0;
/**
* @param id Zone identifier.
*/
IFACEMETHOD_(void, SetId)(size_t id) = 0;
/**
* @retirns Zone identifier.
*/
IFACEMETHOD_(size_t, Id)() = 0;
};

Expand Down
64 changes: 63 additions & 1 deletion src/modules/fancyzones/lib/ZoneSet.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,80 @@
#include "Zone.h"
#include "JsonHelpers.h"


/**
* Class representing single zone layout. ZoneSet is responsible for actual calculation of rectangle coordinates
* (whether is grid or canvas layout) and moving windows through them.
*/
interface __declspec(uuid("{E4839EB7-669D-49CF-84A9-71A2DFD851A3}")) IZoneSet : public IUnknown
{
/**
* @returns Unique identifier of zone layout.
*/
IFACEMETHOD_(GUID, Id)() = 0;
/**
* @returns Type of the zone layout. Layout type can be focus, columns, rows, grid, priority grid or custom.
*/
IFACEMETHOD_(JSONHelpers::ZoneSetLayoutType, LayoutType)() = 0;
/**
* Add zone to the zone layout.
*
* @param zone Zone object (defining coordinates of the zone).
*/
IFACEMETHOD(AddZone)(winrt::com_ptr<IZone> zone) = 0;
/**
* Get zone from cursor coordinates.
*
* @param pt Cursor coordinates.
* @returns Zone object (defining coordinates of the zone).
*/
IFACEMETHOD_(winrt::com_ptr<IZone>, ZoneFromPoint)(POINT pt) = 0;
/**
* Get index of the zone inside zone layout by window assigned to it.
*
* @param window Handle of window assigned to zone.
* @returns Zone index withing zone layout.
*/
IFACEMETHOD_(int, GetZoneIndexFromWindow)(HWND window) = 0;
/**
* @returns Array of zone objects (defining coordinates of the zone) inside this zone layout.
*/
IFACEMETHOD_(std::vector<winrt::com_ptr<IZone>>, GetZones)() = 0;
/**
* Assign window to the zone based on zone index inside zone layout.
*
* @param window Handle of window which should be assigned to zone.
* @param zoneWindow The m_window of a ZoneWindow, it's a hidden window representing the
* current monitor desktop work area.
* @param index Zone index within zone layout.
*/
IFACEMETHOD_(void, MoveWindowIntoZoneByIndex)(HWND window, HWND zoneWindow, int index) = 0;
/**
* Assign window to the zone based on direction (using WIN + LEFT/RIGHT arrow).
*
* @param window Handle of window which should be assigned to zone.
* @param zoneWindow The m_window of a ZoneWindow, it's a hidden window representing the
* current monitor desktop work area.
* @param vkCode Pressed arrow key.
*/
IFACEMETHOD_(void, MoveWindowIntoZoneByDirection)(HWND window, HWND zoneWindow, DWORD vkCode) = 0;
/**
* Assign window to the zone based on cursor coordinates.
*
* @param window Handle of window which should be assigned to zone.
* @param zoneWindow The m_window of a ZoneWindow, it's a hidden window representing the
* current monitor desktop work area.
* @param pt Cursor coordinates.
*/
IFACEMETHOD_(void, MoveWindowIntoZoneByPoint)(HWND window, HWND zoneWindow, POINT ptClient) = 0;
/**
* Calculate zone coordinates within zone layout based on number of zones and spacing. Used for one of
* the predefined layouts (focus, columns, rows, grid, priority grid) or for custom layout.
*
* @param monitorInfo Information about monitor on which zone layout is applied.
* @param zoneCount Number of zones inside zone layout.
* @param spacing Spacing between zones in pixels.
* @returns Boolean if calculation was successful.
*/
IFACEMETHOD_(bool, CalculateZones)(MONITORINFO monitorInfo, int zoneCount, int spacing) = 0;
};

Expand Down
2 changes: 1 addition & 1 deletion src/modules/fancyzones/lib/ZoneWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ struct ZoneWindow : public winrt::implements<ZoneWindow, IZoneWindow>
HMONITOR m_monitor{};
std::wstring m_uniqueId; // Parsed deviceId + resolution + virtualDesktopId
wchar_t m_workArea[256]{};
wil::unique_hwnd m_window{};
wil::unique_hwnd m_window{}; // Hidden tool window used to represent current monitor desktop work area.
HWND m_windowMoveSize{};
bool m_drawHints{};
bool m_flashMode{};
Expand Down
65 changes: 65 additions & 0 deletions src/modules/fancyzones/lib/ZoneWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,84 @@ namespace ZoneWindowUtils
std::wstring GenerateUniqueId(HMONITOR monitor, PCWSTR deviceId, PCWSTR virtualDesktopId);
}

/**
* Class representing single work area, which is defined by monitor and virtual desktop.
*/
interface __declspec(uuid("{7F017528-8110-4FB3-BE41-F472969C2560}")) IZoneWindow : public IUnknown
{
/**
* A window is being moved or resized. Track down window position and give zone layout
* hints if dragging functionality is enabled.
*
* @param window Handle of window being moved or resized.
* @param dragEnabled Boolean indicating is giving hints about active zone layout enabled.
* Hints are given while dragging window while holding SHIFT key.
*/
IFACEMETHOD(MoveSizeEnter)(HWND window, bool dragEnabled) = 0;
/**
* A window has changed location, shape, or size. Track down window position and give zone layout
* hints if dragging functionality is enabled.
*
* @param ptScreen Cursor coordinates.
* @param dragEnabled Boolean indicating is giving hints about active zone layout enabled.
* Hints are given while dragging window while holding SHIFT key.
*/
IFACEMETHOD(MoveSizeUpdate)(POINT const& ptScreen, bool dragEnabled) = 0;
/**
* The movement or resizing of a window has finished. Assign window to the zone of it
* is dropped within zone borders.
*
* @param window Handle of window being moved or resized.
* @param ptScreen Cursor coordinates where window is droped.
*/
IFACEMETHOD(MoveSizeEnd)(HWND window, POINT const& ptScreen) = 0;
/**
* Abort tracking down of window position and giving zone layout hints (if dragging functionality is enabled).
*/
IFACEMETHOD(MoveSizeCancel)() = 0;
/**
* @returns Boolean indicating is giving hints about active zone layout enabled. Hints are
* given while dragging window while holding SHIFT key.
*/
IFACEMETHOD_(bool, IsDragEnabled)() = 0;
/**
* Assign window to the zone based on zone index inside zone layout.
*
* @param window Handle of window which should be assigned to zone.
* @param index Zone index within zone layout.
*/
IFACEMETHOD_(void, MoveWindowIntoZoneByIndex)(HWND window, int index) = 0;
/**
* Assign window to the zone based on direction (using WIN + LEFT/RIGHT arrow).
*
* @param window Handle of window which should be assigned to zone.
* @param vkCode Pressed arrow key.
*/
IFACEMETHOD_(void, MoveWindowIntoZoneByDirection)(HWND window, DWORD vkCode) = 0;
/**
* Cycle through active zone layouts (giving hints about each layout).
*
* @param vkCode Pressed key representing layout index.
*/
IFACEMETHOD_(void, CycleActiveZoneSet)(DWORD vkCode) = 0;
/**
* Save information about zone in which window was assigned, when closing the window.
* Used once we open same window again to assign it to its previous zone.
*
* @param window Window handle.
*/
IFACEMETHOD_(void, SaveWindowProcessToZoneIndex)(HWND window) = 0;
/**
* @returns Unique work area identifier. Format: <device-id>_<resolution>_<virtual-desktop-id>
*/
IFACEMETHOD_(std::wstring, UniqueId)() = 0;
/**
* @returns Work area resolution (not same as monitor resolution).
*/
IFACEMETHOD_(std::wstring, WorkAreaKey)() = 0;
/**
* @returns Active zone layout for this work area.
*/
IFACEMETHOD_(IZoneSet*, ActiveZoneSet)() = 0;
};

Expand Down

0 comments on commit 7653d5f

Please sign in to comment.