# Windows, How To Work Them

## Basic Window Management

In computer terminology, a window is a rectangular area containing information that can be moved around the desktop. Each application running in &tde; uses at least one window and some applications use more than one window. These windows are manipulated or controlled in many ways to make the desktop useful. Here is a typical window: A normal window

### Switching Between Windows

A window must be active or receive the focus to be used. When first starting an application the main window immediately receives the focus and is ready to use. Only one window can be active at a time. The active window is the one that responds to user actions and can be distinguished from other windows by the different colored titlebar.

The titlebar is the top bar of a window that displays the name and description of the window. The default titlebar also contains the Minimize, Maximize, and Close buttons on the far right side.

With the &tde; default theme, the active window has a `light blue` titlebar, and the inactive windows have `gray` titlebars.

To work in a different window requires activating that window. There are two ways to do this:

- Use the mouse pointer to select a window. When selected the window receives the focus and becomes active and will be raised to the foreground above other windows.

- With the keyboard, press and hold either &Alt; key and press the key. A popup dialog appears with a list of available windows. The currently active window that has the focus will be selected automatically in the list. While pressing the &Alt; key, select a different window by again pressing the key to scroll through the list. Release the &Alt; key and the window that is selected in the list receives the focus and becomes the active window.

### Moving Windows

One way to organize the windows on a desktop is to move them. There are three ways to move a window:

- Select the window titlebar using the &LMB; and continue holding the &LMB;. When selected in this manner, moving the mouse pointer moves the window. Release the mouse button and the window remains at that position.

- Select the window titlebar using the &RMB;, which causes a popup menu to appear as displayed in the following image. From the popup menu select Move. The mouse pointer moves to the center of the window. Move the mouse pointer to move the window. After moving the window to the desired position, use the &LMB; to release the window.

  The Window Menu The Window Menu

- Place the mouse pointer over the window to move. Press and hold either &Alt; key and the &LMB;. The mouse pointer changes to a compass. Moving the mouse then moves the window. Release the mouse button to release the window. This method is useful when the window titlebar has moved off the screen and the previous methods cannot be used.

### Resizing Windows

The window size can be changed: bigger, smaller, wider, or taller. There are two ways to resize a window. Use either method:

- Move the mouse pointer over one of the side borders of the window. The mouse pointer changes into a horizontal double-headed arrow. Press and hold the &LMB; and drag the window border, making the window bigger or smaller. Similarly, selecting the top or bottom borders of the window will change the height of the window. To concurrently change both width and height of a window, move the mouse pointer over the corner of the window. When the pointer becomes a diagonal double-headed arrow, select the border corner and drag.

- Use the left-most button on the window titlebar to display the window menu. Choose the Resize entry, and the mouse pointer will become a double-headed arrow. Move the mouse pointer around to resize, and use the &LMB; to release the window.

- When the window border or the button for the window menu are not visible, usethe &Alt; key and &RMB;: Press and hold the &Alt; key and drag with the &RMB;. The window will resize. Release the &RMB; when finsihed resizing.

Windows may be maximized in size to use the entire screen. Use the Maximize
button, which is located on the window titlebar, the second button from the right. Selecting that button with the mouse will force the window to resize as large as the screen allows in both directions. Alternately, selecting that button with the &MMB;
or the &RMB;
will increase the window's size in only the vertical or horizontal direction, respectively.

### Hiding Windows

A window can be made to shrink out of view without closing the application. There are two ways to shrink a window: minimizing and shading. To minimize a window, select the Minimize button, which is located on the window titlebar, third button from the right. The window will not be displayed, but the application remains running as can be seen in the taskbar on the panel. To display the window again, use the mouse to select the respective rectangular button in the taskbar or use the &Alt;
as described in switching-between-windows.

Shading windows is similar to minimizing, but the titlebar of the window remains on the screen. To shade a window, use the mouse to "double-click" on the titlebar. To restore the window, again "double-click" on the titlebar.

### Cascading Windows

