Set up Hotkeys to switch between multiple desktops on your Raspberry Pi 4

Background

Scope: How to set up Ctrl-Alt-arrow to switch between multiple desktops.

For the past two and a half hours I’ve been trying to figure out how to configure my Raspberry Pi 4 keyboard shortcuts to be more like my Windows 10 work laptop. I started following one tutorial online that generally taught me what to do. I then looked at a bunch of other tutorials that led me in 1000 other directions but I finally figured out what worked through xahlee.info. By default, my RPi 4 used Ctrl-Alt-arrow to snap a window to one half of the screen (a convenient shortcut but not what I wanted). 

How to Set Up Multiple Desktops

Originally, the window that allows you to enable multiple desktops may not be shown in your menu. To reveal it, click the menu button in the top left corner of the screen (hint: it’s a raspberry icon). Select the Preferences tab and then select the Main Menu Editor. The Main Menu Editor (shown below) will pop up. Go to the Preferences tab and select Openbox Configuration Manager. Now Openbox will appear in Preferences in your main menu. Open Openbox Configuration Manager.

Select the Desktop tab in the Openbox Configuration Manager (shown below). I pumped my number of desktops up to 3 (a comfortable amount without going overboard IMHO - if that doesn’t work for you, do what you like).

FYI - it is easiest to visualize the orientation of these desktops with respect to one another as only one desktop is shown at a time. Visualize the three desktops as three picture frames hanging up on the wall. Picture frame 1, Picture frame 2, and Picture frame 3. The 3 picture frames are the exact same size and are hung side-by-side in a horizontal line. Picture frame 2 is to the right of Picture frame 1 and to the left of Picture frame 3. E.g. look at Picture frame 2, then move to the right, and now you will be looking at Picture frame 3.

The three desktops are very similar in this fashion. If you’re looking at Desktop 1, move to the right once to look at Desktop 2, and to the right once more to look at Desktop 3.

A handy panel item to have when you have multiple desktops is the Desktop Pager (as seen in the top right of the screenshot below). The Desktop Pager shows you which of your desktops that you’re currently on and also shows a preview of what you have open in your other desktops.

Enable the Desktop Pager panel item by right clicking on the Taskbar at the top of your screen (mine is black in the screenshot below). 

In the options that come up, select Add/Remove Panel Items. Then a Panel Preferences window will appear. Select the Add button on the right. Scroll down in the Add plugin to panel window that appears until you find Desktop Pager. Select Desktop Pager and click Add.

The Desktop Pager will appear in the top right of the Taskbar.

How To set up custom Hotkeys

Similar to what xahlee’s tutorial says to do, we will be editing this file:

~/.config/openbox/lxde-pi-rc.xml

The name of our file is different than xahlee’s because xahlee is likely doing this edit on a strictly Linux machine. The RPi is a Linux based machine running Raspbian. The file that we are editing is in the same directory location but is named differently - our’s will have “pi” in the filename (as seen above).

I recommend navigating to this file using the file explorer.

Other tutorials will say to navigate to this file and edit it in your terminal. They will give you a line like the one below that you can simply copy and paste into your terminal:

sudo nano /etc/xdg/openbox/lxde-pi-rc.xml

That method will work as well, however, I find actually editing the file to be very cumbersome in-terminal which is why I navigate to the file in the file explorer. When I find the file, I right click on the file and select to open with Geany.

We will be editing the keyboard shortcuts section starting at line 170 (shown below).

The correct piece of xml code to put in this section, which I found from xahlee.info, is:

  <keyboard>
    ...
    <keybind key="C-A-Left">
      <action name="DesktopLeft">
        <dialog>no</dialog>
        <wrap>yes</wrap>
      </action>
    </keybind>
    <keybind key="C-A-Right">
      <action name="DesktopRight">
        <dialog>no</dialog>
        <wrap>yes</wrap>
      </action>
    </keybind>
    ...
  </keyboard>

After inserting the above code into lxde-pi-rc.xml, we now need to reset Openbox. Open a terminal window. Copy and paste the following code into the terminal:

openbox --reconfigure

This resets Openbox. Your keyboard shortcuts to maneuver through your various desktops will now work.

FYI

With this list, you can customize which keys change desktops. In the code above, we have "C-A-Right" as the shortcut to go to the desktop to the right. That means press Control and Alt and the Right-Arrow keys on your keyboard all at the same time. If you’d rather use Shift, substitute "S" for “C”; e.g. S-A-Right.

  • A - ALT
  • C - CTRL
  • S - Shift
  • W - Windows Key
  • Print - Print Screen
  • Up / Down / Right / Left - arrow keys
  • Prior - Pg Up
  • Next - Pg Dn
  • Space - spacebar
  • Home - home
  • End - end
  • Return - enter
  • BackSpace - backspace

Trouble Shooting

NOTE: Some websites recommend copying and pasting an rc.xml file into .config/openbox. Don’t do this. Believe me, changes made to that file (which didn’t exist in that location in the first place) will not reconfigure your system. Adding this file to my folder from the beginning probably cost me an hour alone.

NOTE: Some websites, even the Openbox official website, state to set action name=”GoToDesktop. This does not work. This was the other major issue I was having. RPi uses Openbox 3.6.1 (which I found by opening terminal and typing openbox --version) which is the most up do date version. I’m unsure why GoToDesktop doesn’t work. All I know is, set action name=”DesktopRight or DesktopLeft or you won’t get the desired result. If copying and pasting the above code did not work for you, please consider the following:

1) Use proper Openbox syntax:The .xml file you are editing has a VERY specific structure that MUST be followed or it will not work. There are large chunks of code and get broken down into smaller pieces - those smaller pieces are the commands that we are editing. For example, we are working in the large chunk of code defined by:

<keyboard>


</keyboard>

The ellipse (“...”) in this instance is just a substitute for all the code in between the section header (<keyboard>) and footer (</keyboard>). Similarly, each shortcut has a header ( <keybind key="C-A-...">) and a footer (</keybind>). All parts of .xml code have a header and a footer. Each header must have a footer. Each footer must have a header. If either is left solo without the other, the code will not work.

2) Check Spelling: Misspelled words will not allow code to work.

3) Check spacing and indentation: Following is an example of the code with all spaces replace by a · .

··<keyboard>
···<keybind key="C-A-Left">
·····<action name="DesktopLeft">
·······<dialog>no</dialog>
·······<wrap>yes</wrap>
·····</action>
···</keybind>
··</keyboard>

Notice how <keyboard> and </keyboard> wrap around the other code and all the other code are indented at least two more spaces in. Code that is being wrapped by other code needs to be indented two spaces more than the header and footer is wrapped by. Make sure your spacing is correct.

My Code

You can also just copy and paste my code from my github 😉

Leave a Reply