albtechportal

  • Subscribe to our RSS feed.
  • Twitter
  • StumbleUpon
  • Reddit
  • Facebook
  • Digg

Wednesday, 27 November 2013

Switching Monitor Profiles

Posted on 05:24 by Unknown
It's funny, when your home office is your couch, you tend to forget how nice it can be when you dock a laptop and have all the extra screen real estate a monitor brings. For many years, I left my work laptop docked at work, and when I worked from home, I just VPNed in with a personal laptop. Lately though, I've recognized the benefits of splitting personal life and work, so I've taken to carrying my laptop with me when I go to and from the office. Because we invested in a docking station, it's relatively simple to transition between a laptop on my lap and a laptop on a desk with an extra monitor—except for one little thing: my external monitor is in portrait mode.
It must have been about two years ago that I started favoring widescreen monitors in portrait mode (Figure 1). Really, all I need to get work done is a Web browser and a few terminals, and I found if I keep the Web browser on the laptop screen, I can fit a nice large screen session or two in all the vertical space of a portrait-mode monitor. This makes reading man pages and other documentation nice, plus I always can split my screens vertically if I need to compare the contents of two terminals (see my "Do the Splits" column in the September 2008 issue for more information on how to do that: http://www.linuxjournal.com/article/10159). The only problem with portrait mode is that all the GUI monitor configuration tools tend not to handle portrait-mode monitors well, particularly if you want to combine them with a landscape-mode laptop screen. So, I found I needed to run a special xrandr command to set up the monitor and make sure it lined up correctly with my laptop screen. Plus, every time I transition between docked and undocked modes, I need to move my terminal windows from the large portrait-mode monitor over to a second desktop on my laptop screen. This all seemed like something a script could figure out for me, so in this article, I explain the script I use to transition from docked to undocked mode.
Figure 1. Kyle's Current Desktop Setup
Basically, my script needs to do two things when it's run. First, it needs to run the appropriate xrandr command to enable or disable the external display, and second, it needs to reset all of my windows to their default location. Although I could just have one script I run when I'm docked and another when I'm undocked, I can find out my state from the system itself, so I can keep everything within one script. I've set up a script like this on my last two work-provided laptops and on the ThinkPad X220, I was able to use a /sys file to gauge the state of the dock:

#!/bin/bash
DOCKED=$(cat /sys/devices/platform/dock.0/docked)
case "$DOCKED" in
"0")
echo undocked
;;
"1")
echo docked
;;
esac
Unfortunately, on my new laptop (a ThinkPad X230) this file no longer can detect the dock state. At first I was annoyed, but when writing this column, I realized that this made the script potentially more useful for everyone who doesn't have a docking station. My workaround was to use xrandr itself to check for the connection state of a video device my external monitor was connected to that was present only when I was docked. If you run xrandr with no other arguments, you will see a list of a number of different potential video devices on your system:

$ xrandr
Screen 0: minimum 320 x 200, current 1366 x 768, maximum 8192 x 8192
LVDS1 connected 1366x768+0+0 (normal left inverted right x axis y axis)
↪277mm x 156mm
1366x768 60.0*+
1360x768 59.8 60.0
1024x768 60.0
800x600 60.3 56.2
640x480 59.9
VGA1 disconnected (normal left inverted right x axis y axis)
HDMI1 disconnected (normal left inverted right x axis y axis)
DP1 disconnected (normal left inverted right x axis y axis)
HDMI2 disconnected (normal left inverted right x axis y axis)
HDMI3 disconnected (normal left inverted right x axis y axis)
DP2 disconnected (normal left inverted right x axis y axis)
DP3 disconnected (normal left inverted right x axis y axis)
In the above case, the laptop is not docked, so only the primary monitor (LVDS1) is connected. When I docked the device and ran the same command, I noticed that my monitor was connected to HDMI3, so I could grep for the connection state of HDMI3 to detect when I'm docked. My new skeleton script looks more like this:

#!/bin/bash
xrandr | grep -q "HDMI3 disconnected"
case "$?" in
"0")
echo undocked
;;
"1")
echo docked
;;
esac
In your case, you would compare the output of xrandr when docked (or when an external monitor is connected) and when undocked, and use that to determine which device it corresponds to.
Now that I can detect whether I'm docked, I should do something about it. The first thing I need to do is to enable output on my external monitor (HDMI3), tell xrandr that it's to the right of my laptop screen, and set it to portrait mode by telling xrandr to rotate it left:

