1 | #!/usr/lib/9base/bin/rc |
---|
2 | # periodically print stuff to the bar |
---|
3 | |
---|
4 | PIDFILE=/tmp/.ixp-$USER/statuspid-$WMII_IDENT |
---|
5 | if(test -r $PIDFILE) { |
---|
6 | kill -2 `{cat $PIDFILE} >[2]/dev/null |
---|
7 | } |
---|
8 | echo $pid >$PIDFILE |
---|
9 | |
---|
10 | # current track playing in mpd |
---|
11 | |
---|
12 | # Implement many of mpc's actions in a menu |
---|
13 | wmiir create /menu/items/mpc/prev 'prev' |
---|
14 | wmiir create /menu/items/mpc/play 'play' |
---|
15 | wmiir create /menu/items/mpc/pause 'pause' |
---|
16 | wmiir create /menu/items/mpc/stop 'stop' |
---|
17 | wmiir create /menu/items/mpc/next 'next' |
---|
18 | wmiir create /menu/items/mpc/toggle 'toggle' |
---|
19 | wmiir create /menu/items/mpc/start 'seek 00:00:00' |
---|
20 | wmiir create /menu/items/mpc/back 'seek -00:00:05' |
---|
21 | wmiir create /menu/items/mpc/fwd 'seek +00:00:05' |
---|
22 | wmiir create /menu/items/mpc/clear 'clear' |
---|
23 | wmiir create /menu/items/mpc/shuffle 'shuffle' |
---|
24 | wmiir create /menu/items/mpc/load 'load wmii' |
---|
25 | wmiir create /menu/items/mpc/save 'save wmii' |
---|
26 | wmiir create /menu/items/mpc/voldn 'volume -10' |
---|
27 | wmiir create /menu/items/mpc/volup 'volume +10' |
---|
28 | wmiir create /menu/items/mpc/repeat 'repeat' |
---|
29 | wmiir create /menu/items/mpc/random 'random' |
---|
30 | wmiir create /menu/items/mpc/update 'update' |
---|
31 | |
---|
32 | mpdlab=`{wmiir read /bar/new} |
---|
33 | # Colour between selected and normal |
---|
34 | wmiir write /bar/$mpdlab/fgcolor '#d4d4d4' |
---|
35 | wmiir write /bar/$mpdlab/bgcolor '#293139' |
---|
36 | wmiir write /bar/$mpdlab/bordercolor '#303840' |
---|
37 | |
---|
38 | wmiir write /bar/$mpdlab/b1press 'extern mpc toggle' |
---|
39 | wmiir write /bar/$mpdlab/b2press 'wmiir write /menu/precmd ''extern mpc''; wmiir write /menu/lookup /items/mpc; wmiir write /menu/ctl ''display 1''' |
---|
40 | wmiir write /bar/$mpdlab/b3press 'extern mpc next' |
---|
41 | |
---|
42 | # When changing the volume, display it |
---|
43 | # (Involves calling bash because I don't really know how to do 9rc) |
---|
44 | wmiir create /bar/$mpdlab/x-delay 0 |
---|
45 | wmiir write /bar/$mpdlab/b4press 'wmiir write /bar/'^$mpdlab^'/x-delay 1; extern bash -c ''wmiir write /bar/'^$mpdlab^'/data "$(mpc volume -5 | grep ^volume:)"''' |
---|
46 | wmiir write /bar/$mpdlab/b5press 'wmiir write /bar/'^$mpdlab^'/x-delay 1; extern bash -c ''wmiir write /bar/'^$mpdlab^'/data "$(mpc volume +5 | grep ^volume:)"''' |
---|
47 | |
---|
48 | # date and load average |
---|
49 | |
---|
50 | label=`{wmiir read /bar/new} |
---|
51 | wmiir write /bar/$label/b1press 'wmiir write /wm/ctl ''select prev''' |
---|
52 | wmiir write /bar/$label/b3press 'wmiir write /wm/ctl ''select next''' |
---|
53 | wmiir write /bar/$label/b4press 'wmiir write /wm/ctl ''select prev''' |
---|
54 | wmiir write /bar/$label/b5press 'wmiir write /wm/ctl ''select next''' |
---|
55 | |
---|
56 | # install signal handler for artificial sigexit: |
---|
57 | fn sigint { |
---|
58 | if(test -f $PIDFILE && ~ `{cat $PIDFILE} $pid) |
---|
59 | rm -f $PIDFILE |
---|
60 | wmiir write /bar/ctl 'destroy '^$mdlab |
---|
61 | wmiir write /bar/ctl 'destroy '^$label |
---|
62 | exit |
---|
63 | } |
---|
64 | |
---|
65 | fn mpdstatus { |
---|
66 | echo (`{$HOME/.wmii/scripts/mpd-status.py}) |
---|
67 | } |
---|
68 | |
---|
69 | fn statustext { |
---|
70 | # if you need a formatted date, use awk |
---|
71 | echo (`{date} `{uptime | sed 's/.*://; s/,//g'}) |
---|
72 | } |
---|
73 | |
---|
74 | mpdtext=`{mpdstatus} |
---|
75 | text=`{statustext} |
---|
76 | while(wmiir write /bar/$label/data $"text >[2]/dev/null) { |
---|
77 | sleep 2 |
---|
78 | text=`{statustext} |
---|
79 | # If we've been told to delay, don't update this time round |
---|
80 | delay=`{wmiir read /bar/$mpdlab/x-delay} |
---|
81 | if(~ $delay 1) wmiir write /bar/$mpdlab/x-delay 0 |
---|
82 | if not { |
---|
83 | mpdtext=`{mpdstatus} |
---|
84 | wmiir write /bar/$mpdlab/data $"mpdtext >[2]/dev/null |
---|
85 | } |
---|
86 | } |
---|