mirror of
				https://github.com/tmux/tmux.git
				synced 2025-11-04 00:56:10 +00:00 
			
		
		
		
	Add hooks for alerts (bell, silence, activity), from Thomas Adam.
This commit is contained in:
		
							
								
								
									
										23
									
								
								alerts.c
									
									
									
									
									
								
							
							
						
						
									
										23
									
								
								alerts.c
									
									
									
									
									
								
							@@ -29,6 +29,7 @@ int	alerts_enabled(struct window *, int);
 | 
			
		||||
void	alerts_callback(int, short, void *);
 | 
			
		||||
void	alerts_reset(struct window *);
 | 
			
		||||
 | 
			
		||||
void	alerts_run_hook(struct session *, struct winlink *, int);
 | 
			
		||||
int	alerts_check_all(struct session *, struct winlink *);
 | 
			
		||||
int	alerts_check_bell(struct session *, struct winlink *);
 | 
			
		||||
int	alerts_check_activity(struct session *, struct winlink *);
 | 
			
		||||
@@ -55,8 +56,6 @@ alerts_callback(__unused int fd, __unused short events, __unused void *arg)
 | 
			
		||||
 | 
			
		||||
	RB_FOREACH(w, windows, &windows) {
 | 
			
		||||
		RB_FOREACH(s, sessions, &sessions) {
 | 
			
		||||
			if (s->flags & SESSION_UNATTACHED)
 | 
			
		||||
				continue;
 | 
			
		||||
			RB_FOREACH(wl, winlinks, &s->windows) {
 | 
			
		||||
				if (wl->window != w)
 | 
			
		||||
					continue;
 | 
			
		||||
@@ -73,6 +72,22 @@ alerts_callback(__unused int fd, __unused short events, __unused void *arg)
 | 
			
		||||
	alerts_fired = 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
alerts_run_hook(struct session *s, struct winlink *wl, int flags)
 | 
			
		||||
{
 | 
			
		||||
	struct cmd_find_state	 fs;
 | 
			
		||||
 | 
			
		||||
	if (cmd_find_from_winlink(&fs, s, wl) != 0)
 | 
			
		||||
		return;
 | 
			
		||||
 | 
			
		||||
	if (flags & WINDOW_BELL)
 | 
			
		||||
		hooks_run(s->hooks, NULL, &fs, "alert-bell");
 | 
			
		||||
	if (flags & WINDOW_SILENCE)
 | 
			
		||||
		hooks_run(s->hooks, NULL, &fs, "alert-silence");
 | 
			
		||||
	if (flags & WINDOW_ACTIVITY)
 | 
			
		||||
		hooks_run(s->hooks, NULL, &fs, "alert-activity");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int
 | 
			
		||||
alerts_check_all(struct session *s, struct winlink *wl)
 | 
			
		||||
{
 | 
			
		||||
@@ -81,8 +96,10 @@ alerts_check_all(struct session *s, struct winlink *wl)
 | 
			
		||||
	alerts  = alerts_check_bell(s, wl);
 | 
			
		||||
	alerts |= alerts_check_activity(s, wl);
 | 
			
		||||
	alerts |= alerts_check_silence(s, wl);
 | 
			
		||||
	if (alerts != 0)
 | 
			
		||||
	if (alerts != 0) {
 | 
			
		||||
		alerts_run_hook(s, wl, alerts);
 | 
			
		||||
		server_status_session(s);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return (alerts);
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										16
									
								
								cmd-find.c
									
									
									
									
									
								
							
							
						
						
									
										16
									
								
								cmd-find.c
									
									
									
									
									
								
							@@ -879,6 +879,22 @@ cmd_find_from_session(struct cmd_find_state *fs, struct session *s)
 | 
			
		||||
	return (0);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* Find state from a winlink. */
 | 
			
		||||
int
 | 
			
		||||
cmd_find_from_winlink(struct cmd_find_state *fs, struct session *s,
 | 
			
		||||
    struct winlink *wl)
 | 
			
		||||
{
 | 
			
		||||
	cmd_find_clear_state(fs, NULL, 0);
 | 
			
		||||
 | 
			
		||||
	fs->s = s;
 | 
			
		||||
	fs->wl = wl;
 | 
			
		||||
	fs->w = wl->window;
 | 
			
		||||
	fs->wp = wl->window->active;
 | 
			
		||||
 | 
			
		||||
	cmd_find_log_state(__func__, fs);
 | 
			
		||||
	return (0);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* Find state from a window. */
 | 
			
		||||
int
 | 
			
		||||
cmd_find_from_window(struct cmd_find_state *fs, struct window *w)
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										10
									
								
								tmux.1
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								tmux.1
									
									
									
									
									
								
							@@ -3224,6 +3224,16 @@ Each hook has a
 | 
			
		||||
.Em name .
 | 
			
		||||
The following hooks are available:
 | 
			
		||||
.Bl -tag -width "XXXXXXXXXXXXXXXX"
 | 
			
		||||
.It alert-activity
 | 
			
		||||
Run when a window has activity.
 | 
			
		||||
See
 | 
			
		||||
.Ic monitor-activity .
 | 
			
		||||
.It alert-bell
 | 
			
		||||
Run when a window has received a bell.
 | 
			
		||||
.It alert-silence
 | 
			
		||||
Run when a window has been silent.
 | 
			
		||||
See
 | 
			
		||||
.Ic monitor-silence .
 | 
			
		||||
.It client-attached
 | 
			
		||||
Run when a client is attached.
 | 
			
		||||
.It client-detached
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										2
									
								
								tmux.h
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								tmux.h
									
									
									
									
									
								
							@@ -1780,6 +1780,8 @@ void		 cmd_find_copy_state(struct cmd_find_state *,
 | 
			
		||||
void		 cmd_find_log_state(const char *, struct cmd_find_state *);
 | 
			
		||||
int		 cmd_find_from_session(struct cmd_find_state *,
 | 
			
		||||
		     struct session *);
 | 
			
		||||
int		 cmd_find_from_winlink(struct cmd_find_state *,
 | 
			
		||||
		     struct session *, struct winlink *);
 | 
			
		||||
int		 cmd_find_from_window(struct cmd_find_state *, struct window *);
 | 
			
		||||
int		 cmd_find_from_pane(struct cmd_find_state *,
 | 
			
		||||
		     struct window_pane *);
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user