Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preswitch hook and arandr method for dumping current xrandr config #34

Closed
wants to merge 2 commits into from

Conversation

gabrys
Copy link

@gabrys gabrys commented Jan 28, 2015

Hi,

I wanted to use autorandr as I think it represents a brilliant idea. Unfortunately I had a problem with the dumper code, it seems to misinterpret the xrandr output. Here the output from xrandr:

Screen 0: minimum 8 x 8, current 1366 x 768, maximum 32767 x 32767
LVDS1 connected primary 1366x768+0+0 (normal left inverted right x axis y axis) 293mm x 164mm
   1366x768      60.02*+  40.01  
   1360x768      59.80    59.96  
   1024x768      60.00  
   800x600       60.32    56.25  
   640x480       59.94  
DP1 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)
HDMI1 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)
VGA1 disconnected (normal left inverted right x axis y axis)
VIRTUAL1 disconnected (normal left inverted right x axis y axis)

Here's what autorandr outputs when --config option is used:

output LVDS1
mode primary
pos x
rotate 1366x768+0+0
output DP1
off
output DP2
off
output DP3
off
output HDMI1
off
output HDMI2
off
output HDMI3
off
output VGA1
off
output VIRTUAL1
off

(Note the pos x for example).

When trying to load such config xrandr prints an error

xrandr: failed to parse 'x' as a position
Try 'xrandr --help' for more information.

Parsing xrandr seems very brave to me, since the command output can change from version to version (and I think this is what did happen and caused the isuse). Using the xrandr lib would be perfect, but then autorandr is such a shell script, right? Fortunately there's a nice Python utility to help called arandr that ships with a tool called unxrandr, that use the xrandr lib bindings to dump the current xrandr state in a form of a xrandr command call ready to use, for example:

$ unxrandr 
xrandr --output VIRTUAL1 --off --output DP3 --off --output DP2 --off --output DP1 --off --output HDMI3 --off --output HDMI2 --off --output HDMI1 --off --output LVDS1 --mode 1366x768 --pos 0x0 --rotate normal --output VGA1 --off

I augmented the autorandr code to take advantage of this great tool. The patch follows the conventions already used by the tool author just adding a new method to dump the config (the idea of methods in the script is very nice!).

The second commit of the pull request is much more straight-forward. I added the preswitch hook that are launched just before the config is applied. This is useful for me, because I have an Intel card that is capable of displaying on at maximum 2 screen at once and can't switch from displaying 2 external screens to the laptop screen (the common scenario when detaching from a docking station) without disabling the external screens first. In this case I just put the following in the preswitch hook:

#!/bin/bash

xrandr \
  --output LVDS1 --off \
  --output DP1 --off \
  --output DP2 --off \
  --output DP3 --off \
  --output HDMI1 --off \
  --output HDMI2 --off \
  --output HDMI3 --off \
  --output VGA1 --off

... and everything works nicely.

Hope this pull request makes sense to you and follows the conventions, thus could be merged for others' profit.

@phillipberndt
Copy link

This repository is unmaintained. See #33. All of the problems you're experiencing have likely already been solved by earlier pull requests: See https://github.com/phillipberndt/autorandr/ for the most recent version. Especially, a preswitch hook is present, but not needed, since this version takes care of the order of operations (deactivates screens first, then activates the used ones).

Parsing xrandr seems very brave to me, since the command output can change from version to
version (and I think this is what did happen and caused the isuse).

In theory, yes, but in practice, it doesn't. See phillipberndt/autorandr#17 (comment)

Fortunately there's a nice Python utility to help called arandr that ships with a tool called unxrandr,
that use the xrandr lib bindings to dump the current xrandr state in a form of a xrandr command call
ready to use

As far as I can see, arandr also parses the output of xrandr (https://github.com/raboof/arandr/blob/master/screenlayout/xrandr.py#L51) Judging from https://github.com/raboof/arandr/blob/master/screenlayout/xrandr.py#L258 it also only has support for the basics, and not for more advanced features like --transform.

@gabrys
Copy link
Author

gabrys commented Jan 29, 2015

@phillipberndt thanks for the answers. I'll take a look at the fork :-).

@gabrys gabrys closed this Sep 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants