Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # Names of the displays you want to use for presentation as well as mirroring of said presentation screen.
- # They can be easily read from arandr, or listed using `xrandr --listmonitors`
- PRESENTATION_DISPLAY="DP-1"
- MIRROR_DISPLAY="DVI-I-1"
- # These variables depend on how you arranged your screens using arandr/xrandr.
- # To Verify/Correct them, open arandr, arrange your screens as you prefer, export the command
- # and then read the "--pos" value for the desired mirror and presentation output/display.
- MIRROR_ORIG_UPPER_LEFT="1920x1392"
- PRESENTATION_UPPER_LEFT="0x0"
- # Space-separated list of workspaces you bound to the presentation display/output
- # using `workspace <num:name> output <display>`, as you are referring to them in the i3 config
- PRESENTATION_WORKSPACES='11:TV'
- TARGET_WORKSPACE=$1
- # The below command automates extraction of the output resolution. However, it takes too long due to long xrandr response times.
- # Therefore, reading the resolution once (using the command) and then manually writing it into this variable is probably preferrable.
- # Alternatively, you could also setup your presentation display with --mode 1920x1080 using xrandr so the resultion I put below is correct from the get-go (assuming the display supports that high resolution).
- # presentation_output_resolution=$(xrandr | grep "$PRESENTATION_DISPLAY" | cut -d' ' -f3 | cut -d'+' -f1)
- presentation_output_resolution="1920x1080"
- # Underlying Idea: Overlay mirror display onto presentation display and scale it as necessary whenever presentation workspace is chosen
- RESTORE_COMMAND="xrandr --output $MIRROR_DISPLAY --pos $MIRROR_ORIG_UPPER_LEFT --scale 1"
- MIRROR_COMMAND="xrandr --output $MIRROR_DISPLAY --pos $PRESENTATION_UPPER_LEFT --scale-from $presentation_output_resolution"
- focused_workspace=$(i3-msg -t get_workspaces | python3 -c "import sys,json
- for workspace in json.load(sys.stdin):
- if workspace['focused']:
- print(workspace['name'])
- break")
- if [[ $TARGET_WORKSPACE == $focused_workspace ]]; then
- exit 0 # Don't do anything when targeting already focused workspace. Workspace back-and-forth wouldn't be possible, since we don't know whether this sends us back to a normal or a presentation workspace.
- # TODO: Idea: Read out workspace back_and_forth target, set this as the new target workspace and continue script with that
- fi
- [[ " $PRESENTATION_WORKSPACES " =~ .*\ $focused_workspace\ .* ]]
- already_on_presentation=$? # exit status (i.e. here truth value) of previous command/conditional expression
- if [[ " $PRESENTATION_WORKSPACES " =~ .*\ $TARGET_WORKSPACE\ .* ]]; then # Check if targeted workspace is a presentation workspace. Taken from https://stackoverflow.com/a/46564084
- if [[ $already_on_presentation == 1 ]]; then
- # We are coming from a normal workspace. Setup screen before switching to new workspace.
- eval $MIRROR_COMMAND
- fi
- i3-msg workspace $TARGET_WORKSPACE
- else
- # We are targetting a normal workspace
- if [[ $already_on_presentation == 0 ]]; then
- eval $RESTORE_COMMAND
- fi
- i3-msg workspace $TARGET_WORKSPACE
- fi
Add Comment
Please, Sign In to add comment