From 59025f2e1194b637acd045f33b09e4d1f845c2fa Mon Sep 17 00:00:00 2001
From: Andreas Gerlach <andi@appelgriebsch.org>
Date: Fri, 24 Jul 2020 22:33:30 +0200
Subject: [PATCH] [sway] make help overlay autostart only once; improve
 reliability of wofi by adding missing image svg

---
 overlays/sway/etc/skel/.firstrun              |  0
 .../sway/config.d/99-autostart-applications   |  2 +-
 overlays/sway/usr/local/bin/swhelp.sh         | 26 ++++++++++++++++---
 .../sway/usr/share/icons/image-missing.svg    |  8 ++++++
 4 files changed, 32 insertions(+), 4 deletions(-)
 create mode 100644 overlays/sway/etc/skel/.firstrun
 create mode 100644 overlays/sway/usr/share/icons/image-missing.svg

diff --git a/overlays/sway/etc/skel/.firstrun b/overlays/sway/etc/skel/.firstrun
new file mode 100644
index 00000000..e69de29b
diff --git a/overlays/sway/etc/sway/config.d/99-autostart-applications b/overlays/sway/etc/sway/config.d/99-autostart-applications
index f0839c65..103342d4 100644
--- a/overlays/sway/etc/sway/config.d/99-autostart-applications
+++ b/overlays/sway/etc/sway/config.d/99-autostart-applications
@@ -18,4 +18,4 @@ exec --no-startup-id pamac-tray-appindicator
 exec --no-startup-id nm-applet --indicator
 exec --no-startup-id blueman-applet
 exec --no-startup-id mntray
-exec --no-startup-id swhelp.sh
+exec --no-startup-id swhelp.sh --autostart
diff --git a/overlays/sway/usr/local/bin/swhelp.sh b/overlays/sway/usr/local/bin/swhelp.sh
index bc1090f5..89d282eb 100755
--- a/overlays/sway/usr/local/bin/swhelp.sh
+++ b/overlays/sway/usr/local/bin/swhelp.sh
@@ -4,7 +4,10 @@
 # Author: Appelgriebsch
 # License: MIT
 
-if [ -f $HOME/.swhelp_overlay ]; then exit 1; fi
+PIDFILE=$HOME/.swhelp_visible
+FIRST_RUN=$HOME/.firstrun
+
+if [ -f $PIDFILE ]; then exit 1; fi
 
 DMENU_OPT="--conf /etc/xdg/wofi/overlay --style /etc/xdg/wofi/style.css --location 7 --xoffset 10 --yoffset -10"
 
@@ -22,8 +25,25 @@ cat <<EOF | wofi --show dmenu $DMENU_OPT
   Open Help Overlay: <b>\$mod</b> + <b>?</b>
   Close Help Overlay: <b>Escape</b>
 EOF
-if [ -f $HOME/.swhelp_overlay ]; then rm $HOME/.swhelp_overlay; fi
+if [ -f $PIDFILE ]; then rm $PIDFILE; fi
+if [ -f $FIRST_RUN ]; then rm $FIRST_RUN; fi
 }
 
-touch $HOME/.swhelp_overlay
+for i in "$@"
+do
+case $i in
+  --autostart)
+    AUTOSTART=YES
+    ;;
+  *)
+    # unknown option
+    ;;
+esac
+done
+
+if [ "$AUTOSTART" == "YES" ]; then
+    if [ ! -f $FIRST_RUN ]; then exit 1; fi
+fi
+
+touch $PIDFILE
 spawn_help_overlay &
diff --git a/overlays/sway/usr/share/icons/image-missing.svg b/overlays/sway/usr/share/icons/image-missing.svg
new file mode 100644
index 00000000..30b5eb46
--- /dev/null
+++ b/overlays/sway/usr/share/icons/image-missing.svg
@@ -0,0 +1,8 @@
+<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24">
+ <defs>
+  <style id="current-color-scheme" type="text/css">
+   .ColorScheme-Text { color:#dfdfdf; } .ColorScheme-Highlight { color:#4285f4; }
+  </style>
+ </defs>
+ <path style="fill:currentColor" class="ColorScheme-Text" d="M 8 1 C 4.137 1 1 4.137 1 8 C 1 11.863 4.137 15 8 15 C 11.863 15 15 11.863 15 8 C 15 4.137 11.863 1 8 1 z M 8 3 C 9.0194 3 9.959 3.28763 10.75 3.8125 L 3.8125 10.75 C 3.28763 9.95898 3 9.0194 3 8 C 3 5.2407 5.2408 3 8 3 z M 12.1875 5.25 C 12.71237 6.04102 13 6.9806 13 8 C 13 10.7592 10.7592 13 8 13 C 6.9806 13 6.041 12.71237 5.25 12.1875 L 12.1875 5.25 z" transform="translate(4 4)"/>
+</svg>
-- 
GitLab