smxo_appmenu: replace if/grep with case in programchoicesinit
On a PinePhone, this function took ~90 ms before the change and ~45 ms after. Signed-off-by: Anjandev Momi <anjan@momi.ca>
This commit is contained in:
parent
7fe317c71b
commit
51815acb0a
1 changed files with 36 additions and 19 deletions
|
@ -14,14 +14,15 @@ gracefulexit() {
|
||||||
|
|
||||||
programchoicesinit() {
|
programchoicesinit() {
|
||||||
XPROPOUT="$(xprop -id "$(xdotool getactivewindow)")"
|
XPROPOUT="$(xprop -id "$(xdotool getactivewindow)")"
|
||||||
WMCLASS="${1:-$(echo "$XPROPOUT" | grep WM_CLASS | cut -d ' ' -f3-)}"
|
WMCLASS="${1:-$(echo "$XPROPOUT" | grep WM_CLASS | cut -d ' ' -f3- | tr '[:upper:]' '[:lower:]')}"
|
||||||
if [ -z "$XPROPOUT" ]; then
|
if [ -z "$XPROPOUT" ]; then
|
||||||
echo "sxmo_appmenu: detected no active window, no problem, opening system menu" >&2
|
echo "sxmo_appmenu: detected no active window, no problem, opening system menu" >&2
|
||||||
else
|
else
|
||||||
echo "sxmo_appmenu: opening menu for wmclass $WMCLASS" >&2
|
echo "sxmo_appmenu: opening menu for wmclass $WMCLASS" >&2
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if echo "$WMCLASS" | grep -i "scripts"; then
|
case "$WMCLASS" in
|
||||||
|
scripts )
|
||||||
# Scripts menu
|
# Scripts menu
|
||||||
CHOICES="
|
CHOICES="
|
||||||
$icon_mic Record ^ 0 ^ sxmo_record.sh
|
$icon_mic Record ^ 0 ^ sxmo_record.sh
|
||||||
|
@ -46,7 +47,8 @@ programchoicesinit() {
|
||||||
"
|
"
|
||||||
fi
|
fi
|
||||||
WINNAME=Scripts
|
WINNAME=Scripts
|
||||||
elif echo "$WMCLASS" | grep -i "applications"; then
|
;;
|
||||||
|
applications )
|
||||||
# Apps menu
|
# Apps menu
|
||||||
if [ -x "$XDG_CONFIG_HOME/sxmo/hooks/apps" ]; then
|
if [ -x "$XDG_CONFIG_HOME/sxmo/hooks/apps" ]; then
|
||||||
CHOICES=$("$XDG_CONFIG_HOME/sxmo/hooks/apps")
|
CHOICES=$("$XDG_CONFIG_HOME/sxmo/hooks/apps")
|
||||||
|
@ -117,7 +119,8 @@ programchoicesinit() {
|
||||||
"
|
"
|
||||||
fi
|
fi
|
||||||
WINNAME=Apps
|
WINNAME=Apps
|
||||||
elif echo "$WMCLASS" | grep -i "config"; then
|
;;
|
||||||
|
config )
|
||||||
# System Control menu
|
# System Control menu
|
||||||
CHOICES="
|
CHOICES="
|
||||||
$icon_aru Brightness ^ 1 ^ sxmo_brightness.sh up
|
$icon_aru Brightness ^ 1 ^ sxmo_brightness.sh up
|
||||||
|
@ -146,7 +149,8 @@ programchoicesinit() {
|
||||||
$icon_cfg Edit configuration ^ 0 ^ st -e $EDITOR $XDG_CONFIG_HOME/sxmo/xinit
|
$icon_cfg Edit configuration ^ 0 ^ st -e $EDITOR $XDG_CONFIG_HOME/sxmo/xinit
|
||||||
"
|
"
|
||||||
WINNAME=Config
|
WINNAME=Config
|
||||||
elif echo "$WMCLASS" | grep -i "audioout"; then
|
;;
|
||||||
|
audioout )
|
||||||
# Audio Out menu
|
# Audio Out menu
|
||||||
CURRENTDEV="$(sxmo_audiocurrentdevice.sh)"
|
CURRENTDEV="$(sxmo_audiocurrentdevice.sh)"
|
||||||
CHOICES="
|
CHOICES="
|
||||||
|
@ -158,7 +162,8 @@ programchoicesinit() {
|
||||||
$icon_ard Volume down ^ 1 ^ sxmo_vol.sh down
|
$icon_ard Volume down ^ 1 ^ sxmo_vol.sh down
|
||||||
"
|
"
|
||||||
WINNAME="Audio"
|
WINNAME="Audio"
|
||||||
elif echo "$WMCLASS" | grep -i "power"; then
|
;;
|
||||||
|
power )
|
||||||
# Power menu
|
# Power menu
|
||||||
CHOICES="
|
CHOICES="
|
||||||
$icon_lck Lock ^ 0 ^ sxmo_lock.sh
|
$icon_lck Lock ^ 0 ^ sxmo_lock.sh
|
||||||
|
@ -169,7 +174,8 @@ programchoicesinit() {
|
||||||
$icon_pwr Poweroff ^ 0 ^ st -e sudo poweroff
|
$icon_pwr Poweroff ^ 0 ^ st -e sudo poweroff
|
||||||
"
|
"
|
||||||
WINNAME="Power"
|
WINNAME="Power"
|
||||||
elif echo "$WMCLASS" | grep -i "mpv"; then
|
;;
|
||||||
|
*mpv* )
|
||||||
# MPV
|
# MPV
|
||||||
CHOICES="
|
CHOICES="
|
||||||
$icon_pau Pause ^ 0 ^ key space
|
$icon_pau Pause ^ 0 ^ key space
|
||||||
|
@ -185,7 +191,8 @@ programchoicesinit() {
|
||||||
$icon_inf Seek Info ^ 1 ^ key o
|
$icon_inf Seek Info ^ 1 ^ key o
|
||||||
"
|
"
|
||||||
WINNAME=Mpv && return
|
WINNAME=Mpv && return
|
||||||
elif echo "$WMCLASS" | grep -i "feh"; then
|
;;
|
||||||
|
*feh* )
|
||||||
# Feh
|
# Feh
|
||||||
CHOICES="
|
CHOICES="
|
||||||
$icon_arr Next ^ 1 ^ key space
|
$icon_arr Next ^ 1 ^ key space
|
||||||
|
@ -201,7 +208,8 @@ programchoicesinit() {
|
||||||
$icon_inf Toggle filename ^ 1 ^ key d
|
$icon_inf Toggle filename ^ 1 ^ key d
|
||||||
"
|
"
|
||||||
WINNAME=Feh && return
|
WINNAME=Feh && return
|
||||||
elif echo "$WMCLASS" | grep -i "sxiv"; then
|
;;
|
||||||
|
*sxiv* )
|
||||||
# Sxiv
|
# Sxiv
|
||||||
CHOICES="
|
CHOICES="
|
||||||
$icon_arr Next ^ 1 ^ key space
|
$icon_arr Next ^ 1 ^ key space
|
||||||
|
@ -215,7 +223,8 @@ programchoicesinit() {
|
||||||
$icon_grd Thumbnail ^ 0 ^ key Return
|
$icon_grd Thumbnail ^ 0 ^ key Return
|
||||||
"
|
"
|
||||||
WINNAME=Sxiv && return
|
WINNAME=Sxiv && return
|
||||||
elif echo "$WMCLASS" | grep -i "st-256color"; then
|
;;
|
||||||
|
*st-256color* )
|
||||||
# St
|
# St
|
||||||
# First we try to handle the app running inside st:
|
# First we try to handle the app running inside st:
|
||||||
WMNAME="${1:-$(echo "$XPROPOUT" | grep -E "^WM_NAME" | cut -d ' ' -f3-)}"
|
WMNAME="${1:-$(echo "$XPROPOUT" | grep -E "^WM_NAME" | cut -d ' ' -f3-)}"
|
||||||
|
@ -355,7 +364,8 @@ programchoicesinit() {
|
||||||
"
|
"
|
||||||
WINNAME=St
|
WINNAME=St
|
||||||
fi
|
fi
|
||||||
elif echo "$WMCLASS" | grep -i "sthotkeys"; then
|
;;
|
||||||
|
*sthotkeys* )
|
||||||
# St hotkeys
|
# St hotkeys
|
||||||
CHOICES="
|
CHOICES="
|
||||||
Send Ctrl-C ^ 0 ^ key Ctrl+c
|
Send Ctrl-C ^ 0 ^ key Ctrl+c
|
||||||
|
@ -366,7 +376,8 @@ programchoicesinit() {
|
||||||
Send Ctrl-B ^ 0 ^ key Ctrl+b
|
Send Ctrl-B ^ 0 ^ key Ctrl+b
|
||||||
"
|
"
|
||||||
WINNAME=St
|
WINNAME=St
|
||||||
elif echo "$WMCLASS" | grep -i netsurf; then
|
;;
|
||||||
|
*netsurf* )
|
||||||
# Netsurf
|
# Netsurf
|
||||||
CHOICES="
|
CHOICES="
|
||||||
$icon_flt Pipe URL ^ 0 ^ sxmo_urlhandler.sh
|
$icon_flt Pipe URL ^ 0 ^ sxmo_urlhandler.sh
|
||||||
|
@ -376,7 +387,8 @@ programchoicesinit() {
|
||||||
$icon_arr History ^ 1 ^ key Alt+Right
|
$icon_arr History ^ 1 ^ key Alt+Right
|
||||||
"
|
"
|
||||||
WINNAME=Netsurf
|
WINNAME=Netsurf
|
||||||
elif echo "$WMCLASS" | grep surf; then
|
;;
|
||||||
|
*surf* )
|
||||||
# Surf
|
# Surf
|
||||||
CHOICES="
|
CHOICES="
|
||||||
$icon_glb Navigate ^ 0 ^ key Ctrl+g
|
$icon_glb Navigate ^ 0 ^ key Ctrl+g
|
||||||
|
@ -394,7 +406,8 @@ programchoicesinit() {
|
||||||
$icon_rld Refresh ^ 0 ^ key Ctrl+Shift+r
|
$icon_rld Refresh ^ 0 ^ key Ctrl+Shift+r
|
||||||
"
|
"
|
||||||
WINNAME=Surf
|
WINNAME=Surf
|
||||||
elif echo "$WMCLASS" | grep -i firefox; then
|
;;
|
||||||
|
*firefox* )
|
||||||
# Firefox
|
# Firefox
|
||||||
CHOICES="
|
CHOICES="
|
||||||
$icon_flt Pipe URL ^ 0 ^ sxmo_urlhandler.sh
|
$icon_flt Pipe URL ^ 0 ^ sxmo_urlhandler.sh
|
||||||
|
@ -407,7 +420,8 @@ programchoicesinit() {
|
||||||
$icon_rld Refresh ^ 0 ^ key Ctrl+Shift+r
|
$icon_rld Refresh ^ 0 ^ key Ctrl+Shift+r
|
||||||
"
|
"
|
||||||
WINNAME=Firefox
|
WINNAME=Firefox
|
||||||
elif echo "$WMCLASS" | grep -i lagrange; then
|
;;
|
||||||
|
*lagrange* )
|
||||||
# Lagrange
|
# Lagrange
|
||||||
CHOICES="
|
CHOICES="
|
||||||
$icon_mnu Toggle sidebar ^ 0 ^ key Ctrl+Shift+p
|
$icon_mnu Toggle sidebar ^ 0 ^ key Ctrl+Shift+p
|
||||||
|
@ -421,7 +435,8 @@ programchoicesinit() {
|
||||||
$icon_rld Refresh ^ 0 ^ key Ctrl+r
|
$icon_rld Refresh ^ 0 ^ key Ctrl+r
|
||||||
"
|
"
|
||||||
WINNAME=Lagrange
|
WINNAME=Lagrange
|
||||||
elif echo "$WMCLASS" | grep -i foxtrot; then
|
;;
|
||||||
|
*foxtrot* )
|
||||||
# Foxtrot GPS
|
# Foxtrot GPS
|
||||||
CHOICES="
|
CHOICES="
|
||||||
$icon_itm Locations ^ 0 ^ sxmo_gpsutil.sh menulocations
|
$icon_itm Locations ^ 0 ^ sxmo_gpsutil.sh menulocations
|
||||||
|
@ -438,7 +453,8 @@ programchoicesinit() {
|
||||||
$icon_usr Locate Me ^ 0 ^ sxmo_gpsutil.sh gpsgeoclueset
|
$icon_usr Locate Me ^ 0 ^ sxmo_gpsutil.sh gpsgeoclueset
|
||||||
"
|
"
|
||||||
WINNAME=Maps
|
WINNAME=Maps
|
||||||
else
|
;;
|
||||||
|
* )
|
||||||
# Default system menu (no matches)
|
# Default system menu (no matches)
|
||||||
CHOICES="
|
CHOICES="
|
||||||
$icon_grd Scripts ^ 0 ^ sxmo_appmenu.sh scripts
|
$icon_grd Scripts ^ 0 ^ sxmo_appmenu.sh scripts
|
||||||
|
@ -456,7 +472,8 @@ programchoicesinit() {
|
||||||
$icon_pwr Power ^ 0 ^ sxmo_appmenu.sh power
|
$icon_pwr Power ^ 0 ^ sxmo_appmenu.sh power
|
||||||
"
|
"
|
||||||
WINNAME=Sys
|
WINNAME=Sys
|
||||||
fi
|
;;
|
||||||
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
getprogchoices() {
|
getprogchoices() {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue