Panel: Cinnamon Javascript Reference Manual

## Panel Panel — The file responsible for managing panels |

## Functions

array | calculateAllocation ()
| checkPanelUpgrade ()

## Description

This file is where everything about panels happens. `Main` will create a `PanelManager` object, which is responsible for creating and moving panels. There is also a `checkPanelUpgrade` function used as a transition between the old panel settings and the new panel settings.

## Functions

### calculateAllocation ()

    array
    calculateAllocation (real      leftMin,
                         real      leftNatural,
                         real      centerMin,
                         real      centerNatural,
                         real      rightMin,
                         real      rightNatural,
                         real      alloc,
                         boolean   centerOccupied);

Given the minimum and natural width requested by each box, this function calculates how much width should actually allocated to each box. The function returns two variables [`left`, `right`], which is the expected width of each side.

The expected outcome of the code is as follows:

Assuming that the centerBox is filled, the primary objective is to center the centerBox whenever possible. This will be done all the time unless doing so requires some box's width to go under its minimum width.

If we are centering the centerBox, there are two possible scenarios. Firstly, if the centerBox can be perfectly centered while everything takes their natural size, then everything will be allocated at least their natural size such that the centerBox is centered, leftBox is left aligned, rightBox is right aligned.

Otherwise, we first allocate the minWidth to every box, and then distribute the remaining space proportional to how much more space each box wants. This is done in a way that ensures the leftWidth and rightWidth are equal.

If it is not possible to center the centerBox, but there is enough space to just allocate the boxes, the centerBox will be made as centered as possible without making things go under their minWidth. This is achieved by making the shorter box go to their min width, and distributing the remaining space among the two other boxes.

Finally, if there isn't even enough space to just put the things, the width allocated is just proportional to the minimum width.

In the cases where the centerBox is not occupied, a similar mechanism is employed. If there is enough space for everything to get their natural width, this will happen. Otherwise, we first allocate the minimum width and then distribute the remaining space proportional to how much more space each box wants. In the scenario where the isn't enough space to just allocate the minimum width, we just allocate proportional to the minimum width.

#### Parameters

leftMin | minimum width of left box |
leftNatural | natural width of left box |
centerMin | minimum width of center box |
centerNatural | natural width of center box |
rightMin | minimum width of right box |
rightNatural | natural width of right box |
alloc | total available width to allocate |
centerOccupied | whether the center box is occupied. |

#### Returns

The left and right widths to be allocated.

### checkPanelUpgrade ()

    checkPanelUpgrade ();

Run from main, prior to PanelManager being initialized this handles the one-time transition between panel implementations to make this transition invisible to the user. We will evaluate the desktop-layout key, and pre-set applets-enabled and panels-enabled appropriately.