Bug 362511

Summary: Allow setting desktop widget geometry using scripting API
Product: [Plasma] plasmashell Reporter: C.P.A.vanrun
Component: ScriptingAssignee: David Edmundson <kde>
Status: CONFIRMED ---    
Severity: wishlist CC: bshah, nate, notmart, plasma-bugs-null, ptrendx
Priority: NOR    
Version First Reported In: 5.4.2   
Target Milestone: 1.0   
Platform: Kubuntu   
OS: Linux   
Latest Commit: Version Fixed/Implemented In:
Sentry Crash Report:
Attachments: Examplescript to show the addition of a simple plasmoid with failed height settings.

Description C.P.A.vanrun 2016-04-30 18:32:40 UTC
While trying to create a custom desktop layout via desktop scripting (Javascript API) I failed to set any of the geometry for widgets. It works for panel objects. I tried the org.kde.plasma.folder plasmoid and several others but to no avail. Somehow setting the geometry for widgets has zero effect. An example script is given below.

This is a major problem because it is preventing me from setting up kubuntu for a small set of computers I am reconfiguring with certain settings. And without geometries the shell scripting is pretty limited to panels.

Note: new qdbus to open Desktop Console for test scripting:
qdbus org.kde.plasmashell /PlasmaShell org.kde.PlasmaShell.showInteractiveConsole

// Example script:
// Save as <something>.js and use above desktop console to test it.
print(scriptingVersion) //20
print(applicationVersion)// 5.4.2

var desktopsArray = desktops();
for( var j = 0; j < desktopsArray.length; j++) {
    var clock = desktopsArray[j].addWidget("org.kde.plasma.digitalclock");
    print("Height before setting height: " + clock.geometry.height)
    clock.geometry.height=400;
    print("Height after setting height: " + clock.geometry.height)
    print("Height before replacing geometry: " + clock.geometry.height);
    clock.geometry = new QRectF(0,0,400,400);
    print("Height before replacing geometry: " + clock.geometry.height);
}


Reproducible: Always

Steps to Reproduce:
1. Test above mentioned script or adjust plasma/shells/org.kde.plasma.desktop/contents/layout.js
2. Run the Interactive Console or restart plasmashell (removing ~/.config/plasma-org.kde.plasma.desktop-appletrc)
3. Make a sad face because a plasmoid is very small.

Actual Results:  
Geometry settings are not picked up, plasmoids autosize.

Expected Results:  
Plasmoids get the geometry as specified in the desktop shell script.

Running kubuntu 15.04 (but I can confirm the problem also occurs in kubuntu 16.04).
Comment 1 C.P.A.vanrun 2016-04-30 19:59:07 UTC
Created attachment 98713 [details]
Examplescript to show the addition of a simple plasmoid with failed height settings.
Comment 2 Marco Martin 2016-05-04 11:27:10 UTC
geometry for applets is not available from the desktop scripting console.

one thing that may be changed is the position at creation time.
the api would be something like
desktopsArray[j].addWidget("org.kde.plasma.digitalclock", 200, 300);
 (doesn't exist yet, but could be eventually added)
Comment 3 C.P.A.vanrun 2016-05-04 14:00:55 UTC
Is there an up to date overview which parts are available? In any format?

I'd like to edit https://userbase.kde.org/KDE_System_Administration/PlasmaDesktopScripting but rather to so with more information so it's a good overhaul.
Comment 4 ptrendx 2025-11-09 00:41:03 UTC
(In reply to Marco Martin from comment #2)
> geometry for applets is not available from the desktop scripting console.
> 
> one thing that may be changed is the position at creation time.
> the api would be something like
> desktopsArray[j].addWidget("org.kde.plasma.digitalclock", 200, 300);
>  (doesn't exist yet, but could be eventually added)

Is there any fundamental reason why implementing setting the widget geometry is hard? I looked at the source of Plasma Workspace and see that the SetGeometry function is empty and I could try implementing it, although probably it's just my ignorance that makes me not see the difficulties there. Do you have any advice you could share before I start setting up the dev environment to compile plasma and try to fix this?

Thanks!