shithub: riow

ref: 92b2606926a90158e8c9c6ecb0c73c93e5ac424b
dir: /riow/

View raw version
#!/bin/rc
rfork ne

alt=0
ctl=0
glenda=0
shift=0

fn scrsize {
	s=`{syscall -o read 0 buf 60 </dev/screen >[2]/dev/null}
	screenw=$s(4)
	screenh=$s(5)
}

fn fullscreen {
	scrsize
	for(f in /dev/wsys/*){
		a=`{syscall -o read 0 buf 64 <$f/wctl >[2]/dev/null}
		if(~ $a(5) current){
			winid=`{basename $f}
			if(~ $a(1) 0 && ~ $a(2) 0 && ~ $a(3) $screenw && ~ $a(4) $screenh)
				echo resize -r `{eval echo '$winsize_'^$winid} >$f/wctl
			if not {
				eval 'winsize_'^$winid'=$a(1 2 3 4)'
				echo resize -r 0 0 9999 9999 >$f/wctl
			}
		}
	}
}

fn handle {
	# remember old states
	oalt=$alt
	octl=$ctl
	oglenda=$glenda
	oshift=$shift

	m=$1
	state=0
	if(~ $1 k)
		state=1
	shift

	key=''
	if(~ $state K && ~ $#* 0){
		alt=0
		ctl=0
		glenda=0
		shift=0
	}
	if not {
		while(! ~ $#* 0){
			if(~ $1 alt || ~ $1 ctl || ~ $1 glenda || ~ $1 shift){
				eval '$1=$state'
			}
			if not {
				# only react to 'c'
				if(~ $m c) 
					key=$1
			}
			shift
		}
	}
	if(~ $key enter)
		window
	if(~ $key f)
		fullscreen
}

while(s=`{read}){
	handle $s
}