From: Mikael Magnusson <mikachu@gmail.com>
To: Ray Andrews <rayandrews@eastlink.ca>
Cc: Zsh Users <zsh-users@zsh.org>
Subject: Re: command on switching terminals?
Date: Mon, 8 Jan 2018 07:25:12 +0100 [thread overview]
Message-ID: <CAHYJk3TJa=XX0e-wLQVARyi=_Vqyz+WYd=o1-1uuxqk37E7poQ@mail.gmail.com> (raw)
In-Reply-To: <CAHYJk3S=p9xtwZKDj-rD+UPCb4TdWN0dSCiqoqYdO0tExuCRog@mail.gmail.com>
On Sat, Jan 6, 2018 at 11:20 PM, Mikael Magnusson <mikachu@gmail.com> wrote:
> On Sat, Jan 6, 2018 at 6:33 AM, Ray Andrews <rayandrews@eastlink.ca> wrote:
>> Is it possible for zsh to know when the terminal in which it is running has
>> awakened by having the mouse moved into that window? I understand that it's
>> the window manager that decides which terminal is active of course, but
>> perhaps zsh knows when it is put to sleep by the mouse moving out of it's
>> window, and also knows when it has been awakened again? I have a utility
>> that lets you hotkey a mouse jump between terminals so as to jump between
>> them without having to reach for the mouse itself, and I can call it fine
>> within a function, but I'd like to be able to also execute some code after
>> each jump but in the new window. As it is, zsh just wakes up without
>> seeming to know it's been asleep so there's nothing to 'attach' any commands
>> to. precmd() and preexec() are not aroused. Any commands inside the
>> calling function placed after the command to jump to the new terminal are
>> executed in the old terminal, which is not surprising, so it would have to
>> depend on the awakened terminal knowing it's been awakened. Sorta like
>> precmd but hooked to the activation of the terminal. I understand that this
>> might be outside of zsh's domain.
>
> You can, yes. Note that if a program was running in the foreground,
> zsh won't know if the terminal is active or not once that program
> finishes though. I have never found a practical use for this.
>
> # this might work for more terminals but i haven't tested, adjust as needed
> # also check if you already have hooks for zle-line-init/finish and
> adjust those as needed instead
> # note also that leaving/entering a terminal will disable paste
> hilighting when the following stuff is enabled
> # These two hooks will enable and disable the terminal sending an
> escape code to the terminal when it receives/loses focus, since most
> programs won't handle them.
> function _zle_line_init() {
> # enable focus events
> [[ $TERM == rxvt-unicode || $TERM = xterm ]] && printf '\e[?1004h'
> }
>
> function _zle_line_finish() {
> # disable focus events
> [[ $TERM == rxvt-unicode || $TERM = xterm ]] && printf '\e[?1004l'
> }
> zle -N zle-line-init _zle_line_init
> zle -N zle-line-finish _zle_line_finish
>
> # Handle FocusIn/Out events
> bindkey '^[[I' focus-in
> bindkey '^[[O' focus-out
> # you can use two different functions too of course,
> # i just happened to want the same thing to happen in both cases
> # when i was testing this
> zle -N focus-in _focus_handler
> zle -N focus-out _focus_handler
> function _focus_handler() {
> # $WIDGET will be focus-in when terminal receives
> # focus and focus-out when losing it, eg
> if [[ $WIDGET = focus-in ]]; then
> zle -M "hey we got focus"
> fi
> }
I forgot to include these lines,
# this is as close to no-op as you get in menuselect/isearch
bindkey -M menuselect '^[[I' redisplay
bindkey -M menuselect '^[[O' redisplay
bindkey -M isearch '^[[I' redisplay
bindkey -M isearch '^[[O' redisplay
--
Mikael Magnusson
next prev parent reply other threads:[~2018-01-08 6:25 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-01-06 5:33 Ray Andrews
2018-01-06 22:20 ` Mikael Magnusson
2018-01-06 22:45 ` Ray Andrews
2018-01-07 18:48 ` Grant Taylor
2018-01-07 0:51 ` Ray Andrews
2018-01-07 13:24 ` Mikael Magnusson
2018-01-07 16:45 ` Ray Andrews
2018-01-07 18:23 ` Mikael Magnusson
2018-01-07 18:39 ` Grant Taylor
2018-01-07 19:06 ` Ray Andrews
2018-01-07 20:27 ` Bart Schaefer
2018-01-07 20:43 ` Grant Taylor
2018-01-07 21:12 ` Ray Andrews
2018-01-07 21:36 ` Grant Taylor
2018-01-08 1:43 ` Ray Andrews
2018-01-07 20:29 ` Grant Taylor
2018-01-08 6:25 ` Mikael Magnusson [this message]
2018-01-08 6:28 ` Mikael Magnusson
2018-01-08 15:39 ` Ray Andrews
2018-01-08 16:08 ` Peter Stephenson
2018-01-08 16:38 ` Ray Andrews
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAHYJk3TJa=XX0e-wLQVARyi=_Vqyz+WYd=o1-1uuxqk37E7poQ@mail.gmail.com' \
--to=mikachu@gmail.com \
--cc=rayandrews@eastlink.ca \
--cc=zsh-users@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).