/usr/bin/xrandr --output HDMI3 --auto --right-of LVDS1 --rotate left
This works fine; however, the way that the portrait-mode monitor and my laptop line up on the desktop makes moving a mouse between the two rather awkward. When I move from the top of the laptop screen to the far right edge, the mouse pointer moves a foot up to the top of the external monitor. Ideally, I'd like the mouse pointer to more or less be lined up when it crosses between screens, but because one monitor is landscape and the other is portrait, I need to tell xrandr to place my laptop monitor lower in the virtual desktop. Depending on your respective resolutions, this position takes some tinkering, but I found the following command lined up my two displays well:

/usr/bin/xrandr --output LVDS1 --pos 0x1152
This takes care of my screen when I'm docked, so when I'm undocked, I basically have to undo any of the above changes I've made. This means turning the HDMI3 output off and moving the position of LVDS1 back to the 0x0 coordinates:

/usr/bin/xrandr --output HDMI3 --off
/usr/bin/xrandr --output LVDS1 --pos 0x0
The complete case statement turns out to be:

#!/bin/bash
xrandr | grep -q "HDMI3 disconnected"
case "$?" in
"0") # undocked
/usr/bin/xrandr --output HDMI3 --off
/usr/bin/xrandr --output LVDS1 --pos 0x0
;;
"1") # docked
/usr/bin/xrandr --output HDMI3 --auto --right-of LVDS1
↪--rotate left
/usr/bin/xrandr --output LVDS1 --pos 0x1152
;;
esac
After I saved the script, I bound a key combination on my desktop I could press to execute it whenever I docked or undocked. Of course, ideally I would set up some sort of udev script or something like it to run the script automatically, but so far, I haven't found the right hook that worked on my laptop. The only other addition I've made is after the above case statement, I sleep for a second and then call a reset_windows shell script that uses wmctrl, much like I discussed in my November 2008 Hack and / column "Memories of the Way Windows Were" (http://www.linuxjournal.com/article/10213), only it also contains the same case statement so it moves windows one way when docked and another when not:

#!/bin/bash
xrandr | grep -q "HDMI3 disconnected"
case "$?" in
"0") # undocked
wmctrl -r 'kyle-ThinkPad-X230' -t 1
wmctrl -r 'kyle-ThinkPad-X230' -e '0,2,24,1362,362'
wmctrl -r snowball -t 1
wmctrl -r snowball -e '0,2,410,1362,328'
;;
"1") # docked
wmctrl -r 'kyle-ThinkPad-X230' -t 0
wmctrl -r 'kyle-ThinkPad-X230' -e '0,1368,0,1080,1365'
wmctrl -r snowball -t 0
wmctrl -r snowball -e '0,1368,1387,1080,512'
;;
esac
Of course, the above wmctrl commands are completely custom to my terminal titles, but it should serve as an okay guide for getting started on your own. In my case, I want to move two terminals to the second desktop when in laptop mode and to the external monitor on the first desktop when docked. Why not just combine the two scripts? Well, I want to be able to reset my windows sometimes outside of docking or undocking (this script also is bound to a different key combo). In the end, I have a simple, easy-to-modify set of scripts I can use to keep windows and my desktops exactly how I want them.

Source
Email ThisBlogThis!Share to XShare to FacebookShare to Pinterest
Posted in Linux | No comments
Newer Post Older Post Home

0 comments:

Post a Comment

Subscribe to: Post Comments (Atom)

