Skip to content

Instantly share code, notes, and snippets.

@anosatsuk124
Last active July 18, 2025 01:32
Show Gist options
  • Save anosatsuk124/7751287eb245972d6115ea3cf31c5b72 to your computer and use it in GitHub Desktop.
Save anosatsuk124/7751287eb245972d6115ea3cf31c5b72 to your computer and use it in GitHub Desktop.
[Unit]
Description=iPad Sunshine Service for configuration: %i
[Service]
Type=simple
ExecStart=/bin/sh -c '/usr/bin/sunshine output_name=%i'
#!/usr/bin/env bash
set -euo pipefail
# プライマリ出力の幅を取得
primary_height=$(swaymsg -t get_outputs -r | jq -r '.[] | select(.rect.x == 0 and .rect.y == 0) | select(.current_mode != null) | .current_mode.height')
primary_width=$(swaymsg -t get_outputs -r | jq -r '.[] | select(.rect.x == 0 and .rect.y == 0) | select(.current_mode != null) | .current_mode.width')
# 既存の HEADLESS-* 出力名を探す
output_name=$(swaymsg -t get_outputs -r |
jq -r '.[] | select(.name | test("^HEADLESS-")) | .name')
output_is_active=$(swaymsg -t get_outputs -r |
jq -r '.[] | select(.name | test("^HEADLESS-")) | .active')
if [ "$output_is_active" = "true" ]; then
swaymsg output "$output_name" disable
systemctl --user stop ipad-wayvnc.service
systemctl --user stop 'ipad-sunshine@*.service'
notify-send "iPad output disabled"
exit 0
elif [ -z "$output_name" ]; then
swaymsg create_output
output_name=$(swaymsg -t get_outputs -r | jq -r '.[] | select(.name | test("^HEADLESS-")) | .name')
fi
swaymsg output "$output_name" enable
is_exist_DP3=$(swaymsg -t get_outputs -r | jq -r '.[] | select(.name == "DP-3") | .name')
is_exist_eDP_1=$(swaymsg -t get_outputs -r | jq -r '.[] | select(.name == "eDP-1") | .name')
headless_number=$(swaymsg -t get_outputs -r | jq -r 'to_entries[] | select(.value.name | test("^HEADLESS-")) | .key')
width=$((1640 / 1))
height=$((2360 / 1))
scale=2
if [ -n "$is_exist_DP3" ]; then
wlr-randr --output "$output_name" --scale ${scale} --mode ${height}x${width}@60Hz --below DP-3
elif [ -n "$is_exist_eDP_1" ]; then
wlr-randr --output "$output_name" --scale ${scale} --mode ${height}x${width}@60Hz --right-of eDP-1
fi
systemctl --user restart ipad-wayvnc.service
systemctl --user start "ipad-sunshine@${headless_number}.service"
# sudo sh -c 'systemctl stop rustdesk.service && systemctl start rustdesk.service'
notify-send "iPad output enabled at ${width}x${height}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment