Home
Home Blogs k4tz's blog
    • Blog
    • Clinic
    • Contact
    • Download
    • Video
    • Login

Poll

Favourite console text editor in Ubuntu:

LXer -- Linux and Open Source News

  • Eban Moglen: Doing What It Takes: Current Legal Issues in Defending FOSS
  • This Little App Went to Market, Part 1
  • Wind River board partners spin Intel-based embedded kits
  • Linux Foundation's Jim Zemlin Offers Sneak Peek at 2010 End User Summit
  • Linux Mint Based On Debian Released - And It's A Rolling Distribution!
more

Linux Today

  • The Commons As An Actor in Transforming Global Political Economy
  • My Quest for Free Licensed Japanese Pop Music
  • C++ Help: Installing and Using Code::Blocks On Linux
  • Help an Old PC: Give KDE 3.5 the Oxygen Touch
  • Linux Mint 9 (Debian) Review
more

Linux Insider

  • How Linux Land Got Better Since Last Summer
  • Clam or Klam? Either Way, It's Easy Linux Protection
  • Android May Paddle Samsung Canoe Into Turbulent Web TV Waters
  • Why Do We Love Linux?
more

Enable Nvidia Displays from Command Line

Submitted by k4tz on Sat, 01/03/2009 - 06:53
  • Blog
  • Multimedia
  • Nvidia
  • Ubuntu

Source: http://ubuntuforums.org/showthread.php?t=922956

I have a Lenovo Thinkpad T61, and I had been trying to find a way switch between monitors using a keystroke. Particularly, this meant finding a way to enable/disable monitors using the command line.

This thread suggested that nvidia-settings should make this possible, but apparently, it isn't implemented by Nvidia, yet... (or so the "TODO" section of this document) suggests)

Luckily, we can compile the nv-control-dpy tool, which will give us the tools we need to enable or disable monitors, with a little extra help from scripts I wrote.

First, lets get the source code.

Code:
$ mkdir nvidia-source
$ cd nvidia-source
$ apt-get source nvidia-settings
$ cd nvidia-settings-*

Next, download dependencies

Code:
$ sudo apt-get install build-essential libxext-dev libx11-dev

First, you have to compile the an nvidia library:

Code:
$ cd src/libXNVCtrl
$ make

Now, build nv-control-dpy:

Code:
$ cd ../../sample
$ make nv-control-dpy

If all went well, you should have an executable nv-control-dpy file in your directory. This application lets us perform many of the low-level operations that nvidia-settings performs when you use it from the GUI interface.

Test it out:

Code:
$ ./nv-control-dpy -h

Let's install this executable somewhere convenient:

Code:
$ sudo cp nv-control-dpy /usr/local/bin

I have written some bash scripts to parse the output of nv-control-dpy, and some command-line php scripts to do to the enabling and disabling operations (because my Perl-fu is weak ). These files are attached to this post.

To install the scripts:

Code:
$ tar xzvf nv-tools.tar.gz
$ cd nv-tools
$ sudo cp -r scripts/* /usr/local/bin

Included scripts:

  • nv-get-displays - list the currently attached displays
  • nv-get-metamodes - list metamodes in a format easily consumable by my php scripts
  • nv-get-current-metamode - get the id of the currently attached metamode
  • nvidia/nvidia.inc.php - functions for parsing metamodes and switching between modes.

You can control these by writing a simple command-line php script. The "sample/" subdirectory has a few examples of how to enable a single monitor, or enable multiple monitors. Here's an example of enabling a CRT monitor at 1280x1024 resolution:

PHP Code:

#!/usr/bin/php5
<?
require_once('/usr/bin/nvidia/nvidia.inc.php');

enable_single_display('CRT-0', "1280x1024");

Note: you'll need to change /usr/bin/php5 to wherever your command-line php interpreter is located. Also, you may wish to locate the nvidia.inc.php file elsewhere in your filesystem, so update the require_once line if you do

To enable multiple monitors, use the following syntax:

PHP Code:

#!/usr/bin/php5
<?
require_once('/usr/bin/nvidia/nvidia.inc.php');

$displays = array(
'DFP-0' => '1280x800',
'CRT-0' => '1280x1024'
);

enable_displays($displays);

Now, you can just make these scripts executable, and assign them to a key-combination.

If you are interested in how this all works, it goes something like this: For a specific configuration, you have to create a "metamode" using nv-control-dpy which says which monitors are enabled, at what resolution, and at what location relative to one another. The command is: "nv-conrol-dpy --add-metamode <meta-modeline>" . Once you've created a metamode, nv-control-dpy will assign it an id. Using the xrandr utility you can switch to this new configuration by specifying the display resolution and specifying the id as the framerate. Nvidia uses the framerate to store the id, because there is no simple way distinguish two different configurations that have the same resolution in xrandr. The resolution you give to xrandr is the total size of the virtual screen made up of all enabled monitors (e.g. if I have a 1280x1024 monitor cloned with a 1440x900 monitor, the resolution would be 1440x1024).

Attached Files

File Type: gz nv-tools.tar.gz (6.4 KB, 24 views)

  • k4tz's blog
  • Add new comment

Recent blog posts

  • How to install PHP-GTK in Ubuntu 10.04 Lucid Lynx
  • Download Linux Mint 9 "Xfce"
  • ISO Booting with Grub 2 in Ubuntu
  • Howto Fix Rhythmbox Iphone + Ipod Sync Issues in Ubuntu
  • How to install Ubuntu 10.04 on Thinkpad x201
  • Fix for Audio Problem in Dell Studio 1450 in Ubuntu 10.04 (lucid lynx)
  • Howto optimize Flash in Firefox on Ubuntu
  • HP Laserjet P1006 Printer not Working on Ubuntu
  • How to get video recording working with Acer Crystal Eye Webcam on Ubuntu
  • Reset your Windows password and edit the Windows Registry from Ubuntu
more

Linux World

  • Net Neutrality: what does the Google Verizon proposal mean for GNU Linux?
  • Why can't free software lead to hardware innovation?
Archive Syndicate content

Recent comments

  • Re
    35 weeks 3 days ago
  • Re
    35 weeks 3 days ago
  • Re
    36 weeks 3 days ago
  • Re
    36 weeks 6 days ago
  • Re
    37 weeks 4 days ago
  • Re
    37 weeks 4 days ago
  • Re
    37 weeks 5 days ago
  • iwl3945
    39 weeks 2 days ago
  • HomeBank
    51 weeks 4 days ago
  • KMyMoney and direct connect to banks
    1 year 3 weeks ago
All contents copyright © 2008, Dhuha Net. All rights reserved
Ubuntudoctor® is a member of the Dhuha Network. Privacy Policy
RoopleTheme