A Way to Switch Between Portrait and Landscape

Discussion in 'Linux' started by samguyjones, Nov 9, 2008.

  1. samguyjones

    samguyjones

    Joined:
    Oct 11, 2008
    Messages:
    44
    Likes Received:
    0
    It's sometimes handy to be able to look at a long, narrow screen than a short, wide screen. When I'm reading PDFs, for example, I usually prefer to do it holding the netbook sideways like a book. It's a more familar way of reading, and I can see more of the page.

    Fortunately, this is really easy to do in most forms of Linux, including Linpus. You need to use a command called xrandr. Open an editor and paste this very short script that checks to see if your screen is in portrait or landscape and switches it to whichever one it isn't. Once you save the script, right click on its file icon, choose "Properties" then "Permissions" and check the box to allow it to run as a program.

    You can now run it from a terminal or just hit Alt-F2 and type "porlan". Running the command again will return your screen to normal.

    Code:
    #!/usr/bin/perl
    open PROP, "/usr/bin/xrandr --prop |";
    unless (<PROP> =~ /current\s+(\d+)\s*x\s*(\d+)/) {
        print "Problem reading input.\n";
    } elsif ($1 > $2) {
        exec("/usr/bin/xrandr","-o","left");
    } else {
        exec("/usr/bin/xrandr","-o","normal");
    }
    
    You can also bind this script to a keystroke by going to 'Settings' -> "Keyboard Setting' -> 'Shortcuts'.

    It's a very simple trick, but I hope it might save someone the twenty minutes it takes to hunt down the information.
     
    samguyjones, Nov 9, 2008
    #1
  2. samguyjones

    giav

    Joined:
    Aug 11, 2008
    Messages:
    4
    Likes Received:
    0
    Wow!
    That was easy! It would have taken me more than 20 minutes as I had no idea that it was possible. Next how to rotate the keyboard :D
     
    giav, Nov 9, 2008
    #2
  3. samguyjones

    galliganer

    Joined:
    Oct 5, 2008
    Messages:
    4
    Likes Received:
    0
    In only few seconds!
    Thanks
     
    galliganer, Nov 9, 2008
    #3
  4. samguyjones

    Jack Vermicelli

    Joined:
    Sep 26, 2008
    Messages:
    84
    Likes Received:
    0
    Location:
    MI, US
    I created the script, named it "porlan", and then altered it to make the screen the "left page" rather than the right. It works fine from the icon, but isn't found when I try to run it from terminal. Need it be saved to a specific location?
     
    Jack Vermicelli, Nov 10, 2008
    #4
  5. samguyjones

    rbil

    Joined:
    Aug 14, 2008
    Messages:
    730
    Likes Received:
    0
    Location:
    The Wet Coast, Canada
    If you placed the script within your system's PATH, it would probably find it. To see the environment variable defining your PATH, do this in a terminal:

    echo $PATH

    Typically you'd place something like that in /usr/bin or if you like, since it's of your own making: /home/user/bin which is also defined in the PATH, even though you probably don't have the directory created yet. :)

    If the script isn't in a directory that is defined as part of your PATH you should be able to run it by:

    ./yourscript

    if you're in the directory that contains the script.

    Lastly, it's possible to add other directories to the User specific environment by editing this file:

    .bash_profile

    in your home directory. You'll see where PATH is defined. New directories outside of those defined by the system-wide PATH or presently defined User paths can be defined by separating each directory using a : (colon) as you'll see when you look at that file.


    Cheers.
     
    rbil, Nov 10, 2008
    #5
  6. samguyjones

    donec

    Joined:
    Sep 11, 2008
    Messages:
    952
    Likes Received:
    0
    Nice script but just try and move your mouse while looking at the screen in the normal format it is like rubbing your head and patting your belly. :D BTW Thanks.
     
    donec, Nov 11, 2008
    #6
  7. samguyjones

    Edge

    Joined:
    Sep 2, 2008
    Messages:
    19
    Likes Received:
    0
    Thank you very much for this it works brilliantly!!
     
    Edge, Dec 28, 2008
    #7
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.