Skip to content

Instantly share code, notes, and snippets.

@naranyala
Created June 7, 2024 07:36
Show Gist options
  • Save naranyala/f40ec461dce9213b4a061ae9cd6dbe00 to your computer and use it in GitHub Desktop.
Save naranyala/f40ec461dce9213b4a061ae9cd6dbe00 to your computer and use it in GitHub Desktop.
switch between screen mode (like in case of presentation)
#!/bin/bash
# Define the path to the mode file
MODE_FILE=~/.config/polybar/current_screen_mode
# Create the mode file with a default value if it doesn't exist
if [ ! -f "$MODE_FILE" ]; then
echo "default" > "$MODE_FILE"
fi
# Get the current mode
MODE=$(cat "$MODE_FILE")
# Get the primary screen
PRIMARY=$(xrandr | grep " connected primary" | cut -d' ' -f1)
# Get the largest screen (excluding the primary screen)
LARGEST=$(xrandr | grep " connected" | grep -v "$PRIMARY" | awk '{print $1, $4}' | sort -nrk2,2 | head -n1 | awk '{print $1}')
# Ensure that a secondary screen is available
if [ -z "$LARGEST" ]; then
LARGEST=$PRIMARY
fi
# Define the options for rofi
OPTIONS="default\nmirror\nextend"
# Use rofi to get the user selection
SELECTION=$(echo -e "$OPTIONS" | rofi -dmenu -p "Select screen mode:")
# Apply the selected mode
case "$SELECTION" in
"default")
xrandr --output $PRIMARY --auto
echo "default" > "$MODE_FILE"
;;
"mirror")
xrandr --output $LARGEST --auto --same-as $PRIMARY
echo "mirror" > "$MODE_FILE"
;;
"extend")
xrandr --output $LARGEST --auto --right-of $PRIMARY
echo "extend" > "$MODE_FILE"
;;
*)
# Handle the case where no valid option is selected
echo "Invalid selection or operation canceled."
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment