-
-
Save Anduh/12635a35d0031bf8819391c4b07e9b32 to your computer and use it in GitHub Desktop.
Screen watcher for Linux Mint Immersed (dis)connect.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Unit] | |
Description=Brings up Virtual monitors when Immersed (dis)connects | |
[Service] | |
Type=simple | |
Restart=on-failure | |
ExecStart=~/Scripts/ScreenMonitor.sh | |
[Install] | |
WantedBy=default.target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/bash | |
OUTPUT_NAME="DVI-I-2-2" | |
OUTPUT_MODE="1920x1080" | |
OUTPUT_LOCATION="--right-of DP-1-3" | |
LOG_DIR="~/.Immersed/Logs" | |
agent_started() { | |
pgrep Immersed &> /dev/null 2>&1 | |
return $? | |
} | |
most_recent_log() { | |
ls -t1 $LOG_DIR | head -n 1 | |
} | |
is_most_recent_log() { | |
if [[ $LOG_FILE == $(most_recent_log) ]] ; then | |
return 0 | |
fi | |
return 1 | |
} | |
session_has_started() { | |
grep -Fq "will init display" "$LOG_DIR/$LOG_FILE" | |
return $? | |
} | |
create_screen() { | |
xrandr --addmode $OUTPUT_NAME $OUTPUT_MODE | |
xrandr --output $OUTPUT_NAME --mode $OUTPUT_MODE $OUTPUT_LOCATION | |
} | |
remove_screen() { | |
xrandr --output $OUTPUT_NAME --off | |
} | |
watch_for_connect() { | |
while ! session_has_started ; do | |
sleep 1 | |
if ! is_most_recent_log ; then | |
return | |
fi | |
done | |
} | |
watch_for_disconnect() { | |
while is_most_recent_log ; do | |
sleep 1; | |
done | |
} | |
while true; do | |
while ! agent_started ; do sleep 1 ; done | |
LOG_FILE=$(most_recent_log) | |
if session_has_started | |
then | |
create_screen | |
watch_for_disconnect | |
else | |
remove_screen | |
watch_for_connect | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment