Detect External Monitor

First post for this website completely in English.

I have a bunch of on going projects and things I'd like to talk about, but time is not on my side (as usual), but this I think it's worth talking about.

This is a very stupid guide on how to setup a simple script I wrote on how to detect the external monitor and use it automatically.

The basic setup and use I will cover are:

  • configure basic functionality of the script
  • setup keyboard keys (usually Fn+F7) for use with the script
  • autoload script at logon for using the external monitor automatically

Notes

Unfortunately this script works only under certain conditions. While researching before starting to write it I probably understood why nobody actually ever tried to do it (or maybe not and my searches didn't dig deep enough).
This script relies on a fantastic program called disper, which, at the moment, is working only on nVidia cards.

So, if you are a lucky owner of a laptop with an nVidia card and an external monitor/projector, this document is for you :-)

Requirements

As written in the head of the script, the requirements for it to work are:

  • disper (for gentoo-users: ebuild on bugzilla)
  • Xosd
  • xrandr
  • a RANDR capable Xorg installation
  • a quite recent nVidia card with dual head (tested on a 6200Go and a GT218)
  • an external monitor to use

Will it blend?

The script itself is very easy to use and understand, so you feel free to play with it, find its bugs and submit/request changes to it, it's free software! ;-)

Configure

Download the script from here.

The only thing you would like to change in the script is the default resolution your laptop has:

DefaultScreenSize="1920x1080" # CONFIGURE THIS VARIABLE

There's more you can tweak, but for the moment is enough.

Install the rest of dependencies written above.

Make it work!

Place the file in a safe enough position, I'd use as an example my solution: being in a multiuser environment I've preferred to use a system wide position as /usr/local/share/scripts/ so:

# cp detectExternalMonitor.sh /usr/local/share/scripts/
# chmod a+x /usr/local/share/scripts/detectExternalMonitor.sh
# ln -s /usr/local/share/scripts/detectExternalMonitor.sh /usr/local/bin/detectExternalMonitor

The last command assumes /usr/local/bin is in your $PATH.

Now try to launch it from a terminal (from within X) to see if it's working, like:

$ detectExternalMonitor -check
nothing to do

If you didn't had the monitor plugged in everything would have worked as above.

Mind that invoking the script without arguments would force the second display output, even if it's not enabled. In that case just invoke the script with "-check" as an argument.

Bind it!

Now we just need to bind the script to a key press (I would use Fn+F7 since it's used widely).

For doing this I've used xbindkeys. This program works with a daemon together with a configuration file that you will need to generate. In order to launch the daemon, just run it without arguments and add this program so that it could be started whenever you login into your wm (instructions not included). The first time you run it, it will require the configuration file to be present and show you how to generate it in case you don't have it.

Now launch it with -k and press the key combination (mine was Fn+F7) to find out the key you need to bind:

$ xbindkeys -k
Press combination of keys or/and click under the window.
You can use one of the two lines after "NoCommand"
in $HOME/.xbindkeysrc to bind a key.
"NoCommand"
    m:0x0 + c:151
    XF86WakeUp

This is my output, but your can be different. In my case I just added this piece of code to .xbindkeysrc:
"detectExternalMonitor"
    m:0x0 + c:151

In case you cannot capture the keybinding check out your kernel log (/var/log/messages) for a line like:
atkbd.c: Unknown key pressed (translated set 2, code 0xf4 on isa0060/serio0).
atkbd.c: Use 'setkeycodes e074 <keycode>' to make it known.

In this case you need to "make it known": add a line like this in your system startup script:
setkeycodes e074 235

In gentoo it was added into /etc/conf.d/local.start.

I'd really like to understand where the "235" comes from, but my searches end here, if you know more, let me know :)

Btw, now you're done, key binded.

Final touches...

As you have added the xbindkeys daemon to the startup of your wm, you could do the same with the program itself adding the "-check" flag, that will automate the process without you to worry about it.

detectExternalMonitor -check

Some tech notes

The big problem in writing this script was to understand how to detect the external monitor.

It would have been great if nvidia-settings -q ConnectedDisplays worked, but with the monitor plugged in/out the values were not changing, so I must assume either it works only on recent hardware or I misunderstood something. Because of that I based the detect script on the default name of the external monitor (CRT-0): if it's not plugged in, the name will remain the default one, if the monitor is PnP (? I didn't have time to investigate what actually is sent read from the monitor.. EDID? if anyone knows...) it will show another name. Easy enough?

Since the external monitor enable/disable would blank out everything for a couple of seconds, I've tried to avoid to redo any action for example in case the monitor has been plugged in/out and stuff like that.

