home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  


Linux in a NutshellLinux in a NutshellSearch this book

19.3. Adding Keyboard Shortcuts

The system.fvwmrc file that we started with offers little in the way of keyboard shortcuts, or accelerators, for window management functions. But if you're one of those users who prefer to keep their hands on the keyboard and off the mouse as much as possible, you can easily define keys in your .fvwm2rc file to perform a variety of functions.

19.3.1. Navigating the Desktop

The Pager is a great tool for getting around one or more desktops, but many people hate using the mouse. You can configure certain keys and key combinations to let you move around in various ways.

Add the following lines to your .fvwm2rc file to set up key combinations to scroll one page in any direction on the desktop using Ctrl plus an arrow key. The view scrolls in the direction of the arrow.

Each definition uses the Key variable followed by:

  1. The name of the key

  2. The context (location) in which it must be typed

  3. Any modifying keys that must also be held down

  4. The action initiated by the key or key combination

Thus, in the following example, the first definition line says that pressing the left arrow key (Left) in any (A) context, while also holding down the Ctrl (C) key scrolls the screen one page to the left on the current desktop:

# Press arrow + Control in any context
# to scroll by one page in the direction of the arrow
Key Left            A            C            Scroll -100 0
Key Right           A            C            Scroll +100 +0
Key Up              A            C            Scroll +0  -100
Key Down            A            C            Scroll +0  +100

Table 19-1 summarizes the functionality.

Table 19-1. Key combinations to change the page

Key combination

Moves view

Control, right arrow key

One page to the right

Control, left arrow key

One page to the left

Control, up arrow key

One page up

Control, down arrow key

One page down

The Scroll variable takes the same parameters as EdgeScroll, which was explained in the previous section. See the fvwm2 manpage for more information. Note that the key combinations we've defined let you get around a single desktop but won't let you advance to another desktop. We'll deal with that contingency later.

Here's another possible key binding. This one advances the view to every page in the desktop in order, and finally wraps back to the first page. You use the Tab key while holding down Control, again in any context. The definition line looks like:

# Press Tab + Control in any context to scroll 
# by one page with wrap scrolling
Key Tab         A       C       Scroll 100000 0

Table 19-2 summarizes another page-changing combination.

Table 19-2. Another key combination to change the page

Key combination

Moves view

Control, Tab

To the next page in the desktop

Since application windows can straddle pages, there may be times when you want the screen to display a screenful other than a page proper. (You might also want to look at windows on two different pages at once.) The following shortcuts scroll the view one-tenth of a page at a time. Instead of Control, these shortcuts use the so-called Meta key. This is a symbolic name—the actual key that serves the Meta function varies from keyboard to keyboard. In many cases, the key labeled Alt serves as the Meta key. Here are the configuration file definition lines:

## Press arrow + meta key in any context
## to scroll by 1/10 of a page in the direction of arrow
Key Left            A            M            Scroll -10 +0
Key Right           A            M            Scroll +10 +0
Key Up              A            M            Scroll +0   -10
Key Down            A            M            Scroll +0   +10

These lines establish the functionality outlined in Table 19-3.

Table 19-3. Key combinations to scroll the page by 1/10

Key combination

Moves view

Meta, left arrow key

One-tenth of a page to the left

Meta, right arrow key

One-tenth of a page to the right

Meta, up arrow key

One-tenth of a page up

Meta, down arrow key

One-tenth of a page down

If you have more than one desktop, you can also create shortcuts to move between desktops. The following two shortcuts let you go back and forth between desktops in a two-desktop environment:

## Press Control + Return in any context 
## to scroll forward by 1 desktop
Key Return         A       C       Desk 1 1 1
## Press Shift + Control + Return in any context 
## to scroll back by 1 desktop
Key Return         A       SC      Desk -1 0 0

Table 19-4 summarizes these shortcuts.

Table 19-4. Key combinations to scroll to the next desktop

Key combination

Moves view

Control, Return

One desktop ahead

Shift, Control, Return

One desktop back

The second and third parameters to the Desk variable constrain the paging so that you can't page beyond the first or second desktops. (Theoretically, you can page outside the view of the Pager!) If you have more than two desktops, you will need to edit these definitions. See the fvwm2 manpage for more about the Desk variable.

