wmii

git clone git://oldgit.suckless.org/wmii/
Log | Files | Refs | README | LICENSE

wmiirc (9066B)


      1 #!/bin/sh -f
      2 test $#* '=' 0 || {
      3 	p="$PATH"
      4 	which rc >/dev/null || PATH="$PLAN9:$p"
      5 	which rc >/dev/null || PATH="/usr/local/plan9/bin:$p"
      6 	which rc >/dev/null || PATH="/usr/local/9/bin:$p"
      7 	which rc >/dev/null || PATH="/opt/plan9/bin:$p"
      8 	which rc >/dev/null || PATH="/opt/9/bin:$p"
      9 	which rc >/dev/null || PATH="/usr/plan9/bin:$p"
     10 	which rc >/dev/null || PATH="/usr/9/bin:$p"
     11 	exec rc $0
     12 }
     13 
     14 cd
     15 scriptname=$0
     16 oldpath=$path; path=($PLAN9/bin $path)
     17 . wmii.rc wmiirc # Include utility functions
     18 
     19 # WMII Configuration
     20 
     21 # Keys
     22 MODKEY=Mod4
     23 UP=k
     24 DOWN=j
     25 LEFT=h
     26 RIGHT=l
     27 
     28 # Bars
     29 noticetimeout=5
     30 noticebar=/rbar/!notice
     31 
     32 # Theme
     33 wmiifont='drift,-*-fixed-*-*-*-*-9-*-*-*-*-*-*-*'
     34 wmiifont='-*-fixed-medium-r-*-*-13-*-*-*-*-*-*-*'
     35 wmiinormcol=('#000000' '#c1c48b' '#81654f')
     36 wmiifocuscol=('#000000' '#81654f' '#000000')
     37 wmiibackground='#333333'
     38 wmiifloatbackground='#222222'
     39 fn setbackground { xsetroot -solid $* }
     40 
     41 # Programs
     42 WMII_TERM=(xterm)
     43 
     44 # Column Rules
     45 wmiir write /colrules <<!
     46     /gimp/ -> 17+83+41
     47     /.*/ -> 62+38 # Golden Ratio
     48 !
     49 
     50 # Tagging Rules
     51 wmiir write /rules <<!
     52     # Apps with system tray icons like to their main windows
     53     # Give them permission.
     54     /^Pidgin:/ allow=+activate
     55 
     56     # MPlayer and VLC don't float by default, but should.
     57     /MPlayer|VLC/ floating=on
     58 
     59     # ROX puts all of its windows in the same group, so they open
     60     # with the same tags.  Disable grouping for ROX Filer.
     61     /^ROX-Filer:/ group=0
     62 !
     63 
     64 # Status Bar Info
     65 fn status {
     66 	echo -n label `{uptime | sed 's/.*://; s/, / /g'} '|' \
     67 		      `{date} }
     68 
     69 # Generic overridable startup details
     70 fn startup { witray & }
     71 
     72 # End Configuration
     73 
     74 # For the time being, this file follows the lisp bracing
     75 # convention. i.e.:
     76 #  if(frob this) {
     77 #    frob that
     78 #    if(frob theother) {
     79 #      unfrob this
     80 #      unfrob that}}
     81 # Comments welcome.
     82 
     83 confpath=`{echo $WMII_CONFPATH | sed 'y/:/ /'}
     84 
     85 # Events
     86 fn sigexit {
     87 	rm -f $progs_file
     88 	wi_cleankeys}
     89 
     90 fn Event-CreateTag {
     91 	echo colors $wmiinormcol $wi_newline label $* | wmiir create /lbar/$"*}
     92 fn Event-DestroyTag {
     93 	wmiir remove /lbar/$"*}
     94 fn Event-FocusTag {
     95 	wmiir xwrite /lbar/$"* colors $wmiifocuscol}
     96 fn Event-UnfocusTag {
     97 	wmiir xwrite /lbar/$"* colors $wmiinormcol}
     98 fn Event-UrgentTag {
     99 	shift
    100 	wmiir xwrite /lbar/$"* label '*'$"*}
    101 fn Event-NotUrgentTag {
    102 	shift
    103 	wmiir xwrite /lbar/$"* label $"*}
    104 fn Event-AreaFocus {
    105 	if(~ $1 '~')
    106 		setbackground $wmiifloatbackground
    107 	if not
    108 		setbackground $wmiibackground }
    109 
    110 fn Event-Unresponsive {
    111 	client = $1; shift
    112 	@{
    113 		msg = 'The following client is not responding. What would you like to do?'
    114 		resp = `{wihack -transient $client \
    115 				xmessage -nearmouse -buttons Kill,Wait -print \
    116 				$msg $wi_newline '' `{wmiir read /client/$client/label}}
    117 		if(~ $resp Kill)
    118 			wmiir xwrite /client/$client/ctl slay
    119 	}&}
    120 fn Event-Notice {
    121 	wmiir xwrite $noticebar label $wi_arg
    122 
    123 	/bin/kill $xpid >[2]/dev/null # Let's hope this isn't reused...
    124 	{ sleep $noticetimeout; wmiir xwrite $noticebar ' ' }& # Bug...
    125 	xpid = $apid}
    126 
    127 fn Event-LeftBar^(Click DND) {
    128 	shift; wmiir xwrite /ctl view $*}
    129 
    130 fn ClientMenu-3-Delete {
    131 	wmiir xwrite /client/$1/ctl kill}
    132 fn ClientMenu-3-Kill {
    133 	wmiir xwrite /client/$1/ctl slay}
    134 fn ClientMenu-3-Fullscreen {
    135 	wmiir xwrite /client/$1/ctl Fullscreen on}
    136 fn Event-ClientMouseDown {
    137 	wi_fnmenu Client $2 $1 &}
    138 
    139 fn LBarMenu-3-Delete {
    140 	tag=$1; clients=`{wmiir read /tag/$tag/index | awk '/[^#]/{print $2}'}
    141 	for(c in $clients) {
    142 		if(~ $tag `{wmiir read /client/$c/tags})
    143 			wmiir xwrite /client/$c/ctl kill
    144 		if not
    145 			wmiir xwrite /client/$c/tags -$tag}
    146 	if(~ $tag `{wi_seltag}) {
    147 		newtag = `{wi_tags | awk -v't='$tag '
    148 			$1 == t { if(!l) getline l
    149 				  print l
    150 				  exit }
    151 			{ l = $0 }'}
    152 		wmiir xwrite /ctl view $newtag}}
    153 fn Event-LeftBarMouseDown {
    154 	wi_fnmenu LBar $* &}
    155 
    156 # Actions
    157 fn Action-exec {
    158 	wmiir xwrite /ctl exec $*}
    159 fn Action-quit {
    160 	wmiir xwrite /ctl quit}
    161 fn Action-rehash {
    162 	comm -23 <{ls `{namespace}^/proglist.* >[2]/dev/null | awk -F'.' '{print $NF}'} \
    163 		 <{ps | awk '{print $2}'} |
    164 	while(id=`{read})
    165 		rm `{namespace}^/proglist.$id
    166 	wi_proglist $PATH >$progs_file}
    167 fn Action-showkeys {
    168 	echo $wmiikeyhelp | xmessage -file -
    169 }
    170 fn Action-status {
    171 	flag x -; flag r -
    172 	if(wmiir remove /rbar/status >[2]/dev/null)
    173 		sleep 2
    174 	echo colors $wmiinormcol | wmiir create /rbar/status
    175 	while(status | wmiir write /rbar/status)
    176 		sleep 1
    177 }
    178 
    179 # Source Variables, &c
    180 if(~ $0 ('' */)wmiirc_local.rc)
    181 	wi_notice This file should not be named wmiirc_local.rc
    182 if not
    183 	. `{wi_script -f wmiirc_local.rc}
    184 echo colors $wmiinormcol | wmiir create $noticebar
    185 startup
    186 
    187 # Key Bindings
    188 _keys = `{wi_getfuns Key}
    189 fn keygroup {
    190 	wmiikeyhelp = $wmiikeyhelp ^ $wi_newline ^ '  ' ^ $"* ^ $wi_newline}
    191 fn key {
    192 	help=$1; shift
    193 	key=()
    194 	for(k) {
    195 		if(! ~ $k $_keys) {
    196 			ifs=() { wmiikeyhelp = `{
    197 				printf "%s    %- 20s %s\n" $wmiikeyhelp $k $help}}
    198 			key = ($key Key-$k)}}
    199 	~ $#key 0}
    200 
    201 keygroup Moving around
    202 key 'Select the client to the left' $MODKEY-$LEFT || fn $key {
    203 	wmiir xwrite /tag/sel/ctl select left}
    204 key 'Select the client to the right' $MODKEY-$RIGHT || fn $key {
    205 	wmiir xwrite /tag/sel/ctl select right}
    206 key 'Select the client below' $MODKEY-$DOWN || fn $key {
    207 	wmiir xwrite /tag/sel/ctl select down}
    208 key 'Select the client above' $MODKEY-$UP || fn $key {
    209 	wmiir xwrite /tag/sel/ctl select up}
    210 
    211 key 'Toggle between floating and managed layers' $MODKEY-space || fn $key {
    212 	wmiir xwrite /tag/sel/ctl select toggle}
    213 
    214 keygroup Moving through stacks
    215 key 'Select the stack below' $MODKEY-Control-$DOWN || fn $key {
    216 	wmiir xwrite /tag/sel/ctl select down stack}
    217 key 'Select the stack above' $MODKEY-Control-$UP || fn $key {
    218 	wmiir xwrite /tag/sel/ctl select up stack}
    219 
    220 keygroup Moving clients around
    221 key 'Move selected client to the left' $MODKEY-Shift-$LEFT || fn $key {
    222 	wmiir xwrite /tag/sel/ctl send sel left}
    223 key 'Move selected client to the right' $MODKEY-Shift-$RIGHT || fn $key {
    224 	wmiir xwrite /tag/sel/ctl send sel right}
    225 key 'Move selected client down' $MODKEY-Shift-$DOWN || fn $key {
    226 	wmiir xwrite /tag/sel/ctl send sel down}
    227 key 'Move selected client up' $MODKEY-Shift-$UP || fn $key {
    228 	wmiir xwrite /tag/sel/ctl send sel up}
    229 
    230 key 'Toggle selected client between floating and managed layers' $MODKEY-Shift-space || fn $key {
    231 	wmiir xwrite /tag/sel/ctl send sel toggle}
    232 
    233 keygroup Client actions
    234 key 'Toggle selected client''s fullsceen state' $MODKEY-f || fn $key {
    235 	wmiir xwrite /client/sel/ctl Fullscreen toggle}
    236 key 'Close client' $MODKEY-Shift-c || fn $key {
    237 	wmiir xwrite /client/sel/ctl kill}
    238 
    239 keygroup Changing column modes
    240 key 'Set column to default mode' $MODKEY-d || fn $key {
    241 	wmiir xwrite /tag/sel/ctl colmode sel default-max}
    242 key 'Toggle between floating and managed layers' $MODKEY-s || fn $key {
    243 	wmiir xwrite /tag/sel/ctl colmode sel stack-max}
    244 key 'Set column to max mode' $MODKEY-m || fn $key {
    245 	wmiir xwrite /tag/sel/ctl colmode sel stack+max}
    246 
    247 keygroup Running programs
    248 key 'Open wmii actions menu' $MODKEY-a || fn $key {
    249 	Action `{wi_actions | wimenu -h $hist.action -n $histlen} &}
    250 key 'Open program menu' $MODKEY-p || fn $key {
    251 	ifs=() { cmd = `{wimenu -h $hist.prog -n $histlen <$progs_file} }
    252 	wi_runcmd $cmd & }
    253 
    254 key 'Launch a terminal' $MODKEY-Return || fn $key {
    255 	wi_runcmd $WMII_TERM &}
    256 
    257 keygroup Other
    258 key 'Toggle all other key bindings' $MODKEY-Control-t || fn $key {
    259 	switch(`{wmiir read /keys | wc -l}) {
    260 	case 0 1
    261 		wmiir xwrite /keys $keys
    262 		wmiir xwrite /ctl grabmod $MODKEY
    263 	case *
    264 		ifs=() { keys=`{wmiir read /keys} }
    265 		wmiir xwrite /keys $MODKEY-Control-t
    266 		wmiir xwrite /ctl grabmod Mod3
    267 	}}
    268 
    269 keygroup Tag actions
    270 key 'Change to another tag' $MODKEY-t || fn $key {
    271 	tag=`{wi_tags | wimenu -h $hist.tag -n 50} && wmiir xwrite /ctl view $tag &}
    272 key 'Retag the selected client' $MODKEY-Shift-t || fn $key {
    273 	sel=`{wi_selclient} {
    274 	tag=`{wi_tags | wimenu -h $hist.tag -n 50} && wmiir xwrite /client/$sel/tags $tag } &}
    275 key 'Move to the next tag' $MODKEY-n || fn $key {
    276 	wmiir xwrite /ctl view `{wi_tags | wi_nexttag}}
    277 key 'Move to the previous tag' $MODKEY-b || fn $key {
    278 	wmiir xwrite /ctl view `{wi_tags | sort -r | wi_nexttag}}
    279 
    280 key 'Move to the numbered view' $MODKEY-^`{seq 0 9} || fn $key {
    281 	wmiir xwrite /ctl view `{echo $1 | sed 's/.*-//'}}
    282 key 'Retag selected client with the numbered tag' Shift-$MODKEY-^`{seq 0 9} || fn $key {
    283 	wmiir xwrite /client/sel/tags `{echo $1 | sed 's/.*-//'}}
    284 # WM Configuration
    285 wmiir write /ctl <<!
    286 	grabmod $MODKEY
    287 	border 2
    288 	font $wmiifont
    289 	focuscolors $wmiifocuscol
    290 	normcolors $wmiinormcol
    291 !
    292 setbackground $wmiibackground
    293 
    294 # Source Overrides
    295 Action overridekeys
    296 
    297 # Misc Setup
    298 progs_file=`{namespace}^/proglist.$pid
    299 hist=`{echo $WMII_CONFPATH | sed 's,:.*,/,'}^/history
    300 histlen=5000
    301 Action status &
    302 Action rehash &
    303 
    304 # Tag Bar Setup
    305 ifs=$wi_newline {
    306 	rc -c 'wmiir rm /lbar/^$*' >[2]/dev/null \
    307 		`{comm -23 <{wmiir ls /lbar} \
    308 			   <{wi_tags}}
    309 	seltag=`{wi_seltag}
    310 	for(tag in `{wi_tags}) {{
    311 		if(~ $tag $seltag)
    312 			echo colors $wmiifocuscol $wi_newline label $tag
    313 		if not
    314 			echo colors $wmiinormcol $wi_newline label $tag
    315 		} | wmiir create /lbar/$tag}}
    316 wi_eventloop