Using the Keyboard to Switch Desks

From Nekochan
Jump to: navigation, search


Using 4DWM it's possible to bind custom keys to quickly switch between different desktops; this allows you to assigning desks to different tasks, for example one desktop for web surfing, another for editing, etc.

In this tutorial we'll create a series of four desktops that can be switched between by pressing <ALT-1> through <ALT-4>. More desktops can of course be added as needed.

To start, open Desks Overview by selecting Desktop -> Extra Desks in the Toolchest. By default, Desks Overview will contain two desks, the current desktop labeled 'Desk 1' and the Global desk. Create two more desktops by selecting Menu -> Desk -> New Desk.

Now let's rename the desks to match the tasks we're going to assign. For this example, we'll use 'System', 'Editing' and 'Web', leaving 'Global' alone as it is a special purpose desk (anything placed on Global is mirrored on the other desks). Rename each desk by first selecting it with the mouse, then right click to bring up the contextual menu. Select Desk -> Rename Selected and then type in the new name above each.

Now it's time to configure 4Dwm to use our custom hot keys. First we need to create a ~/.4Dwmrc file by copying /usr/lib/X11/system.4Dwmrc to your home directory as ~/.4Dwmrc:

cp -i /usr/lib/X11/system.4Dwmrc ~/.4Dwmrc

Open ~/.4Dwmrc with a text editor and find the following section:

!
!! SGI 4Dwm Key Binding Description
!!
Keys 4DwmKeyBindings
{
# Same as the standard OSF Key Bindings
Shift<Key>Escape window|icon f.post_wmenu
Alt<Key>space window|icon f.post_wmenu
Alt<Key>Tab root|icon|window f.next_key
Alt Shift<Key>Tab root|icon|window f.prev_key
Alt<Key>Escape root|icon|window f.circle_down
Alt Shift<Key>Escape root|icon|window f.circle_up
Alt Shift Ctrl<Key>exclam root|icon|window f.set_behavior
Alt<Key>F6 window f.next_key transient
Alt Shift<Key>F6 window f.prev_key transient
Shift<Key>F10 icon f.post_wmenu
! Alt Shift<Key>Delete root|icon|window f.restart
# SGI added key bindings
Shift<Key>Escape root f.menu 4DwmRootMenu
Alt<Key>space root f.menu 4DwmRootMenu
}

Add the following lines after the # SGI added key bindings section, but before the closing brace:

#change desktops
Alt<Key>1 root|icon|window f.switch_desk "System"
Alt<Key>2 root|icon|window f.switch_desk "Editing"
Alt<Key>3 root|icon|window f.switch_desk "Web"
Alt<Key>4 root|icon|window f.switch_desk "Global"
#Alt<Key>5 root|icon|window f.switch_desk "Desk 5"
#Alt<Key>6 root|icon|window f.switch_desk "Desk 6"
#Alt<Key>7 root|icon|window f.switch_desk "Desk 7"
#Alt<Key>8 root|icon|window f.switch_desk "Desk 8"

Notice that desks 5-8 are commented out; if you need more desktops in the future uncomment these and change the description in the quotes to match your desktop title.

After restarting the X-server (logging out then back in will work) you should now be able to cycle through your desktops using <ALT-1> through <ALT-4>. I find that setting a custom background for each desktop makes it easier to tell them apart.

References

This article originally appeared here and has been modified to fit this format.

See Also