# detect monitor rotation

## drjimmy42

I just got this amazingly cool Samsung SyncMaster 213t 1600x1200 LCD monitor that rotates 90 degrees.  So cool.

I have xrandr working with the nvidia drivers to rotate the screen, BUT

Does anyone know if there is a way to have the kernel detect when the screen is rotated?  Is any event, acpi or otherwise, generated when the monitor is rotated?  Thanks for the help.

John

----------

## Master Shake

nvidia-settings should tell you if that's of any help.  Are you trying to write a script or something of that natrue?

----------

## drjimmy42

yeah, I already have the script that runs xrandr, determines what the current orientation is by the xrandr output and then runs xrandr again to toggle the orientation.  Its bound to a keybinding, which is fine, but I thought it would be ubercool to have it just flip when I rotated the monitor.  

What do you mean by nvidia-settings telling me?

Thanks

----------

## infiniteedge

can you post your config for doing all that?

----------

## NeddySeagoon

drjimmy42,

That implys some electromics to detect the rotation.

It would cost more to build that in and the blurb would tell you.

----------

## drjimmy42

Sorry, never did post my script.  Here it is. 

```
#!/bin/bash

# Toggle between normal and left handed rotation

function jjr-dialog ()

{

    if [ -e `which zenity > /dev/null 2>&1` ] && [ -n "$DISPLAY" ]  ; then

        zenity --title "$1" --info --text "$2" > /dev/null 2>&1

    elif [ -e `which xmessage > /dev/null 2>&1` ] && [ -n "$DISPLAY" ] ; then

        xmessage -bg black -fg green -bd white -center \

            -buttons OK -default OK "$2" > /dev/null 2>&1

    else

        echo "$1: $2"

    fi

}

if ! which xrandr > /dev/null 2>&1 ; then

    jjr-dialog "XRandr not found" "Could not find the xrandr system command"

    exit 1

fi

if xrandr | egrep -i "current rotation - normal" ; then

    if xrandr | egrep -i "rotations possible.*left" ; then

        xrandr -o left

    else

        jjr-dialog "Rotation not available" "Left is not listed as a possible rotation by xranrd"

    fi

else 

    xrandr -o normal

fi

```

as for config, the only parts I needed were to add

```
    Option "RandR" "true"
```

to the serverlayout section of xorg.conf and 

```
        Option "RandRRotation" "on"
```

in the device section.  I've only gotten this to work with my nvidia cards.  No luck with the ati one in my laptop.

----------

## infiniteedge

I made the modifications you listed to my xorg.conf and copied the script but I can't seem to get screen rotation to work.

```
dguido@deimos ~ $ xrandr -o left

X Error of failed request:  BadMatch (invalid parameter attributes)

  Major opcode of failed request:  159 (RANDR)

  Minor opcode of failed request:  2 (RRSetScreenConfig)

  Serial number of failed request:  12

  Current serial number in output stream:  12

dguido@deimos ~ $
```

