Suffering eyestrain from looking at a flickering monitor? Can't quite fit everything you want in your display? Ordinarily, problems like these call for a new monitor, or at least switching to a different standard resolution -- say, going down in resolution if the problem is flicker, or going up from 1024x768 to 1280x1024 to get more screen real estate.
Suffering eyestrain from looking at a flickering monitor? Can’t quite fit everything you want in your display? Ordinarily, problems like these call for a new monitor, or at least switching to a different standard resolution — say, going down in resolution if the problem is flicker, or going up from 1024×768 to 1280×1024 to get more screen real estate.
Linux, though, is about extreme configurability and choices, and it (or XFree86, really) provides you with tools you need to tweak your video modes to make the best use of your monitor. To be sure, the procedures described here won’t let you make huge differences in your display, but they will help you get the most out of your video card and monitor by increasing the refresh rate a bit, squeezing a few extra pixels onto the screen, or both.
One caveat: these procedures are useful for tweaking displays on traditional cathode ray tube (CRT) monitors. The newer liquid crystal display (LCD) monitors have fixed resolutions, and refresh rates don’t have any visible effect either. Thus, tweaking the settings for LCD monitors is mostly pointless, with one small exception. If an analog LCD monitor consistently brings up your Linux display off-center or slightly too large or too small, you may be able to fix the problem using the xvidtune utility described toward the end of this column.
And a warning: before proceeding further, you should know that adjusting your monitor’s video modes as described here can be dangerous! This is particularly true of older monitors sold prior to the mid-1990s. Such monitors accept signals beyond their design specifications, but using those signals can cause damage. More modern monitors are designed to ignore out-of-spec signals and are less prone to damage from errors in configuration. So, exercise caution in tweaking your monitor settings, even with new models.
Finding the Limits of Your Hardware
CRT monitors, like televisions, work by quickly passing a narrow beam of electrons over the screen. This beam paints the screen one line at a time. When one line is done, the beam moves on to the next line, and so on. The horizontal sync rate refers to the number of horizontal lines that the monitor can or does display per second. When an entire screen has been drawn, the monitor turns off the beam and re-aims it at the top of the screen to begin again (that is, it engages is a vertical refresh operation). Typically, the process of painting an entire screen happens 60-100 times per second. A monitor’s capabilities, in particular its maximum resolution and the vertical refresh rate, are determined by the combination of its limits on horizontal sync and vertical refresh.
The first step in tweaking your display settings is to find the monitor’s horizontal sync and vertical refresh limits. These can be found in your monitor’s manual, and are expressed as frequency limits. The horizontal frequencies are measured in kilohertz (kHz), and the vertical frequencies are expressed in hertz (Hz). These values are entered in your XF86Config file using the HorizSync and VertRefresh keywords in the Monitor section.
For instance, an XF86Config file that controls a 19-inch Iiyama VisionMaster Pro 450 monitor contains the following lines:
XFree86 uses these values to determine whether a given video mode can be accepted by the monitor. If the combination of resolution and overall vertical refresh rate exceed either the horizontal sync or vertical refresh limits, XFree86 rejects the video mode and tries another. For this reason, it’s extremely important that you enter the correct values for these limits. If your limits are too narrow, XFree86 may reject modes that would otherwise have worked perfectly well, thus frustrating your attempts to improve your display. If your limits are too wide, you may end up sending a signal to your monitor that it will reject (at best) or that will damage it (at worst).
Be sure to double-check your horizontal sync and vertical refresh values. Both specifications are usually printed in your monitor’s manual, so consult it to be sure they’re set correctly. If not, correct your XF86Config settings before proceeding.
Another important limit is your maximum dot clock. This refers to the rate of analog data flow between the video card and the monitor. Both video cards and monitors have maximum dot clocks, and either one can be the limiting factor in your configuration. Your monitor’s maximum dot clock should be printed in its manual. For the video card, you can use X to discover the dot clock. Check for an X log file, typically /var/log/ XFree86.0. It’s likely to contain a line or two like the following:
(==) SIS(0): Min pixel clock is 12 MHz
(–) SIS(0): Max pixel clock is 390 MHz
In this example, the maximum dot clock is 390 MHz. (The minimum dot clock isn’t likely to be an issue.)
On some systems, you can type X -probeonly to find this information, but you’ll need to ensure that X is not currently running. (Unfortunately, phrasing from one system to another varies substantially, so you may need to search carefully to find the dot clocks. The relevant line usually contains the word clock, so do a search for that word first.)
XFree86′s Resolution Tools
If you’ve configured video settings in Windows or in the more user-friendly Linux tools, you’ve set video modes by specifying a combination of resolution and vertical refresh rate. For instance, you might set your display to 1280×1024 at 75 Hz.
However, this isn’t the way it’s done in XF86Config. As long-time Linux users know, XF86Config specifies a video mode using a keyword called Mode or ModeLine in the Monitor section. Typically, ModeLine is used, but the Mode keyword accepts a multi-line format that’s easier to parse. A typical Mode looks like this:
HTimings 1280 1312 1416 1664
VTimings 1024 1027 1030 1064
This example creates a 1280×1024 mode with a 76 Hz vertical refresh rate. The vertical refresh rate isn’t obvious in the mode specification, but the resolution is easy to spot — it’s embedded as the first number after the HTimings and VTimings keywords, respectively.
By convention, the mode name is also the resolution, although it need not be — you could call your mode Fred, 1984, or anything else you like. But, using the resolution as the mode name makes it easy to specify the resolution in the Screen section of XF86Config.
Multiple mode specifications can have the same name. For instance, two 1280×1024 modes might exist. If one of these is to be used, XFree86 tries the one with the highest refresh rate first. If it doesn’t work (typically because it would generate timings outside of the monitor’s horizontal or vertical capabilities), XFree86 tries the second mode. If it doesn’t work, XFree86 tries a fallback resolution. If all fallback resolutions fail, X doesn’t start.
An equivalent single-line entry to the preceding one would begin with ModeLine and include the mode name (“1280×1024″ in this example) and all the numbers on the next three lines. The ModeLine format omits the DotClock, HTimings, VTimings, and EndMode keywords, though.
In the days of XFree86 3.3.6 and earlier, XF86Config files were typically filled with dozens of ModeLine statements. With XFree86 4.0 and later, though, information on a set of standard VESA modes is built into the X server, so XF86Config files for XFree86 4.0 and later typically have few or no ModeLine or Mode statements. If you want to squeeze a slightly higher refresh rate out of your monitor, though, or if you want to use a non-standard display size, you’ll need to create a custom mode.
Creating Your Own Mode
The simplest way to create a custom video mode is to use a tool that’s available online at http://xtiming.sourceforge.net. It’s shown in Figure One. To use it, you first enter the information you collected earlier: the monitor’s horizontal and vertical timing limits and the lower of the video card’s and monitor’s maximum dot clocks. You can then specify information in the second box (which falls off the bottom of Figure One) to optimize your display.
|Figure One: The online XFree86 Modeline Generator can help you generate a video mode|
You can use this page in a few ways:
To generate a mode for the best vertical refresh rate at a given resolution, enter the resolution and dot clock (which should match the one in the monitor section) and leave the refresh rate box empty.
To generate a mode for the highest resolution at a given refresh rate, enter the refresh rate and dot clock (which should match the one in the monitor section) and leave the refresh rate box empty.
To generate a mode that matches particular specifications (such as the refresh rate and resolution you use in another OS), fill out both the resolution and refresh rate fields.
In all cases, you can also tell the utility that you want to exactly match a particular aspect ratio (4:3 or 16:9) to keep your pixels close to square, activate interlace or double scan modes, or enter other advanced features.
When you’re done, click Calculate Modeline to generate a ModeLine entry. If the tool also generates a warning in red text about parameters being above the specified limits, it means that you’ve been too ambitious and your monitor can’t handle the mode you’re trying to create. (Alternatively, you might have entered monitor or video card specifications that are too pessimistic, so go back and double-check those values.)
To test your video mode, you must make two changes to your XF86Config file. First, cut and paste the mode generated by the web page into the Monitor section of your XF86Config file. If the file already contains any modes, you may want to enter the new one just before or after the existing ones. Next, in the Screen section, locate the Display subsection for your default color depth and add the mode name to the start of the Modes line.
For instance, suppose you run in 24-bit color depth (as defined by a DefaultColorDepth 24 line) and you’ve just created a mode called 1280×1024&95. Your 24-bit Display subsection might now look like this:
Modes “1280×1024&95″ “1024×768″
This configuration tells XFree86 to use your new custom mode if possible, but to fall back to a standard 1024×768 mode if the custom mode fails. You could also use a fallback to a standard mode of your target resolution, if you’re trying to use a standard resolution at an unusual refresh rate. You can now save your modified XF86Config file — but be sure to keep a copy of your working original!
How you test the new mode depends to some extent on your distribution and your default settings.
If you normally log into Linux in text mode, quit from X and restart it as you normally do. When X restarts, it’ll use the new settings.
On some distributions, logging out of an X-based login will restart the X server with the new settings.
If you log into X but it doesn’t restart the server when you log out, you’ll need to restart the server in some way. Drop back to a text-mode login with no X login server running and then test X by typing startx. To do this, though, you’ll need to shut down the XDM login server.
When you test your mode, you should first verify that it’s doing what you want — giving you extra screen real estate, eliminating flicker, or both. You can then work on making some final adjustments. You may want to better center the display on the screen, for instance.
To tweak the video mode, use the xvidtune program, which ships with most distributions and is shown in Figure Two. Be sure to run xvidtune by typing its name in an xterm or similar command-line window, since you’ll need to cut-and-paste the output that xvidtune displays in the xterm.
|Figure Two: The xvidtune program helps you fine-tune your video display|
xvidtune shows you the values that make up the current mode, mostly in the “HDisplay” and “VDisplay” columns of its window. Beneath each of these columns are buttons called Left, Right, Wider, and Narrower for the HDisplay column, or Up, Down, Shorter, and Taller for the VDisplay column.
Click these buttons to adjust the mode’s values, but be aware that your changes won’t appear immediately. You must click Test to see the effect of your changes. The test will only last for a few seconds, and sometimes the effect can be subtle, so pay attention.
If xvidtune doesn’t seem to have any effect when you click Test, you may need to check your XF86Config file for a line that reads Option “DisableVidModeExtension” “yes” and change its value to “no”. You’ll then need to restart X again. Alternatively, you can enter your new mode into XF86Config “blind” and restart it to test.
When you’re satisfied with your tests (or if you chose to enter a change blind), click Show. You should see a new mode line appear in the xterm that launched xvidtune. Copy this mode line into your XF86Config file, much as you copied the mode line from the XFree86 Modeline Generator web page.
You may want to rename the mode to something distinctive or copy the values over the values you created previously. Once that’s done, shut down and restart X, as described earlier. You should see your new mode come up, properly centered.
Roderick W. Smith is the author or co-author of twelve books, including
Linux Power Tools and
The Definitive Guide to Samba 3. He can be reached at email@example.com.