I often use Sunshine to stream my PC games to my Android phone using Moonlight, but one thing that always bothered me is that I cannot turn my monitor off while streaming or else no video would be sent to Moonlight.
To solve this I would need to:
- Use an HDMI Dummy Plug to get a fake monitor
- Move video content from the real monitor to the fake monitor
- Stream the fake monitor
- Turn off the real monitor
(And do these steps in reverse when ending the stream)
However I don't plan on buying a Dummy Plug, so I'm going to use a virtual display which is implemented in Hyprland via hyprctl output
.
This script is used before streaming via Sunshine
#!/bin/bash
# Your main monitor (change this)
MONITOR="DP-3"
# Create headless virtual display
hyprctl output create headless
# Disable the monitor
hyprctl keyword monitor $MONITOR,disable
This script is used after Sunshine stream ends
#!/bin/bash
# Your main monitor (change this)
MONITOR="DP-3"
# Turn monitor back on (you may want to change these options)
hyprctl keyword monitor $MONITOR,highrr,auto,1
# Get name of headless display
HEADLESS=$(hyprctl -j monitors | jq -r '.[] | select(.name | test("HEADLESS-"; "i")).name')
# Remove headless virtual display
hyprctl output remove "$HEADLESS"
- Note that getting the name of the headless display is required here since Hyprland will name it
HEADLESS-2
the first time you create it, but will increment the number each time a new one is created in the current session (HEADLESS-3
,HEADLESS-4
, ...)
You should make Sunshine automatically run these scripts before and after the stream. To do so:
Edit
your Sunshine application > go to Command Preparations
> click on Add commands
>
- Add the full path of your
screenOFF
script in theDo Command
field:/home/user/scripts/screenOFF
- Add the full path of your
screenON
script in theUndo Command
field:/home/user/scripts/screenON
- Sunshine may crash while streaming and the
screenON
script will never be executed, leaving you with a blank monitor and no connection to your computer. Therefore, it is highly recommended that you bindscreenON
in yourhyprland.conf
like so:# Turn monitor on bind = $mainMod SHIFT, F1, exec, ~/scripts/screenON
- Hyprland headless displays are limited to 1920x1080 resolution AFAIK