Moreover when switching manually I had to set a temp file, to realize some sort of state machine.

This script will obviously conflict with any script that will work with several copies of xorg.conf to be swiched on and off (seen a couple of these solutions around, but probably way too complicated IMHO).

I hope you'll enjoy it :-)

If you really liked it and want to improve it, please send me your thoughts, here in the comments or via the web mail form, I'd be happy to update it.

my personal opinion

hi website's master, i like such video and article presented in this website. I am the website owner of movies website from Indonesia. You could contact me in my website ceritafilm.com.Nice to meet you all guys

house cleaning San Antonio

This is a good blog that i ever saw thanks for the opportunity for sharing you post.house cleaning San Antonio

payday one

This subject is very stimulating and I thank you for this great post.

If it is working correctly

If it is working correctly for the first time the why not now. It might be possible that the HDMI cable is not properly working and that is why you are getting the issue with the same.
Tanden Bleken

Your ideas was a blessing. I

Your ideas was a blessing. I was looking for this kind of article for my paper and I got here. Truly educational. breast actives Thank you so much.
friv games

acne treatment

The codes shared in the post are very useful for me, all are amazing.

Mike Hough Music

There are so many comments here that are really interesting and useful to me thanks for sharing a link especially for sharing this blog. Mike Hough Music

You are writing such

You are writing such wonderful articles on diversified topics from a long time and this is another great addition to the collection.
Kindle Fire Review

There are so motivating info

There are so motivating info and many remarks underneath the article, thank you for everything......
Magic Of Making Up

Gainesville Computer Repair

It does so by connecting to a cellular network provided by a mobile phone operator, allowing access to the public telephone network. By contrast, a cordless telephone is used only within the short range of a single, private base station....
Gainesville Computer Repair

Youre so awesome, man! I cant

Youre so awesome, man! I cant believe I missed this blog for so long. Its just great stuff all round. Your design, man...too amazing! I cant wait to read what youve got next. I love everything that youre saying and want more, more, MORE! Keep this up, man! Its just too good.
free beats

reply

Your websites are as a result terrific. I’m amazed within the points that could you’ve about this web site. That will unearths exactly how effectively you realize our next topic. Increased this brilliant net internet site web site, will probably be renewed with regard to reports. I came across just the truth I just before appeared over the position meant for couldn't come across.

Nice to very useful info for

Nice to very useful info for me.Because i'm new in blogging and i'm need good tutorial like your post.
Premier Nutrition Protein Shake

There's more you can tweak,

There's more you can tweak, but for the moment is enough.

reply

Great stuff from you man. Ive read your stuff before and youre just too awesome. I love what youve got here love what youre saying and the way you say it. You make it entertaining and you still manage to keep it smart. I cant wait to read more from you. This is really a great blog.
code promo weight watchers

great post

You sure do know what you're talking about. Man, this blog is just great!
I cant wait to read more of what you've got to say. I'm really happy that
I came across this when I did because I was really starting to get bored with
the whole blogging scene. You've turned me around,

preteen models

Search Engine Optimization Edmonton

nice Post, Thanks For Share this wonderful Post, Keep Writing more topics.. Thanks

Pearl Jewellery

Really appreciate the information your providing use avid readers.

Gay Porn

This is a very intriguing post, I was looking for this knowledge. Just so you know I found your web site when I was searching for blogs like mine .

Cheap truck

Your post is handsomely written. I have bookmarked you for keeping abreast with your new posts.thank you so much.

IT Insurance Quotes

Good efforts. All the best for future posts. I have bookmarked you. Well done. I read and like this post. Thanks.

catering melbourne

Nice!!This is a very brilliant blog post. What i was actually looking for the past 2 hours. Thanks for the share and really treasure your effort.

Cheap Glasses

The post is handsomely written. I have bookmarked you for keeping abreast with your new posts.

Rattan Garden Furniture

All I can say is keep up the good work and keeping serving the same stuff.

Edmonton Moving Companies

Simply fantastic. Truly informative, thanks for sharing the post.Really its a very good post.i like ur post.

San Francisco Limo

I absolutely loved how you have created your website, it's simple, neat, simple to navigate and extremely easy on the eyes. Is it possible to let me know which theme or designer did you use.

SEO India

"I think other web-site proprietors should take this web site as an model - very clean and excellent style and design, as well as the content. You're an expert in this topic! "

SEO India | Performance Based SEO | India SEO | Freelance SEO | Pay for Performance SEO | Web Design India | SEO Freelancer | Freelance SEO | Freelance SEO

resume templates

Your blog is well done and I enjoyed reading this post.

Marietta bankruptcy attorney, emagrecer & Idol White

