May 15, 2011 — Hans

One common complaint about activities in KDE Plasma Workspaces is that it’s hard to switch between them. With virtual desktops you have many alternatives – you can use the Pager widget, desktop effects, keyboard shortcuts, switch desktop on screen edges etc. But what about activities? I counted the methods that I know and ended up with 7 different ways to switch activities (depending on how you count), all of which I’ll share in this post. Who knows, maybe you’ll find a new favorite?

Continuing with activities after a hiatus, this time how to switch between them

Note that I’m using Plasma Desktop 4.6.x – some of things described might be different in earlier versions (for example different locations in System Settings), and some might not work at all.



Standard ways

Let’s start by reviewing some standard ways to change activities, i.e., ways that are available from a fresh setup. In the next section, “Additional ways”, the methods will require some tweaking, such as changing settings or installing additional programs. I won’t cover the case when you have “Different widgets for each desktop” enabled.

Mouse

By default there are two easy ways to access the activity manager by using your mouse:

Click on the desktop Tool Box (usually in the top-right corner) and select Activities

(usually in the top-right corner) and select Right click on the desktop and select Activities…

From the activity manager, click on the activity you want to switch to. You can then close the manager by clicking on the close button , pressing Esc or by moving focus to a window (for example by clicking on the window).

Activity manager

The disadvantage of these methods is that you need to have access to the desktop in order to use them.

Keyboard

Personally I prefer to use the keyboard as much as possible. If you right click on the desktop you’ll see that the default keyboard shortcut to open the activity manager is

Alt+D, Alt+A

It requires that the desktop has focus, which you can give it by clicking on a part of the desktop or by switching to an empty virtual desktop. This has the same problem as the mouse methods above. There is a solution though, called global shortcuts which work regardless of the application in focus (as long as it doesn’t steal the keyboard input). The default global shortcut for the activity manager is

Meta+Q

Meta is usually the “Windows” key on standard keyboards. You can reassign the shortcut by clicking on the desktop Tool Box , select Shortcut Settings and click on the shortcut under “Global” on the “Activities…” row.

Finally there are two global keyboard settings to switch to the previous and next activity:

Meta+Tab – Next Activity

– Next Activity Meta+Shift+Tab – Previous Activity

They can be reassigned in System Settings → Common Appearance and Behavior → Shortcuts and Gestures → Global Keyboard Shortcuts → KDE component: Plasma Desktop Shell.

Additional ways

If you aren’t satisfied with the default ways to switch activities, here are suggestions for other methods you can use.

Mouse actions

If you like to use the mouse but find it troublesome to switch via the activity manager, there are faster ways. Plasma Workspaces allow you to define the actions different mouse buttons trigger on the desktop. For example, you can configure the left mouse button to pop up a context menu with your activities.

Context menu to switch between activities

Click on the desktop Tool Box and select Desktop Settings. Choose Mouse Actions in the left sidebar. You can either change one of the existing mouse actions, or you can add a new action. For example, try to click on Add Action…, click on the button again with your left mouse button and select Switch Activity in the drop-down list. Now you can switch activities by left clicking on the desktop and choosing the activity you want to switch to in the menu.

If you use the Switch Activity action with a scroll button it will switch to the previous/next activity instead of popping up a menu. By default vertical scroll is assigned to Switch Desktop, try to change it to Switch Activity and scroll up/down with the mouse pointer over the desktop to switch to the previous/next activity

These are just examples, of course you can use whichever mouse buttons you prefer. If you redefine the action of the right mouse button and can’t access the desktop right-click menu anymore, you can use the desktop Tool Box to open Desktop Settings again.

The problem with these methods is the same as before – you need access to the desktop to use them (note that they also work on the Dashboard). Unfortunately Plasma Workspaces don’t support global mouse shortcuts yet, but I’ll show you how to use another tool to achieve this under “Mouse shortcuts”. Before that, however, I’ll introduce another way to use the mouse – mouse gestures.

Mouse gestures

Mouse gestures allow you to trigger different actions by holding down a mouse button and making a gesture with the mouse. For example, moving the mouse in a straight line to the right while holding down the middle button could mean “Next activity”.

Before we can add new mouse gestures we need a command to switch activities and to show the activity manager. I couldn’t find any specific D-Bus calls to achieve this, but all shortcuts in KDE Software can be called using D-Bus. (There’s a “Send Keyboard Input” option in the System Settings module , but I can’t get it to invoke keyboard shortcuts.)

Go to System Settings → Common Appearance and Behavior → Shortcuts and Gestures → Custom Shortcuts. Click on Settings and make sure that “Start the Input Actions daemon on login” and “Gestures” are checked. “Mouse button” is the mouse button you hold down to activate a gesture. Personally I like to set it to 2, which in most cases is the middle mouse button.

To create a new gesture, click on Edit → New → Mouse Gesture Action → Command/URL. Click on the Trigger tab → Edit and draw the gesture in the new window while holding down the left mouse button.

Drawing a new mouse gesture

In the Action tab, you can use one of the following commands:

qdbus org.kde.kglobalaccel /component/plasma_desktop invokeShortcut "manage activities" #open the activity manager

qdbus org.kde.kglobalaccel /component/plasma_desktop invokeShortcut "Next Activity" #switch to next activity

qdbus org.kde.kglobalaccel /component/plasma_desktop invokeShortcut "Previous Activity" #switch to previous activity

After pressing Apply you can test your new mouse gestures. If they don’t work, make sure that the commands work, that the group and action are enabled (checkbox to the right), that gestures are enabled in the settings and that you hold down the correct mouse button.

Mouse shortcuts

As said Plasma Workspaces don’t support global mouse shortcuts yet, which is unfortunate given that many mouse models nowadays have extra buttons. However, it’s possible to set up mouse shortcuts using an application called xbindkeys. A more detailed post about mouse shortcuts can be found here.

So first of all, install xbindkeys. Open ~/.xbindkeysrc in a text editor . Here’s an example of a .xbindkeysrc to bind one mouse button, usually for the action “Back”, to open the activity manager, and vertical scroll to switch to the next/previous activity. The button numbering can vary so you might need to change the numbers ( b:8 etc.) to work with your mouse.

# Activity manager

"qdbus org.kde.kglobalaccel /component/plasma_desktop invokeShortcut "manage activities""

b:8

# Next activity

"qdbus org.kde.kglobalaccel /component/plasma_desktop invokeShortcut "Next Activity""

b:7

# Previous activity

"qdbus org.kde.kglobalaccel /component/plasma_desktop invokeShortcut "Previous Activity""

b:6

You can also use other buttons if you want – the xev command is useful for finding the button number.

Finding the mouse button with xev

When you’re satisfied with your configuration your need to start xbindkeys by running xbindkeys in a terminal (or Alt+F2). If xbindkeys already is running, you can use the following command to restart it: killall xbindkeys && xbindkeys

If you find that you need to start xbindkeys every time you login, add it to autostart in System Settings → System Administration → Startup and Shutdown → Autostart → Add Program… → xbindkeys → OK.

Icon

Yet another way to switch activities with your mouse is to put an icon on your desktop and/or panel.

An icon to show/hide the activity manager

Below you’ll find a .desktop file that opens the activity manager when clicked. Copy and paste the text in a text editor, save the file somewhere as activitymanager.desktop and you’ll have your own activity manager icon.

[Desktop Entry]

Comment=Shows the activity manager

Exec=qdbus org.kde.kglobalaccel /component/plasma_desktop invokeShortcut "manage activities"



GenericName=Activity Manager

Icon=preferences-activities

Name=Activity Manager

StartupNotify=false

Type=Application

X-DBUS-StartupType=none

X-KDE-SubstituteUID=false

The first time you click on the icon it will show a warning asking if you want to start the program. Make sure the command looks right, click on Continue, and the activity manager should show up.

