Controlling KDE activities via dbus
KDE can be controlled from the command line with qdbus
. The general syntax is qdbus COMPONENT PATH METHOD ARGUMENT1...
where COMPONENT
is typically something like org.freedesktop.Foo
or org.kde.Bar
, PATH
denotes a class exposed by the component, METHOD is the name of a particular action in that class, and there may be further arguments depending on the method.
Here are commands for KDE ≥4.7 to list activities, to get the current activity, and to set the current activity.
qdbus org.kde.kactivitymanagerd /ActivityManager org.kde.ActivityManager.ListActivities
qdbus org.kde.kactivitymanagerd /ActivityManager org.kde.ActivityManager.CurrentActivity
qdbus org.kde.kactivitymanagerd /ActivityManager org.kde.ActivityManager.SetCurrentActivity "activity identifier "
Finding out what dbus can do
KDE's dbus documentation is very poor. Each class is minimally documented, e.g. Activity, DesktopCorona). But you'll probably have to experiment and perhaps read the source (there are links in the API documentation pages) to find out what is available.
If you type qdbus
with up to two arguments, it will list the possibilities for the next argument. The following shell snippet lists all available Qt-dbus methods:
for x in $(qdbus | sed '/^:/d'); do
for y in $(qdbus $x); do
qdbus $x $y | sed "s~^~$x $y ~"
done
done 2>/dev/null >qdbus.list
Another way to explore the dbus tree is qdbusviewer
in the Qt development tools. There is also a Python qt-dbus interface as part of PyQt.
Getting the shell to react
To make a shell react to external events, the best you can reasonably do is make it check something before displaying a prompt. Bash runs $PROMPT_COMMAND
before displaying a prompt, and zsh executes the precmd
function. So you can look up the current KDE activity and do something if it's changed from the last time you looked.
This question may be old, but I think I have found the perfect solution.
- Go to System Settings > Window Behaviour > Window Rules
- Add a new Rule
- Mark all window properties as 'Unimportant'
- Select all 'Window' types like in the screenshot
- In the tab 'Size & Position', tick 'Activities' and configure it as 'Apply initially' and 'All Activites', like in the screenshot
- Click 'Ok'
This should set all windows to be on all activities by default.
Best Answer
Ok first you want to open your activities (SUPER ( Windows )+Q) unlock widgets, and create at least one other activity. Make sure that more than one of the activities are not stopped (e.g. red X).
*(note: Remember the activity that is highlighted is the currently active one, and according to aseigo only one can be active at a time, though I haven't found this to be exactly true.)
Now right click on the title bar of the window you want to associate with an activity. Go to Activities, and select the activity you want it to be associated with. Please note this dialog is only present if the there are other activites in "not stopped state:" if you stop all but one it won't show the activities dialog. Stopped activities are not shown in this dialog.
note: only works in 4.6 (or later? activities have changed much over kde 4's lifetime, I actually don't know if they'll work this way in 4.7, I honestly hope they don't, this is not intuitive)