(Added how to add systemtray widgets and some other systemtray things) |
|||
| Line 256: | Line 256: | ||
* '''reloadConfig()''': causes the widget to reload its configuration; reaction to configuration changes made using readConfig are usually activated on script exit, but this can be triggered earlier on a per-widget basis using this method | * '''reloadConfig()''': causes the widget to reload its configuration; reaction to configuration changes made using readConfig are usually activated on script exit, but this can be triggered earlier on a per-widget basis using this method | ||
* '''showConfigurationInteface()''': shows the configuration user interface for this widget on the screen | * '''showConfigurationInteface()''': shows the configuration user interface for this widget on the screen | ||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
=== Screen Geometry === | === Screen Geometry === | ||
| Line 442: | Line 361: | ||
* '''moveTo(number x, number y)''': moves the top left of the rect to point (x, y) | * '''moveTo(number x, number y)''': moves the top left of the rect to point (x, y) | ||
* '''moveTop(number delta)''': moves the top by delta pixels | * '''moveTop(number delta)''': moves the top by delta pixels | ||
| + | |||
| + | |||
| + | == Configuration Keys == | ||
| + | Here you find a list of commonly used configuration keys to use with the '''writeConfig''' command. Where the documentation notes that a key is in a subgroup, remember to first use '''currentConfigGroup'''. | ||
| + | |||
| + | === Common configuration keys === | ||
| + | Here are some keys that can be used with all widgets: | ||
| + | |||
| + | * '''Share''' (true/false): Whether or not the widget is to be announces throughout the network (Share tab) | ||
| + | |||
| + | === Digital clock (digital-clock) === | ||
| + | * '''announceInterval''' (number ≥ 0): Interval in minutes that the time is read out loud | ||
| + | * '''calendarType''' (local/coptic/ethopian/gregorian/gregorian-proleptic/hebrew/hijri/indian-national/jalali/japanese/julian/minguo/thai): Calendar system to be used, defaults to local | ||
| + | * '''defaultTimezone''' (Local/…): Time zone to be used | ||
| + | * '''displayHolidays''' (true/false): Whether holidays are to be displayed | ||
| + | * '''holidayRegions''' (tbd): tbd | ||
| + | * '''holidayRegionaDaysOff''' (tbd): tbd | ||
| + | * '''plainClockColor''' (rrr,ggg,bbb): Color set for clock font (e. g. 192,0,0 - to be used with useCustomColor=true!) | ||
| + | * '''plainClockDrawShadow''' (true/false): Whether a shadow is to bed drawn (defaults to true) | ||
| + | * '''plainClockShadowColor''' (rrr,ggg,bbb): Color set for clock shadow (e. g. 64,97,128 - to be used with useCustomShadowColor=true!) | ||
| + | * '''plainClockFont''' (tbd): Font to be used for clock (e. g. Serif,12,-1,5,75,0,0,0,0,0) | ||
| + | * '''showDate''' (true/false): self-explanatory | ||
| + | * '''showDay''' (true/false): self-explanatory | ||
| + | * '''showSeconds''' (true/false): self-explanatory | ||
| + | * '''showTimezone''' (true/false): self-explanatory | ||
| + | * '''showYear''' (true/false): self-explanatory | ||
| + | * '''timeZones''' (Europe/Andorra,…): Comma-separated list of timezones to be used (e. g. Europe/Andorra,Indian/Antananarivo,Asia/Aqtau) | ||
| + | * '''useCustomColor''' (true/false): Whether or not a custom color is to be used (use with plainClockColor=rrr,ggg,bbb!) | ||
| + | * '''useCustomShadowColor''' (true/false): Whether or not a custom shadow color is to be used (use with plainClockShadowColor=rrr,ggg,bbb!) | ||
| + | |||
| + | === Folderview (folderview) === | ||
| + | * '''alignToGrid''' (true/false): self-explanatory | ||
| + | * '''customIconSize''' (16/22/24/32/48/…): Use custom icon size for files/folders (use only default/common icon sizes, powers of 2) | ||
| + | * '''customLabel''': Use custom title rather than default path or place name | ||
| + | * '''drawShadows''' (true/false): Whether or not file labels are to draw shadows | ||
| + | * '''filter''' (0/1/2): Defines whether a filter is to be used or not (0 = No filter, 1 = Show only matching files, 2 = Hide matching files) | ||
| + | * '''filterFiles''': Wildcard filter to filter file names | ||
| + | * '''mimeFilter''': Comma-separated list of mimetypes to be filtered (shown/hidden depends on filter-setting) | ||
| + | * '''iconsLocked''' (true/false): Whether or not icons can be moved | ||
| + | * '''numTextLines''' (number > 0): Amount of lines a file name can have before it is truncated | ||
| + | * '''url''': Folder URL to be displayed (e. g. desktop:/// or file:///home/yourusername) | ||
| + | * '''sortColumn''' (-1/0/1/2/3/4/5): The way files and folders are sorted (-1 = No sorting, 0 = By name, 1 = By size, 2 = By type, 3 = By date) | ||
| + | * '''sortDirsFirst''' (true/false): Whether or not folders are displayed before files (defaults to true) | ||
| + | * '''textColor''' (rrr,ggg,bbb): Color the icon labels will have | ||
| + | |||
| + | === Kickoff menu (launcher) === | ||
| + | * '''SwitchTabsOnHover''' (true/false): self-explanatory | ||
| + | * '''ShowAppsByName''' (true/false): Apps are sorted by name rather than by description | ||
| + | |||
| + | === Taskbar (tasks) === | ||
| + | * '''groupingStrategy''' (0/1/2): Defines how taskbar entries are to be grouped (0 = Never, 1 = Manually, 2 = By Program Name) | ||
| + | * '''groupWhenFull''' (true/false): Only group when taskbar is full (to be used with groupingStrategy=2 only!) | ||
| + | * '''highlightWindows''' (true/false): Highlight a window if your mouse cursor is hovering its taskbar entry (requires Desktop Compositing and “Highlight windows” effect enabled to work) | ||
| + | * '''maxRows''' (number > 0): Amount of rows taskbar entries can take | ||
| + | * '''forceRows''' (true/false): Force row setting for taskbar entries | ||
| + | * '''showOnlyCurrentActivity''' (true/false): Show only windows from current activity | ||
| + | * '''showOnlyCurrentDesktop''' (true/false): Show only windows from current virtual desktop | ||
| + | * '''showOnlyCurrentScreen''' (true/false): Show only windows from current screen (multi monitor setup) | ||
| + | * '''showTooltip''' (true/false): Whether or not tooltips are to be shown | ||
| + | * '''sortingStrategy''' (0/1/2/3): How taskbar entries are to be sorted (0 = Never, 1 = Manually, 2 = Alphabetically, 3 = By Desktop) | ||
| + | |||
| + | === System Tray === | ||
| + | The System Tray has some unique behaviors since it can host widgets and configuring it is not as easy as most other widgets, particularly when adding and removing widgets. This section will help you deal with its specific behavior. | ||
| + | |||
| + | ==== Generic Systemtray configuration keys ==== | ||
| + | * '''DefaultAppletAdded''' (true/false): Remembers whether the default plasmoids (networkmanagement, device manager, notifications) have already been added(??) | ||
| + | * '''ShowApplicationStatus''' (true/false): Show system tray icons of applications that belong to the group “Applications” | ||
| + | * '''ShowCommunications''' (true/false): Show system tray icons of applications that belong to the group “Applications” (i. e. Messenger, IRC chat) | ||
| + | * '''ShowHardware''' (true/false): Show system tray icons of applications that belong to the group “Hardware” (i. e. volume control, printer applet) | ||
| + | * '''ShowSystemServices''' (true/false): Show system tray icons of applications that belong to the group “System Services” (i. e. Nepomuk Indexing Agent) | ||
| + | * '''ShowUnknown''' (true/false): Show system tray icons that do not belong into one of the categories mentioned above (or that do not use KDE’s system tray protocol and thus do not provide such information) | ||
| + | * '''alwaysShown''': Comma-separated list of widgets and entries that are to be shown all the time (e. g. KMix,notifier) | ||
| + | * '''hidden''': Comma-separated list of widgets and entries that are to be hidden all the time (e. g. Nepomuk Indexing Agent,Klipper,kmail) | ||
| + | |||
| + | ==== Add a widget to systemtray ==== | ||
| + | You can not add widgets to the systemtray in a similar way like you would add them to a panel or containment using addWidget. Instead, to add, manage and remove them, you need to utilize writeConfig changing the currentConfigGroup. | ||
| + | <code bash>systray = panel.addWidget("systemtray") // First add a systemtray to your panel | ||
| + | systray.currentConfigGroup = Array("Applets","0") // then change the currentConfig Group | ||
| + | // to the subnode [Applets][0]. Use any number you like(?)</code> | ||
| + | |||
| + | Now you can “create” the plasmoid by adding a “plugin” configuration entry | ||
| + | <code bash>systray.writeConfig("plugin","notifier") // This will add a Device Notifier Plasmoid</code> | ||
| + | You can modify the plasmoid’s configuration by using writeConfig. | ||
| + | <code bash>systray.writeConfig("property","value")</code> | ||
| + | To change back to the top configuration level and thus edit the systemtray plasmoid itself pass an empty array to currentConfigGroup. | ||
| + | |||
| + | ==== Edit existing widgets in systemtray ==== | ||
| + | |||
| + | ==== Remove a widget from systemtray ===== | ||
Contents |
It is possible to control and interact with a Plasma user interface shell such as a plasma-desktop or (starting in KDE SC 4.5) plasma-netbook session using ECMA Script (aka JavaScript). This scripting mechanism exposes containments (Desktop Activities and Panels), widgets and various other aspects of plasma-desktop configuration using the widely known and used ECMA Script language. The QtScript engine is used for the runtime environment.
This document describes the API that is provided along with how to run such scripts in plasma-desktop.
A set of examples can be found here that demonstrate the use of various aspects of Plasma shell scripting.
Contributions of additional examples are welcome and an be sent to the Plasma development mailing list (plasma-devel at kde.org) for inclusion if you do not have commit rights to the kdeexamples module.
There are three ways that scripts can be executed in plasma-desktop:
| Note |
|---|
| For security reasons, scripts located in the user's home directory will not be run during this phase. |
`kde4-config --path data`/plasma-desktop/updates/
with a ".js" suffix for scripts that have not yet been run. If there is more than one script which has not been run yet they will be executed serially in the alphabetical order of the file names.
A record of which update scripts have been run is kept in the application's config file in the [Updates] group. This means that if the plasma-desktop configuraiton file is removed, all the update scripts will be run again.
| Note |
|---|
| For security reasons, scripts located in the user's home directory will not be run during this phase. |
qdbus org.kde.plasma-desktop /MainApplication showInteractiveConsole
qdbus org.kde.plasma-desktop /MainApplication loadScriptInInteractiveConsole /path/to/file
Templates are named packages that contain scripts. This provides a way for common functionality to be easily reused, helping to increase consistency and lower maintenance costs. Templates can be loaded from other scripts by name and they are also used to populate some parts of the user interface, such as the entries in the Add Panels menu.
A template is a small set of files in a specified file hierarchy (or, in Plasma terms, a "Package"). In particular, a Template package contains the following files:
Templates are stored under share/apps/plasma/layout-templates and may be installed using `plasmapkg -t layout-template -i /path/to/package`. Template packages may also be provided as a .zip file with a .plasmalayout suffix.
The metadata.desktop file contains the usual .desktop entries such as Name and Icon but must also contain Type=Service and ServiceTypes=Plasma/LayoutTemplate entries. If the layout is specific to a given Plasma application, such as plasma-desktop, this can be specific using X-Plasma-Shell. X-Plasma-ContainmentCategories defines what kind of layout it is with possible values being panel and desktop. Finally a X-KDE-PluginInfo-Name entry is required to provide a globally unique internal name for the Template. Here is an example of a Template that provides a Panel layout for Plasma Netbook:
[Desktop Entry]
Encoding=UTF-8
Name=Cool Panel
Type=Service
ServiceTypes=Plasma/LayoutTemplate
X-Plasma-Shell=plasma-netbook
X-Plasma-ContainmentCategories=panel
X-KDE-PluginInfo-Author=Aaron Seigo
X-KDE-PluginInfo-Email=aseigo@kde.org
X-KDE-PluginInfo-Name=org.kde.CoolNetbookPanel
X-KDE-PluginInfo-Version=1.0
X-KDE-PluginInfo-Website=http://plasma.kde.org/
X-KDE-PluginInfo-Category=
X-KDE-PluginInfo-Depends=
X-KDE-PluginInfo-License=GPL
X-KDE-PluginInfo-EnabledByDefault=true
When running a template, two global variables will be accessible in read-only mode: templateName and templateComment. They will contain the Name and Comment fields of the above desktop file, and are translated if a localization is available.
A good example of the use of templates is the use case that triggered the creation of this feature: the desire to make it easy for users to re-create the default panel that is created on first start. There is a Template called org.kde.plasma-desktop.defaultPanel that ships with the KDE Plasma Workspace which contains the layout for the initial default panel. This is referenced by the default Plasma Desktop init script and, because it is marked as a Panel Template in the metadata.desktop file it also shows up to the user in the Add Panels menu. When selected by the user from the menu, the exact same panel that is created on desktop start up is created for them, complete with Plasma Widgets and configuration.
Another example of the usefulness of templates is the "Find Widgets" template. This template, which first shipped with Plasma Desktop v4.5, provides a function for finding widgets by name. It appears in the toolbar "Load" and "Use" menus in the Desktop Console in plasma-desktop, and makes finding widgets as simple as:
var template = loadTemplate('org.kde.plasma-desktop.findWidgets')
template.findWidgets('systemtray')
Probably the most user visible use of templates are "Activity templates". The structure of Activity templates is similar to the other use of templates, but a few extra features are provided in the metadata.desktop file. Here is an example of such an activity template:
[Desktop Entry]
Encoding=UTF-8
Name=Cool Activity Template
Icon=user-desktop
Type=Service
ServiceTypes=Plasma/LayoutTemplate
X-Plasma-Shell=plasma-desktop
X-Plasma-ContainmentCategories=desktop
X-Plasma-ContainmentLayout-ExecuteOnCreation=dolphin $desktop, gwenview $pictures
X-Plasma-ContainmentLayout-ShowAsExisting=true
X-KDE-PluginInfo-Author=John Doe
X-KDE-PluginInfo-Email=john@doe.org
X-KDE-PluginInfo-Name=org.kde.plasma-desktop.CoolTemplate
X-KDE-PluginInfo-Version=1.0
X-KDE-PluginInfo-Website=http://john.doe.org
X-KDE-PluginInfo-Category=
X-KDE-PluginInfo-Depends=
X-KDE-PluginInfo-License=GPL
X-KDE-PluginInfo-EnabledByDefault=true
The layout itself is still created from the layout.js file as usual, but this template also shows as a precreated activity to the user thanks to the X-Plasma-ContainmentLayout-ShowAsExisting key. Additionally, it starts applications in the newly created activity using the X-Plasma-ContainmentLayout-ExecuteOnCreation key.
That key is a list of commands to execute, and it supports the following variables:
They all expand into the path toward the user corresponding default folder.
In addition to the normal ECMA Script API and the Qt-specific extensions (such as signal/slot support) provided by QtScript, the following API is provided for use by scripts.
All of the API below, unless otherwise noted with a version noticed, appear as below in the KDE Software Compilation v4.4.0 and later. API that is not noted as being part of a given class or object is part of the global namespace.
| Note |
|---|
| API compatibility is guaranteed from version to version starting with KDE Software Compilation v4.4.0. |
Starting with KDE SC 4.5, the version number of both the scripting API and the application is available to the script via the following read-only properties:
Activities are the desktop layer in a plasma-desktop session and may contain widgts. In sightly more technical terms, they are desktop containments. Activities can be created, enumerated, modified and destroyed.
New Activities can be created using the Activity constructor, like this:
var activity = new Activity("folderview")
The string passed into the constructor maps to the X-KDE-PluginInfo-Name= entry in the plugin's .desktop file). See the documentation on the Containment object class below.
Read-only properties:
Functions:
Panels can be created, enumerated, modified and destroyed. A panel object combines both a containment as well as the container itself, allowing for full control of things such as where it appears on screen and the hiding features associated with them.
New Panels can be created using the Panel constructor, like this:
var panel = new Panel("dock")
The string passed into the constructor maps to the X-KDE-PluginInfo-Name= entry in the plugin's .desktop file).
Read-only properties:
Functions:
Activity and Panel objects, once created by the script, or as returned by activityById, activityForScreen, or panelById) provide the following read-only properties:
as well as the following read/write properties:
and the following methods:
in the widget's .desktop file
for the default value
In addition to all of the above properties and functions, Panel objects also provide the folowing read/write properties:
Widgets may be enumerated by calling the widgetIds property on a Activity or Panel object. With a widget id in hand, a Widget object can be retrieved by calling widgetById(id) on an Activity or Panel object. New Widgets can be created with add addWidget(String) function provided by Activity and Panel objects.
A list of all installed widget types can be retrieved the following read-only property:
A Widget object provides the following read-only properties:
as well as the following read-write properties:
and the following methods:
for the default value
for the default value
Read-only properties:
Functions:
If a second string is passed in, it is considered a request for a specific path and the following types are recognized:
The second parameter should be a specific resource to find the path to. An example might be userDataPath("data", "plasma-desktop").
Read-write properties:
Read-only properties:
Functions:
A rectangle class is also provided for use with Widget, Panel and screen geometry properties and functions.
Read-only properites:
Read-write properties:
Constructors:
Functions:
Here you find a list of commonly used configuration keys to use with the writeConfig command. Where the documentation notes that a key is in a subgroup, remember to first use currentConfigGroup.
Here are some keys that can be used with all widgets:
The System Tray has some unique behaviors since it can host widgets and configuring it is not as easy as most other widgets, particularly when adding and removing widgets. This section will help you deal with its specific behavior.
You can not add widgets to the systemtray in a similar way like you would add them to a panel or containment using addWidget. Instead, to add, manage and remove them, you need to utilize writeConfig changing the currentConfigGroup.
systray = panel.addWidget("systemtray") // First add a systemtray to your panel
systray.currentConfigGroup = Array("Applets","0") // then change the currentConfig Group
// to the subnode [Applets][0]. Use any number you like(?)
Now you can “create” the plasmoid by adding a “plugin” configuration entry
systray.writeConfig("plugin","notifier") // This will add a Device Notifier Plasmoid
You can modify the plasmoid’s configuration by using writeConfig.
systray.writeConfig("property","value")
To change back to the top configuration level and thus edit the systemtray plasmoid itself pass an empty array to currentConfigGroup.