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:

committed by
Anjandev Momi

parent
59e241d891
commit
c446e9f23e
@@ -41,26 +41,26 @@ xorgscreenshot() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
screenshot() {
|
screenshot() {
|
||||||
case "$WM" in
|
case "$SXMO_WM" in
|
||||||
sway)
|
sway)
|
||||||
swayscreenshot "$@"
|
swayscreenshot "$@"
|
||||||
;;
|
;;
|
||||||
xorg|dwm)
|
dwm)
|
||||||
xorgscreenshot "$@"
|
xorgscreenshot "$@"
|
||||||
;;
|
;;
|
||||||
ssh)
|
*)
|
||||||
exitMsg "cannot screenshot ssh"
|
exitMsg "We dont know the WM, cannot screenshot."
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
filepathoutput() {
|
filepathoutput() {
|
||||||
printf %s "$FILENAME"
|
printf %s "$FILENAME"
|
||||||
case "$WM" in
|
case "$SXMO_WM" in
|
||||||
sway)
|
sway)
|
||||||
wl-copy "$FILENAME"
|
wl-copy "$FILENAME"
|
||||||
;;
|
;;
|
||||||
xorg|dwm)
|
dwm)
|
||||||
printf %s "$FILENAME" | xsel -b -i
|
printf %s "$FILENAME" | xsel -b -i
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
@@ -68,7 +68,5 @@ filepathoutput() {
|
|||||||
|
|
||||||
FILENAME="${SXMO_SCREENSHOT_DIR:-$HOME/$(date +%Y-%m-%d-%T).png}"
|
FILENAME="${SXMO_SCREENSHOT_DIR:-$HOME/$(date +%Y-%m-%d-%T).png}"
|
||||||
|
|
||||||
WM="$(sxmo_wm.sh)"
|
|
||||||
|
|
||||||
screenshot "$@"
|
screenshot "$@"
|
||||||
filepathoutput
|
filepathoutput
|
||||||
|
@@ -5,28 +5,28 @@
|
|||||||
|
|
||||||
case "$1" in
|
case "$1" in
|
||||||
isopen)
|
isopen)
|
||||||
case "$(sxmo_wm.sh)" in
|
case "$SXMO_WM" in
|
||||||
sway|ssh)
|
sway)
|
||||||
exec pgrep bemenu
|
exec pgrep bemenu
|
||||||
;;
|
;;
|
||||||
xorg|dwm)
|
dwm)
|
||||||
exec pgrep dmenu
|
exec pgrep dmenu
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
;;
|
;;
|
||||||
close)
|
close)
|
||||||
case "$(sxmo_wm.sh)" in
|
case "$SXMO_WM" in
|
||||||
sway|ssh)
|
sway)
|
||||||
exec pkill bemenu
|
exec pkill bemenu
|
||||||
;;
|
;;
|
||||||
xorg|dwm)
|
dwm)
|
||||||
exec pkill dmenu
|
exec pkill dmenu
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
;;
|
;;
|
||||||
esac > /dev/null
|
esac > /dev/null
|
||||||
|
|
||||||
case "$(sxmo_wm.sh)" in
|
case "$SXMO_WM" in
|
||||||
sway)
|
sway)
|
||||||
swaymsg mode menu -q # disable default button inputs
|
swaymsg mode menu -q # disable default button inputs
|
||||||
cleanmode() {
|
cleanmode() {
|
||||||
@@ -40,14 +40,14 @@ case "$(sxmo_wm.sh)" in
|
|||||||
cleanmode
|
cleanmode
|
||||||
exit "$returned"
|
exit "$returned"
|
||||||
;;
|
;;
|
||||||
xorg|dwm)
|
dwm)
|
||||||
if sxmo_keyboard.sh isopen; then
|
if sxmo_keyboard.sh isopen; then
|
||||||
exec dmenu -c -l "$(sxmo_rotate.sh isrotated > /dev/null && printf 5 || printf 12)" "$@"
|
exec dmenu -c -l "$(sxmo_rotate.sh isrotated > /dev/null && printf 5 || printf 12)" "$@"
|
||||||
else
|
else
|
||||||
exec dmenu -c -l "$(sxmo_rotate.sh isrotated > /dev/null && printf 7 || printf 15)" "$@"
|
exec dmenu -c -l "$(sxmo_rotate.sh isrotated > /dev/null && printf 7 || printf 15)" "$@"
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
ssh)
|
*)
|
||||||
export BEMENU_BACKEND=curses
|
export BEMENU_BACKEND=curses
|
||||||
exec bemenu -w "$@"
|
exec bemenu -w "$@"
|
||||||
;;
|
;;
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
#!/usr/bin/env sh
|
#!/usr/bin/env sh
|
||||||
|
|
||||||
if [ "$(sxmo_wm.sh)" != "ssh" ]; then
|
if [ -n "$SXMO_WM" ]; then
|
||||||
if sxmo_keyboard.sh isopen; then
|
if sxmo_keyboard.sh isopen; then
|
||||||
wasopen="1"
|
wasopen="1"
|
||||||
fi
|
fi
|
||||||
|
@@ -35,10 +35,9 @@ xorgidle() {
|
|||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
wm="$(sxmo_wm.sh)"
|
case "$SXMO_WM" in
|
||||||
case "$wm" in
|
dwm) xorgidle "$@" & ;;
|
||||||
dwm|xorg) xorgidle "$@" & ;;
|
*) "${SXMO_WM}idle" "$@" & ;;
|
||||||
*) "${wm}idle" "$@" & ;;
|
|
||||||
esac
|
esac
|
||||||
IDLEPID=$!
|
IDLEPID=$!
|
||||||
|
|
||||||
|
@@ -4,7 +4,7 @@
|
|||||||
# shellcheck source=scripts/core/sxmo_common.sh
|
# shellcheck source=scripts/core/sxmo_common.sh
|
||||||
. "$(dirname "$0")/sxmo_common.sh"
|
. "$(dirname "$0")/sxmo_common.sh"
|
||||||
|
|
||||||
case "$(sxmo_wm.sh)" in
|
case "$SXMO_WM" in
|
||||||
sway) swaymsg kill;;
|
sway) swaymsg kill;;
|
||||||
xorg|dwm) xdotool windowkill "$(xdotool getactivewindow)";;
|
dwm) xdotool windowkill "$(xdotool getactivewindow)";;
|
||||||
esac
|
esac
|
||||||
|
@@ -71,14 +71,14 @@ xorg() {
|
|||||||
defaultconfig /usr/share/sxmo/appcfg/dunst.conf "$XDG_CONFIG_HOME/dunst/dunstrc" 744
|
defaultconfig /usr/share/sxmo/appcfg/dunst.conf "$XDG_CONFIG_HOME/dunst/dunstrc" 744
|
||||||
}
|
}
|
||||||
|
|
||||||
case "$(sxmo_wm.sh)" in
|
case "$SXMO_WM" in
|
||||||
sway)
|
sway)
|
||||||
sway
|
sway
|
||||||
;;
|
;;
|
||||||
xorg|dwm)
|
dwm)
|
||||||
xorg
|
xorg
|
||||||
;;
|
;;
|
||||||
ssh|none)
|
*)
|
||||||
sway
|
sway
|
||||||
xorg
|
xorg
|
||||||
;;
|
;;
|
||||||
|
@@ -83,18 +83,16 @@ swayrotleft() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
isrotated() {
|
isrotated() {
|
||||||
case "$wm" in
|
case "$SXMO_WM" in
|
||||||
sway)
|
sway)
|
||||||
"swayisrotated"
|
"swayisrotated"
|
||||||
;;
|
;;
|
||||||
dwm|xorg)
|
dwm)
|
||||||
"xorgisrotated"
|
"xorgisrotated"
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
wm="$(sxmo_wm.sh)"
|
|
||||||
|
|
||||||
if [ -z "$1" ] || [ "rotate" = "$1" ]; then
|
if [ -z "$1" ] || [ "rotate" = "$1" ]; then
|
||||||
shift
|
shift
|
||||||
if isrotated; then
|
if isrotated; then
|
||||||
@@ -104,11 +102,11 @@ if [ -z "$1" ] || [ "rotate" = "$1" ]; then
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
case "$wm" in
|
case "$SXMO_WM" in
|
||||||
sway)
|
sway)
|
||||||
"sway$1" "$@"
|
"sway$1" "$@"
|
||||||
;;
|
;;
|
||||||
dwm|xorg)
|
dwm)
|
||||||
"xorg$1" "$@"
|
"xorg$1" "$@"
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
@@ -6,15 +6,6 @@
|
|||||||
REDLED_PATH="/sys/class/leds/red:indicator/brightness"
|
REDLED_PATH="/sys/class/leds/red:indicator/brightness"
|
||||||
BLUELED_PATH="/sys/class/leds/blue: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() {
|
finish() {
|
||||||
kill "$BLINKPID"
|
kill "$BLINKPID"
|
||||||
|
|
||||||
|
@@ -4,7 +4,7 @@
|
|||||||
# shellcheck source=scripts/core/sxmo_common.sh
|
# shellcheck source=scripts/core/sxmo_common.sh
|
||||||
. "$(dirname "$0")/sxmo_common.sh"
|
. "$(dirname "$0")/sxmo_common.sh"
|
||||||
|
|
||||||
WM="$(sxmo_wm.sh)"
|
WM="$SXMO_WM"
|
||||||
|
|
||||||
forceupdate() {
|
forceupdate() {
|
||||||
kill "$SLEEPID"
|
kill "$SLEEPID"
|
||||||
@@ -13,8 +13,8 @@ trap "forceupdate" USR1
|
|||||||
|
|
||||||
setbar() {
|
setbar() {
|
||||||
case "$WM" in
|
case "$WM" in
|
||||||
sway|ssh) printf "%s\n" "$*";;
|
|
||||||
dwm) xsetroot -name "$*";;
|
dwm) xsetroot -name "$*";;
|
||||||
|
*) printf "%s\n" "$*";;
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -9,7 +9,7 @@ wtype_to_xdotool() {
|
|||||||
key="$2"
|
key="$2"
|
||||||
shift 2
|
shift 2
|
||||||
xdotool keydown "$key"
|
xdotool keydown "$key"
|
||||||
sxmo_type.sh -f xorg "$@"
|
sxmo_type.sh "$@"
|
||||||
xdotool keyup "$key"
|
xdotool keyup "$key"
|
||||||
exit
|
exit
|
||||||
elif [ "-m" = "$1" ] || [ "-p" = "$1" ]; then
|
elif [ "-m" = "$1" ] || [ "-p" = "$1" ]; then
|
||||||
@@ -29,20 +29,11 @@ wtype_to_xdotool() {
|
|||||||
wtype_to_xdotool "$@"
|
wtype_to_xdotool "$@"
|
||||||
}
|
}
|
||||||
|
|
||||||
# enforce wm
|
case "$SXMO_WM" in
|
||||||
# usefull to recurse without reprobing the wm
|
|
||||||
if [ "$1" = "-f" ]; then
|
|
||||||
wm="$2"
|
|
||||||
shift 2
|
|
||||||
else
|
|
||||||
wm="$(sxmo_wm.sh)"
|
|
||||||
fi
|
|
||||||
|
|
||||||
case "$wm" in
|
|
||||||
sway)
|
sway)
|
||||||
wtype "$@"
|
wtype "$@"
|
||||||
;;
|
;;
|
||||||
dwm|xorg)
|
dwm)
|
||||||
wtype_to_xdotool "$@"
|
wtype_to_xdotool "$@"
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
printf "Sxmo "
|
printf "Sxmo "
|
||||||
cat /usr/share/sxmo/version
|
cat /usr/share/sxmo/version
|
||||||
case "$(sxmo_wm.sh)" in
|
case "$SXMO_WM" in
|
||||||
dwm)
|
dwm)
|
||||||
/usr/bin/dwm -v
|
/usr/bin/dwm -v
|
||||||
/usr/bin/dmenu -v
|
/usr/bin/dmenu -v
|
||||||
|
@@ -4,6 +4,7 @@
|
|||||||
envvars() {
|
envvars() {
|
||||||
# shellcheck disable=SC1091
|
# shellcheck disable=SC1091
|
||||||
[ -f /etc/profile ] && . /etc/profile
|
[ -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 BEMENU_OPTS='--fn "Monospace 14" --scrollbar autohide -s -n -w -c -l8 -M 40 -H 20'
|
||||||
export MOZ_ENABLE_WAYLAND=1
|
export MOZ_ENABLE_WAYLAND=1
|
||||||
export SDL_VIDEODRIVER=wayland
|
export SDL_VIDEODRIVER=wayland
|
||||||
|
@@ -135,27 +135,25 @@ xorgswitchfocus() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
guesswm() {
|
guesswm() {
|
||||||
if [ -n "$SWAYSOCK" ]; then
|
SWAYSOCK="$(cat "$CACHEDIR"/sxmo.swaysock)"
|
||||||
printf "sway"
|
export SWAYSOCK
|
||||||
elif [ -n "$DISPLAY" ]; then
|
if swaymsg; then
|
||||||
printf "dwm"
|
export SXMO_WM=sway
|
||||||
elif [ -n "$SSH_CLIENT" ] || [ -n "$SSH_TTY" ]; then
|
export WAYLAND_DISPLAY=wayland-1
|
||||||
printf "ssh"
|
|
||||||
else
|
else
|
||||||
printf "none"
|
unset SWAYSOCK
|
||||||
|
export DISPLAY=":0"
|
||||||
|
export SXMO_WM=dwm
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
wm="$(guesswm)"
|
if [ -z "$SXMO_WM" ]; then
|
||||||
|
guesswm
|
||||||
if [ -z "$1" ]; then
|
|
||||||
printf %s "$wm"
|
|
||||||
exit
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
action="$1"
|
action="$1"
|
||||||
shift
|
shift
|
||||||
case "$wm" in
|
case "$SXMO_WM" in
|
||||||
dwm|xorg) "xorg$action" "$@";;
|
dwm) "xorg$action" "$@";;
|
||||||
*) "$wm$action" "$@";;
|
*) "$SXMO_WM$action" "$@";;
|
||||||
esac
|
esac
|
||||||
|
@@ -63,4 +63,4 @@ dwm() {
|
|||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
"$(sxmo_wm.sh)" "$@"
|
"$SXMO_WM" "$@"
|
||||||
|
@@ -4,6 +4,7 @@
|
|||||||
envvars() {
|
envvars() {
|
||||||
# shellcheck disable=SC1091
|
# shellcheck disable=SC1091
|
||||||
[ -f /etc/profile ] && . /etc/profile
|
[ -f /etc/profile ] && . /etc/profile
|
||||||
|
export SXMO_WM=dwm
|
||||||
command -v "$TERMCMD" || export TERMCMD="st -e"
|
command -v "$TERMCMD" || export TERMCMD="st -e"
|
||||||
command -v "$BROWSER" || export BROWSER=surf
|
command -v "$BROWSER" || export BROWSER=surf
|
||||||
command -v "$EDITOR" || export EDITOR=vis
|
command -v "$EDITOR" || export EDITOR=vis
|
||||||
|
Reference in New Issue
Block a user