Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Algorithm to fit windows on desktop (like tile)

I searching algorithm to solve problem like this:

I have few windows, each window can be moved and re sized but with specified ratio between width and height, eg. 2:1 (height:width).

Each window can't be on other window and all windows must be fully visible. Free area (desktop wallpaper visibility) must be minimal.

Can anyone tell me what algorithm i need for this type of problem?

Greetings,

like image 355
Svisstack Avatar asked Dec 16 '10 02:12

Svisstack


People also ask

How do tiling window managers work?

The idea behind the tiling window manager is to efficiently and automatically organize your desktop for you. Most tiling window managers do this quite well—you open one app and it places it, automatically maximized, on your screen. Open another app and it splits the screen with the first app.

What is computer tile?

A tile is a type of shortcut you can only find in a grid, on the right side of your Windows 10 Start Menu. Colorful, sometimes animated, and larger than the regular sized icons used for desktop shortcuts, Windows tiles come in four different sizes.

What are the advantages of tiled windows?

Most systems provide two-dimensional tiled windows, adjustable in both height and width. advantages: The system usually allocates and positions windows for the user, eliminating the necessity to make positioning decisions. Open windows are always visible, eliminating the possibility of them being lost and forgotten.


2 Answers

Another approach, which might be simpler to implement than packing, would be to subdivide your screen size into the required number of panes, then fit a window which satisfies your other requirements inside the pane. Since you'll probably have a small number of windows open at any time, and since your screen doesn't change its size dynamically, you can probably pre-compute all the arrangements you need for 1 up to O(100) open windows.

like image 68
High Performance Mark Avatar answered Oct 03 '22 03:10

High Performance Mark


If you can relax the requirement that all windows have a given "aspect ratio" then the problem becomes very simple. Suppose you have N "tiles" to arrange on a single screen, then these can be arranged in columns where the number of columns, NumCols is the square root of N rounded up when N is not a perfect square. All columns of tiles are of equal width. The number of tiles in each column is then N/NumCols rounded either up or down as necessary to make the total number of columns be N. This is what Microsoft Excel does under View > Arrange All > Tiled. Excel chooses to put the columns with one fewer tiles on the left of the screen.

like image 38
Philip Swannell Avatar answered Oct 03 '22 03:10

Philip Swannell