Bug 303756 - Allow Scripts to add menus to useractions menu
Summary: Allow Scripts to add menus to useractions menu
Alias: None
Product: kwin
Classification: Plasma
Component: scripting (show other bugs)
Version: git master
Platform: unspecified Linux
: NOR wishlist
Target Milestone: 4.10
Assignee: Martin Flöser
URL: https://git.reviewboard.kde.org/r/106...
Depends on:
Reported: 2012-07-18 17:21 UTC by Martin Flöser
Modified: 2012-09-07 05:32 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In: 4.10
mgraesslin: ReviewRequest+


Note You need to log in before you can comment on or make changes to this bug.
Description Martin Flöser 2012-07-18 17:21:13 UTC
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) {
       {separator: true},
        title: "My &second Item",
        checkable: true,
        onSelected: function (checked) {

Comment 1 Martin Flöser 2012-09-07 05:32:32 UTC
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