Sometimes you might have a whole lot of windows open and all over the place. By selecting to cascade windows &tde; will automatically line them up as a succession from the top-left of your screen. To use this option use your &MMB; on the desktop, and then select Cascade Windows.

### Uncluttering Windows

By selecting to unclutter your opened windows &tde; will attempt to use the maximum available space of the desktop in order to display as much of each window as possible. For example, should you have four windows open and you request that they be uncluttered, they will each be placed in a corner of the desktop, regardless of where they were originally. To use this option once again use your &MMB; on the desktop and then select Unclutter Windows.

### Closing Windows

When you finish using an application, you will want to stop the application and close its window. Once again, you have the choice of a few options:

- Click on the right-most button on the window titlebar. If you are editing a document with that application, you will be asked whether you want to Save your changes, Discard them, or Cancel your command to close the application.

- Use the File Quit option on the menubar. You will be presented with the same choice of Save, Discard, or Cancel.

- Right-click on the respective window in &kicker;, the &tde; panel, and then select Close. You will be prompted with an option to save any documents that were being edited.

- Press &Alt;F4
  . Once again, the confirmation dialog will be shown if you were editing any documents.

## Advanced Window Management

kstart

### &kstart;

The simplest way to access the advanced window management facilities in &tde; is to use a little known utility called &kstart;. &kstart; lets you control the way an application interacts with the window manager. The command is usually used to define special behavior for commonly-used applications, but it can also be useful for integrating non-&tde; applications into your desktop.

Using &kstart; is easy: you simply put ``kstart`` and some options before a command. To begin, let's look at how we might use &kstart; to customize the behaviour of a &kcalc; window. The command we'll use is as follows:

    % kstart --ontop --alldesktops kcalc

Hopefully the effect this command is obvious - the kcalc window will stay on top of all the others and be visible on every virtual desktop. A feature that is less obvious is that this command will work with any NET compliant environment, not just &tde;.

We can pass arguments to programs we invoke with &kstart; as normal, for example:

    % kstart --skiptaskbar --desktop 1 xmessage 'Hello World'

This command displays `Hello World` with xmessage and ensures that the window will be shown on the first virtual desktop and will be omitted from the taskbar. The fact that this program is written using the Xt toolkit rather than being a native &tde; application does not cause any problem for &kstart;. Hopefully this illustrates how &kstart; can be used to integrate foreign applications into your &tde; desktop.

### Other Special Window Settings

While you can use &kstart; to assign particular window settings, &tde; also allows you to alter these — as well as other similar settings — from the program window itself. Simply select the left-most button in the window titlebar (or press &Alt;F3 after the window is focused), and then go to Advanced Special Window Settings.... As you can see, from here you change various things from its geometry upon startup, to whether it should have a border or not.

### The System Tray

Now that we know how to customize the decoration of a window let's take a look at another aspect of the desktop: the system tray. The system tray is an area in which an application can display a small window. It is used to display status information or provide quick access to commands. A window that has an item in the system tray usually disappears from the task manager when minimised with the tray icon providing a replacement. Normally tray icons are specifically developed as part of an application, but as with window decorations, &tde; provides a tool for changing this: ksystraycmd.

To begin with, we'll take the standard application &kcalc; and turn it into a system tray application. This is acheived with one simple command:

    % ksystraycmd --title 'kcalc' kcalc

The icon shown in the tray is the one specified in the window hints and will be updated if the icon changes. The window title is shown as a tooltip if you hold the mouse pointer over the icon. ksystraycmd follows standard &tde; behaviour so the target window can be shown and hidden by clicking the tray icon, and a standard context menu is available.

### More Complex Uses of ksystraycmd

To illustrate the other features of ksystraycmd, we'll use a more complicated example: a &konsole; window tracking the `.xsession-errors` file (this is the log file that records what's happening on your desktop). To begin with, we'll simply look at how we can view this:

    % konsole --icon log --caption 'X Log' \
    --nomenubar --notabbar --noframe \
    -e tail -f ~/.xsession-errors

