Bug 394699 - Enums from KWin are missing in QML scripts
Summary: Enums from KWin are missing in QML scripts
Status: RESOLVED WORKSFORME
Alias: None
Product: kwin
Classification: Plasma
Component: scripting (show other bugs)
Version: 5.12.5
Platform: Other Linux
: NOR normal
Target Milestone: ---
Assignee: KWin default assignee
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-05-26 10:46 UTC by Sigma
Modified: 2021-12-06 04:39 UTC (History)
3 users (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments
Minimal examples for QML and Javascript (681 bytes, application/gzip)
2018-05-26 10:46 UTC, Sigma
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Sigma 2018-05-26 10:46:15 UTC
Created attachment 112877 [details]
Minimal examples for QML and Javascript

The following command prints different things when called from a QML script (X-Plasma-API=declarativescript) or from plain Javascript (X-Plasma-API=javascript):

print(Object.keys(KWin));

In QML:
[objectName,objectNameChanged,readConfig,readConfig,registerWindow,registerShortcut]

In Javascript:
"PlacementArea,MovementArea,MaximizeArea,MaximizeFullArea,FullScreenArea,WorkArea,FullArea,ScreenArea,ElectricTop,ElectricTopRight,ElectricRight,ElectricBottomRight,ElectricBottom,ElectricBottomLeft,ElectricLeft,ElectricTopLeft,ELECTRIC_COUNT,ElectricNone"

Because of this there is no way to use these enums in QML.

I added my testcases as an attachment.
Comment 1 Martin Flöser 2018-05-26 10:59:48 UTC
which Qt version are you using?
Comment 2 Sigma 2018-05-26 11:05:54 UTC
I am using Qt 5.10.1.
Comment 3 Martin Flöser 2018-05-26 13:36:26 UTC
The enums might be available on the workspace object.
Comment 4 Sigma 2018-05-26 15:25:32 UTC
It does not seem so (I added workspace to the examples from the attachment), neither in JS nor QML.
Comment 5 Kai Uwe Broulik 2018-05-28 14:39:55 UTC
The problem is that KWin sets JSEngineGlobalMethodsWrapper as context property but in QML enums are bound to a type and not a specific instance.

So KWin would need to qmlRegisterType under an import to make this work. Not sure that import can be under the same name as the context property, so a simple "KWin.PlacementArea" like is done in JS is probably not possible. Another approach would be to add a bunch of CONSTANT int Q_PROPERTYs on the object to make it behave exactly like the JS one.

(Also I noticed the class is missing the electric border enum that JS has)
Comment 6 Martin Flöser 2018-05-28 15:38:20 UTC
My analysis is slightly different. For JS the WorkspaceWrapper is exported as "KWin", while for QML the JSEngineGlobalMethodsWrapper is exported as KWin. I don't really see a solution to make this work in an API compatible way, which I think is not that much of a problem. We never tried to have JS and QML API compatible.
Comment 7 kde.org 2021-11-06 20:58:30 UTC
This issue report is quite old. Can you please confirm, that it still persists with KDE 5.23?
Comment 8 Bug Janitor Service 2021-11-21 04:40:13 UTC
Dear Bug Submitter,

This bug has been in NEEDSINFO status with no change for at least
15 days. Please provide the requested information as soon as
possible and set the bug status as REPORTED. Due to regular bug
tracker maintenance, if the bug is still in NEEDSINFO status with
no change in 30 days the bug will be closed as RESOLVED > WORKSFORME
due to lack of needed information.

For more information about our bug triaging procedures please read the
wiki located here:
https://community.kde.org/Guidelines_and_HOWTOs/Bug_triaging

If you have already provided the requested information, please
mark the bug as REPORTED so that the KDE team knows that the bug is
ready to be confirmed.

Thank you for helping us make KDE software even better for everyone!
Comment 9 Bug Janitor Service 2021-12-06 04:39:30 UTC
This bug has been in NEEDSINFO status with no change for at least
30 days. The bug is now closed as RESOLVED > WORKSFORME
due to lack of needed information.

For more information about our bug triaging procedures please read the
wiki located here:
https://community.kde.org/Guidelines_and_HOWTOs/Bug_triaging

Thank you for helping us make KDE software even better for everyone!