```
xorg.conf:

Section "ServerLayout"

        Identifier     "X.org Configured"

        Screen      0  "Screen0" 0 0

        InputDevice    "Mouse0" "CorePointer"

        InputDevice    "Keyboard0" "CoreKeyboard"

        Option         "RandR" "true"

EndSection

Section "Extensions"

    Option "Composite" "Enable"

EndSection

Section "Files"

        RgbPath      "/usr/lib/X11/rgb"

        ModulePath   "/usr/lib/modules"

        FontPath     "/usr/share/fonts/misc/"

        FontPath     "/usr/share/fonts/TTF/"

        FontPath     "/usr/share/fonts/Type1/"

        FontPath     "/usr/share/fonts/CID/"

        FontPath     "/usr/share/fonts/75dpi/"

        FontPath     "/usr/share/fonts/100dpi/"

EndSection

Section "Module"

        Load  "glx"

        Load  "record"

        Load  "extmod"

        Load  "dbe"

#       Load  "dri"

        Load  "xtrap"

        Load  "freetype"

        Load  "type1"

EndSection

Section "InputDevice"

        Identifier  "Keyboard0"

        Driver      "kbd"

EndSection

Section "InputDevice"

        Identifier  "Mouse0"

        Driver      "mouse"

        Option      "Protocol" "auto"

        Option      "Device" "/dev/input/mice"

        Option      "Buttons" "10"

        Option      "ZAxisMapping" "9 10"

EndSection

Section "Monitor"

        Identifier   "Monitor0"

        VendorName   "Samsung"

        ModelName    "153T"

        HorizSync    30-60

        VertRefresh  56-75

EndSection

Section "Device"

        ### Available Driver options are:-

        ### Values: <i>: integer, <f>: float, <bool>: "True"/"False",

        ### <string>: "String", <freq>: "<f> Hz/kHz/MHz"

        ### [arg]: arg optional

        #Option     "DigitalVibrance"           # <i>

        #Option     "NoFlip"                    # [<bool>]

        #Option     "Dac8Bit"                   # [<bool>]

        Option     "NoLogo" "true"              # [<bool>]

        #Option     "UBB"                       # [<bool>]

        #Option     "Stereo"                    # <i>

        #Option     "SWcursor"                  # [<bool>]

        #Option     "HWcursor"                  # [<bool>]

        #Option     "VideoKey"                  # <i>

        #Option     "NvAGP"                     # <i>

        #Option     "IgnoreEDID"                # [<bool>]

        #Option     "NoDDC"                     # [<bool>]

        #Option     "ConnectedMonitor"          # <str>

        #Option     "ConnectedMonitors"         # <str>

        #Option     "TVStandard"                # <str>

        #Option     "TVOutFormat"               # <str>

        Option     "RenderAccel" "true"         # [<bool>]

        #Option     "CursorShadow"              # [<bool>]

        #Option     "CursorShadowAlpha"         # <i>

        #Option     "CursorShadowXOffset"       # <i>

        #Option     "CursorShadowYOffset"       # <i>

        #Option     "UseEdidFreqs"              # [<bool>]

        #Option     "FlatPanelProperties"       # <str>

        #Option     "TwinView"                  # [<bool>]

        #Option     "TwinViewOrientation"       # <str>

        #Option     "SecondMonitorHorizSync"    # <str>

        #Option     "SecondMonitorVertRefresh"  # <str>

        #Option     "MetaModes"                 # <str>

        #Option     "UseInt10Module"            # [<bool>]

        #Option     "NoTwinViewXineramaInfo"    # [<bool>]

        #Option     "NoRenderExtension"         # [<bool>]

        #Option     "Overlay"                   # [<bool>]

        #Option     "CIOverlay"                 # [<bool>]

        #Option     "ForceEmulatedOverlay"      # [<bool>]

        #Option     "TransparentIndex"          # <i>

        #Option     "OverlayDefaultVisual"      # [<bool>]

        #Option     "NvEmulate"                 # <i>

        #Option     "NoBandWidthTest"           # [<bool>]

        #Option     "CustomEDID-CRT-0"          # <str>

        #Option     "CustomEDID-CRT-1"          # <str>

        #Option     "CustomEDID-DFP-0"          # <str>

        #Option     "CustomEDID-DFP-1"          # <str>

        #Option     "CustomEDID-TV-0"           # <str>

        #Option     "CustomEDID-TV-1"           # <str>

        #Option     "TVOverScan"                # <f>

        #Option     "IgnoreDisplayDevices"      # <str>

        #Option     "MultisampleCompatibility"  # [<bool>]

        #Option     "RegistryDwords"            # <str>

        #Option     "RegistryBinary"            # <str>

        #Option     "NoPowerConnectorCheck"     # [<bool>]

        #Option     "AllowDFPStereo"            # [<bool>]

        #Option     "XvMCUsesTextures"          # [<bool>]

        #Option     "HorizSync"                 # <str>

        #Option     "VertRefresh"               # <str>

        Option      "RandRRotation" "on"

        Option      "AllowGLXWithComposite" "true"      # [<bool>]

        Identifier  "Card0"

        Driver      "nvidia"

        VendorName  "nVidia Corporation"

        BoardName   "Unknown Board"

        BusID       "PCI:1:0:0"

EndSection

Section "Screen"

        Identifier "Screen0"

        Device     "Card0"

        Monitor    "Monitor0"

        DefaultDepth 24

        SubSection "Display"

                Viewport   0 0

                Depth     16

                Modes   "1024x768"

        EndSubSection

        SubSection "Display"

                Viewport   0 0

                Depth     24

                Modes   "1024x768"

        EndSubSection

EndSection
```

