Spider-OS

login - registration

Back to the post list

Windows manager
2019 Feb 10

Quickly when coding the GUI, I realized that a window manager was needed. The number one issue is taking into account the overlap of the windows. I display a window A, and then I display a window B on top: what happens to the part covered ?

window overlap

Second issue, if I reduce the window B, I have to erase it, so you have to save it somewhere else. Also if there is background processing in this window, this one must be updated (including if it is minimized).

window minimize

And then we have to restore the area that was covered by window B.

window restore area

I explain to you how I did : here

Comments :

Aran (webmaster)
2019 Feb 10 14:12

First of all, you have to reserve a memory space to store all the windows. A non-visible space outside the framebuffer.

For example a screen that has three overlapping windows, also has a hidden area with the entire three non-overlapping windows. This allows them to be restored on demand. And also updates them when they are not visible on the screen. Either because they are reduced, or else covered by another window.

hidden windows area

This is the function windowCreate, which is responsible for creating the window in the hidden area, in an optimal way to save space.

To manage the overlay of the windows I use a matrix. This indicates for each pixel the number of the associated window. If there is window overlay, the window number in the foreground is indicated. In the image below, each square represents a pixel with the number of the associated window. As window B is in the foreground, its number is indicated for each pixel of the area covered (in blue).

common matrix

This common matrix makes it possible to know which pixels are visible on the screen. That is to say those in the foreground, not covered by another window.

When I want to display a window, I use the windowDisplay function. This one uses the common matrix to know the windows already there in the same area.

In the example below, we want to display a window B in the blue area. The common matrix indicates that part of the window A is in the area, the rest corresponds to the wallpaper. Before updating the common matrix, with the number of the window B, it is necessary to save the current area covered. An another memory area is available for that, it stores all the back matrix of the windows. The windowDisplay function copies the overlapped part of the common matrix to this memory location. The number 0 corresponds to the wallpaper.

back matrix window

So for summary, a window is actually composed of several elements :

With all this, we still do not have the window on the screen ;-) The windowDisplay function also displays the window. It will simply copy the window from the hidden area to the visible screen. Below, we display the window B, it is in the foreground on the screen.

windowDisplay

Let's take another example.

We have three overlapped windows. And we want to pass the window A in the foreground.

3 windows overlap

First step : find the windows that will be covered, here B and C. This is the windowSearch function, which looks for window numbers in the common matrix. As window A goes to the foreground, windows B and C have no more A window behind them. We must update their back matrix.

Yes but you will tell me, what will it have behind the windows B and C ? Well what was behind the window A (since it leaves) ;-) So we update the back matrices of the windows B and C with the back matrix of the window A (here wallpaper), like this :

update back matrix

You will notice that the back matrix of window C, still has window number 2. This is because window B is still behind it.

Second step : Window A is in the foreground, now there are windows B and C behind. The back matrix of window A must be updated.
And the second question : what are we updating with ? Well with the common matrix. It contains for the moment, the position of the windows before moving the window A. This is what we need. This gives this :

update matrix foreground

Third step : update of the common matrix. The front matrix of the window is copied into the common matrix.

copy front matrix

And finally last step : we display the window on the visible screen. For this we copy the window of the hidden area in the framebuffer.

copy hidden window

Here is the general operation. I hope it's clear.

A next post on the minimize of an active window...

Add a comment

Page : 1