-
-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add single-output-sway helper script
This doesn't implement HEADLESS mode yet - there are still add corner cases to fix there. Signed-off-by: Jim Ramsay <[email protected]>
- Loading branch information
Showing
2 changed files
with
76 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Example Scripts | ||
|
||
The scripts here are examples of how you can automate interesting things with the wayvncctl IPC events. | ||
|
||
## event-watcher | ||
|
||
This is a pretty simple example that just demonstrates how to tie the | ||
`wayvncctl event-receive` event loop into a bash script. It logs when clients | ||
connect and disconnect. | ||
|
||
## single-output-sway | ||
|
||
This is more purposeful, and implements an idea for multi-output wayland | ||
servers, collapsing all outputs down to one when the first client connects, and | ||
restoring the configuration when the last client exits. | ||
|
||
The mechanism used to collapse the outputs depends on the version of sway installed: | ||
|
||
- For sway-1.7 and earlier, the script just temporarily disables all outputs | ||
except the one being captured. This moves all workspaces to the single | ||
remaining output. | ||
|
||
- For sway-1.8 and later, the script creates a temporary virtual output called | ||
`HEADLESS-1' and then disables all physical outputs, which moves all | ||
workspaces to the virtual output. On disconnect, all original physical | ||
outputs are re-enabled, and the virtual output is destroyed. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#!/bin/bash | ||
|
||
WAYVNCCTL=${WAYVNCCTL:-wayvncctl} | ||
SWAYMSG=${SWAYMSG:-swaymsg} | ||
|
||
OUTPUTS_TO_RECONNECT=() | ||
restore_outputs() { | ||
[[ ${#OUTPUTS_TO_RECONNECT[@]} -ge 1 ]] || return | ||
echo "Restoring original output state" | ||
for output in "${OUTPUTS_TO_RECONNECT[@]}"; do | ||
echo "Re-enabling output $output" | ||
$SWAYMSG output "$output" enable | ||
done | ||
OUTPUTS_TO_RECONNECT=() | ||
} | ||
trap restore_outputs EXIT | ||
|
||
collapse_outputs() { | ||
for output in $($WAYVNCCTL -j get-outputs | jq -r '.[] | select(.captured==false).name'); do | ||
echo "Disabling extra output $output" | ||
$SWAYMSG output "$output" disable | ||
OUTPUTS_TO_RECONNECT+=("$output") | ||
done | ||
} | ||
|
||
connection_count_now() { | ||
local count=$1 | ||
if [[ $count == 1 ]]; then | ||
collapse_outputs | ||
elif [[ $count == 0 ]]; then | ||
restore_outputs | ||
fi | ||
} | ||
|
||
while IFS= read -r EVT; do | ||
case "$(jq -r '.method' <<<"$EVT")" in | ||
client-*onnected) | ||
count=$(jq -r '.params.connection_count' <<<"$EVT") | ||
connection_count_now "$count" | ||
;; | ||
wayvnc-shutdown) | ||
echo "wayvncctl is no longer running" | ||
connection_count_now 0 | ||
;; | ||
wayvnc-startup) | ||
echo "Ready to receive wayvnc events" | ||
;; | ||
esac | ||
done < <("$WAYVNCCTL" --wait --reconnect --json event-receive) | ||
|