any ideas?

----------

## drjimmy42

Try just running xrandr by itself.  It should list all legal rotations.

Also, check out the Xorg.0.log and look for the word "randr" to see if the option is enabled. 

specifically

```
(**) RandR enabled
```

----------

## infiniteedge

```
dguido@deimos ~ $ xrandr

 SZ:    Pixels          Physical       Refresh

*0   1024 x 768    ( 302mm x 232mm )  *75   70   60

 1    832 x 624    ( 302mm x 232mm )   75

 2    800 x 600    ( 302mm x 232mm )   75   72   60   56

 3    640 x 480    ( 302mm x 232mm )   75   73   60

 4    512 x 384    ( 302mm x 232mm )   75   70   60

 5    416 x 312    ( 302mm x 232mm )   75

 6    400 x 300    ( 302mm x 232mm )   75   72   60   56

 7    320 x 240    ( 302mm x 232mm )   75   73   60

Current rotation - normal

Current reflection - none

Rotations possible - normal

Reflections possible - none

dguido@deimos /var/log $ cat Xorg.0.log|grep RandR

(**) Option "RandR" "true"

(WW) NVIDIA(0): Option "RandRRotation" is not used

(**) RandR enabled
```

I don't get it.  Obviously something with the Device option of RandRRotation is wrong.  I'm using the stable nvidia-kernel and nvidia-glx for my video drivers.  Is that the problem?

----------

## infiniteedge

I upgraded to unstable nvidia-kernel and nvidia-glx and it seems to have worked  :Smile: .  I'm typing this from a rotated screen.

----------

## drjimmy42

I guess that was it.  Happy rotating.

----------

## TheKat

Did you ever figure out how to tell if the screen was rotated? I don't know if that information travels over the USB link (lsusb lists 2 new devices on the USB connection of my monitor) or somehow over the DVI connection.

Also, did you get it working with KDE? My KDE will rotate on demand, but does not update the resolution properly for existing programs so, for example, kicker ends up in the middle of the screen.

----------

## drjimmy42

I never figured out a way to have the monitor figure out of it is rotated, so I just went with the script that just toggles it.  I run it whenever I turn the screen.  I don't use KDE ( openbox ) but my guess is it is the responsiblity of the window manager to resize stuff as the resolution changes.  Try a different window manager just to see if it works better.  Then maybe open a bug with KDE if that's the issue.

----------

## BlackB1rd

Does this only work with Nvidia cards, because I always get a current rotation of normal and no other possibilities on my Intel 915G on-board videocard. I've got a brand new Samsung 204Ts and I'd like to take advantage of the rotation possibility. But if it is for sure that Nvidia cards definitely will work with this feature, I'll get one of these.

----------

## jlg

I have a similar script and xrandr  is working with KDE no problem. I imagine the only way to know if the monitor is rotated or not would be through a monitor driver. With my SyncMaster 204B theres a CD with apps and drivers  it says magic rotation. I guess that is what makes it auto switch in windows.

----------

## jlg

what would be cool  is a little motor activated by my script  that would rotate  the monitor for me   :Twisted Evil: 

----------

## mottmar

 *jlg wrote:*   

> what would be cool  is a little motor activated by my script  that would rotate  the monitor for me  :twisted:

 

this would be real fun!

however, does xrandr tell you the current rotation status of the hardware? in that case it could be simple to poll this information and call the rotation command... (I don't have a rotating monitor so I can't check it myself, but I'm very curious about that)

----------

