Linux KDE: activer la rotation automatique de l'écran

mamiemando Messages postés 33093 Date d'inscription jeudi 12 mai 2005 Statut Modérateur Dernière intervention 4 mai 2024 - Modifié le 12 août 2022 à 18:27

Ce tutoriel explique comment automatiser la rotation de l'affichage en fonction de l'orientation de l'écran sous Linux. Cette fonctionnalité est supportée nativement pour les versions récentes Gnome mais pas sous KDE plasma. Ce tutoriel propose une solution en attendant que cette fonctionnalité soit supportée sous KDE.

Installation des dépendances

Sous Debian, Ubuntu, Mint:

sudo apt install iio-sensor-proxy

Vérifications

Dans un terminal, on lance la commande :

monitor-sensor

... et on fait pivoter l'écran. On vérifie que la commande détecte bien les changement d'orientation.

Exemple :

(mando@silk) (~) $ monitor-sensor  
   Waiting for iio-sensor-proxy to appear
+++ iio-sensor-proxy appeared
=== Has accelerometer (orientation: normal)
=== No ambient light sensor
=== No proximity sensor
   Accelerometer orientation changed: right-up
   Accelerometer orientation changed: normal


Une fois cette vérification faite, on interrompt le script (ctrl+c).

Script

On crée le script /usr/local/bin/auto-screen-rotate.sh et on y copie colle ce script ou la version simplifiée ci-dessous :

#!/bin/sh
# Based on https://gist.github.com/matoken/1c79ee3546e515e0fdb3bc1e55f9a87e#file-auto-screen-rotate-sh

MONITOR=$1
if [ -z $MONITOR ]; then
	MONITOR="eDP-1"
fi

monitor-sensor \
	| grep --line-buffered "Accelerometer orientation changed" \
	| grep --line-buffered -o ": .*" \
	| while read -r line; do
		line="${line#??}"
		if [ "$line" = "normal" ]; then
			rotate=normal
		elif [ "$line" = "left-up" ]; then
			rotate=left
		elif [ "$line" = "right-up" ]; then
			rotate=right
		elif [ "$line" = "bottom-up" ]; then
			rotate=inverted
		else
			echo "Unknown rotation: $line"
			continue
		fi

		xrandr --output "${MONITOR}" --rotate "$rotate"
	done

Lancement du script au démarrage de KDE

  1. Ouvrir le panneau de configuration KDE
  2. Aller dans Espace de travail > Démarrage automatique
  3. Cliquer sur Ajouter > Ajouter un script de connexion.
  4. Sélectionner /usr/local/bin/auto-screen-rotate.sh
  5. Relancer KDE.