Refactorise to simplify wm detection

We dont use guesswm and rely on a SXMO_WM env variable. We now use
guesswm for non wm action (from ssh, console, rtc wakes, etc). It will
try to setup needed variables.

This way, we avoid to run sxmo_wm.sh and to check variables everytime.

This allow the user to manage sxmo_screenlock.sh from ssh and to run a
desktop software with "sxmo_wm.sh exec foot" by example.

We remove the "ssh" wm cause it does not really make sense anyway.

The sxmo_rtcwake.sh dont try to setup variables anymore cause the user
must use "sxmo_wm.sh exec" if they want to start a destkop software
anyway.

We remove the "xorg" check everywhere cause that make no sense. We
keep the xorg prefixed methods for common xorgs cases.

Signed-off-by: Stacy Harper <contact@stacyharper.net>
Signed-off-by: Anjandev Momi <anjan@momi.ca>
This commit is contained in:
Stacy Harper
2021-11-16 13:34:50 +01:00
committed by Anjandev Momi
parent 59e241d891
commit c446e9f23e
15 changed files with 50 additions and 73 deletions

View File

@@ -41,26 +41,26 @@ xorgscreenshot() {
}
screenshot() {
case "$WM" in
case "$SXMO_WM" in
sway)
swayscreenshot "$@"
;;
xorg|dwm)
dwm)
xorgscreenshot "$@"
;;
ssh)
exitMsg "cannot screenshot ssh"
*)
exitMsg "We dont know the WM, cannot screenshot."
;;
esac
}
filepathoutput() {
printf %s "$FILENAME"
case "$WM" in
case "$SXMO_WM" in
sway)
wl-copy "$FILENAME"
;;
xorg|dwm)
dwm)
printf %s "$FILENAME" | xsel -b -i
;;
esac
@@ -68,7 +68,5 @@ filepathoutput() {
FILENAME="${SXMO_SCREENSHOT_DIR:-$HOME/$(date +%Y-%m-%d-%T).png}"
WM="$(sxmo_wm.sh)"
screenshot "$@"
filepathoutput

View File

@@ -5,28 +5,28 @@
case "$1" in
isopen)
case "$(sxmo_wm.sh)" in
sway|ssh)
case "$SXMO_WM" in
sway)
exec pgrep bemenu
;;
xorg|dwm)
dwm)
exec pgrep dmenu
;;
esac
;;
close)
case "$(sxmo_wm.sh)" in
sway|ssh)
case "$SXMO_WM" in
sway)
exec pkill bemenu
;;
xorg|dwm)
dwm)
exec pkill dmenu
;;
esac
;;
esac > /dev/null
case "$(sxmo_wm.sh)" in
case "$SXMO_WM" in
sway)
swaymsg mode menu -q # disable default button inputs
cleanmode() {
@@ -40,14 +40,14 @@ case "$(sxmo_wm.sh)" in
cleanmode
exit "$returned"
;;
xorg|dwm)
dwm)
if sxmo_keyboard.sh isopen; then
exec dmenu -c -l "$(sxmo_rotate.sh isrotated > /dev/null && printf 5 || printf 12)" "$@"
else
exec dmenu -c -l "$(sxmo_rotate.sh isrotated > /dev/null && printf 7 || printf 15)" "$@"
fi
;;
ssh)
*)
export BEMENU_BACKEND=curses
exec bemenu -w "$@"
;;

View File

@@ -1,6 +1,6 @@
#!/usr/bin/env sh
if [ "$(sxmo_wm.sh)" != "ssh" ]; then
if [ -n "$SXMO_WM" ]; then
if sxmo_keyboard.sh isopen; then
wasopen="1"
fi

View File

@@ -35,10 +35,9 @@ xorgidle() {
done
}
wm="$(sxmo_wm.sh)"
case "$wm" in
dwm|xorg) xorgidle "$@" & ;;
*) "${wm}idle" "$@" & ;;
case "$SXMO_WM" in
dwm) xorgidle "$@" & ;;
*) "${SXMO_WM}idle" "$@" & ;;
esac
IDLEPID=$!

View File

@@ -4,7 +4,7 @@
# shellcheck source=scripts/core/sxmo_common.sh
. "$(dirname "$0")/sxmo_common.sh"
case "$(sxmo_wm.sh)" in
case "$SXMO_WM" in
sway) swaymsg kill;;
xorg|dwm) xdotool windowkill "$(xdotool getactivewindow)";;
dwm) xdotool windowkill "$(xdotool getactivewindow)";;
esac

View File

@@ -71,14 +71,14 @@ xorg() {
defaultconfig /usr/share/sxmo/appcfg/dunst.conf "$XDG_CONFIG_HOME/dunst/dunstrc" 744
}
case "$(sxmo_wm.sh)" in
case "$SXMO_WM" in
sway)
sway
;;
xorg|dwm)
dwm)
xorg
;;
ssh|none)
*)
sway
xorg
;;

View File

@@ -83,18 +83,16 @@ swayrotleft() {
}
isrotated() {
case "$wm" in
case "$SXMO_WM" in
sway)
"swayisrotated"
;;
dwm|xorg)
dwm)
"xorgisrotated"
;;
esac
}
wm="$(sxmo_wm.sh)"
if [ -z "$1" ] || [ "rotate" = "$1" ]; then
shift
if isrotated; then
@@ -104,11 +102,11 @@ if [ -z "$1" ] || [ "rotate" = "$1" ]; then
fi
fi
case "$wm" in
case "$SXMO_WM" in
sway)
"sway$1" "$@"
;;
dwm|xorg)
dwm)
"xorg$1" "$@"
;;
esac

View File

@@ -6,15 +6,6 @@
REDLED_PATH="/sys/class/leds/red:indicator/brightness"
BLUELED_PATH="/sys/class/leds/blue:indicator/brightness"
SWAYSOCK="$(cat "$CACHEDIR"/sxmo.swaysock)"
export SWAYSOCK
if ! swaymsg 2> /dev/null; then
unset SWAYSOCK
fi
if [ -z "$DISPLAY" ]; then
export DISPLAY=":0"
fi
finish() {
kill "$BLINKPID"

View File

@@ -4,7 +4,7 @@
# shellcheck source=scripts/core/sxmo_common.sh
. "$(dirname "$0")/sxmo_common.sh"
WM="$(sxmo_wm.sh)"
WM="$SXMO_WM"
forceupdate() {
kill "$SLEEPID"
@@ -13,8 +13,8 @@ trap "forceupdate" USR1
setbar() {
case "$WM" in
sway|ssh) printf "%s\n" "$*";;
dwm) xsetroot -name "$*";;
*) printf "%s\n" "$*";;
esac
}

View File

@@ -9,7 +9,7 @@ wtype_to_xdotool() {
key="$2"
shift 2
xdotool keydown "$key"
sxmo_type.sh -f xorg "$@"
sxmo_type.sh "$@"
xdotool keyup "$key"
exit
elif [ "-m" = "$1" ] || [ "-p" = "$1" ]; then
@@ -29,20 +29,11 @@ wtype_to_xdotool() {
wtype_to_xdotool "$@"
}
# enforce wm
# usefull to recurse without reprobing the wm
if [ "$1" = "-f" ]; then
wm="$2"
shift 2
else
wm="$(sxmo_wm.sh)"
fi
case "$wm" in
case "$SXMO_WM" in
sway)
wtype "$@"
;;
dwm|xorg)
dwm)
wtype_to_xdotool "$@"
;;
esac

View File

@@ -6,7 +6,7 @@
printf "Sxmo "
cat /usr/share/sxmo/version
case "$(sxmo_wm.sh)" in
case "$SXMO_WM" in
dwm)
/usr/bin/dwm -v
/usr/bin/dmenu -v

View File

@@ -4,6 +4,7 @@
envvars() {
# shellcheck disable=SC1091
[ -f /etc/profile ] && . /etc/profile
export SXMO_WM=sway
export BEMENU_OPTS='--fn "Monospace 14" --scrollbar autohide -s -n -w -c -l8 -M 40 -H 20'
export MOZ_ENABLE_WAYLAND=1
export SDL_VIDEODRIVER=wayland

View File

@@ -135,27 +135,25 @@ xorgswitchfocus() {
}
guesswm() {
if [ -n "$SWAYSOCK" ]; then
printf "sway"
elif [ -n "$DISPLAY" ]; then
printf "dwm"
elif [ -n "$SSH_CLIENT" ] || [ -n "$SSH_TTY" ]; then
printf "ssh"
SWAYSOCK="$(cat "$CACHEDIR"/sxmo.swaysock)"
export SWAYSOCK
if swaymsg; then
export SXMO_WM=sway
export WAYLAND_DISPLAY=wayland-1
else
printf "none"
unset SWAYSOCK
export DISPLAY=":0"
export SXMO_WM=dwm
fi
}
wm="$(guesswm)"
if [ -z "$1" ]; then
printf %s "$wm"
exit
if [ -z "$SXMO_WM" ]; then
guesswm
fi
action="$1"
shift
case "$wm" in
dwm|xorg) "xorg$action" "$@";;
*) "$wm$action" "$@";;
case "$SXMO_WM" in
dwm) "xorg$action" "$@";;
*) "$SXMO_WM$action" "$@";;
esac

View File

@@ -63,4 +63,4 @@ dwm() {
esac
}
"$(sxmo_wm.sh)" "$@"
"$SXMO_WM" "$@"

View File

@@ -4,6 +4,7 @@
envvars() {
# shellcheck disable=SC1091
[ -f /etc/profile ] && . /etc/profile
export SXMO_WM=dwm
command -v "$TERMCMD" || export TERMCMD="st -e"
command -v "$BROWSER" || export BROWSER=surf
command -v "$EDITOR" || export EDITOR=vis