From c446e9f23e8104cf965f3fb8a1bb464b642995c8 Mon Sep 17 00:00:00 2001 From: Stacy Harper Date: Tue, 16 Nov 2021 13:34:50 +0100 Subject: [PATCH] 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 Signed-off-by: Anjandev Momi --- scripts/appscripts/sxmo_screenshot.sh | 14 ++++++-------- scripts/core/sxmo_dmenu.sh | 18 ++++++++--------- scripts/core/sxmo_dmenu_with_kb.sh | 2 +- scripts/core/sxmo_idle.sh | 7 +++---- scripts/core/sxmo_killwindow.sh | 4 ++-- scripts/core/sxmo_migrate.sh | 6 +++--- scripts/core/sxmo_rotate.sh | 10 ++++------ scripts/core/sxmo_rtcwake.sh | 9 --------- scripts/core/sxmo_statusbar.sh | 4 ++-- scripts/core/sxmo_type.sh | 15 +++----------- scripts/core/sxmo_version.sh | 2 +- scripts/core/sxmo_winit.sh | 1 + scripts/core/sxmo_wm.sh | 28 +++++++++++++-------------- scripts/core/sxmo_workspace.sh | 2 +- scripts/core/sxmo_xinit.sh | 1 + 15 files changed, 50 insertions(+), 73 deletions(-) diff --git a/scripts/appscripts/sxmo_screenshot.sh b/scripts/appscripts/sxmo_screenshot.sh index 552a993..c2ff032 100755 --- a/scripts/appscripts/sxmo_screenshot.sh +++ b/scripts/appscripts/sxmo_screenshot.sh @@ -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 diff --git a/scripts/core/sxmo_dmenu.sh b/scripts/core/sxmo_dmenu.sh index c2949c9..9a69328 100755 --- a/scripts/core/sxmo_dmenu.sh +++ b/scripts/core/sxmo_dmenu.sh @@ -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 "$@" ;; diff --git a/scripts/core/sxmo_dmenu_with_kb.sh b/scripts/core/sxmo_dmenu_with_kb.sh index 91fa361..ad9fa00 100755 --- a/scripts/core/sxmo_dmenu_with_kb.sh +++ b/scripts/core/sxmo_dmenu_with_kb.sh @@ -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 diff --git a/scripts/core/sxmo_idle.sh b/scripts/core/sxmo_idle.sh index f07d443..85c23e8 100644 --- a/scripts/core/sxmo_idle.sh +++ b/scripts/core/sxmo_idle.sh @@ -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=$! diff --git a/scripts/core/sxmo_killwindow.sh b/scripts/core/sxmo_killwindow.sh index 54095d7..5aa6415 100755 --- a/scripts/core/sxmo_killwindow.sh +++ b/scripts/core/sxmo_killwindow.sh @@ -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 diff --git a/scripts/core/sxmo_migrate.sh b/scripts/core/sxmo_migrate.sh index e3308b6..a06d26d 100644 --- a/scripts/core/sxmo_migrate.sh +++ b/scripts/core/sxmo_migrate.sh @@ -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 ;; diff --git a/scripts/core/sxmo_rotate.sh b/scripts/core/sxmo_rotate.sh index a237ca1..1a1c171 100755 --- a/scripts/core/sxmo_rotate.sh +++ b/scripts/core/sxmo_rotate.sh @@ -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 diff --git a/scripts/core/sxmo_rtcwake.sh b/scripts/core/sxmo_rtcwake.sh index 1c9439f..2938fab 100644 --- a/scripts/core/sxmo_rtcwake.sh +++ b/scripts/core/sxmo_rtcwake.sh @@ -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" diff --git a/scripts/core/sxmo_statusbar.sh b/scripts/core/sxmo_statusbar.sh index 8cdd7da..c94a06b 100755 --- a/scripts/core/sxmo_statusbar.sh +++ b/scripts/core/sxmo_statusbar.sh @@ -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 } diff --git a/scripts/core/sxmo_type.sh b/scripts/core/sxmo_type.sh index 4ca9921..8b62218 100644 --- a/scripts/core/sxmo_type.sh +++ b/scripts/core/sxmo_type.sh @@ -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 diff --git a/scripts/core/sxmo_version.sh b/scripts/core/sxmo_version.sh index 3bb8d19..8aec691 100755 --- a/scripts/core/sxmo_version.sh +++ b/scripts/core/sxmo_version.sh @@ -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 diff --git a/scripts/core/sxmo_winit.sh b/scripts/core/sxmo_winit.sh index 9e8ee62..f47c45c 100644 --- a/scripts/core/sxmo_winit.sh +++ b/scripts/core/sxmo_winit.sh @@ -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 diff --git a/scripts/core/sxmo_wm.sh b/scripts/core/sxmo_wm.sh index f3a56c1..b1d4cd1 100755 --- a/scripts/core/sxmo_wm.sh +++ b/scripts/core/sxmo_wm.sh @@ -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 diff --git a/scripts/core/sxmo_workspace.sh b/scripts/core/sxmo_workspace.sh index 73e293b..dcfac97 100644 --- a/scripts/core/sxmo_workspace.sh +++ b/scripts/core/sxmo_workspace.sh @@ -63,4 +63,4 @@ dwm() { esac } -"$(sxmo_wm.sh)" "$@" +"$SXMO_WM" "$@" diff --git a/scripts/core/sxmo_xinit.sh b/scripts/core/sxmo_xinit.sh index 355b375..37f8205 100755 --- a/scripts/core/sxmo_xinit.sh +++ b/scripts/core/sxmo_xinit.sh @@ -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