The yellowish looks to the post is a little tacky, eye disturbing.
Marietta bankruptcy attorney
emagrecer
Idol White

Awesome information you got

Awesome information you got here. I've been reading a lot about this and I am thankful for this article. It was indeed a great help. penis extenders Thank you so much.
Naperville Limo

This is a great inspiring

This is a great inspiring article. I am pretty much pleased with your good work. You put really very helpful information. Keep it up. Keep blogging. Looking to reading your next post.

Website Design Rugby

It help me very much to solve

It help me very much to solve some problems. Its opportunity are so fantastic and working style so speedy.
DSL Anbieter

Great information you got

Great information you got here. I've been reading about this topic for one week now for my papers in school and thank God I found it here in your blog. I had a great time reading this
DSL Anbieter

Pounds Till Payday

Sorry, that is not how it happens, but I have liked what you have written.

Guns for Sale

Thanks for sharing this information with us. I am very impressed with this article. Your blog is very interesting. I appreciate your work.

Guns for Sale

Guns for Sale
Looking forward to another great blog. Good luck to the author. all the best.

hi

I discovered lots of useful thing in your weblog especially its discussion. On the numerous feedback on your posts, I guess Im not the only one having all the enjoyment right here! keep up your great work.

I guess autoload script at

I guess autoload script at logon for using the external monitor automatically is a great feature. Vance and Hines exhaust

thanks for the information

thanks for the information, it is very helpful. Will always come back to read your post (english only)

I'd really like to understand

I'd really like to understand where the "235" comes from, but my searches end here, if you know more, let me know

Actually your creative

Actually your creative writing abilities has inspired me to get my own web site now. Really the blogging is spreading its wings fast. Your write up is a good example of it.
templatesspot

Good read.

Un blog (un portmanteau del termine web log) [1] è un diario personale pubblicato sul World Wide Web costituiti da voci discrete ("messaggi") in genere visualizzati in ordine cronologico inverso in modo che il messaggio più recente visualizzato per primo. I blog sono in genere il lavoro di un singolo individuo, a volte di un piccolo gruppo, e spesso sono a tema su un singolo post. Phone insurance.

La nascita e la crescita dei blog alla fine del 1990 ha coinciso con l'avvento di strumenti di web publishing che hanno facilitato il distacco dei contenuti da parte degli utenti non tecnici. (In precedenza la conoscenza di tecnologie come HTML e FTP è stato richiesto di pubblicare contenuti sul Web). Le soggetto. Blog può essere utilizzato anche come un verbo, nel senso di mantenere o aggiungere contenuti ad un blog.

Very perfekt and good

For the first post of this is very good. I read this post with a lot of attention. Really a great post! Come to my Show Site for all artists.

flower arranging courses

I like this post,And I guess that they
having fun to read this post,they shall take a good site to make a
information,thanks for sharing it to me.

I like this post,And I guess that they
having fun to read this post,they shall take a good site to make a
information,thanks for sharing it to me.

rock

they
having fun to read this post,they shall take a good site to make a
information,thanks for sharing it to

I am currently working on an

I am currently working on an assignment and I have been exploring your blog for a few hours. Thank you for your post it proved helpful for me.
Wartrol

flower arranging courses

I like this post,And I guess that they
having fun to read this post,they shall take a good site to make a
information,thanks for sharing it to me.

flower arranging courses
flower arrangement courses

hi

I read this post with a lot of attention. Really a great post! Come to my Show Site for all artists.

Submit Site

where exactly other people tend to be received from with this problem. I'm just pleased that I had the wad of cash to help come across your website. The definitely an essential problem that not enough persons are discussing that i'm grateful...
Submit Site

If it is working correctly

If it is working correctly for the first time the why not now. It might be possible that the HDMI cable is not properly working and that is why you are getting the issue with the same. sprei | sprei murah

Invia nuovo commento

Il contenuto di questo campo è privato e non verrà mostrato pubblicamente.
  • Indirizzi web o e-mail vengono trasformati in link automaticamente
  • Elementi HTML permessi: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <acronym> <h2> <h3> <h4> <h5> <h6> <img> <pre> <span>
  • Linee e paragrafi vanno a capo automaticamente.
  • Puoi abilitare l'evidenziazione della sintassi del codice sorgente usando i seguenti tag: <code>, <blockcode>. The supported tag styles are: <foo>, [foo].
  • Images can be added to this post.

Maggiori informazioni sulle opzioni di formattazione.

CAPTCHA
Se sei qui per dello SPAM hai sbagliato tutto della vita.

Site optimized for Gecko and Webkit browsers - Copyright © 2008 - Matteo 'Peach' Pescarin