# new window code by shade. 

# warn the user if other windows are open.
if ([$#winrefs()]>1) {
  ge due to the way argon handles windowing, you are advised to close all
  ge windows except the main one, /dump all, and reload argon.}

# ok, here are our main window aliases.
@a.loadtime=time()
do ^window name $encode($winnum() $a.loadtime) 
do ^window remove $sar(g/ /,/$winnicklist()) 
do ^window add $sar(g/ /,/$mychannels())

alias _w.new {
  ^window new hide swap last double on split $a.topbar
  ^window name $encode($winnum() $time())
  ge created window \#$winnum() at $_fixmtime().}

alias _w.kill {
  if (winnum()!=1) {
    @_w.tmp=winnum()
    if ([$winnicklist()]) {
      ^part $sar(g/ /,/$winnicklist())}
    ^window kill
    ge window \#$_w.tmp killed - window \#$winnum() activated.} else {
    ge you can't kill the main window!}}

alias _w.info {
  ^local bb
  fe ($winrefs()) aa {
    push bb $aa \($winnicklist($aa)\),}
  ge active windows\: $bb}

alias _w.next {
  if ([$#winrefs()]>1) {
    ^window next
    ge window \#$winnum() activated.} else {
    _w.info}}

alias _w.previous {
  if ([$#winrefs()]>1) {
    ^window previous
    ge window \#$winnum() activated.} else {
    _w.info}}

alias _w.swap {
  switch ($0) {
  (+) {_w.next}
  (-) {_w.previous}
  ($winnum()) {
    ge this is window \#$winnum()!}
  (*) {
    if (match($0 $winrefs())) {
      ^window swap $0
      ge window \#$winnum() activated.} else {
      _w.info}}}}

alias _w.uptime {
  ^local aa $decode($winnam())
  ge window \#$word(0 $aa) created at $_fixmtime($word(1 $aa)).}

# and here is our interface.
alias wc _w.new
alias wn _w.next
alias wp _w.previous
alias wj {
  _w.new
  join $*}
alias wk _w.kill
alias ws _w.swap $0
alias wq {
  if ([$*]) {
    query $0
    ^window add $0} else {
   ^window remove $Q
   query}}
bind meta1-^I parse_command _w.next
bind ^W meta5_character
bind meta5-p parse_command _w.previous
bind meta5-c parse_command _w.new
bind meta5-k parse_command _w.kill
bind meta5-n parse_command _w.next
bind meta5-space parse_command _w.next
bind meta5-u parse_command _w.uptime
bind meta5-i parse_command _w.info
bind meta5-1 parse_command _w.swap 1
bind meta5-2 parse_command _w.swap 2
bind meta5-3 parse_command _w.swap 3
bind meta5-4 parse_command _w.swap 4
bind meta5-5 parse_command _w.swap 5
bind meta5-6 parse_command _w.swap 6
bind meta5-7 parse_command _w.swap 7
bind meta5-8 parse_command _w.swap 8
bind meta5-9 parse_command _w.swap 9

# now we need something to handle the nicklist and ^x correctly.
on #-join_me 1 * {
  ^window add $0}
on #-leave 1 * {
  if ([$0]==N) {
    ^window remove $1}}
on #-kick 1 * {
  if ([$0]==N) {
    ^window remove $2}}
alias _switch_channels {
  ^join $nextw($C $pattern(#* $winnicklist()))}
bind ^x parse_command _switch_channels

alias nextw {
  ^local aa $findw($*)
  ^local bb $1-
  @function_return=aa+1==#bb?word(0 $bb):word(${aa+1} $bb)}
#sjk'97
