LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Desktop
User Name
Password
Linux - Desktop This forum is for the discussion of all Linux Software used in a desktop context.

Notices

Reply
 
Search this Thread
Old 04-25-2012, 01:01 PM   #1
SaintDanBert
Senior Member
 
Registered: Jan 2009
Location: Austin, TX
Distribution: Mint-15 with Cinnamon & KDE
Posts: 1,324
Blog Entries: 3

Rep: Reputation: 86
seeking help with rotating screen(s)


I have a desktop monitor that can rotate portrait and landscape.
I have "tablet-PC" workstations with screens that rotate portrait and landscape.
I do work in both orientations and I need help getting these to
  1. work in the first place
  2. work well
  3. integrate
  4. maintainable
with my routine use of the workstations involved.

First, I want to have some command or button or control such that I can alter the device orientation, use the control, and then use the device in the new orientation. Once I learn how, I'll write a python or similar desktop button that runs a whatever is needed to toggle the orientation. (I can use the same "whatever" later.)

All of the devices claim to throw events so that orientation changes can happen auto-magically. "Work well" implies that things work smoothly with these events. (Here is where I'll use the "whatever" mentioned earlier.)

Both "work" and "work well" implies that up-down-left-right arrow keys and pointer movements adjust for the change in display orientation.

"Integration" implies that the various applications (LibreOffice, Gimp, Xournal, etc) learn about and operate in both portrait and landscape orientation. I know this part will be a long term work in progress.

"Maintainable" implies that I can carry this forward as my distribution and applications evolve over time.
Currently, I'm running various editions of the Ubuntu family
of distro's: v10.04, v11.10, Mint-12(v11.10 w/ Cinnamon desktop),
and Mint-12 KDE (v11.10 with KDE desktop).

I've read about xrandr but there seem to be legion examples for very specific environments versus a more generic HOWTO. Couple this with the dynamic configuration of X-11 (X-windows, X-org, etc)
devices and I am completely lost and confused.

Can anyone out there help ... REALLY HELP ... me sort this out?
I'm not techno-naive, but I'm not a bit-wizard either.
I am desperate with lots of hardware that I'm not able to use.

Thanks in advance,
~~~ 0;-Dan
 
Old 04-25-2012, 09:45 PM   #2
Nominal Animal
Senior Member
 
Registered: Dec 2010
Location: Finland
Distribution: Xubuntu, CentOS, LFS
Posts: 1,723
Blog Entries: 3

Rep: Reputation: 942Reputation: 942Reputation: 942Reputation: 942Reputation: 942Reputation: 942Reputation: 942Reputation: 942
Quote:
Originally Posted by SaintDanBert View Post
I've read about xrandr but there seem to be legion examples for very specific environments versus a more generic HOWTO.
xrandr can certainly do this for you. It uses the RandR protocol to tell the X server what to do, so you can do it directly in X-aware programs in most programming languages. But using the xrandr utility is usually a better option.

First, you must be aware of which output you wish to control. These are named VGA-0, VGA-1 and so on for analog VGA outputs, DVI-0, DVI-1 and so on for DVI outputs, HDMI-0, HDMI-1 and so on for HDMI outputs, and LVDS-0, LVDS-1 and so on for laptop screens. The names are defined by the graphics driver, and sometimes may be labeled wrong (especially wrt. HDMI and DVI, since the digital video part is electrically and signal-wise the same, only the connector is different). Sometimes some of the outputs don't even have physical connectors attached, so you might see some you cannot even use sometimes. (They do exist in the computer, but are useless for the user.)

You can obtain the list of outputs available using
Code:
xrandr --query
On my machine, the output looks like this:
Code:
Screen 0: minimum 320 x 200, current 1920 x 1080, maximum 8192 x 8192
VGA-0 disconnected (normal left inverted right x axis y axis)
HDMI-0 connected 1920x1080+0+0 (normal left inverted right x axis y axis) 477mm x 268mm
   1920x1080      60.0*+
   1680x1050      60.0  
   1600x900       60.0  
   1280x1024      75.0     60.0  
   1280x960       60.0  
   1152x864       75.0  
   1280x720       60.0  
   1152x720       60.0  
   1024x768       75.1     60.0  
   832x624        74.6  
   800x600        75.0     60.3  
   640x480        75.0     60.0  
   720x400        70.1
While I have two outputs, only one, HDMI-0 is connected; thus only one screen.

After you know the output, you can set the display rotation to whatever you like. Note that rotation is not set relative to current rotation, but absolute. Running the same command twice in a row will just set the rotation to the same twice, not rotate the display further.

When I rotate my normally landscape display right/counterclockwise to portrait mode, I just run
Code:
xrandr --output HDMI-0 --rotate right
This also rotates the pointer orientation; my mouse will work correctly, "up" being towards the short edge of the display (that used to be the right edge).

When I go back to the default landscape orientation, I just run
Code:
xrandr --output HDMI-0 --rotate normal
This works not only on my workstation, but also on my Linux laptop. Except that the output is LVDS-0 instead on my laptop, since it is built-in display I want to rotate there.

If you happen to have a display that tells your graphics driver about the orientation change, and the Linux driver supports that, it will show up as a keyboard event. Open the keyboard shortcuts panel (for your desktop environment; I use XFCE, but they all have one in their settings), create a new keyboard shortcut, and instead of pressing a key combination, just rotate the display to see if it generates the event automatically.

If not, there is no support for the orientation detection, and you have to set a keyboard shortcut to do that. You use one the set "portrait mode", and one to set "landscape mode".

If you want a toggle instead -- for example, if you have a nice unused key on your keyboard you'd like to use like I do (my display has no orientation detection) --, write a small script similar to the following:
Code:
#!/bin/bash
if [ $# -ne 1 ]; then
    exec >&2
    echo ""
    echo "Usage: $0 OUTPUT"
    echo ""
    echo "This flips between normal and right rotation"
    echo "for the XrandR output OUTPUT. If unsure, try"
    echo "VGA-0, LVDS-0, HDMI-0, or DVI-0."
    echo ""
    exit 1
fi
OUTPUT="$1"
STATE=$( xrandr --query | awk -v o="$OUTPUT" '($1==o) { print $2 "-" $4 }')
case "$STATE" in
  connected-right)
    xrandr --output "$OUTPUT" --rotation normal
    ;;
  connected-\(*)
    xrandr --output "$OUTPUT" --rotation right
    ;;
  connected-*)
    xrandr --output "$OUTPUT" --rotation normal
    ;;
esac
This works by using awk to pick just the second and fourth fields from the xrandr query output for the desired output. If it is connected and in right rotation, it sets the normal rotation. If it is connected and in normal rotation (the fourth field is missing; the fifth field starts with an open parenthesis), it sets the right rotation. If it is connected but in a weird rotation, it sets the normal rotation. If it is disconnected, none of the cases match, so the script does nothing.

The above example script is just a dummy example; I believe you could do much better. For one, you could see if the xrandr output only lists one active display. Or, you could apply the rotation to all active displays.

For me, this all works perfectly, although it does take a couple of seconds for the display to adjust (it stays black during the switch). The integration is perfect, too: applications only notice that the screen size changes. From the applications' point of view, the orientation has not changed, only the screen size. (Technically, they still draw all graphics the same way they always do, it's the X server which does the magic.)
Maintainability should not be an issue, either: this stuff is very stable. Perhaps, if new features are added, the xrandr query output might change a bit -- so you might not want to parse the output like I do in the flip script above --, but that is about it. The xrandr parameters are very unlikely to change; this should work the same in years to come.

Hope you find this useful,

Last edited by Nominal Animal; 04-25-2012 at 09:55 PM. Reason: Fixed the script.
 
Old 04-25-2012, 10:31 PM   #3
jschiwal
Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 654Reputation: 654Reputation: 654Reputation: 654Reputation: 654Reputation: 654
There may be udev, xorg key events, or acpi messages when you rotate the screen.
Run xev and rotate the screen. There is a udev-monitor program as well. A udev rule could change the display orientation. You can also run commands on certain keynotes using xmodmap.

Last edited by jschiwal; 04-25-2012 at 11:57 PM.
 
Old 04-26-2012, 02:27 PM   #4
SaintDanBert
Senior Member
 
Registered: Jan 2009
Location: Austin, TX
Distribution: Mint-15 with Cinnamon & KDE
Posts: 1,324
Blog Entries: 3

Original Poster
Rep: Reputation: 86
Quote:
Originally Posted by Nominal Animal View Post
...
This works by using awk to pick just the second and fourth fields from the xrandr query output for the desired output. If it is connected and in right rotation, it sets the normal rotation. If it is connected and in normal rotation (the fourth field is missing; the fifth field starts with an open parenthesis), it sets the right rotation. If it is connected but in a weird rotation, it sets the normal rotation. If it is disconnected, none of the cases match, so the script does nothing.
...
I get the following in normal orientation:
Code:
prompt$ xrandr --query | grep '[ ]connected'

LVDS1 connected 1366x768+0+0 (normal left inverted right x axis y axis) 277mm x 156mm

Follow-Up:
The grep command added ahead of the awk command would only search active displays, not those known to the software that might be offline at the time.


I get the following in left orientation:
Code:
prompt$ xrandr --query | grep '[ ]connected'

LVDS1 connected 768x1366+0+0 left (normal left inverted right x axis y axis) 277mm x 156mm
The awk command thus reports:
Code:
prompt$ xrandr --query | awk -v o="$OUTPUT" '($1==o) { print $2 "-" $4 }'

connected-(normal
--or--
Code:
prompt$ xrandr --query | awk -v o="$OUTPUT" '($1==o) { print $2 "-" $4 }'

connected-left
depending on the orientation. Thus the need for the cases "connected-XXXXX" and "connected-(YYYY". Tres chic.

Am I correct that xrandr will re-orient the pointer and arrow keys as well as the display? If so, all that remains will be orientation on the stylus and touch pointers.

Happy Joy Joy
~~~ 0;-Dan

Last edited by SaintDanBert; 04-26-2012 at 02:31 PM.
 
Old 04-26-2012, 03:50 PM   #5
SaintDanBert
Senior Member
 
Registered: Jan 2009
Location: Austin, TX
Distribution: Mint-15 with Cinnamon & KDE
Posts: 1,324
Blog Entries: 3

Original Poster
Rep: Reputation: 86
I have a question about the gawk command:
Code:
awk -v o="$OUTPUT" '($1==o) { print $2 "-" $4 }'
First, "-v" could be written "--assign" saying that we assign the value of the expanded expression "$OUTPUT" to the awk variable "o".

Next, we execute the gawk program:
Code:
($1==o)  { print $2 "-" $4 }
I understand this to mean, "If $1 is the same as variable 'o' then print $2 and $4 with a dash separator."

My question: At the top of the code, we set OUTPUT=$1.
The gawk options sets o=$OUTPUT.
Why then compare 'o' with $1?

What do we use the awk variable 'o' for anyway?


~~~ 0;-Dan

Last edited by SaintDanBert; 04-26-2012 at 04:25 PM.
 
Old 04-26-2012, 05:14 PM   #6
Nominal Animal
Senior Member
 
Registered: Dec 2010
Location: Finland
Distribution: Xubuntu, CentOS, LFS
Posts: 1,723
Blog Entries: 3

Rep: Reputation: 942Reputation: 942Reputation: 942Reputation: 942Reputation: 942Reputation: 942Reputation: 942Reputation: 942
Quote:
Originally Posted by SaintDanBert View Post
I get the following in normal orientation
Correct: the current rotation is omitted in the output if it is normal. That is why my scriptlet matches against connected-( to detect the normal rotation.

Quote:
Originally Posted by SaintDanBert View Post
Am I correct that xrandr will re-orient the pointer and arrow keys as well as the display? If so, all that remains will be orientation on the stylus and touch pointers.
Pointer, yes.

You could say that the arrow keys are also reoriented, but actually they just perform the same logical operation: row up, row down, one character to left, or one character to right. From an applications point of view, these all stay the same. So too for the user. (But nothing really needs to be done for this.)

Certain touchpad/stylus drivers do not seem to have orientation support yet; synaptics has a patch available here. The patches are very simple, but getting them upstream would take a bit of cajoling from upstream developers. Or you can just recompile your own drivers.

It is also technically possible to adjust for it in userspace using an uinput daemon, but I recommend getting the drivers fixed if they don't support orientation yet.

Quote:
Originally Posted by SaintDanBert View Post
we assign the value of the expanded expression "$OUTPUT" to the awk variable "o".
Correct.

Quote:
Originally Posted by SaintDanBert View Post
Code:
($1==o)  { print $2 "-" $4 }
I understand this to mean, "If $1 is the same as variable 'o' then print $2 and $4 with a dash separator."
Correct.

Note that the awk script is in single quotes. This means that $1, $2, and $4 are awk variables, not shell variables. The shell does not interpret them at all (since they're used within single quotes), awk does. In awk, they are the first, second, and fourth field of the current record.

This means that you can read the rule thusly: "If the first field matches the value of the o variable for this record, output the second and fourth fields with a dash in between."

Quote:
Originally Posted by SaintDanBert View Post
Why then compare 'o' with $1?
Because they are both awk variables. Because it is in single quotes, supplied to awk, the $1 here refers to the first field in the current record, not the first positional parameter to the calling script. It looks the same, but that's just a coincidence; it is a different $1 than what the shell script bit earlier refers to.

The reason I want to compare the first field against o is that I am only interested in the state for the selected output. If we didn't have that, then awk would just print the second and fourth fields with a dash in between for every record (line). This way it will only output the one pertinent line.

Last edited by Nominal Animal; 04-26-2012 at 05:17 PM.
 
Old 04-26-2012, 06:57 PM   #7
SaintDanBert
Senior Member
 
Registered: Jan 2009
Location: Austin, TX
Distribution: Mint-15 with Cinnamon & KDE
Posts: 1,324
Blog Entries: 3

Original Poster
Rep: Reputation: 86
Quote:
Originally Posted by Nominal Animal
Note that the awk script is in single quotes. This means that $1, $2, and $4 are awk variables, not shell variables. The shell does not interpret them at all (since they're used within single quotes), awk does. In awk, they are the first, second, and fourth field of the current record.
Now it all makes sense.
Code:
$1 ..... the X-display device name
$2 ..... "connected" or "disconnected"
$4 ..... "(normal" or "left" or "right" or "inverted"
Doh! I've not used awk/gawk for years. I forgot about the "awk variables" feature.

Quote:
Originally Posted by Nominal Animal
Because it is in single quotes, supplied to awk, the $1 here refers to the first field in the current record, not the first positional parameter to the calling script. It looks the same, but that's just a coincidence; it is a different $1 than what the shell script bit earlier refers to.
{wagging finger; clucking tongue} a simple comment reminder that "$1" is two different animals(sic) might go a long way.

My tablet is a Wacom(R) and there is xsetwacom utility.
Now I get to play with that for touch and stylus orientation.

You've been a great help.
~~~ 0;-Dan

Last edited by SaintDanBert; 04-26-2012 at 07:00 PM.
 
Old 04-26-2012, 08:43 PM   #8
Nominal Animal
Senior Member
 
Registered: Dec 2010
Location: Finland
Distribution: Xubuntu, CentOS, LFS
Posts: 1,723
Blog Entries: 3

Rep: Reputation: 942Reputation: 942Reputation: 942Reputation: 942Reputation: 942Reputation: 942Reputation: 942Reputation: 942
Quote:
Originally Posted by SaintDanBert View Post
Now it all makes sense.
Code:
$1 ..... the X-display device name
$2 ..... "connected" or "disconnected"
$4 ..... "(normal" or "left" or "right" or "inverted"
Exactly.

Quote:
Originally Posted by SaintDanBert View Post
{wagging finger; clucking tongue} a simple comment reminder that "$1" is two different animals(sic) might go a long way.
Sorry I just tried to make it as clear as I could. What I lack in sanity, I make up in verbosity.

Quote:
Originally Posted by SaintDanBert View Post
My tablet is a Wacom(R) and there is xsetwacom utility.
Excellent! The linuxwacom rotation Wiki page has example scripts and details you might find useful.

Glad to be of help,
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
seeking HOWTO inhibit screen saver from command-line SaintDanBert Programming 6 01-16-2013 05:09 AM
Seeking advice on Desktop Manager with touch screen and light support (Debian on ARM 11 667MHz CPU) newuser10 Linux - Newbie 0 04-09-2012 01:01 PM
Rotating screen on Android/Linux/Windows CE Tablet rogerbowering Linux - Mobile 16 10-06-2010 02:47 AM
SEEKING: Realtime, on-screen Apache Monitoring tool. (Even if it's for Windows...) cyryl_the_wolf Linux - Software 4 08-24-2006 11:08 AM
rotating the screen delos Suse/Novell 1 12-11-2005 04:07 AM


All times are GMT -5. The time now is 06:17 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration