[SOLVED] Dual monitor - Applications open in switched off monitor

Please post suggestions for improvement of Cinnamon on:
https://github.com/linuxmint/Cinnamon
Forum rules
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
Locked
Halbarad
Level 1
Level 1
Posts: 31
Joined: Tue Feb 05, 2019 2:30 pm

[SOLVED] Dual monitor - Applications open in switched off monitor

Post by Halbarad »

Hi, LM Vanessa, 5.15.0-56-generic. I have two monitors connected to my desktop PC: an oldish LG for normal use and a Benq video-projector for watching movies with my family. The video-projector is recognized as HDMI-1, the desktop screen is HDMI-2.
When I booted from the Vanessa live USB the LG screen only showed (a part of) the wallpaper; panel and icons were output to the switched off BENQ, set to primary. The BENQ was switched off but connected to the PC. After installation (which I made with the BENQ on), I set HDMI-2 (LG) to primary, which is working: I get the panel etc. on my LG after boot. But when I start an application it sometimes opens in the switched off HDMI-1 -- which was a bit puzzling at the beginning.

I have written two short bash programs using xrandr to switch between the monitors -- I never use both the monitors at the same time -- and I have made two keyboard shortcuts for them. So, the ghost screen problem is actually no big deal, because the hidden window comes back to HDMI-2 as soon as I press CTRL-ALT-O (which basically calls the line of code "xrandr --output HDMI-1 --off"). I'd prefer a cleaner solution though.

So, the question is: is there a way for having Vanessa send out its output only to a monitor that is switched on? I am a bit pessimistic, because I think that xrandr can only distinguish between a connected and a disconnected monitor, but not between two states (on and off) of a connected one. I just hope I'm wrong or there is a way for bypassing xrandr.
Last edited by LockBot on Tue Jun 06, 2023 10:00 pm, edited 2 times in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
User avatar
SMG
Level 25
Level 25
Posts: 31738
Joined: Sun Jul 26, 2020 6:15 pm
Location: USA

Re: Dual monitor - Applications open in switched off monitor

Post by SMG »

Halbarad wrote: Tue Dec 06, 2022 11:23 am But when I start an application it sometimes opens in the switched off HDMI-1
Is it always the same application which does this?
Or does the same application sometimes do it and sometimes not?

I could be wrong, but I thought there was a way to set where an application opened. Maybe someone else knows for sure.
Image
A woman typing on a laptop with LM20.3 Cinnamon.
Halbarad
Level 1
Level 1
Posts: 31
Joined: Tue Feb 05, 2019 2:30 pm

Re: Dual monitor - Applications open in switched off monitor

Post by Halbarad »

Thank you SMG!
I noticed that some apps systematically opened in the "ghost" videoprojector screen: System Monitor, Calculator, Libreoffice Writer. I didn't study their behavior though (whether they remember the last monitor location etc.) because I eventually made up my mind to add a short bash to my startup programs, setting HDMI-1 to off and HDMI-2 to auto. Not clean as it could be but cleaner than hunting for each application's monitor preferences.
This is the short code, in the (unlikely) case anyone else should be interested in it:

Code: Select all

#!/bin/bash
if xrandr | grep "HDMI-1 disconnected"; then
    exit
fi
xrandr --output HDMI-1 --off
xrandr --output HDMI-2 --primary --auto
(Remember to set the Execute flag for the bash file.)
In Control Center (System Settings/Hardware/Keyboard/Shortcuts/Custom Shortcuts) I also assigned the combination CTRL-ALT-O to this bash.
To re-activate the projector and switch off the desktop LG monitor my code is:

Code: Select all

#!/bin/bash
if xrandr | grep "HDMI-1 disconnected"; then
    exit
fi
xrandr --output HDMI-2 --off
xrandr --output HDMI-1 --primary --auto 
to which I assigned the combination CTRL-ALT-V. In this way, I can switch between the monitors.
If you want to activate both the monitors, just replace "--off" with "--auto" in either bash file (and assign a new combination to it if convenient).
To find out the names of your connected devices, I suggest you open a terminal and type

Code: Select all

 xrandr | grep " connected" 
(there is a leading space in " connected" in order not to output the lines including "disconnected").

Ok, that's it...
billyswong
Level 8
Level 8
Posts: 2169
Joined: Wed Aug 14, 2019 1:02 am

Re: [SOLVED] Dual monitor - Applications open in switched off monitor

Post by billyswong »

Halbarad wrote: Tue Dec 06, 2022 11:23 am I never use both the monitors at the same time
In such case I wonder if "Mirror displays" can be a cleaner solution than setting up all the scripts.

(https://www.technipages.com/linux-mint- ... resolution)
Image
Halbarad
Level 1
Level 1
Posts: 31
Joined: Tue Feb 05, 2019 2:30 pm

Re: [SOLVED] Dual monitor - Applications open in switched off monitor

Post by Halbarad »

billyswong wrote:In such case I wonder if "Mirror displays" can be a cleaner solution than setting up all the scripts.
Thank you billyswong. You may be right, but I had already written the scripts for alternating between monitors, and so it was pretty straightforward to run one of them at startup.
IMHO the really clean thing would be, not to send any output to a switched off monitor, or at least not to set a switched off monitor to primary by default at the first boot. xrandr doesn't tell if a connected monitor is on or off but other commands do, e.g. "inxi -aG": the OS has a way to know it if it just wants :wink:
billyswong
Level 8
Level 8
Posts: 2169
Joined: Wed Aug 14, 2019 1:02 am

Re: [SOLVED] Dual monitor - Applications open in switched off monitor

Post by billyswong »

Halbarad wrote: Sat Dec 10, 2022 1:28 pm IMHO the really clean thing would be, not to send any output to a switched off monitor, or at least not to set a switched off monitor to primary by default at the first boot. xrandr doesn't tell if a connected monitor is on or off but other commands do, e.g. "inxi -aG": the OS has a way to know it if it just wants :wink:
It depends. For many dual monitor setup, the user may not want switching off one monitor to trigger application windows a jump to the remaining monitor. The user may just want to switch off/on both monitors but unable to do them at exactly the same time. Or the user may sincerely want to use turning off a monitor as a way to not show some application windows to others.
Locked

Return to “Cinnamon”