Panel desktop scripting

Eike Hein hein at kde.org
Sat Nov 16 19:10:13 UTC 2013


Hi,

while creating a template for a 'sidebar' panel type, I've
noticed that using desktop scripting to set the geometry of
a vertical panel doesn't work quite right.

Take this following example:

var panel = new Panel;
panel.location = 'right';
panel.length = 900;
panel.height = 200;

Given that, 'length' is supposed to be the length of the
panel along the screen edge, and 'height' is the axis per-
pendicular to the screen edge (i.e. actually the width, in
case of a vertical panel).

However, these aren't understood right because the call
sequence is as follows:

1. Assigning to panel.location results in a call to
   Plasma::Containment::setLocation(), which calls
   updateConstraints().
2. updateConstraints() schedules a constraints update
   for the following event loop iteration.
3. When the timer times out, the new location is
   delivered to Panel (a Containment implementation)
   in constraintsEvent(), which adjusts the form factor
   accordingly depending on the screen edge.

I.e. the problem is that the length/height writes happen
inbetween #2 and #3, when the Panel still believes to be
horizontal.

Just swapping the axis doesn't work because height has
sanity checks like "no more than a third of the screen
height" which make the 900 in the example not work.

Swapping the order obviously doesn't work either.

So far the workarounds I can think of:

1. Spinning the event loop in scripting's location
   setter so the constraints update is guaranteed to
   happen before control is returned to the script.
   Dirty ...

2. Calling Containment::setFormFactor in the scripting's
   location setter, thus doing what Panel will end up
   doing anyway, just later. Also super-dirty.

Thoughts on a clean(er) fix?


Cheers,
Eike




More information about the Plasma-devel mailing list