Extension that transform windows into icons that behave as a window

Hi,
I am trying to create an extension that can be triggered with a keyboard shortcut, and that transform my currently focused windows into a draggable icon and that can be restored to the initial windows context with the same shortcut or a double click on the iconized window, it’s a required functionnality for a professional environment i am working on.

My issues are that i need the transformed windows ( transformed into a little square with fixed size) to be draggable and act as it was the same windows but with the defined size of the icon,

for now, i have a working proof of concept but am unable to adress some points, here is how it works :
when triggered i hide the window by calling hide on every children of the windowactor
then i create a new content with the icon of the application, i play with the position and dimensions to make it dragable etc,
I m getting issues with the position on screen, collision, etc.

it works, but i think that the architecture i use is really bad and i do not know what would be a clean way to achieve what i want to do.

Does anyone could give me some hints please to help me go forward please ?

Thank you.