You can easily adapt this desktop file to make icons for previous/next activity. The commands ( Exec= ) you need are listed at the end of the “Mouse gestures” section.

To add the icons to your desktop or panel, unlock your widgets and simply drag and drop them. See Plasma HowTo for more information.

Widgets

Finally, there are a few widgets you can use to switch activities. Activity bar is shipped with the default widgets and is exactly what it sounds like – a bar that shows your activities. A lot of people like to put it in a panel that is set to autohide, so that it stays out of the way most of the time.

Activity bar in a vertical and horizontal panel

While Activity bar provides a fast and easy way to switch between activities, it has some limitations. For example you can’t stop activities from it nor start already paused activities.

There’s a third-party widget called Activity Manager Plasmoid that acts as an alternative activity manager. It currently lacks some features compared to the original manager, such as the ability to create a new activity from a template, but for the purpose of switching between activities it does the job well. Activity Manager Plasmoid can be put on the desktop and panel as well as in the system tray.

Activity Manager Plasmoid in the system tray

These widgets are usually added to a panel to make them accessible all the time, independent of your current activity. (Your desktop changes depending on your activity.) Another solution could be to set the Dashboard to show an independent widget set instead of the current desktop and then use the Dashboard as an activity switcher. This option is found in System Settings → Workspace Appearance and Behavior → Workspace Behavior → Workspace → Dashboard: Show an Independent Widget set. Apply the setting, invoke the Dashboard (Ctrl+F12 by default) and add the widget(s) of your choice to it.

The future

There are exciting times ahead for fans of activities. In 4.7 there will be a KRunner plugin for activities, and someone mentioned a new UI for managing activities, but I don’t know what the current plans are.

This is what I would like to see in the future regarding switching activities (in no particular order):

Make it easier to use D-Bus to switch activity. I couldn’t find a way to switch to the previous/next activity or to bring up the activity manager using D-Bus (update: now I know a workaround way, thanks to a comment below), and when I asked on IRC, I was told that this was already in the plans.

The possibility to set a keyboard shortcut for each activity, for example Meta+F1 for the first activity, Meta+F2 for the second one etc. I found a way to do it with D-Bus, but a GUI option would be nice.

A more streamlined UI for switching activities would be nice. I love how smooth the desktop effects feel, even on this ancient computer – maybe a desktop effect for switching activities?

One thing I dislike about the current manager is that it gives the impression that you need two clicks to switch activity, one to switch and another one to close the activity manager. If you open the activity manager from the Toolbar → Activities…, it sums up to four click just to switch activity! That’s at least two clicks too much, in my opinion.

One thing I dislike about the current manager is that it gives the impression that you need two clicks to switch activity, one to switch and another one to close the activity manager. If you open the activity manager from the Toolbar → Activities…, it sums up to four click just to switch activity! That’s at least two clicks too much, in my opinion. Give activities a more central place in the workspace (like in Plasma Active). Perhaps adding an icon/widget to the default panel to show the activity manager.

Note that this is just my personal wishlist and should not be confused with the actual plans. In any case, I’m looking forward to seeing what the future brings.

Update May 15, 2011: Replaced xte commands with D-Bus calls thanks to ArnAud‘s suggestion. If the D-Bus commands for some reason don’t work for you (those starting with qdbus ), you can install xte, which is usually part of a package called xautomation, and use the following commands instead:

xte 'keydown Super_L' 'key Q' 'keyup Super_L' #open the activity manager

xte 'keydown Super_L' 'key Tab' 'keyup Super_L' #switch to next activity

xte 'keydown Super_L' 'keydown Shift_L' 'key Tab' 'keyup Shift_L' 'keyup Super_L' #switch to previous activity

This assumes that you haven’t changed the default global shortcuts, otherwise you have to modify the commands.

Update May 16, 2011: Added a mention of KDE Plasma Workspaces in the beginning and a note about which version this post describes.

Update May 20, 2011: Added a link to the new post about switching to specific activities with keyboard shortcuts.