Blog-Archiv

Sonntag, 30. Juni 2024

Activating Second Screen after LINUX Suspension State

I am using LINUX 5.15.0-105 on Ubuntu 22.04.4 LTS, still with XOrg window manager (not Wayland).

Not always, but mostly, my second screen is not waking up when I push the ON/OFF button after I have put the computer into suspension state. What I have to do then is

  1. Call "Setting" in top right taskbar menu
  2. Select the "Displays" tab
  3. Click onto "Join Displays"
  4. Click onto "Apply"
  5. Wait some seconds until the screen gets activated
  6. Click onto "Keep Changes" in the dialog appearing in the middle of the activated screen

This is quite a procedure. It has been like that for years, and I assumed that someday it will be fixed by an OS-upgrade. But it has not, so now I searched for a quicker solution.

You can use xrandr for manipulating screens in LINUX. When I call this without arguments, I get an output similar to this:

$ xrandr
Screen 0: minimum 320 x 200, current 3046 x 1050, maximum 16384 x 16384
eDP-1 connected primary 1366x768+0+0 (normal left inverted right x axis y axis) 344mm x 193mm
   1366x768      60.00*+  48.01  
   1280x720      60.00  
   .... // lots of other lines
   320x180       60.00  
HDMI-1 connected 1680x1050+1366+0 (normal left inverted right x axis y axis) 474mm x 297mm
   1680x1050     59.95*+
   1920x1080     60.00    59.94  
   .... // lots of other lines
   720x400       70.08  

That means, my primary screen is "eDP-1", and the second one is "HDMI-1". In my environment, HDMI-1 is the one that does not wake up in time.
After reading the manual of xrandr, I tried out the following command:

$ xrandr --output HDMI-1 --auto --right-of eDP-1

The "--output HDMI-1" argument targets the second screen for activation.
The "--right-of eDP-1" argument places that screen to the right of my primary screen (you can use also "--left-of").
And "--auto": for connected but disabled outputs, this will enable them using their first preferred DPI setting; for disconnected but enabled outputs, this will disable them. (I am not sure whether --auto actually is necessary...)

This command did not output anything, but it

  • turned on my second screen and
  • moved all application-windows that had been relocated to the primary screen to their former positions.

I have put this command into a newly created "Activate HDMI-1 Screen.desktop" file in directory $HOME/Desktop and took it into a text editor:

[Desktop Entry]
Version=1.0
Name=Activate HDMI-1 Screen
Exec=xrandr --output HDMI-1 --auto --right-of eDP-1
Icon=/usr/share/icons/gnome/16x16/devices/video-display.png
Terminal=true
Type=Application
Categories=Utility;Application;
Comment[en_US]=Activates the HDMI-1 screen

When the icon appeared on desktop, I had to click "Allow Launching" in the right-mouse context menu of the desktop icon. After that, a double click onto the icon activated my second screen.
To test it, I could turn off the secondary screen HDMI-1 by entering this:

$ xrandr --output HDMI-1 --off

Just one problem remained: when the second screen is OFF, tons of application windows block access to the desktop icon on primary screen. Until now I could not find a way to add my new desktop-icon to the gnome launch bar on the left.

I found no accurate help on this topic on the web, so I hope this article will be helpful for others.




Keine Kommentare: