You are not logged in.

#1 2023-11-11 19:14:43

Xwang
Member
From: EU
Registered: 2012-05-14
Posts: 414

How to set up the laptop to automatically switch to external monitor?

Hi,
I'm using plasma with Wayland and when I connect the external monitor, I would like that automatically the external monitor is used and the internal is disabled.
That is the behaviour the same PC has with X11, but not with plasma.
Moreover in plasma executing xrandr only the display in use is shown, not all the connected ones as it happens under X11.
Can you help me please?
The laptop is a Dell Latitude D9330 2in1 with intel graphic

inxi -Ga 
Graphics:
  Device-1: Intel Alder Lake-UP4 GT2 [Iris Xe Graphics] vendor: Dell
    driver: i915 v: kernel arch: Gen-12.2 process: Intel 10nm built: 2021-22+
    ports: active: DP-3 off: eDP-1 empty: DP-1,DP-2,HDMI-A-1 bus-ID: 00:02.0
    chip-ID: 8086:46aa class-ID: 0300
  Display: wayland server: X.org v: 1.21.1.9 with: Xwayland v: 23.2.2
    compositor: kwin_wayland driver: X: loaded: modesetting unloaded: vesa
    alternate: fbdev,intel dri: iris gpu: i915 display-ID: 0
  Monitor-1: DP-3 res: 1920x1080 size: N/A modes: N/A
  API: EGL v: 1.5 hw: drv: intel iris platforms: device: 0 drv: iris
    device: 1 drv: swrast surfaceless: drv: iris wayland: drv: iris x11:
    drv: iris inactive: gbm
  API: OpenGL v: 4.6 compat-v: 4.5 vendor: intel mesa v: 23.2.1-arch1.2
    glx-v: 1.4 direct-render: yes renderer: Mesa Intel Graphics (ADL GT2)
    device-ID: 8086:46aa memory: 14.9 GiB unified: yes display-ID: :0.0
  API: Vulkan Message: No Vulkan data available.

Offline

#2 2023-11-12 20:20:27

Xwang
Member
From: EU
Registered: 2012-05-14
Posts: 414

Re: How to set up the laptop to automatically switch to external monitor?

Meantime I've prepared this script:

#!/bin/bash


TMP_EXT_MONITOR_NAME=$(kscreen-doctor -o | grep 'DisplayPort' | grep connected | cut -d ' ' -f 3)
TMP_INT_MONITOR_NAME=$(kscreen-doctor -o | grep 'Panel' | grep connected | cut -d ' ' -f 3)
echo "Internal monitor is: $TMP_INT_MONITOR_NAME"
echo "External monitor is: $TMP_EXT_MONITOR_NAME"

if [ -z "$TMP_EXT_MONITOR_NAME" ]
then
    echo "External monitor is empty"
    if [ -z "$TMP_INT_MONITOR_NAME" ]
    then
        echo "ERROR!!! Internal monitor is empty"
    else
        echo "Internal monitor is: $TMP_INT_MONITOR_NAME"
        if [ -z "$(kscreen-doctor -o | grep $TMP_INT_MONITOR_NAME | grep enabled | cut -d ' ' -f 3)" ]
        then
            echo "Internal monitor is not enabled"
        else
            echo "Internal monitor is already enabled: nothing to do. Bye!"
        fi
    fi
else
    echo "External monitor is: $TMP_EXT_MONITOR_NAME"
    if [ -z "$(kscreen-doctor -o | grep $TMP_EXT_MONITOR_NAME | grep enabled | cut -d ' ' -f 3)" ]
    then
        echo "External monitor is not enabled"
    else
        echo "External monitor is already enabled: nothing to do. Bye!"
    fi
fi

It detects correctly if an external monitor is connected or not and retieves the monitor names, but still I do not know which command to use to switch off the internal monitor and enable the external one after the echo  "External monitor is not enabled" (plugging of external monitor) and viceversa after the echo "Internal monitor is not enabled" (unplugging of external monitor).
Can you help me, please?

Offline

#3 2023-11-12 22:01:08

Xwang
Member
From: EU
Registered: 2012-05-14
Posts: 414

Re: How to set up the laptop to automatically switch to external monitor?

I've find the way to do it

#!/bin/bash

sleep 5

TMP_EXT_MONITOR_NAME=$(kscreen-doctor -o | grep 'DisplayPort' | grep connected | cut -d ' ' -f 3)
TMP_INT_MONITOR_NAME=$(kscreen-doctor -o | grep 'Panel' | grep connected | cut -d ' ' -f 3)
echo "Internal monitor is: $TMP_INT_MONITOR_NAME"
echo "External monitor is: $TMP_EXT_MONITOR_NAME"

if [ -z "$TMP_EXT_MONITOR_NAME" ]
then
    echo "External monitor is empty"
    if [ -z "$TMP_INT_MONITOR_NAME" ]
    then
        echo "ERROR!!! Internal monitor is empty"
    else
        echo "Internal monitor is: $TMP_INT_MONITOR_NAME"
        if [ -z "$(kscreen-doctor -o | grep $TMP_INT_MONITOR_NAME | grep enabled | cut -d ' ' -f 3)" ]
        then
            echo "Internal monitor is not enabled"
            kscreen-doctor output.$TMP_EXT_MONITOR_NAME.disable output.$TMP_INT_MONITOR_NAME.enable
        else
            echo "Internal monitor is already enabled: nothing to do. Bye!"
        fi
    fi
else
    echo "External monitor is: $TMP_EXT_MONITOR_NAME"
    if [ -z "$(kscreen-doctor -o | grep $TMP_EXT_MONITOR_NAME | grep enabled | cut -d ' ' -f 3)" ]
    then
        echo "External monitor is not enabled"
        kscreen-doctor output.$TMP_INT_MONITOR_NAME.disable output.$TMP_EXT_MONITOR_NAME.enable
    else
        echo "External monitor is already enabled: nothing to do. Bye!"
    fi
fi

I've created a rule in udev to call a systemd service that call this script.

I've tried and it worked, but reading the journalctl I've noted that the service was exiting with error code 1 and I don't know how, by removing the udev rule and the service the PC now is switching automatically to the external monitor when it is connected.

So I could say that the problem is solved, but I do not know how!!! Could anyone help me understand, please?

Offline

Board footer

Powered by FluxBB