Set a variable for the CID like you did for the channel...

you set %DesktopPopup.LastChannel to $chan or #
so also set %DesktopPopup.LastCID to $cid

then use the /scid command in your script with the new variable %DesktopPopup.LastCID

Code:
menu @DesktopPopup {
  sclick { 
    showmirc $iif($appstate == minimized,-r,-s)
    scid %DesktopPopup.LastCID window -a %DesktopPopup.LastChannel
  }
  rclick { DesktopPopup.doclose $iif($mouse.key & 4,-s) }
  $DesktoPopup.doclose
}
;DesktopPopup.LastChannel stores the channel which "produce" the DestopPopup
;DesktopPopup.LastCID stores the connection ID (CID) which "produce" the DesktopPopup