Popular Posts

  • Review: Seagate 600 480GB SSD
    Seagate Joins the Fray It’s been quite an interesting turn of events over the past couple years in the storage industry. Whereas practical...
  • Top 10 Ways to Customize Your Desktop
    1 Expand You spend a lot of waking hours at your computer, so why not make it a little prettier (and more productive)? Here are 10 ways to...
  • CCBoot - LAN Boot Software for Windows
    LAN Boot Solution Background LAN boot is a technology based on IP (Internet Protocol), UDP (User Datagram Protocol), DHCP (Dynamic ...
  • ‘Strata’ for iOS and Android game review
    There are games that are fun. There are games that look great. And then there are games that do both. Strata is one such game that h...
  • Adobe Photoshop CS6 Extended 13.0 & Plugins + Textures
    Adobe Photoshop CS6 Extended 13.0 & Plugins + Textures | 3.5 GB Adobe Photoshop CS6 Extended software delivers even more imaging magi...
  • Intel NUC DC53427RKE / HYE Review
    Manufacturer: Intel UK Price (as reviewed): £308.32 (inc VAT) US Price (as reviewed): $539.99 (ex TAX) Preferred Partner Price: £308.32...
  • ASUS R9 270X DirectCU II TOP 2 GB
    AMD's new Radeon R9 270X draws its lineage more from the Radeon HD 7800 series than any other. The R9 270X is, for all intents and purp...
  • Corsair Raptor M40 Review
    Manufacturer: Corsair UK price (as reviewed): £44.99 (inc VAT) US price (as reviewed): $59.99 (ex Tax) Along with the Raptor M30, Corsai...
  • Call of Duty: Ghosts Review
    Developer: Infinity Ward Publisher: Activision Platforms: PC, X360, PS3, PS4, Xbox One Price: £39.99 Reviewing a Call of Duty game is a ...
  • How to remotely install apps on your smartphone
    You can download and install apps to your iPhone and Android phone without being anywhere near it. That sorcery is this? It isn't sorce...

Categories

  • Android
  • Apple
  • Audio
  • Blogger
  • C/C++
  • Cabling
  • Cameras
  • Cases
  • CISCO
  • Cooling
  • CPU
  • Desktop
  • DNS
  • Ebook
  • Fiber Optic
  • Gadgets
  • Game
  • Google
  • Graphic Card
  • Hardware
  • HDD
  • HTC
  • HTMLCSS
  • Hyper-V
  • Intel
  • iOS
  • iPad
  • Iphone
  • IT
  • jQuery
  • Laptop
  • Linux
  • Mac
  • MacTut
  • Microsoft
  • Mobile
  • Mouse
  • Networking
  • News
  • Nexus
  • Nokia
  • Nvidia
  • OS
  • PERIPHERALS & COMPONENTS
  • Photoshop
  • Printers
  • Programming
  • Projectors
  • PS4
  • Ram
  • RedHat
  • Review
  • Samsung
  • Scanners
  • Seagate
  • Security
  • Server2008
  • Server2012
  • Servers
  • Smartphone
  • Software
  • Sony
  • Storage
  • Tablets
  • TechNews
  • Template
  • Tutorials
  • TV
  • Ubuntu
  • Voip
  • Webdesign
  • Webiste
  • WebServer
  • Win7
  • Win8
  • Windows Phone
  • Wordpress
  • Workstation
  • XBOX

Blog Archive

  • ▼  2013 (495)
    • ►  December (35)
    • ▼  November (332)
      • DesktopOK 3.71 + Portable
      • Lynda - Up and Running with iOS SDK with Ron Lisle
      • SIM-free BlackBerry Z10 now available for $199
      • Hands-on with the Fitbit Force
      • Lenovo IdeaCentre Erazer X700 Gaming PC Review
      • LG G2 to get the Android KitKat update in Q1, 2014
      • Image shows Nokia Lumia 929 in white; leak reveals...
      • Watch Out for Seagate Drives Allegedly Sold Under ...
      • Starting a Website? Get a Domain Name and Hosting ...
      • Our Favorite Android, iOS and Windows Phone Apps o...
      • iBuypower Chimera 4SE FX Ultimate: AMD Gaming PC
      • How to Buy a Business Desktop
      • Google Nexus phones are vulnerable to rebooting vi...
      • Android 4.4 KitKat now seeding to Korean LG G2
      • Best For Music: PS4 or Xbox One?
      • Fix your Mac yourself with the new TechTool Pro 7!
      • How to buy the right sound bar to go with your TV
      • Understanding LSI SandForce SF3700 Series Controller
      • ASUS R9 270X DirectCU II TOP 2 GB
      • FIFA rolls out iOS and Android apps ahead of 2014 ...
      • How to Protect Wi-Fi network From Hackers
      • Recover Deleted Files From External Hard Drive
      • Best Video Editing Apps for Android Users-Must have
      • iPhone 6 Release Date,Full Specifications-whats new
      • How to r00t on server : Free E-Book
      • Samsung Galaxy S5 will not have OIS camera
      • Create Windows 8 Bootable Pendrive
      • Top 5 things to look for in a PC monitor
      • 5 things to look for in an 802.11ac router and ada...
      • 7 ways to maximise your Wi-Fi speeds
      • How to make your own Android ROM
      • VMWare Fusion 6 Opens Windows On Your Mac
      • Control iTunes & Apple TV From The Palm Of Your Ha...
      • Use Your Computer, Don’t Let It Use You: Five “U”s...
      • What’s Trending? Find Out With These Real-Time Dat...
      • Cool Websites & Tools – Remote Website Sharing, Lo...
      • Fascinating Earth: 5 Citizen Science Projects For ...
      • Brix on BRIX – Colin talks to Newegg about the lat...
      • Samsung Galaxy S5 Coming Early 2014 With 64-Bit Ex...
      • Get Your (Linux) Game On: Steam Autumn Sale Highli...
      • Firefox debuts new UI that looks like Chrome, but ...
      • World’s fastest wireless network hits 100 gigabits...
      • Intel Unveils 72-Core x86 Knights Landing CPU for ...
      • United States falls to 31st place in global broadb...
      • Xbox One vs. PS4: How They Stack Up Today
      • Got a Defective Xbox? Here’s How Microsoft Will Ma...
      • ASUS Releases “Faster Than Titan” ROG Mars 760 Vid...
      • How to get Android and iOS apps for free or on the...
      • How to remotely install apps on your smartphone
      • Community driven Core Apps convergence
      • Introduction & Packaging
      • Fix: Change PC Settings does not open in Windows 8...
      • How to make your Android look like it's running iOS 7
      • Switching Monitor Profiles
      • Web Administration Scripts
      • Top 10 apps from last week: Courses123, 500 Firepa...
      • Does the idea of a modular phone appeal to you?
      • How to Boost and Increase your Internet Speed
      • Ubuntu Linux server with ARM processor rolled out ...
      • 6 steps for setting up a small business server room
      • The best home backup plan options - Part 3: Extern...
      • The best home backup plan options - Part 4: Cloud ...
      • The best home backup plan options - Part 5: A comp...
      • How to Backup Files On Your Computer - Part 1: The...
      • The best home backup plan options - Part 2: Same m...
      • How To: Crucial Ballistix Elite Memory Installatio...
      • iBuypower Reveals First Steam Machine Prototypes
      • Kingston ships HyperX Predator 2800MHz Memory for ...
      • Samsung ChatON for Android now supports SMS and MM...
      • Grand Theft Auto: San Andreas coming to Android, i...
      • Google bakes photo goodies deep inside KitKat, but...
      • Oops -- YouTube's new commenting system actually i...
      • WD My Cloud Personal Cloud Server Review
      • Acer Unleashes Affordable, Touchscreen Chromebook
      • Apple iPhone 5s makes up a larger percentage of th...
      • Microsoft giving a free game to owners of Xbox One...
      • Samsung Galaxy S4 Google Play edition scores Andro...
      • Apple iPad mini 2 vs Google Nexus 7
      • Sony resetting some PSN passwords as a 'precaution...
      • Chromecast stand-in CheapCast now beams browser ta...
      • Galaxy S5 rumors, the Snapdragon 805 chip, and wil...
      • What about the Wii U?
      • Red Mac Pro Designed by Jony Ive, Marc Newson Fetc...
      • HTC One GPE getting Android 4.4 KitKat
      • BlackBerry ousts marketing and operations chiefs, ...
      • Recuva Data Recovery Software: Recover deleted fil...
      • Mass-market HTC One in Gold goes official
      • Assassin's Creed: Pirates launches for phones and ...
      • WP to put pressure on iOS in enterprise market
      • New Tegra 4-powered Nook leaked from GFXBench
      • Apple confirms PrimeSense buyout, paves way for mo...
      • Pen computing returns: Revenge of the stylus
      • 3D Systems Sense review: a 3D scanner for the mass...
      • Intel Demonstrates First 64-bit Android Tablet
      • DOOO for iPhone Makes Gorgeous To-Do Lists With Te...
      • Chinese supercomputer twice as fast as closest US ...
      • Best 802.11ac routers
      • Mac vs. PC: Is an Apple computer really better tha...
      • Android 4.4 Kit Kat Update Rolling Out to AT&T Mot...
      • Review: Seagate 600 480GB SSD
    • ►  October (12)
    • ►  September (27)
    • ►  August (2)
    • ►  July (10)
    • ►  June (42)
    • ►  May (35)
Powered by Blogger.

About Me

Unknown
View my complete profile