19.3.2. Moving the Pointer

The previous section outlines some keyboard shortcuts you can define to scroll the page view. But you can also define shortcuts to move the position of the pointer on the screen. If you prefer using the keyboard to the mouse, these shortcuts can come in handy. They employ the CursorMove variable, also described on the fvwm2 manpage.

The keyboard accelerators in the first group move the cursor symbol one-tenth of a screen at a time. The first definition line says that pressing the left arrow key in any (A) context, while also holding down the Shift (S) and Meta (M) keys, moves the cursor one-tenth of a page in the direction of the arrow:

## Press Shift + Meta + arrow in any context
## to move the pointer by 1/10 of a page in direction of arrow
Key Left            A            SM            CursorMove -10  +0
Key Right           A            SM            CursorMove +10  +0
Key Up              A            SM            CursorMove +0   -10
Key Down            A            SM            CursorMove +0   +10

Table 19-5 summarizes the commands.

Table 19-5. Key combinations to move the pointer by 1/10 of the page

Key combination

Moves pointer

Meta, Shift, left arrow key

One-tenth of a page to the left

Meta, Shift, right arrow key

One-tenth of a page to the right

Meta, Shift, up arrow key

One-tenth of a page up

Meta, Shift, down arrow key

One-tenth of a page down

If you want as much control moving the pointer with keystrokes as you do moving it by hand, you can specify shortcuts to move it a mere one percent of a page at a time:

## Press Shift + Control + arrow in any context 
## to move the pointer by 1% of a page in direction of arrow
Key Left            A            SC            CursorMove -1 0
Key Right           A            SC            CursorMove +1 +0
Key Up              A            SC            CursorMove +0 -1
Key Down            A            SC            CursorMove +0 +1

Table 19-6 summarizes the commands.

Table 19-6. Key combinations to move the pointer by 1 percent of the page

Key combination

Moves pointer

Shift, Control, left arrow key

One percent of a page to the left

Shift, Control, right arrow key

One percent of a page to the right

Shift, Control, up arrow key

One percent of a page up

Shift, Control, down arrow key

One percent of a page down

19.3.3. Menu and Window Manipulation

So far we've limited our keyboard shortcuts to scrolling the view and moving the pointer. But you can create keyboard bindings for any window manager function.

Here are some sample bindings to perform simple window operations and to display a few menus:

# Keyboard accelerators
Key F1          A       M       Iconify
Key F2          A       M       Move
Key F3          A       M       Resize
Key F4          A       M       Popup "RootMenu"
Key F5          A       M       Popup "Misc-Ops"
Key F6          A       M       Popup "Utilities"
Key F7          A       M       Popup "Module-Popup"
Key F10         A       M       Restart fvwm2
Key F12         A       SM      Close

These are just sample bindings; you may want to set up your own keyboard shortcuts to do entirely different things. But these bindings illustrate some of the possibilities, as well as potential problems.

In our sample definition lines, the first binding specifies that if you press the F1 function key while holding down the Meta (M) key, with the pointer in any (A) context, the focus window is iconified (or deiconified). Meta-F2 lets you initiate moving the focus window, while Meta-F3 starts a resize operation.

Note that if you've adopted the keyboard bindings to move the pointer (as described in the previous section), you can perform the move and resize operations entirely with keystrokes. For example, use Meta-F2 to begin a move, drag the window outline by moving the pointer symbol using the appropriate keyboard shortcuts, then press the Return key to complete the operation.

In addition, we've set up function keys to pop up four different menus, the contents of which are predefined in the .fvwm2rc file. Once a menu is popped up, you can use the up and down arrow keys to highlight items on the menu, right and left keys to move down and up through submenus (cascading menus), the Return key to select an item, and Esc to pop down the menu without making a selection.

Because we're doing a lot of tinkering with fvwm2 customization, we have set up Meta-F10 to restart the window manager. This is much faster than bringing up menus.

We've also created a key combination to close the focus window: Shift-Meta-F12. Certainly it's handy to be able to get rid of a window with a keyboard shortcut, but you don't want it to be too easy or you may do it by mistake. Having an extra modifying key (Shift) and using the very last function key (F12) require you to act deliberately in closing a window using this method.



Library Navigation Links

Copyright © 2003 O'Reilly & Associates. All rights reserved.