Implement the individual windows sharing feature

Original MR: https://gitlab.com/tile-os/tileos-settings-sway/-/merge_requests/21
This commit is contained in:
Aleksey Samoilov 2025-02-28 00:16:34 +04:00
parent ee226de17d
commit d8e0fa71c2
9 changed files with 105 additions and 3 deletions

View file

@ -17,7 +17,7 @@
# #
# If this option is set to mouse or keyboard, the monitor option # If this option is set to mouse or keyboard, the monitor option
# will be ignored. # will be ignored.
follow = none follow = mouse
### Geometry ### ### Geometry ###

View file

@ -97,7 +97,6 @@ $bindsym $mod+6 workspace $ws6
$bindsym $mod+7 workspace $ws7 $bindsym $mod+7 workspace $ws7
$bindsym $mod+8 workspace $ws8 $bindsym $mod+8 workspace $ws8
$bindsym $mod+9 workspace $ws9 $bindsym $mod+9 workspace $ws9
$bindsym $mod+0 workspace $ws10
set $focus_ws [ "$focus_after_move" == 'true' ] && swaymsg workspace set $focus_ws [ "$focus_after_move" == 'true' ] && swaymsg workspace

View file

@ -0,0 +1,18 @@
#
# Screenmirror:
#
# The mode allows the user to mirror the headless output.
# This is primarily used when screencasting to cast only the windows that
# belong to the headless output instead of casting the entire screen.
#
# See the following link for more details:
# https://github.com/emersion/xdg-desktop-portal-wlr/issues/107#issuecomment-1596107337
set $screenmirror /usr/share/sway/scripts/screenmirror.sh
set $start_mirror systemd-cat $screenmirror $headless
set $stop_mirror systemd-cat $screenmirror -k
## Launch // Switch to the workspace for mirroring ##
$bindsym $mod+0 exec $start_mirror, workspace $ws10
## Launch // Switch back from the workspace for mirroring ##
$bindsym $mod+Mod1+0 exec $stop_mirror, workspace back_and_forth

View file

@ -0,0 +1,9 @@
# This output configuration is required for the screenmirror mode to work.
set $headless HEADLESS-1
output $headless {
position 16000 16000
}
workspace $ws10 output $headless
exec swaymsg create_output

View file

@ -72,7 +72,7 @@ set $ws6 number 6
set $ws7 number 7 set $ws7 number 7
set $ws8 number 8 set $ws8 number 8
set $ws9 number 9 set $ws9 number 9
set $ws10 number 10 set $ws10 "<span baseline_shift='-20pt' weight='bold'>🖵</span>"
# Screenshot # Screenshot
set $grimshot /usr/bin/grimshot set $grimshot /usr/bin/grimshot

View file

@ -0,0 +1,3 @@
[screencast]
chooser_type=dmenu
chooser_cmd=/usr/share/sway/scripts/select-output.sh

View file

@ -52,12 +52,14 @@ main() {
wf-recorder --audio -g "$area" --file="$file" wf-recorder --audio -g "$area" --file="$file"
else else
file="$target_path/$timestamp.webm" file="$target_path/$timestamp.webm"
output="$(swaymsg -t get_outputs | jq -r '.[] | select(.focused) | .name')"
wf-recorder \ wf-recorder \
-g "$area" -c libvpx \ -g "$area" -c libvpx \
--codec-param="qmin=0" \ --codec-param="qmin=0" \
--codec-param="qmax=25" \ --codec-param="qmax=25" \
--codec-param="crf=4" \ --codec-param="crf=4" \
--codec-param="b:v=1M" \ --codec-param="b:v=1M" \
-o "$output" \
--file="$file" --file="$file"
fi fi

View file

@ -0,0 +1,38 @@
#!/bin/bash
#
# This script implements the function of mirroring outputs.
# It uses wl-mirror and Sway's ability to create headless outputs.
#
# The script is written as a singleton. It allows the user to run only one
# instance of itself and kills all others. This is necessary so that wl-mirror
# instances do not interfere with each other.
SELF_NAME="$(basename "$0")"
SELF_PID="$$"
get_pgid() {
ps -h -o "%r" -p "$1" | awk '{print $1}'
}
SELF_PGID="$(get_pgid "$SELF_PID")"
kill_by_pgid() {
pkill -"$2" -g "$1"
}
kill_copies() {
mapfile -t pids < <(pgrep -u "$USER" -x "$SELF_NAME")
for pid in "${pids[@]}" ; do
pgid="$(get_pgid "$pid")"
[[ $pgid -ne $SELF_PGID ]] && kill_by_pgid "$pgid" "INT"
done
}
main() {
# Don't single quote the trap's command!
# It must be expanded when the trap is defined.
# shellcheck disable=SC2064
trap "kill_by_pgid $SELF_PGID TERM" INT
kill_copies
[[ "$1" != "-k" ]] && wl-mirror -F "${1:-HEADLESS-1}"
}
main "$@"

View file

@ -0,0 +1,33 @@
#!/bin/bash
export LC_ALL=C
TITLE="Select the output for the screencast"
OUT_NAME="HEADLESS-1"
FONT_SIZE="12"
ROSEWATER="#f4dbd6"
FONT="Noto Sans ${FONT_SIZE}"
FONT_COLOR="${ROSEWATER}"
I_SIZE="$(awk "BEGIN {print (${FONT_SIZE}*1.08)}")"
OUT_SIZE="$(awk "BEGIN {print (${FONT_SIZE}*0.94)}")"
TIP_SHIFT="$(awk "BEGIN {print (1+(${I_SIZE}-${FONT_SIZE})/2)}")"
TIP="\
<span color='${FONT_COLOR}'>\
<span size='${I_SIZE}pt'></span> \
<span baseline_shift='${TIP_SHIFT}pt'>use \
<span size='${OUT_SIZE}pt'>${OUT_NAME}</span> \
to cast only chosen windows\
</span>\
</span>\
"
swaymsg -t get_outputs \
| jq -r '.[] | .name' \
| rofi \
-dmenu -i -l 4 \
-p "${TITLE}" \
-window-title "${TITLE}" \
-mesg "${TIP}" \
-font "${FONT}"