Sunday, September 23, 2007

Refreshingly Simple: SyncMastery Achieved

About a week ago, I noticed that my monitor, a Dell 1703FP I've had for almost five years, would flicker when returning from power-save mode. I decided I would rather start shopping for a replacement immediately than wait for it to die altogether.

After some deliberation, I chose a Samsung SyncMaster 932B, a 19" TFT-LCD with a maximum supported resolution of 1280 × 1024 @ 75 Hz. The picture looks gorgeous, and the brightness presets have already proven useful. As I anticipated, it presented a small challenge when configuring X.

The monitor's manual states its recommended refresh rate is 60 Hz, but X seemed determined to use the highest available rate. Thinking this must be hard on the monitor, I looked up the supported frequency ranges in the manual and manually added them to my xorg.conf. To edit the file, do
sudo vi /etc/X11/xorg.conf
and add the appropriate ranges to the "Monitor" section. Mine looks like this:
Section "Monitor"
Identifier "Samsung SyncMaster 932B"
Option "DPMS"
HorizSync 30-81
VertRefresh 56-75
# 1280x1024 @ 60.00 Hz (GTF) hsync: 63.30 kHz; pclk: 108.88 MHz
Modeline "1280x1024_60.00" 108.88 1280 1360 1496 1712 1024 1025 1028
1060 -Hsync +Vsync
EndSection
HorizSync is measured in kHz and VertRefresh in Hz. DPMS stands for Display Power Management Signaling, and you should enable it if your hardware supports it. I'll explain the last two lines in a moment. They turned out to be essential for getting X to use the monitor's optimum refresh rate.

Before I added those lines, X insisted on pushing the monitor to 75 Hz and wouldn't acknowledge other possibilities. I searched until I found an informative how-to and downloaded the GTF modeline generator from the link it provided. To compile the generator, I did the following:
gcc gtf.c -o gtf -lm -Wall
Initially GCC warned me
gtf.c: In function ‘parse_command_line’:
gtf.c:665: warning: implicit declaration of function ‘strcmp’
I've seen that warning before; it usually means you forgot to explicitly include the header file for some C library function—in this case, strcmp, which string.h defines. So I did
vi gtf.c
and added
#include <string.h>
after the other includes. As expected, the warning disappeared.

I wanted to be able to run gtf from any working directory, so I moved the executable to /usr/bin:
sudo mv gtf /usr/bin
I ran it with the desired resolution and refresh rate as arguments:
gtf 1280 1024 60
This produced two lines, which I added to the end of the "Monitor" section above. I also needed to change every occurrence of "1280x1024" in the "Screen" section to "1280x1024_60.00" to match the modeline. Then I saved the file, logged out and restarted X with Ctrl+Alt+Backspace.

Problem solved!

No comments: