mIRC Homepage
Posted By: pball Status window open/close - 29/01/11 06:44 AM
Is there any way to know when a status window is opened/closed?

on disconnect is a decent substitute for when closing but i have to add a timer since the window is open after it disconnects.

on connect isn't a good substitute for when opening a status window since it doesn't connect instantly and can be opened without trying to connect to anything.
Posted By: Tomao Re: Status window open/close - 29/01/11 07:36 AM
Originally Posted By: pball
Is there any way to know when a status window is opened?
You can try something like the code below and place it in mIRC's perform dialog:
Code:
window -a $qt(status window) | echo -a * Status Window's been opened!
As to status window being closed, I'm clueless.
Posted By: jaytea Re: Status window open/close - 29/01/11 08:46 AM
an event for all cases: no. but for most cases you can count on an ACTIVE event triggering:

Code:
on *:active:*:{
  if (!$cid($lactivecid)) {
    ; connection ID $lactivecid was just closed
  }
  ; check if $cid has been saved before, then save it etc. to detect a new window
}


unfortunately this doesn't detect things like windows opened via /server -z, or closed when all other windows are minimized, etc.

you should always try to tie in the actions with your /close, /window and /server commands wherever possible. in general, and as ugly as it sounds, a timer is your only failsafe option. using a delay as high as possible (consider if you need to detect open/close very quickly, if you can afford to be imprecise) and checking for changes in $scon(0) should be relatively low impact.
Posted By: Tomao Re: Status window open/close - 29/01/11 09:27 AM
jaytea, it should've been $scid() :
Quote:
if (!$scid($lactivecid)) {
Posted By: jaytea Re: Status window open/close - 29/01/11 09:38 AM
quite right, thanks!
Posted By: pball Re: Status window open/close - 29/01/11 04:27 PM
It seems we just need on open/close to work with all windows. It makes no sense why they don't.

I'm not gonna bother "hacking" a lot to do this. Like monitor /server and other commands. Doing all of that would probably double the size of my script.

If anyone cares I want this for a script that lets you hide/unhide windows from the switchbar. I hide some @windows and status windows for nets I don't really care about.

I made a nice right click menu which has nice dynamic submenus.
Posted By: Tomao Re: Status window open/close - 29/01/11 06:19 PM
Originally Posted By: pball
It seems we just need on open/close to work with all windows. It makes no sense why they don't.
Not sure if this has been suggested before, but it won't hurt if you post that under the feature suggestions.

* Edit - I just saw you did just that.
Posted By: DJ_Sol Re: Status window open/close - 29/01/11 09:42 PM
For possible solutions, I'd want to know why you want to know if status window has been opened or closed. You can always check for the "status window" on your $scid or $scon.
Posted By: pball Re: Status window open/close - 29/01/11 11:01 PM
Well I said what the script is in my last post, a script to hide windows from the switchbar. But the technical reason I'd like to know when a status window is open/closed is because I have to update the right click menu. So when a new status window is opened I need to update and add that window to the right click options.

If anyone wants to say use $submenu() and $scon() to make a dynamic submenu. That won't work since I need the right click menus to be 3 deep, which I already have working. I just have to run an update to add/remove status windows from the popup..

Code:
Ex. right click option
Hide Windows
-@windows
--@Spam
--@Highlight
-Rizon
--Rizon (Status Window)
--Chans
---#help.script
---#hmm?
--DCC Chats
--Queries
-2nd Network
etc...
Posted By: DJ_Sol Re: Status window open/close - 01/02/11 04:36 PM
When I did what you want to do I used popups.dll. This allowed me to put loops in my menu to scan through the different scons. Other than that I can't think of how you would dynamically list all connections and have 3+ deep nested menus.

Oh, picwin menus. Seems like a lot of work though.

With popups.dll:

Code:
;I wrote this 4 or 5 years ago.
;Change paths to your dll.
;$hget(soulfly,$chan(%ch_i)) is the channel name cleaned up.
;these are all aliases. Load to alias section or add the word alias to each one.
;Window List
chann {
  echo -a chan 1= $1 2= $2
  var %a = $active, %m = $mnick
  mdx_pop New ch 16 16
  mdx_pop SetStyle ch bordericon bordertext
  mdx_pop LoadImg ch icon small $mdx_icon(1x)
  mdx_pop LoadImg ch icon small $mdx_icon(o)
  mdx_pop LoadImg ch icon small $mdx_icon(q)
  mdx_pop LoadImg ch icon small $mdx_icon(w)
  mdx_pop LoadImg ch icon small $mdx_icon(refresh)
  mdx_pop AddItem ch end +D,d 1 $str($chr(160),6) Windows List
  mdx_pop AddItem ch end
  var %sc = $scon(0), %sc_i = 1
  while (%sc_i <= %sc) {
    scon %sc_i | var %sx = $scon(%sc_i), %sn = $scon(%sc_i).mnick
    mdx_pop AddItem ch end 1 $chr(160) Status $str($chr(160),3) ( %sn ) $cr sta_sc %sx
    $iif(!$chan(1),mdx_pop AddItem ch end)
    var %ch = $chan(0), %ch_i = 1 | while (%ch_i <= %ch) {
      mdx_pop AddItem ch end +D $iif(%a == $chan(%ch_i),5,2) $iif(%a == $chan(%ch_i),5,1) $str($chr(160),5) -> $hget(soulfly,$chan(%ch_i)) $cr sta_sc %sx $chan(%ch_i)
      inc %ch_i | if (%ch_i > %ch) mdx_pop AddItem ch end
    }
    var %q = $query(0), %q_i = 1
    $iif(%q != 0,mdx_pop AddItem ch end $+(+D,$chr(44),d) 3 $str($chr(160),5) Whispers)
    while (%q_i <= %q) {
      var %qn = $query(%q_i)
      mdx_pop AddItem ch end $iif($1 == %qn,1,2) 1 $str($chr(160),11) %qn $cr sta_sc %sx %qn
      inc %q_i | if (%q_i > %q) mdx_pop AddItem ch end
    }
    inc %sc_i
  }
  var %w = $window(0), %w_i = 1
  $iif(%w > 1,mdx_pop AddItem ch end $+(+D,$chr(44),d) 4 Windows)
  while (%w_i <= %w) {
    var %wn = $window(%w_i)
    $iif(%wn != @uwho,mdx_pop AddItem ch end $iif($1 == %wn,1,2) 1 $str($chr(160),7) $+($chr(40),-,$chr(41)) $str($chr(160),3) $remove(%wn,@) $cr window -a %wn)
    inc %w_i
  }
  pop1 ch $mouse.dx $mouse.dy
}
sta_sc {
  scid $1
  if ($2) window -a $2
  else window -a "Status Window"
}
;popup
mdx_pop {
if ($isid) return soulfly\dll\popups.dll
else dll soulfly\dll\popups.dll $1-
}
pop1 {
tokenize 32 $dll(soulfly\dll\popups.dll,Popup,$1-)
if ($isid) return $1-
$iif($4- != did not select a menu item,$4-)
}

Posted By: hixxy Re: Status window open/close - 01/02/11 08:28 PM
Code:
alias rebuildmenu {
  var %popupfile = $qt($scriptdir $+ popups.mrc)
  .fopen -o popups %popupfile
  if ($ferr) { return }
  var %ai = 1, %v1, %n = 1
  while ($isalias(___visible $+ %ai)) {
    .alias ___visible $+ %ai
    inc %i
  }
  .fwrite -n popups menu status $chr(123)
  if ($window(@*,0)) {
    .fwrite -n popups @Windows
    var %@i = 1
    while ($window(@*,%@i)) {
      %v1 = $v1
      .alias ___visible $+ %n $chr(123) return $!iif(!$window( %v1 ).tbstate || !$window( %v1 ).sbstate,0,1) $chr(125)
      .fwrite -n popups $+(.,$!iif(!$___visible $+ %n $chr(44) Show $chr(44) Hide) %v1,: $chr(123) window $!iif(!$___visible $+ %n $chr(44) -w3 $chr(44) -w0) $v1 $chr(125))
      inc %@i
      inc %n
    } 
  }
  if ($chat(0)) { 
    .fwrite -n popups .DCC Chats 
    var %chi = 1
    while ($chat(%chi)) {
      %v1 = $v1
      .alias ___visible $+ %n $chr(123) return $!iif(!$window( = $+ %v1 ).tbstate || !$window( = $+ %v1 ).sbstate,0,1) $chr(125)
      .fwrite -n popups $+(..,$!iif(!$___visible $+ %n $chr(44) Show $chr(44) Hide) %v1,:,$chr(123) scon %ni $chr(124) window $!iif(!$___visible $+ %n $chr(44) -w3 $chr(44) -w0) = $+ %v1 $chr(125))
      inc %chi
      inc %n
    }
  }
  var %ni = 1
  while ($scon(%ni)) {
    scon %ni
    .alias ___visible $+ %n $chr(123) scon %ni $chr(124) return $!iif(!$window(status window).tbstate || !$window(status window).sbstate,0,1) $chr(125)
    .fwrite -n popups $scon(%ni).network
    .fwrite -n popups $+(.,$!iif(!$___visible $+ %n $chr(44) Show $chr(44) Hide) $scon(%ni).network (Status Window):,$chr(123) scon %ni $chr(124) window $!iif(!$___visible $+ %n $chr(44) -w3 $chr(44) -w0) "status window" $chr(125))
    inc %n
    if ($chan(0)) {
      .fwrite -n popups .Channels
      var %ci = 1
      while ($chan(%ci)) {
        %v1 = $v1
        .alias ___visible $+ %n $chr(123) scon %ni $chr(124) return $!iif(!$window( %v1 ).tbstate || !$window( %v1 ).sbstate,0,1) $chr(125)
        .fwrite -n popups $+(..,$!iif(!$___visible $+ %n $chr(44) Show $chr(44) Hide) %v1,:,$chr(123) scon %ni $chr(124) window $!iif(!$___visible $+ %n $chr(44) -w3 $chr(44) -w0) %v1 $chr(125))
        inc %ci
        inc %n
      }
    }
    if ($query(0)) {
      %v1 = $v1
      .fwrite -n popups .Queries
      var %qi = 1
      while ($query(%qi)) {
        %v1 = $v1
        .alias ___visible $+ %n $chr(123) scon %ni $chr(124) return $!iif(!$window( %v1 ).tbstate || !$window( %v1 ).sbstate,0,1) $chr(125)
        .fwrite -n popups $+(..,$!iif(!$___visible $+ %n $chr(44) Show $chr(44) Hide) %v1,:,$chr(123) scon %ni $chr(124) window $!iif(!$___visible $+ %n $chr(44) -w3 $chr(44) -w0) %v1 $chr(125))
        inc %qi
        inc %n
      }
    }
    inc %ni
  }
  .fwrite -n popups $chr(125)
  .fclose popups
  .reload -rs %popupfile
}

on *:join:#:{
  if ($nick == $me) { rebuildmenu }
}
on *:part:#:{
  if ($nick == $me) { rebuildmenu }
}
on *:kick:#:{
  if ($knick == $me) { rebuildmenu }
}
on *:quit:{
  if ($nick == $me) { rebuildmenu }
}
on *:connect:{ rebuildmenu }
on *:disconnect:{ rebuildmenu }
on *:open:?:{ rebuildmenu }
on *:close:*:{ rebuildmenu }


Kinda messy but it works and it's fast.

I seriously doubt you'll have any aliases called ___visible<N>, but this script will delete and manage all aliases by that name.

Enjoy smile
Posted By: DJ_Sol Re: Status window open/close - 02/02/11 03:49 AM
haha I didn't think of doing it that way.

I've written code to file before like that using /write and making sure to /load when I was finished. I'm sure using fopen is much better. lol
Posted By: pball Re: Status window open/close - 02/02/11 04:41 AM
@DJ_Sol
I'd rather stay away from dlls

@hixxy
I already have a working script. I personally feel it's better also since all chans, queries, dcc chats, and @windows are all dynamic. Meaning the popups file I make and load only has to be updated and reloaded when a network is open/closed. So checking when a status window is opened/closed is why I made this thread.
Posted By: DJ_Sol Re: Status window open/close - 02/02/11 03:42 PM
Just a quick glance at hixxy's script. It appears that it dynamically creates a menu for you. Which means that when something happens it will write the code for a menu that includes your status window and will allow you to nest the menu as deep as you like.

If you don't like dll's I can't think of any other solution other than this or possibly working with picwin menus. Good luck!
Posted By: hixxy Re: Status window open/close - 02/02/11 07:54 PM
Yeah that was a pretty hideous way of doing it, I don't know what I was thinking!

Here's a much shorter and more functional way:

Code:
alias server {
  server $1-
  rebuildmenu
}
alias vis { 
  scon $1
  return $iif(!$window(status window).sbstate || !$window(status window).tbstate,0,1)
}
alias mnu { 
  if ($istok(begin end,$1,32)) { return - }
  if ($3 isnum) { scon $3 }
  if ($($+($,$2,$chr(40),$1,$chr(41)),2)) { 
    return $iif($window($iif($2 == chat,=) $+ $($+($,$2,$chr(40),$1,$chr(41)),2)).sbstate || $window($iif($2 == chat,=) $+ $&
      $($+($,$2,$chr(40),$1,$chr(41)),2)).tbstate,Hide,Show) $($+($,$2,$chr(40),$1,$chr(41)),2) : window $iif($window($iif($2 == chat,=) $+ $&
      $($+($,$2,$chr(40),$1,$chr(41)),2)).sbstate || $window($iif($2 == chat,=) $+ $($+($,$2,$chr(40),$1,$chr(41)),2)).tbstate,-w0,-w3) $iif($2 == chat,=) $+ $($+($,$2,$chr(40),$1,$chr(41)),2) 
  }
}
alias mnuwindows {
  if ($istok(begin end,$1,32)) { return - }
  if ($window(@*,$1)) return $iif($window(@*,$1).sbstate || $window(@*,$1).tbstate,Hide,Show) $window(@*,$1) : window $iif($window(@*,$1).sbstate || $window(@*,$1).tbstate,-w0,-w3) $window(@*,$1)
}
alias rebuildmenu {
  var %popupfile = $qt($scriptdir $+ popups.mrc)
  .fopen -o popups %popupfile
  if ($ferr) { return }
  .fwrite -n popups menu status $chr(123)
  var %i = 1
  while ($scon(%i)) {
    scon %i
    .fwrite -n popups $scon(%i).network
    .fwrite -n popups .$iif($vis( %i ),Hide,Show) $scon(%i).network (Status Window) : window $!iif($vis( %i ),-w0,-w3) "status window"
    .fwrite -n popups .$iif($chan(0),Channels)
    .fwrite -n popups ..$submenu($mnu($1,chan, %i ))
    .fwrite -n popups .$iif($query(0),Queries)
    .fwrite -n popups ..$submenu($mnu($1,query, %i ))
    inc %i
  }
  .fwrite -n popups $!iif($chat(0),DCC Chats)
  .fwrite -n popups .$submenu($mnu($1,chat))
  .fwrite -n popups $!iif($window(@*,0),@windows)
  .fwrite -n popups .$submenu($mnuwindows($1))
  .fwrite -n popups $chr(125)
  .fclose popups
  .reload -rs %popupfile
}

on *:active:*:{
  if (!$istok(%popup_cids,$cid,32)) { 
    rebuildmenu
    set %popup_cids $addtok(%popup_cids,$cid,32) 
  }
  elseif (!$scid($lactivecid)) {
    rebuildmenu
    if ($remtok(%popup_cids,$lactivecid,1,32)) { set %popup_cids $v1 }
    else { unset %popup_cids }
  }
}


Seems to work perfectly! Let me know if there's anything it doesn't catch.
Posted By: pball Re: Status window open/close - 03/02/11 05:55 AM
I really appreciate that you are trying to help but you are not addressing the issue this thread was made for. I have a working script with multi level deep dynamic right click menus already.

Can we please get back on topic. I simply want to know when a status window is opened/closed without doing anything too round about.
Posted By: hixxy Re: Status window open/close - 03/02/11 10:35 AM
The event at the bottom does just that..

Code:
on *:active:*:{
  if (!$istok(%popup_cids,$cid,32)) { 
    rebuildmenu
    set %popup_cids $addtok(%popup_cids,$cid,32) 
    ; Status window opening.
  }
  elseif (!$scid($lactivecid)) {
    rebuildmenu
    if ($remtok(%popup_cids,$lactivecid,1,32)) { set %popup_cids $v1 }
    else { unset %popup_cids }
    ; Status window closing.
  }
}


The only thing it doesn't address is things like /server -z, which opens a new server window but doesn't activate it, which is why I aliased the /server command at the top.

I wouldn't say any of that is "too round about" and it does what you ask for, no?
Posted By: pball Re: Status window open/close - 04/02/11 12:44 AM
Well it improves on what I have currently but I found a bit of bug somewhere. When I'm in a debugging mood I'll play with it more and see what the cause is.
Posted By: DJ_Sol Re: Status window open/close - 04/02/11 05:18 AM
Originally Posted By: pball
Can we please get back on topic. I simply want to know when a status window is opened/closed without doing anything too round about.


Oh, well in that case. No, you are out of luck. Or you can try Hixxy's idea.
Posted By: hixxy Re: Status window open/close - 04/02/11 12:16 PM
If you're using my code, to keep the menu up to date it should rebuild the menu on start, easy fix:

Code:
on *:start:{ rebuildmenu }


If you're using your own, I don't know :P
Posted By: pball Re: Status window open/close - 04/02/11 06:21 PM
The second version of your script is very similar to what I have. Including how you did the $submenu() stuff. I just loop through making my popup text file a bit differently and have it organized another way.

Code:
on *:start: hw_update
on *:connect: hw_update
on *:disconnect: .timer -im 1 100 hw_update
on *:load: hw_update
on *:unload:{ .unload -rs $scriptdirhide_windows.txt | .remove $scriptdirhide_windows.txt }

That's what I have for updating it, that does a pretty good job. Only thing those don't do it update when you open a status and don't connect.

I guess I'll just leave it at that for now. I just prefer making scripts as bullet proof as possible
Posted By: hixxy Re: Status window open/close - 04/02/11 07:05 PM
For that you can use:

Code:
alias server { 
  server $1-
  if (-*n* iswm $1) || (-*z* iswm $1) { hw_update }
}
Posted By: pball Re: Status window open/close - 04/02/11 11:58 PM
Thanks for that.

I had a genius idea but just like the on open/close it doesn't really work that well. I though why not update it when you right click. But on hotlink only works when clicking over text and there isn't a general on click type command.
Posted By: hixxy Re: Status window open/close - 05/02/11 12:11 AM
This is possible too, although I won't say it's clean:

Code:
on *:start:{ .timer -h 0 50 rc_check }
alias rc_check {
  if ($mouse.key & 16) && (!%floodprotection) { 
    hw_update
    inc -u5 %floodprotection
  }
}


I haven't tried it but I doubt the menu will update prior to it opening. I suspect you will have to right click, then right click again to see the updated menu.

Your best bet would be to use a small custom dll rather than all of these hacks.

Btw, the reason for the flood protection in the above script is because the script catches about 6 right clicks in the time it takes a menu to open laugh
© mIRC Discussion Forums