Add Book to My BookshelfPurchase This Book Online

Chapter 12 - Terminals

UNIX Systems Programming for SVR4
David A. Curry
 Copyright © 1996 O'Reilly & Associates, Inc.

Terminal Window Size
Both BSD and SVR4 provide a method to keep track of the current terminal size (or window size). The kernel will notify the foreground process group whenever this information is changed (e.g., when the user resizes his window) by sending a SIGWINCH signal. (Background processes should check the window size when they are moved into the foregound, to be sure it hasn't changed.)
The window size is stored in a struct winsize structure, defined in the include file termio.h on SVR4 systems, and the include file sys/ioctl.h on BSD systems:
    struct winsize {
        unsigned short    ws_row;
        unsigned short    ws_col;
        unsigned short    ws_xpixel;
        unsigned short    ws_ypixel;
    };
The ws_row element contains the number of character rows (lines) on the terminal, while the ws_col element contains the number of character columns. The ws_xpixel and ws_ypixel elements contain the size of the window in pixels in the X (horizontal) and Y (vertical) directions, respectively.
The struct winsize structure is manipulated with the ioctl function described earlier. The second argument (request) may be one of:
TIOCGWINSZ
Get the current window size and store it in the structure pointed to by the third argument.
TIOCSWINSZ
Set the current window size to the values contained in the structure pointed to by the third argument. If these values are different from the current values, generate a SIGWINCH signal.

Previous SectionNext Section
Books24x7.com, Inc © 2000 –  Feedback