Given bug #303750 it might be useful to allow scripts to re-add elements to the useractions menu. This would for example allow a script to add an opacity menu to change the opacity of the selected window. An implementation could be quite simple: var menu = { title: "My Custom Menu", items: [{ title: "My &custom Item", checkable: false, onSelected: function (checked) { workspace.foo(); }, {separator: true}, { title: "My &second Item", checkable: true, onSelected: function (checked) { workspace.foo(); } ] }; worrkspace.addUserActionMenu(menu);
Git commit 846715c278582f17deb501eade3b2641c70d6b4f by Martin Gräßlin. Committed on 31/08/2012 at 13:28. Pushed by graesslin into branch 'master'. Allow Scripts to add menus to the UserActionsMenu A script can register a callback through registerUserActionsMenu to be informed when the UserActionsMenu is about to be shown. This menu calls the Scripting component to gather actions to add to a Scripts submenu. The Scripting component now asks all scripts for the actions, which will invoke the registered callbacks with the Client for which the menu is to be shown as argument. The callback is supposed to return a JSON structure describing how the menu should look like. The returned object can either be a menu item or a complete menu. If multiple menu items or menus are supposed to be added by the script it should just register multiple callbacks. The structure for an item looks like the following: { text: "My caption", checkable: true, checked: false, triggered: function (action) { print("The triggered action as parameter"); } } The structure for a complete menu looks quite similar: { text: "My menu caption", items: [ {...}, {...} // items as described above ] } The C++ part of the script parses the returned object and generates either QAction or QMenu from it. All objects become children of the scripts QMenu provided by the UserActionsMenu. Before the menu is shown again the existing menu is deleted to ensure that no outdated values from no longer existing scripts are around. This means the scripts are queried each time the menu is shown. FIXED-IN: 4.10 REVIEW: 106285 M +7 -0 kwin/scripting/documentation-global.xml M +116 -0 kwin/scripting/scripting.cpp M +108 -0 kwin/scripting/scripting.h M +30 -1 kwin/scripting/scriptingutils.h M +31 -0 kwin/useractions.cpp M +4 -0 kwin/useractions.h M +6 -0 kwin/workspace.h http://commits.kde.org/kde-workspace/846715c278582f17deb501eade3b2641c70d6b4f