= Software Design
Erich Schroeter <erich.schroeter@magnetek.com>
v1.0, 2019-08-11
:toc:
:icons: font
:program-name: window-layout-manager

This document provides a centralized location to view design documentation for the *window-layout-manager* program.
The program is not very complicated, or at least started off that way, but is designed in a manner to provide easy cross-platform expansion.

.Version Support
|===
| Version | OS

|v1.0
|Windows
|===

== Use Cases

.Use Cases
[plantuml,align="center"]
----
include::plantuml/use_case_diagram.puml[]
----

=== Create a profile

Creating a profile can be performed manually by writing your own JSON file with the expected JSON objects.
Alternatively, you can use *{program-name}* to generate an initial profile file.

WARNING: Using redirection in PowerShell will by default produce a non-UTF-8 file, which is not compatible with the JSON parsing. As a workaround, pipe the output to create an UTF-8 compatible file:
`window-layout-manager ls --as-json | Out-File -Encoding ASCII myprofile.json`.

.Command line
[source,bash]
----
window-layout-manager ls --as-json > myprofile.json
----

This will create an initial profile that you can modify to your liking.

=== Apply a profile

.Command line
[source,bash]
----
window-layout-manager apply myprofile.json
----

=== List active windows

.Command line
[source,bash]
----
window-layout-manager ls
----

== Applying a profile

=== Windows

In order to modify the state of a window on Windows the program needs a handle to a window (i.e. https://docs.microsoft.com/en-us/windows/win32/winprog/windows-data-types[HWND]).
The windows API provides a https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-enumwindows[EnumWindows] function that iterates over all active windows passing a HWND to a callback function.
Within this custom callback function the program can find a specific window given specific properties specified within a profile.

.EnumWindows Callback Activity Diagram
[plantuml,align="center"]
----
include::plantuml/EnumWindows_callback_activity_diagram.puml[]
----


.Apply Profile Activity Diagram
[plantuml,align="center"]
----
include::plantuml/apply_profile_activity_diagram.puml[]
----
