hhannine / superpaper

A cross-platform multi monitor wallpaper manager.
MIT License
1.14k stars 46 forks source link

Handle disconnecting displays gracefully #25

Open hhannine opened 4 years ago

hhannine commented 4 years ago

Given that on Gnome and forks and on Windows the wallpaper needs to be stitched together from pieces, if a display is disconnected the part of the wallpaper that was on that monitor will move onto the other displays as the desktop environment spans the larger image across the now smaller desktop.

Kde and xfce are likely to be unaffected since they're structured differently.

First thing is to test different DEs to verify is they're affected.

The solution will be to spin a new wallpaper to the new reduced canvas size. Monitoring for disconnecting displays will need to be implemented.

quezak commented 4 years ago

Maybe a nice idea would be to have separate profiles for different number of monitors, and automatically apply a different one when a display is [dis]connected? This should handle most cases, ie. people having one display setup at home, one at work, and one when running around with the laptop.

hhannine commented 4 years ago

In the case of a spanned wallpaper having separate profiles is not needed: the same image can just be crunched again to the new desktop size and the span is recalculated.

In the case of multiple images the issue is more troublesome. In order to use the same profile with some display removed, the displays would need to be uniquely identified to be able to tell which is the respective source image to skip in the process. For this case it would be simpler to just have separate profiles for different number of displays.

yogiee commented 2 years ago

In the case of a spanned wallpaper having separate profiles is not needed: the same image can just be crunched again to the new desktop size and the span is recalculated.

In the case of multiple images the issue is more troublesome. In order to use the same profile with some display removed, the displays would need to be uniquely identified to be able to tell which is the respective source image to skip in the process. For this case it would be simpler to just have separate profiles for different number of displays.

That is pretty much how I'm using it. Have created two profiles for single and multiple monitors, and keyboard shortcut.

I do like this idea of automatically switching between profiles depending on if external monitors are connected or disconnected. I might be wrong, but I assume adding some way to auto-switch between profiles should be doable?

Commenter25 commented 2 years ago

So I've been using Superpaper for about a month, and I came up with a workaround for this which I've been using regularly. I'm now confident it's not going to break down on me out of nowhere, so I'll post it here for everyone.

The script below will automatically check the number of monitors every 5 seconds (change sleep 5 for a different duration), and if the amount has changed since last time; it kills the current Superpaper instance, and starts a new one running the desired profile. If you copy a line from the middle and change the dcount number and profile name, it should scale up to any amount of displays. Not the cleanest method, but functional.

It should work fine as-is if you have Superpaper installed normally. If it doesn't work, you'll have to change the variable at the start of the script to a command that will launch it where you have it installed. If you don't know what to use, you can try python .local/lib/python3.10/site-packages/superpaper/__main__.py

#!/bin/bash

superpaper="superpaper"

# Wait until xrandr works
while ! xrandr>/dev/null ; do sleep 5 ; done

while true; do
    dcount=$(xrandr | grep -c " connected ")
    if [ "$dcount" != "$dprev" ]; then
        pkill -f superpaper # kill anything that says superpaper
        [ "$dcount" == 1 ] && $superpaper --profile single &
        [ "$dcount" == 2 ] && $superpaper --profile multi &
        # copy for more dcounts and profiles
        # END WITH & or it won't loop!!
    fi
    dprev=$dcount
    sleep 5 # seconds before checking again
done

I have this saved in my home folder as displaycheck.sh, and I have it run on startup. For any GNOME users, I had to make a superpaper.desktop file in ~/.local/share/applications, and then set that as a startup application via GNOME Tweaks. Changing the below to use the location of your displaycheck.sh should work.

#!/usr/bin/env xdg-open
[Desktop Entry]
Type=Application
Name=Superpaper
Icon=superpaper
GenericName=Multi-monitor wallpaper manager
Exec=[YOURDIRECTORYHERE]/displaycheck.sh
Terminal=false