Introduction
Ca fait un petit bout de temps que j'essaie d'utiliser mon portable avec mon ecran plat au boulot le plus facilement possible (sans avoir a ouvrir une console et cahnger de fichier xorg.conf par exemple), on pourrait même dire comme sous l'OS de Billou
Warning
Ce how-to utilise une série de script dont je ne suis pas l'auteur je le reconnais volontiers!!!! Ils ont été écrit par Alexander Zimmermann et publiés sous licence GPL, ce qui me permet deonc de vous les proposer ici, sachant que j'ai juste modifié un de ceux-ci pour fonctionner avec Xorg, puisqu'ils ont été écrit pour foncitonner avec Xfree.
1. Prérequis
Je part du principe que vous avez déjà trouver la config "qui va bien" pour faire fonctionner votre ordi en dualhead/singlehead, par exemple pour votre protable seul et votre portable + un écran externe. Je suppose pour cela que vous avez créé un seul fichier xorg.conf avec plusieurs section
Section "ServerLayout"
vosoptionsquivontbien
EndSection
Je vous conseil également de définir une config par défaut
Section "ServerFlags"
Option "DefaultServerLayout" "thelayoutyouwantasdefault"
EndSection
2. Principe de fonctionnement
- On va utiliser un wrapper pour le serveur X qui va lire le fichier /tmp/.xlayout et qui démarre le serveur X avec le layout correspondant. Si ce fichier n'existe pas la config par défaut est utilisée (d'ou l'intérêt de la définir).
- On utilise le programme
xautolock qui est démarré en même temps que GDM.
xautolock lance une action lorsque l'on laisse le curseur de la souris dans un coin de l'écrab pour une seconde ou plus.
- Un terminal xterm s'ouvre alors et lance un script perl qui scanne votre fichier xorg.conf à la recherche des ServerLayouts et vous permet de sélectionner celui que vous voulez utiliser.
- Ce choix est alors écrit dans le fichier /tmp/.xlayout, le script perm relance le serveur X (et donc GDM) qui utilisera alors la configuration voulue.
- Dès que l'utilisateur est idenntifié, gdm tue
xautolock.
3. Programmes nécessaires
Vous vous en doutez, on a besoin d'installer deux trois trucs, par exemple xautolock, perl et xterm...
sudo apt-get install xautolock perl xterm
4. Modification de la config de GDM
Pour pouvoir utiliser le wrapper, il faut dire à GDM de l'utiliser à la place du serveur X par defaut. il faut donc éditer le fichier suivant:
sudo gedit /etc/gdm/gdm.conf
Et remplacer les lignes suivantes
# Definition of the standard X server.
[server-Standard]
name=Standard server
command=/usr/X11R6/bin/X -br -audit 0
flexible=true
par
# Definition of the standard X server.
[server-Standard]
name=Standard server
command=/usr/local/bin/XLayoutSet -audit 0
flexible=true
5. Les scripts
On va utiliser 5 scripts différents
* /usr/local/bin/XLayoutChooser
#!/usr/bin/perl
#
# Copyright (C) 2005 Alexander Zimmermann
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
use strict;
my ($CONF, $XCONF, $XLOCK, @text, @layout, $i, $j, $active);
$CONF = "/tmp/.xlayout";
$XCONF = "/etc/X11/xorg.conf";
$XLOCK = "/tmp/.X0-lock";
unlink($CONF);
open(DATA, "<$XCONF") or exit 0;
@text = <DATA>;
close(DATA);
@layout = ();
$active = 0;
for $i (0..$#text)
{
$active = 1 if $text[$i] =~ /Section.*ServerLayout/;
$active = 0 if $text[$i] =~ /EndSection/;
if ($active and ($text[$i] =~ /Identifier\s*"(.*)"/))
{
push(@layout, $1);
}
}
print "Configured Layouts\n\n 0 : (no change)\n";
for $i (0..$#layout)
{
print " " . ($i+1) . " : $layout[$i]\n";
}
print "\n";
$i = -1;
while ($i lt 0 or $i gt $#layout+1)
{
print "Select: ";
chomp($i = <STDIN>);
}
exit 0 if --$i < 0;
open(DATA, ">$CONF") or exit 0;
print DATA "$layout[$i]\n";
close(DATA);
if (-r $XLOCK)
{
system("kill -3 `cat $XLOCK`");
}
exit 0
* /usr/local/bin/XLayoutSet
#!/bin/sh
#
# Copyright (C) 2005 Alexander Zimmermann
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
CONF=/tmp/.xlayout
BIN=/usr/X11R6/bin/X
OPT=`cat $CONF`
if [ -n "$OPT" ]; then
exec $BIN "$@" -layout "$OPT"
fi
exec $BIN "$@"
* /etc/gdm/PostLogin/Default
#!/bin/sh
#
# Copyright (C) 2005 Alexander Zimmermann
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
killall -9 xautolock
* /etc/gdm/Init/:0
#!/bin/sh
#
# Copyright (C) 2005 Alexander Zimmermann
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
xautolock -cornerdelay 1 -cornerredelay 3599 -secure -time 3599 \
-cornersize 10 -corners ++++ \
-locker "/usr/X11R6/bin/xterm -e /usr/local/bin/XLayoutChooser" &
exec /etc/gdm/Init/Default "$@"
faites un copié-collé des fichiers dans un répertoire ~/layoutchooser
cd /layoutchooser
sudo cp XLayout* /usr/local/bin/
sudo cp Default /etc/gdm/PostLogin/
sudo cp :0 /etc/gdm/Init/
Il faut ensuite donner les droits d'execution à root:
sudo chmod u+x /usr/local/bin/XLayout*
sudo chmod u+x /etc/gdm/PostLogin/Default
sudo chmod u+x /etc/gdm/Init/:0
6. Test
Redémarrez GDM à partir d'une console TTY ou avec CTRL+ALT+BACKSPACE
A l'écran de connexion placez le curseur de la souris dans un coin de l'écran pendant plus de 1 seconde. Un terminal apparait, et vous propose de choisir le ServerLayout voulut. taper le numéro correspondant, gdm redémarre alors avec la bonne config.
Enjoy:cool: