Do you like the way gnome-display-properties works (this is the one that is “System -> Options -> Monitors”) and the monitor switch key on a laptop? Yes? Then you can pass by, the topic is not for you :)
The biggest disadvantage of this applet is the inability to manually configure
the mode switching order : current configuration -> mirror -> extended desktop -> laptop only -> external only -> and again the current configuration. Not too convenient, is it? .. We will solve this problem.
Task
- to force the Switch Display key to switch only two modes:
1) laptop screen is on, external monitor is off
2) laptop screen is off, external monitor is on
- make sure that the laptop does not go into standby mode by slamming the lid, if the external screen is on
Decision
')
1. To begin with we will be defined with switching of monitors. We will do this with the help of the xrandr console utility.
- turn on the external monitor and turn off the internal:
xrandr --output VGA --auto && xrandr --output LVDS --off
- turn off the external and turn on the laptop screen:
xrandr --output LVDS --auto && xrandr --output VGA --off
Note that
VGA and LVDS names
may differ from system to system. These can be: LVDS / VGA, LVDS1 / VGA1, LVDS-1 / VGA-1, etc. To see what names are used on your system, simply type xrandr without parameters.
2. The next step we need to hang these commands on the monitor switching key.
First of all, we will disable the current behavior of this key, which is intercepted by the xrandr plugin from gnome-settings-daemon:
gconftool --set /apps/gnome_settings_daemon/plugins/xrandr/active --type bool false
Note : the same can be done using a graphical interface using gconf-editor
Then create a new binding to the XF86Display key:
gconftool --set /desktop/gnome/keybindings/switch-display/name --type string switch-display
gconftool --set /desktop/gnome/keybindings/switch-display/binding --type string XF86Display
gconftool --set /desktop/gnome/keybindings/switch-display/action --type string switch-display.sh
Note : the same can be done using a graphical interface using gnome-keybinding-properties or gconf-editor
Now this key should launch switch-display.sh, but nothing happens, because There is no script with this name yet.
3. Create a switch script.
Using the same xrandr, we will determine whether the laptop screen is turned on and, depending on the result, perform the switch. Here we will disable and enable the standby mode.
It is necessary to create a file with the text of this script, call it switch-display.sh, place it in the ~ / bin directory (if there is no ~ / bin directory, you need to create it) and give permission to execute it.
4. If you didn’t have the ~ / bin directory before, then before everything works, you will need to log out and log in again.
5. Now everything is ready, you can check!
Notes
- Momet the first - we made all the settings for the current user, this means that such a switch will not work like that of other users of the system, or on the login screen. In addition, since we do not use ACPI in this case (as, in fact, the standard xrandr plugin does), the switch key will not work on the locked screen either.
- The moment of the second - to return the standard key behavior, you must run the following commands:
gconftool --unset /desktop/gnome/keybindings/switch-display/binding
gconftool --unset /desktop/gnome/keybindings/switch-display/action
gconftool --unset /desktop/gnome/keybindings/switch-display/name
gconftool --unset /apps/gnome_settings_daemon/plugins/xrandr/active
All of the above is verified in Ubuntu 10.04 and Ubuntu 11.04.