summaryrefslogtreecommitdiffstats
path: root/window.c
diff options
context:
space:
mode:
authorThomas Adam <thomas@xteddy.org>2021-08-14 01:34:54 +0100
committerThomas Adam <thomas@xteddy.org>2021-08-14 01:34:54 +0100
commit54773d23b5ceb779c524dcac6bf3b848886fb6d6 (patch)
tree5c60007637121f63c8c730a04f4e8e741577c21a /window.c
parent4c07367bfe626fce990f5b5b2d00516ae8249a93 (diff)
parent63aa96864280ff07f706ebbae302b7c15abb964f (diff)
Merge branch 'obsd-master' into master
Diffstat (limited to 'window.c')
-rw-r--r--window.c51
1 files changed, 51 insertions, 0 deletions
diff --git a/window.c b/window.c
index ce02df9e..5fcb547d 100644
--- a/window.c
+++ b/window.c
@@ -465,6 +465,52 @@ window_has_pane(struct window *w, struct window_pane *wp)
return (0);
}
+void
+window_update_focus(struct window *w)
+{
+ if (w != NULL) {
+ log_debug("%s: @%u", __func__, w->id);
+ window_pane_update_focus(w->active);
+ }
+}
+
+void
+window_pane_update_focus(struct window_pane *wp)
+{
+ struct client *c;
+ int focused = 0;
+
+ if (wp != NULL) {
+ if (wp != wp->window->active)
+ focused = 0;
+ else {
+ TAILQ_FOREACH(c, &clients, entry) {
+ if (c->session != NULL &&
+ c->session->attached != 0 &&
+ (c->flags & CLIENT_FOCUSED) &&
+ c->session->curw->window == wp->window) {
+ focused = 1;
+ break;
+ }
+ }
+ }
+ if (!focused && (wp->flags & PANE_FOCUSED)) {
+ log_debug("%s: %%%u focus out", __func__, wp->id);
+ if (wp->base.mode & MODE_FOCUSON)
+ bufferevent_write(wp->event, "\033[O", 3);
+ notify_pane("pane-focus-out", wp);
+ wp->flags &= ~PANE_FOCUSED;
+ } else if (focused && (~wp->flags & PANE_FOCUSED)) {
+ log_debug("%s: %%%u focus in", __func__, wp->id);
+ if (wp->base.mode & MODE_FOCUSON)
+ bufferevent_write(wp->event, "\033[I", 3);
+ notify_pane("pane-focus-in", wp);
+ wp->flags |= PANE_FOCUSED;
+ } else
+ log_debug("%s: %%%u focus unchanged", __func__, wp->id);
+ }
+}
+
int
window_set_active_pane(struct window *w, struct window_pane *wp, int notify)
{
@@ -478,6 +524,11 @@ window_set_active_pane(struct window *w, struct window_pane *wp, int notify)
w->active->active_point = next_active_point++;
w->active->flags |= PANE_CHANGED;
+ if (options_get_number(global_options, "focus-events")) {
+ window_pane_update_focus(w->last);
+ window_pane_update_focus(w->active);
+ }
+
tty_update_window_offset(w);
if (notify)