]> git.lizzy.rs Git - bspwm.git/blob - examples/panel/panel_dzen2
Update panel examples
[bspwm.git] / examples / panel / panel_dzen2
1 #! /bin/sh
2 #
3 # Example panel for dzen2
4
5 font_family='sans-serif'
6 font_size=11
7
8 . panel_colors
9
10 adaptive_centering=0
11 screen_width=$(sres -W)
12 NORMIFS=$IFS
13 FIELDIFS=':'
14 PADDING='  '
15
16 while getopts 'af:s:' opt ; do
17     case "$opt" in
18         a)
19             adaptive_centering=1
20             ;;
21         f)
22             font_family=$OPTARG
23             ;;
24         s)
25             font_size=$OPTARG
26             ;;
27     esac
28 done
29
30 shift $((OPTIND - 1))
31
32 while read -r line ; do
33     case $line in
34         S*)
35             # system informations
36             sys_infos="^fg($COLOR_STATUS_FG)^bg($COLOR_STATUS_BG)^ca(1, bspc toggle_visibility)${PADDING}${line#?}${PADDING}^ca()^fg()^bg()${PADDING}"
37             ;;
38         T*)
39             # focused window title
40             title="^fg($COLOR_TITLE_FG)^bg($COLOR_TITLE_BG)^ca(1, bspc toggle_floating)^ca(2, bspc toggle_locked)^ca(3, bspc close)${PADDING}${line#?}${PADDING}^ca()^ca()^ca()"
41             ;;
42         W*)
43             # window manager informations
44             wm_infos="$PADDING"
45             IFS=$FIELDIFS
46             set - ${line#?}
47             while [ $# -gt 0 ] ; do
48                 item=$1
49                 case $item in
50                     [DdEUu]*)
51                         # desktops
52                         name=${item#?}
53                         case $item in
54                             u*)
55                                 # urgent (inactive) desktop
56                                 FG=$COLOR_URGENT_FG
57                                 BG=$COLOR_URGENT_BG
58                                 ;;
59                             [DU]*)
60                                 # active desktop
61                                 FG=$COLOR_ACTIVE_FG
62                                 BG=$COLOR_ACTIVE_BG
63                                 ;;
64                             d*)
65                                 # inactive desktop
66                                 FG=$COLOR_INACTIVE_FG
67                                 BG=$COLOR_INACTIVE_BG
68                                 ;;
69                             E*)
70                                 # empty desktop
71                                 FG=$COLOR_EMPTY_FG
72                                 BG=$COLOR_EMPTY_BG
73                                 ;;
74                         esac
75                         wm_infos="${wm_infos}^fg(${FG})^bg(${BG})^ca(1, bspc use ${name})^ca(2, bspc send_to ${name})^ca(3, bspc send_to ${name} --follow)${PADDING}${name}${PADDING}^ca()^ca()^ca()"
76                         ;;
77                     L*)
78                         # layout
79                         layout=$(printf "%s" "${item#?}" | sed 's/^\(.\).*/\U\1/')
80                         wm_infos="${wm_infos}^fg()^bg()${PADDING}${PADDING}^fg($COLOR_LAYOUT_FG)^bg($COLOR_LAYOUT_BG)^ca(1, bspc cycle_layout)^ca(2, bspc balance)${PADDING}$layout${PADDING}^ca()^ca()"
81                         ;;
82                 esac
83                 shift
84             done
85             IFS=$NORMIFS
86             ;;
87     esac
88     set - $(printf '%s\0%s\0%s' "$wm_infos" "$title" "$sys_infos" | sed 's/\^[a-z]\+([^)]*)//g' | xargs -0 textwidth -f "$font_family" -s "$font_size")
89     left_width=$1
90     center_width=$2
91     right_width=$3
92     left_indent=0
93     right_indent=$((screen_width - right_width))
94     available_center=$((screen_width - (left_width + right_width)))
95     if [ $available_center -lt $center_width ] ; then
96         center_indent=$((left_indent + left_width))
97     else
98         if [ $adaptive_centering -eq 1 ] ; then
99             center_indent=$((left_width + (available_center - center_width) / 2))
100         else
101             center_indent=$(( (screen_width - center_width) / 2 ))
102         fi
103     fi
104     printf "%s\n" "^pa($center_indent)$title^pa($left_indent)$wm_infos^pa($right_indent)$sys_infos"
105 done