[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] add comments to panel.sh



This patch aims to make panel.sh a bit easier to understand.
I had a while until I got the concept, and I've also seen people in
IRC who don't get it :P

Florian

-- 
() ascii ribbon campaign - stop html mail    www.asciiribbon.org
/\ www.the-compiler.org  | I love long mails http://email.is-not-s.ms/
He who invents adages for others to peruse takes along rowboat when going on 
cruise. 
From 4918bf633fc9f665ff61b51030696b72a810886b Mon Sep 17 00:00:00 2001
From: Florian Bruhin <git _at_ the _minus_ compiler _dot_ org>
Date: Tue, 29 Oct 2013 18:50:19 +0100
Subject: [PATCH] Add comments to panel.sh

---
 share/panel.sh | 31 ++++++++++++++++++++++++++++++-
 1 file changed, 30 insertions(+), 1 deletion(-)

diff --git a/share/panel.sh b/share/panel.sh
index 02a925d..d25c0b7 100755
--- a/share/panel.sh
+++ b/share/panel.sh
@@ -53,10 +53,18 @@ else
 fi
 
 hc pad $monitor $panel_height
+
 {
-    # events:
+    ### Event generator ###
+    # based on different input data (mpc, date, hlwm hooks, ...) this 
generates events, formed like this:
+    #   <eventname>\t<data> [...]
+    # e.g.
+    #   date    ^fg(#efefef)18:33^fg(#909090), 2013-10-^fg(#efefef)29
+
     #mpc idleloop player &
     while true ; do
+        # "date" output is checked once a second, but an event is only
+        # generated if the output changed compared to the previous run.
         date +$'date\t^fg(#efefef)%H:%M^fg(#909090), %Y-%m-^fg(#efefef)%d'
         sleep 1 || break
     done > >(uniq_linebuffered) &
@@ -69,6 +77,11 @@ hc pad $monitor $panel_height
     date=""
     windowtitle=""
     while true ; do
+
+        ### Output ###
+        # This part prints dzen data based on the _previous_ data handling run,
+        # and then waits for the next event to happen.
+
         bordercolor="#26221C"
         separator="^bg()^fg($selbg)|"
         # draw tags
@@ -91,11 +104,13 @@ hc pad $monitor $panel_height
                     ;;
             esac
             if [ ! -z "$dzen2_svn" ] ; then
+                # clickable tags if using SVN dzen
                 echo -n "^ca(1,\"${herbstclient_command[@]:-herbstclient}\" "
                 echo -n "focus_monitor \"$monitor\" && "
                 echo -n "\"${herbstclient_command[@]:-herbstclient}\" "
                 echo -n "use \"${i:1}\") ${i:1} ^ca()"
             else
+                # non-clickable tags if using older dzen
                 echo -n " ${i:1} "
             fi
         done
@@ -108,6 +123,15 @@ hc pad $monitor $panel_height
         width=$($textwidth "$font" "$right_text_only    ")
         echo -n "^pa($(($panel_width - $width)))$right"
         echo
+
+        ### Data handling ###
+        # This part handles the events generated in the event loop, and sets
+        # internal variables based on them. The event and its arguments are
+        # read into the array cmd, then action is taken depending on the event
+        # name.
+        # "Special" events (quit_panel/togglehidepanel/reload) are also handled
+        # here.
+
         # wait for next event
         IFS=$'\t' read -ra cmd || break
         # find out event origin
@@ -150,6 +174,11 @@ hc pad $monitor $panel_height
             #    ;;
         esac
     done
+
+    ### dzen2 ###
+    # After the data is gathered and processed, the output of the previous 
block
+    # gets piped to dzen2.
+
 } 2> /dev/null | dzen2 -w $panel_width -x $x -y $y -fn "$font" -h 
$panel_height \
     -e 'button3=' \
     -ta l -bg "$bgcolor" -fg '#efefef'
-- 
1.8.4.1

Attachment: pgpOIgqOwakjE.pgp
Description: PGP signature