Rotating Screen/Touchpad On Linux

Discussion in 'ViewPad 10' started by waterhead, Feb 4, 2012.

  1. waterhead
    Offline

    waterhead Junior Member

    Joined:
    Jan 16, 2012
    Messages:
    116
    Likes Received:
    13
    Trophy Points:
    0
    Tablet / Device:
    Azpen X1 , HP-Touchpad
    Since the Viewpad 10 has an Intel CPU, Linux can be installed on it very easily. On the most recent versions of Linux, the touchscreen even works out-of-the-box. What doesn't seem to work is screen rotation, and the proper touchscreen orientation after the screen rotaton.

    I have a cousin of the Viewpad 10, the Azpen X1. I have installed openSUSE Linux 12.1-Gnome on it, because it seems to offer a better Desktop for touching. Here is what I had to do to get a screen rotation button working on my desktop.

    First, you need to know the name of your touchscreen. I used the xinput list command for this:
    Code:
    xinput list
    ⎡ Virtual core pointer                        id=2    [master pointer  (3)]
    ⎜   ↳ Virtual core XTEST pointer                  id=4    [slave  pointer  (2)]
    ⎜   ↳[COLOR=#ff0000] ILITEK ILITEK Multi-Touch[/COLOR]                   id=9    [slave  pointer  (2)]
    ⎜   ↳ Logitech USB Receiver                       id=12    [slave  pointer  (2)]
    ⎜   ↳ Logitech USB Receiver                       id=13    [slave  pointer  (2)]
    ⎣ Virtual core keyboard                       id=3    [master keyboard (2)]
        ↳ Virtual core XTEST keyboard                 id=5    [slave  keyboard (3)]
        ↳ Power Button                                id=6    [slave  keyboard (3)]
        ↳ Video Bus                                   id=7    [slave  keyboard (3)]
        ↳ Power Button                                id=8    [slave  keyboard (3)]
        ↳ USB2.0-Camera                               id=10    [slave  keyboard (3)]
        ↳ AT Translated Set 2 keyboard                id=11    [slave  keyboard (3)]
        ↳   SCISSORS Keyboard                         id=14    [slave  keyboard (3)]
    My touchpad is the entry highlighted in red. If your touchscreen is different, use that in the following script.

    I then used the touchscreen name in a sh script, this script is a heavily modified version of one that I found on the internet.
    Code:
    #!/bin/sh 
    
    # Find the line in "xrandr -q --verbose" output that contains current screen orientation and "strip" out current orientation. 
    
    rotation="$(xrandr -q --verbose | grep 'connected' | egrep -o  '\) (normal|left|inverted|right) \(' | egrep -o '(normal|left|inverted|right)')" 
    
    # Using current screen orientation proceed to rotate screen and input tools. 
    
    case "$rotation" in 
        normal) 
    #    -rotate to the right 
        xrandr -o right 
        xinput set-prop --type=int --format=8 "ILITEK ILITEK Multi-Touch" "Evdev Axes Swap" 1
        xinput set-prop --type=int --format=8 "ILITEK ILITEK Multi-Touch" "Evdev Axis Inversion" 0 1
        xinput set-prop --type=int --format=8 4 "Evdev Axis Inversion" 0 1
        ;;
        right) 
    #    -rotate to normal 
        xrandr -o normal 
        xinput set-prop --type=int --format=8 "ILITEK ILITEK Multi-Touch" "Evdev Axes Swap" 0
        xinput set-prop --type=int --format=8 "ILITEK ILITEK Multi-Touch" "Evdev Axis Inversion" 0 0
        xinput set-prop --type=int --format=8 4 "Evdev Axis Inversion" 0 0
        ;; 
    esac
    Save it as rotate.sh. In the first use of xinput, the word Axes is not misspelled! You can run this script from the terminal, but first make it executable. I store mine in a Scripts folder, so I ran this:
    Code:
    chmod +x ~/Scripts/rotate.sh
    Then run it, and it will rotate the screen and touchscreen to the right:
    Code:
    ~/Scripts/rotate.sh
    Running it a second time will return the screen to Normal view. If you just hit the up arrow on the keyboard, it will display the last command entered.

    Now to put a shortcut on the desktop to run the script. You first have to install the gnome-tweak-tool. I believe this is the same in Ubuntu. Open gnome tweak-tool (Applications-->Advanced Settings). Click on the Desktop section, and turn on "Have file manager handle the desktop". You can also then enable any of the other setting in that category that you want shown on the Desktop, and close it.

    Then open a text editor, I use gedit. Then create this file:
    Code:
    #!/usr/bin/env xdg-open
    
    [Desktop Entry]
    Encoding=UTF-8
    Version=1.0
    Name=Rotate
    Comment=Rotate Screen
    Type=Application
    Exec=/home/paul/Scripts/rotate.sh
    Icon=/usr/share/icons/gnome/48x48/actions/view-refresh.png
    Terminal=false
    Catagories=Settings
    StartupNotify=true
    Name[en_US]=Rotate Screen
    Make sure the Exec= is the path to the folder with the rotate.sh script in it. Also, make sure the Icon= path is to an actual icon on your system. Then save the file in your Desktop folder as "Rotate Screen.desktop" (without the quotes). You now should have an icon on your Desktop. Double-touching it should rotate your screen to the right. Double-touching it again will return it to normal.

    Enjoy!
    Last edited: Mar 3, 2012
  2. waterhead
    Offline

    waterhead Junior Member

    Joined:
    Jan 16, 2012
    Messages:
    116
    Likes Received:
    13
    Trophy Points:
    0
    Tablet / Device:
    Azpen X1 , HP-Touchpad
    Some screnshots of my Desktop before and after rotating.



    $ScreenshotNormal.png


    $ScreenshotRight.png
  3. waterhead
    Offline

    waterhead Junior Member

    Joined:
    Jan 16, 2012
    Messages:
    116
    Likes Received:
    13
    Trophy Points:
    0
    Tablet / Device:
    Azpen X1 , HP-Touchpad
    Rotating the screen to the right puts the USB, power and headphone ports at the bottom. If you have anything plugged in, this is not very convenient. I have made a new script to now make it rotate to the left.
    Code:
    #!/bin/sh 
    
    # Find the line in "xrandr -q --verbose" output that contains current screen orientation and "strip" out current orientation. 
    
    rotation="$(xrandr -q --verbose | grep 'connected' | egrep -o  '\) (normal|left|inverted|right) \(' | egrep -o '(normal|left|inverted|right)')" 
    
    # Using current screen orientation proceed to rotate screen and input tools. 
    
    case "$rotation" in 
        normal) 
    #    -rotate to the left 
        xrandr -o left 
        xinput set-prop --type=int --format=8 "ILITEK ILITEK Multi-Touch" "Evdev Axes Swap" 1
        xinput set-prop --type=int --format=8 "ILITEK ILITEK Multi-Touch" "Evdev Axis Inversion" 1 0
        xinput set-prop --type=int --format=8 4 "Evdev Axis Inversion" 1 0
        ;;
        left) 
    #    -rotate to normal 
        xrandr -o normal 
        xinput set-prop --type=int --format=8 "ILITEK ILITEK Multi-Touch" "Evdev Axes Swap" 0
        xinput set-prop --type=int --format=8 "ILITEK ILITEK Multi-Touch" "Evdev Axis Inversion" 0 0
        xinput set-prop --type=int --format=8 4 "Evdev Axis Inversion" 0 0
        ;; 
    esac
    Last edited: Feb 18, 2012
  4. waterhead
    Offline

    waterhead Junior Member

    Joined:
    Jan 16, 2012
    Messages:
    116
    Likes Received:
    13
    Trophy Points:
    0
    Tablet / Device:
    Azpen X1 , HP-Touchpad
    If you are using a USB mouse, I noticed that it did not rotate along with the screen and touchscreen. I added the "Virtual core XTEST pointer" to the script. I used the ID number instead of the name.

    I updated both scripts. Please post if you are having any trouble.
  5. waterhead
    Offline

    waterhead Junior Member

    Joined:
    Jan 16, 2012
    Messages:
    116
    Likes Received:
    13
    Trophy Points:
    0
    Tablet / Device:
    Azpen X1 , HP-Touchpad
    If you find that your touchscreen is not accurate, meaning the point that registers is not exactly where you touched, there is a way to compensate for that. There is the Linux app xinput-calibrator. It can be installed in Ubuntu from the regular repositories:
    Code:
    sudo apt-get install xinput-calibrator
    In openSUSE-12.1, you have to first add a repository (as root):
    Code:
    zypper addrepo http://download.opensuse.org/repositories/home:koprok:base-12.1/standard/home:koprok:base-12.1.repo
    Code:
    zypper refresh
    Code:
    zypper install xinput-calibrator
    Run the app from a terminal window:
    Code:
    xinput_calibrator
    It will ask you to touch the cross-hairs in the four corners. For accuracy, you should use a touchscreen stylus (pen) or a mouse. It will then output data to the terminal window, like this:
    Code:
    paul@AzpenX1:~> xinput_calibrator
    Section "InputClass"
        Identifier    "calibration"
        MatchProduct    "ILITEK ILITEK Multi-Touch"
        Option    "Calibration"    "162 4940 54 2783"
        Option    "SwapAxes"    "0"
        Option "InvertX" "0"
        Option "InvertY" "0"
    EndSection
    
    This is formatted for insertion into a xorg.conf file, but you can use the info from the line Option "Calibration". Add it to the screen rotating script, like so:
    Code:
    xinput setprop "ILITEK ILITEK Multi-Touch" "Evdev Axis Calibration" 162 4940 54 2783
    Of course, use your touchscreen name, and your results from running the xinput-calibrator. You only need to run it once, at the beginning of the script.
    Code:
    #!/bin/sh 
    
    # Find the line in "xrandr -q --verbose" output that contains current screen orientation and "strip" out current orientation. 
    
    rotation="$(xrandr -q --verbose | grep 'connected' | egrep -o  '\)  (normal|left|inverted|right) \(' | egrep -o  '(normal|left|inverted|right)')" 
    
    # Insert screen calibration settings:
    xinput set-prop "ILITEK ILITEK Multi-Touch" "Evdev Axis Calibration" 162 4940 54 2783
    
    # Using current screen orientation proceed to rotate screen and input tools. 
    
    case "$rotation" in 
        normal) 
    #    -rotate to the left 
        xrandr -o left 
        xinput set-prop --type=int --format=8 "ILITEK ILITEK Multi-Touch" "Evdev Axes Swap" 1
        xinput set-prop --type=int --format=8 "ILITEK ILITEK Multi-Touch" "Evdev Axis Inversion" 1 0
        xinput set-prop --type=int --format=8 4 "Evdev Axis Inversion" 1 0
        ;;
        left) 
    #    -rotate to normal 
        xrandr -o normal 
        xinput set-prop --type=int --format=8 "ILITEK ILITEK Multi-Touch" "Evdev Axes Swap" 0
        xinput set-prop --type=int --format=8 "ILITEK ILITEK Multi-Touch" "Evdev Axis Inversion" 0 0
        xinput set-prop --type=int --format=8 4 "Evdev Axis Inversion" 0 0
        ;; 
    esac
    Last edited: Mar 20, 2012
  6. waterhead
    Offline

    waterhead Junior Member

    Joined:
    Jan 16, 2012
    Messages:
    116
    Likes Received:
    13
    Trophy Points:
    0
    Tablet / Device:
    Azpen X1 , HP-Touchpad
    There is a way in Linux to have the tablet automatically rotate the screen when you rotate the tablet. It appears to be reading a sensor, and interpreting it as a keyboard. It outputs it as binary data, which you can see if you enter this command and then rotate the tablet (openSUSE)
    Code:
    cat /dev/input/event0
    Or in Ubuntu:
    Code:
    cat /dev/input/event2
    I don't know if this is from an accelerometer, or a simple gravity sensor. It puzzled me how I could use this data, that is until I ran Ubuntu 11.10 on my tablet.

    Linux has "Workspaces", which are extensions of the desktop. You can run different applications on them, and switch to them with a keyboard shortcut key combo. Ubuntu installs with four workspaces, openSUSE with only two. It seems the output of the sensors is actually a keyboard shortcut! Each position corresponds to a shortcut key combo to switch to a different workspace! In Ubuntu, this was more obvious, and it spurred me to seek a solution. This shortcut-key action can't be by accident, but I can't find any documentation regarding it.

    To use this, you first need to disable the existing shortcut keys. In openSUSE, click on your name in the upper-right corner, and select: System Settings --> Keyboard, and then the Shortcuts tab.

    In Ubuntu the process is similar, except click the gear-like icon next to your name. You should get a window similar to this:


    [​IMG]


    After disabling the workspace shortcuts, you will now use them to run scripts that will rotate the screen. These scripts are attached to this post.

    Select "Custom Shortcuts" from the left side, then create four new shortcuts, by clicking the "+" icon, like these:


    [​IMG]

    Give it any name you want, but in the "Command" line, you must give the full path to where you saved the four rotate scripts. Link each shortcut to the corresponding script. I keep them in a "Scripts" folder in my home directory, so the path I entered is this:

    /home/paul/Scripts/rotate_normal

    If this tablet has more than one user account, you will want to keep the scripts in a folder that is accessible by all. Something like /usr/local/bin/ will work, but you need root permissions to save to that folder:
    Code:
    gksu nautilus
    Then you can move the files. You also need to make them executable files. Open the "Properties" on the file, and on the "Permissions" tab, check the "Allow executing file as program".

    After creating the new shortcuts, it will say "disabled" in the right column. Click on this until it says "New shortcut". Then hold down the keys for the shortcut, in the order that you want them. Use these for proper rotation:

    Rotate Normal: Ctrl+Alt+Up (up arrow)
    Rotate Inverted: Ctrl+Alt+Down (down arrow)
    Rotate Left: Ctrl+Alt+Left (left arrow)
    Rotate Right: Ctrl+Alt+Right (right arrow)

    It seems that openSUSE had a problem recording the "Ctrl" key. I had to manually edit the shortcut config files to add it. They were found in a hidden folder in my home directory:

    /.gconf/desktop/gnome/keybindings/customX/%gconf.xml

    Open it in a text editor (gedit), and add to the last line so that it looks like this:
    Code:
    <stringvalue>&lt;Control&gt;&lt;Alt&gt;Left</stringvalue>
    Ubuntu didn't have this problem, so no file editing is needed.

    I have included screen calibration data in the scripts. This is for my tablet, and may not be good for other tablets. I got the data from running the screen calibration app five or six times, and averaging the outputted data:
    Code:
    xinput_calibrator
    My scripts are for my tablet, the Azpen X1. Since the Viewpad 10 may have a different touchscreen, they will need to be edited to work correctly. I encourage some of the Viewpad 10 owners to post with the info needed.

    Attached Files:

    Last edited: Mar 8, 2012
  7. Daskalos
    Offline

    Daskalos Junior Member

    Joined:
    Feb 4, 2012
    Messages:
    15
    Likes Received:
    0
    Trophy Points:
    0
    Wow your good in solving things.... I'll try this when I reinstall Ubuntu.... Any workarounds for emulating mouse right-click in Ubuntu?
  8. waterhead
    Offline

    waterhead Junior Member

    Joined:
    Jan 16, 2012
    Messages:
    116
    Likes Received:
    13
    Trophy Points:
    0
    Tablet / Device:
    Azpen X1 , HP-Touchpad
    Please do, and don't be afraid to ask for help.
    Open the "Universal Access" in the System settings. On the "Pointing and Clicking" tab, enable the option "Simulate secondary click". That only seems to work so-so, though.
  9. Daskalos
    Offline

    Daskalos Junior Member

    Joined:
    Feb 4, 2012
    Messages:
    15
    Likes Received:
    0
    Trophy Points:
    0
    Hmmm it rarely works for me :)
    It would be nice to have a tap-and-hold for right click like in Windows

    From reading some old threads, I read that on old version of ubuntu you can have a first finger hold and second finger tap to have a right click easily, i don't undertand why it's gone on newer builds.

Share This Page