The `--caption` and `--icon` arguments are provided as standard by &tde; applications. You can get a full list of these global options by running an application with the `--help-kde` and `--help-qt` parameters. Here we give our &konsole; window the title 'X Log' and the icon log. You can use these options with any &tde; application and as mentioned above, ksystraycmd takes account of these when creating the tray icon. The `-e` argument is specific to &konsole; and tells it to run the `less` command. Despite its complexity, we can easily move this window into the tray with ksystraycmd:

    % ksystraycmd --hidden --title 'X Log' \
    konsole --icon log --caption 'XLog' \
    --nomenubar --notabbar --noframe \
    -e tail -f .xsession-errors

In addition to being the most complex command we've used, this example demonstrates the `--hidden` option which starts the command with only the system tray icon visible. This example achieves our aim of providing quick access to the log file, but we can do things a little more efficiently if we only run the konsole process when it is visible. The command we use is

    % ksystraycmd --startonshow \
     --icon log --tooltip 'X Log' \
    konsole --icon log --caption 'X Log' \
    --nomenubar --notabbar --noframe \
    -e tail -f ~/.xsession-errors

The addition of the `--startonshow` parameter tells ksystraycmd to start with only the tray icon visible (like the `--hidden` parameter), and to wait until the user activates the tray icon before running the target command. We've also used the `--quitonhide` parameter which tells ksystraycmd to terminate the target app whenever its window is hidden. Using both these parameters ensures that our &konsole; tray icon doesn't waste resources when we aren't using it. Creating and destroying the target window as we do here prevents the standard icon and title handling of ksystraycmd from working, so we now need to specify the initial icon and tooltip explicitly too.

### Improving Reliability

In all of our previous examples we've relied on &kstart; and ksystraycmd to figure out which window we want to affect, and unless we say otherwise, they assume that the first window to appear is the one we want. This policy is usually OK because we are starting the application at the same time, but it can fail badly when lots of windows are appearing (such as when you log on). To make our commands more robust we can use the `--window` parameter. This specifies the title of the target window. The following example uses the `--window` parameter to ensure that a particular konsole window is affected:

    % kstart --iconify --window 'kstart_me' konsole --caption 'kstart_me' -e tail -f ~/.xsession-errors

Here we've used the tried and tested technique of specifying a title for both &kstart; and the target application. This is generally the best way to use &kstart; and ksystraycmd. The `--window` argument is supported by both &kstart; and `ksystraycmd` and can be regular expression (⪚ window[0-9]) as well as a particular title. (Regular expressions are a powerful pattern matching tool you'll find used throughout &tde;.)

## Using Multiple Desktops

Sometimes, one screen's worth is just not enough space. If you use many applications at the same time, and find yourself drowning in different windows, virtual desktops offer a solution. By default, &tde; has four virtual desktops, each one of which is like a separate screen: you can open windows, move windows around, and set backgrounds and icons on each of the desktops. If you are familiar with the concept of virtual terminals, you will have no trouble with &tde;'s virtual desktops.

### Switching Virtual Desktops

One way to move to a different desktop is to use the desktop pager in the panel. Use the mouse pointer and &LMB; to select the desired desktop.

Another way to move to a different virtual desktop, is using &Ctrl; in the same way as you would use &Alt; to switch between windows (refer to the switching-between-windows): Hold down &Ctrl; and then press . A small popup window appears, showing the virtual desktops, with one highlighted. When you release &Ctrl;, &tde; will switch to the highlighted virtual desktop. To select a different desktop, hold down &Ctrl; whle pressing repeatedly. The selection moves through the available desktops. When the desktop you want to switch to is highlighted, release &Ctrl;.

### Windows and Virtual Desktops

You can move windows to different virtual desktops with the To Desktop item in the window menu button. Use the &LMB; to select the window menu button and select the desktop to which you want to move the window. You can make the window appear on all desktops with the All Desktops
item.