Skip to content

Commit

Permalink
Making termux-x11-preference use options from stdin, updating readme.
Browse files Browse the repository at this point in the history
  • Loading branch information
twaik committed Jun 24, 2024
1 parent a2bba36 commit 4e7a291
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,22 @@ Also you can start `termux-x11` with `-dpi` option.
~ $ termux-x11 :1 -xstartup "xfce4-session" -dpi 120
```

## Changing, dumping and restoring preferences from commandline

It is possible to change preferences of termux-x11 from command line.
`termux-x11-nightly` package contains `termux-x11-preference` tool which can be used like
```shell
termux-x11-preference [list] {key:value} [{key2:value2}]..."
```
Use `termux-x11-preference` to dump current preference.
Use `termux-x11-preference > file` to dump current preferences to file.
Use `termux-x11-preferences < file` to restore preferences from file.
Use `termux-x11-preferences "fullscreen"="false" "showAdditionalKbd"="true"` to disable fullscreen and enable additional key bar. The full list of preferences you can modify is available with `termux-x11-preference list` command. You can specify one or more preferences here.
Termux:X11 activity should be available in background or foreground, otherwise `termux-x11-preferences` tool will hang indefinitely.
In the case if there is `Store preferences for secondary displays separately` preference active `termux-x11-preference` will use/modify preferences of display where Termux:X11 activity is currently opened.
## Using with 3rd party apps
It is possible to use Termux:X11 with 3rd party apps.
Check how `shell-loader/src/main/java/com/termux/x11/Loader.java` works.
Expand Down
17 changes: 15 additions & 2 deletions termux-x11-preference
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/data/data/com.termux/files/usr/bin/bash
COMMAND=("am" "broadcast" "-a" "com.termux.x11.CHANGE_PREFERENCE" "-p" "com.termux.x11")
help() {
echo "$0 {list} {key:value}..."
echo "$0 [list] {key:value} [{key2:value2}]..."
exit 1
}

Expand All @@ -22,7 +22,20 @@ list() {
}

if [ $# -eq 0 ]; then
help
if [ -t 0 ]; then
help
else
OLD_LENGTH="${#COMMAND[@]}"
while IFS= read -r line || [[ -n "$line" ]]; do
[ -z "$line" ] && continue
key=$(echo "$line" | sed -E 's/^"([^"]+)".*/\1/')
value=$(echo "$line" | sed -E 's/^"[^"]+"="(.*)"/\1/')
COMMAND+=("-e" "$key" "$value")
done
if [[ "$OLD_LENGTH" == "${#COMMAND[@]}" ]]; then
help
fi
fi
fi

while [[ $# -gt 0 ]]; do
Expand Down

0 comments on commit 4e7a291

Please sign in to comment.