Skip to content

Instantly share code, notes, and snippets.

@be4zad
Created April 6, 2024 18:13
Show Gist options
  • Save be4zad/69ac059ed043a2e398f6bf845d4dacfa to your computer and use it in GitHub Desktop.
Save be4zad/69ac059ed043a2e398f6bf845d4dacfa to your computer and use it in GitHub Desktop.
Script to run sway wm on vnc
#!/bin/bash
# start-sway-vnc.sh
# Copyright (C) 2024 Behzad Asbahi <behzadasbahi@gmail.com>
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
# This script runs a vnc server with Sway window manager.
# You probably want to modify resolution and scale. the following values are
# suitable just for mobile. If these variables get unset, sway will use the
# default resolution and scale of the monitor.
export RESOLUTION=720x1440
export SCALE=2
# It gets current ip address of interface wls1 which is probably your wi-fi.
# if you don't use wi+fi you must change.
export IP_ADDRESS=$(ip -4 addr show wls1 | grep -oP '(?<=inet\s)\d+(\.\d+){3}')
# Port of the vnc server
export PORT=7060
# Stop sway after pressing Ctrl+C
trap ctrl_c INT
function ctrl_c() {
swaymsg exit --socket /tmp/sway-ipc*
exit 0
}
# Start sway
export XDG_RUNTIME_DIR=/tmp/ WLR_BACKENDS=headless WLR_LIBINPUT_NO_DEVICES=1
sway &
sleep 1
swaymsg --socket /tmp/sway-ipc* output HEADLESS-1 mode $RESOLUTION
swaymsg --socket /tmp/sway-ipc* output HEADLESS-1 scale $SCALE
swaymsg --pretty --socket /tmp/sway-ipc* exec "WAYLAND_DISPLAY=wayland-1 wayvnc $IP_ADDRESS $PORT"
# Wait until pressing Ctrl+C
read -r -d '' _ </dev/tty
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment