Add wmiirc.
[alfplayer.git] / wmiirc
blobb0ac689961afa557fac71fd73962f96e9242f974
1 #!/bin/dash -f
2 # Configure wmii
3 wmiiscript=wmiirc # For wmii.sh
4 . wmii.sh
7 # Configuration Variables
8 MODKEY=Mod4
9 UP=k
10 DOWN=j
11 LEFT=h
12 RIGHT=l
14 # Bars
15 noticetimeout=5
16 noticebar=/rbar/!notice
18 # Colors tuples: "<text> <background> <border>"
19 export WMII_NORMCOLORS='#000000 #c1c48b #81654f'
20 export WMII_FOCUSCOLORS='#000000 #81654f #000000'
22 export WMII_BACKGROUND='#333333'
23 export WMII_FONT='-*-fixed-medium-r-*-*-13-*-*-*-*-*-*-*'
25 set -- $(echo $WMII_NORMCOLORS $WMII_FOCUSCOLORS)
26 export WMII_TERM="xterm"
28 # Ask about MODKEY on first run
29 if ! test -d "${WMII_CONFPATH%%:*}"; then
30 mkdir "${WMII_CONFPATH%%:*}"
31 res=$(wihack -type DIALOG xmessage -nearmouse -buttons Windows,Alt -print -fn $WMII_FONT \
32 "Welcome to wmii,$wi_newline$wi_newline" \
33 "Most of wmii's default key bindings make use of the$wi_newline" \
34 "Windows key, or equivalent. For keyboards lacking such$wi_newline" \
35 "a key, many users change this to the Alt key.$wi_newline$wi_newline" \
36 "Which would you prefer?")
37 [ "$res" = "Alt" ] && MODKEY=Mod1
38 echo "MODKEY=$MODKEY" >"${WMII_CONFPATH%%:*}/wmiirc_local"
39 chmod +x "${WMII_CONFPATH%%:*}/wmiirc_local"
42 # Menu history
43 hist="${WMII_CONFPATH%%:*}/history"
44 histnum=5000
46 # Column Rules
47 wmiir write /colrules <<!
48 /gimp/ -> 17+83+41
49 /.*/ -> 62+38 # Golden Ratio
52 # Tagging Rules
53 wmiir write /rules <<!
54 # Apps with system tray icons like to their main windows
55 # Give them permission.
56 /^Pidgin:/ allow=+activate
58 # MPlayer and VLC don't float by default, but should.
59 /MPlayer|VLC/ floating=on force-tags=+7
61 # ROX puts all of its windows in the same group, so they open
62 # with the same tags. Disable grouping for ROX Filer.
63 /^ROX-Filer:/ group=0
65 #/SMPlayer.*/ force-tags=+7
68 # Status Bar Info
69 status() {
70 echo -n label $(uptime | sed 's/.*://; s/, / /g') '|' $(date)
73 # Generic overridable startup details
74 startup() { witray & }
76 local_events() { true;}
77 wi_runconf -s wmiirc_local
78 startup
80 echo colors $WMII_NORMCOLORS | wmiir create $noticebar
82 # Event processing
83 local_events | wi_events
84 wi_events <<'!'
85 # Events
86 Event CreateTag
87 echo colors "$WMII_NORMCOLORS$wi_newline" label "$@" | wmiir create "/lbar/$@"
88 Event DestroyTag
89 wmiir remove "/lbar/$@"
90 Event FocusTag
91 wmiir xwrite "/lbar/$@" colors "$WMII_FOCUSCOLORS"
92 Event UnfocusTag
93 wmiir xwrite "/lbar/$@" colors "$WMII_NORMCOLORS"
94 Event UrgentTag
95 shift
96 wmiir xwrite "/lbar/$@" label "*$@"
97 Event NotUrgentTag
98 shift
99 wmiir xwrite "/lbar/$@" label "$@"
100 Event LeftBarClick LeftBarDND
101 shift
102 wmiir xwrite /ctl view "$@"
103 Event Unresponsive
105 client=$1; shift
106 msg="The following client is not responding. What would you like to do?$wi_newline"
107 resp=$(wihack -transient $client \
108 xmessage -nearmouse -buttons Kill,Wait -print \
109 -fn "${WMII_FONT%%,*}" "$msg $(wmiir read /client/sel/label)")
110 if [ "$resp" = Kill ]; then
111 wmiir xwrite /client/$client/ctl slay &
114 Event Notice
115 wmiir xwrite $noticebar $wi_arg
117 kill $xpid 2>/dev/null # Let's hope this isn't reused...
118 { sleep $noticetimeout; wmiir xwrite $noticebar ' '; }&
119 xpid = $!
121 # Menus
122 Menu Client-3-Delete
123 wmiir xwrite /client/$1/ctl kill
124 Menu Client-3-Kill
125 wmiir xwrite /client/$1/ctl slay
126 Menu Client-3-Fullscreen
127 wmiir xwrite /client/$1/ctl Fullscreen on
128 Event ClientMouseDown
129 wi_fnmenu Client $2 $1 &
131 Menu LBar-3-Delete
132 tag=$1; clients=$(wmiir read "/tag/$tag/index" | awk '/[^#]/{print $2}')
133 for c in $clients; do
134 if [ "$tag" = "$(wmiir read /client/$c/tags)" ]
135 then wmiir xwrite /client/$c/ctl kill
136 else wmiir xwrite /client/$c/ctl tags -$tag
138 [ "$tag" = "$(wi_seltag)" ] &&
139 wmiir xwrite /ctl view $(wi_tags | wi_nexttag)
140 done
141 Event LeftBarMouseDown
142 wi_fnmenu LBar "$@" &
144 # Actions
145 Action showkeys
146 echo "$KeysHelp" | xmessage -file - -fn ${WMII_FONT%%,*}
147 Action quit
148 wmiir xwrite /ctl quit
149 Action exec
150 wmiir xwrite /ctl exec "$@"
151 Action rehash
152 wi_proglist $PATH >$progsfile
153 Action status
154 set +xv
155 if wmiir remove /rbar/status 2>/dev/null; then
156 sleep 2
158 echo colors "$WMII_NORMCOLORS" | wmiir create /rbar/status
159 while status | wmiir write /rbar/status; do
160 sleep 1
161 done
163 # Key Bindings
164 KeyGroup Moving around
165 Key $MODKEY-$LEFT # Select the client to the left
166 wmiir xwrite /tag/sel/ctl select left
167 Key $MODKEY-$RIGHT # Select the client to the right
168 wmiir xwrite /tag/sel/ctl select right
169 Key $MODKEY-$UP # Select the client above
170 wmiir xwrite /tag/sel/ctl select up
171 Key $MODKEY-$DOWN # Select the client below
172 wmiir xwrite /tag/sel/ctl select down
174 Key $MODKEY-space # Toggle between floating and managed layers
175 wmiir xwrite /tag/sel/ctl select toggle
177 KeyGroup Moving through stacks
178 Key $MODKEY-Control-$UP # Select the stack above
179 wmiir xwrite /tag/sel/ctl select up stack
180 Key $MODKEY-Control-$DOWN # Select the stack below
181 wmiir xwrite /tag/sel/ctl select down stack
183 KeyGroup Moving clients around
184 Key $MODKEY-Shift-$LEFT # Move selected client to the left
185 wmiir xwrite /tag/sel/ctl send sel left
186 Key $MODKEY-Shift-$RIGHT # Move selected client to the right
187 wmiir xwrite /tag/sel/ctl send sel right
188 Key $MODKEY-Shift-$UP # Move selected client up
189 wmiir xwrite /tag/sel/ctl send sel up
190 Key $MODKEY-Shift-$DOWN # Move selected client down
191 wmiir xwrite /tag/sel/ctl send sel down
193 Key $MODKEY-Shift-space # Toggle selected client between floating and managed layers
194 wmiir xwrite /tag/sel/ctl send sel toggle
196 KeyGroup Client actions
197 Key $MODKEY-f # Toggle selected client's fullsceen state
198 wmiir xwrite /client/sel/ctl Fullscreen toggle
199 Key $MODKEY-Shift-c # Close client
200 wmiir xwrite /client/sel/ctl kill
202 KeyGroup Changing column modes
203 Key $MODKEY-d # Set column to default mode
204 wmiir xwrite /tag/sel/ctl colmode sel default-max
205 Key $MODKEY-s # Set column to stack mode
206 wmiir xwrite /tag/sel/ctl colmode sel stack-max
207 Key $MODKEY-m # Set column to max mode
208 wmiir xwrite /tag/sel/ctl colmode sel stack+max
210 KeyGroup Running programs
211 Key $MODKEY-a # Open wmii actions menu
212 action $(wi_actions | wimenu -h "${hist}.actions" -n $histnum) &
213 Key $MODKEY-p # Open program menu
214 eval wmiir setsid "$(wimenu -h "${hist}.progs" -n $histnum <$progsfile)" &
216 Key $MODKEY-Return # Launch a terminal
217 eval wmiir setsid $WMII_TERM &
219 KeyGroup Other
220 Key $MODKEY-Control-t # Toggle all other key bindings
221 case $(wmiir read /keys | wc -l | tr -d ' \t\n') in
222 0|1)
223 echo -n "$Keys" | wmiir write /keys
224 wmiir xwrite /ctl grabmod $MODKEY;;
226 wmiir xwrite /keys $MODKEY-Control-t
227 wmiir xwrite /ctl grabmod Mod3;;
228 esac
230 KeyGroup Tag actions
231 Key $MODKEY-t # Change to another tag
232 wmiir xwrite /ctl view $(wi_tags | wimenu -h "${hist}.tags" -n 50) &
233 Key $MODKEY-Shift-t # Retag the selected client
234 # Assumes left-to-right order of evaluation
235 wmiir xwrite /client/$(wi_selclient)/ctl tags $(wi_tags | wimenu -h "${hist}.tags" -n 50) &
236 Key $MODKEY-n # Move to the next tag
237 wmiir xwrite /ctl view $(wi_tags | wi_nexttag)
238 Key $MODKEY-b # Move to the previous tag
239 wmiir xwrite /ctl view $(wi_tags | sort -r | wi_nexttag)
241 for i in 0 1 2 3 4 5 6 7 8 9; do
242 wi_events <<!
243 Key $MODKEY-$i # Move to the numbered view
244 wmiir xwrite /ctl view "$i"
245 Key $MODKEY-Shift-$i # Retag selected client with the numbered tag
246 wmiir xwrite /client/sel/ctl tags "$i"
248 done
249 wi_events -e
251 # WM Configuration
252 wmiir write /ctl <<!
253 font $WMII_FONT
254 focuscolors $WMII_FOCUSCOLORS
255 normcolors $WMII_NORMCOLORS
256 grabmod $MODKEY
257 border 1
259 xsetroot -solid "$WMII_BACKGROUND" &
261 # Misc
262 progsfile="$(wmiir namespace)/.proglist"
263 action status &
264 wi_proglist $PATH >$progsfile &
266 # Setup Tag Bar
267 IFS="$wi_newline"
268 wmiir rm $(wmiir ls -p /lbar) >/dev/null
269 seltag=$(wmiir read /tag/sel/ctl | sed 1q)
270 unset IFS
271 wi_tags | while read tag
273 if [ "$tag" = "$seltag" ]; then
274 echo colors "$WMII_FOCUSCOLORS"
275 echo label $tag
276 else
277 echo colors "$WMII_NORMCOLORS"
278 echo label $tag
279 fi | wmiir create "/lbar/$tag"
280 done
282 wi_eventloop