Merge branch 'obsd-master'

pull/1050/head
Thomas Adam 2017-08-23 12:01:13 +01:00
commit 3b40f8e42c
6 changed files with 88 additions and 61 deletions

View File

@ -30,12 +30,13 @@ static int alerts_enabled(struct window *, int);
static void alerts_callback(int, short, void *); static void alerts_callback(int, short, void *);
static void alerts_reset(struct window *); static void alerts_reset(struct window *);
static int alerts_action_applies(struct winlink *, const char *);
static int alerts_check_all(struct window *); static int alerts_check_all(struct window *);
static int alerts_check_bell(struct window *); static int alerts_check_bell(struct window *);
static int alerts_check_activity(struct window *); static int alerts_check_activity(struct window *);
static int alerts_check_silence(struct window *); static int alerts_check_silence(struct window *);
static void alerts_set_message(struct session *, struct window *, static void alerts_set_message(struct winlink *, const char *,
struct winlink *, const char *, int, int); const char *);
static TAILQ_HEAD(, window) alerts_list = TAILQ_HEAD_INITIALIZER(alerts_list); static TAILQ_HEAD(, window) alerts_list = TAILQ_HEAD_INITIALIZER(alerts_list);
@ -67,12 +68,33 @@ alerts_callback(__unused int fd, __unused short events, __unused void *arg)
alerts_fired = 0; alerts_fired = 0;
} }
static int
alerts_action_applies(struct winlink *wl, const char *name)
{
int action;
/*
* {bell,activity,silence}-action determines when to alert: none means
* nothing happens, current means only do something for the current
* window and other means only for windows other than the current.
*/
action = options_get_number(wl->session->options, name);
if (action == ALERT_ANY)
return (1);
if (action == ALERT_CURRENT)
return (wl == wl->session->curw);
if (action == ALERT_OTHER)
return (wl != wl->session->curw);
return (0);
}
static int static int
alerts_check_all(struct window *w) alerts_check_all(struct window *w)
{ {
int alerts; int alerts;
alerts = alerts_check_bell(w); alerts = alerts_check_bell(w);
alerts |= alerts_check_activity(w); alerts |= alerts_check_activity(w);
alerts |= alerts_check_silence(w); alerts |= alerts_check_silence(w);
return (alerts); return (alerts);
@ -173,21 +195,22 @@ alerts_check_bell(struct window *w)
wl->session->flags &= ~SESSION_ALERTED; wl->session->flags &= ~SESSION_ALERTED;
TAILQ_FOREACH(wl, &w->winlinks, wentry) { TAILQ_FOREACH(wl, &w->winlinks, wentry) {
if (wl->flags & WINLINK_BELL) /*
continue; * Bells are allowed even if there is an existing bell (so do
* not check WINLINK_BELL).
*/
s = wl->session; s = wl->session;
if (s->curw != wl) { if (s->curw != wl)
wl->flags |= WINLINK_BELL; wl->flags |= WINLINK_BELL;
notify_winlink("alert-bell", wl); if (!alerts_action_applies(wl, "bell-action"))
} continue;
notify_winlink("alert-bell", wl);
if (s->flags & SESSION_ALERTED) if (s->flags & SESSION_ALERTED)
continue; continue;
s->flags |= SESSION_ALERTED; s->flags |= SESSION_ALERTED;
alerts_set_message(s, w, wl, "Bell", alerts_set_message(wl, "Bell", "visual-bell");
options_get_number(s->options, "bell-action"),
options_get_number(s->options, "visual-bell"));
} }
return (WINDOW_BELL); return (WINDOW_BELL);
@ -211,18 +234,17 @@ alerts_check_activity(struct window *w)
if (wl->flags & WINLINK_ACTIVITY) if (wl->flags & WINLINK_ACTIVITY)
continue; continue;
s = wl->session; s = wl->session;
if (s->curw != wl) { if (s->curw != wl)
wl->flags |= WINLINK_ACTIVITY; wl->flags |= WINLINK_ACTIVITY;
notify_winlink("alert-activity", wl); if (!alerts_action_applies(wl, "activity-action"))
} continue;
notify_winlink("alert-activity", wl);
if (s->flags & SESSION_ALERTED) if (s->flags & SESSION_ALERTED)
continue; continue;
s->flags |= SESSION_ALERTED; s->flags |= SESSION_ALERTED;
alerts_set_message(s, w, wl, "Activity", alerts_set_message(wl, "Activity", "visual-activity");
options_get_number(s->options, "activity-action"),
options_get_number(s->options, "visual-activity"));
} }
return (WINDOW_ACTIVITY); return (WINDOW_ACTIVITY);
@ -246,64 +268,48 @@ alerts_check_silence(struct window *w)
if (wl->flags & WINLINK_SILENCE) if (wl->flags & WINLINK_SILENCE)
continue; continue;
s = wl->session; s = wl->session;
if (s->curw != wl) { if (s->curw != wl)
wl->flags |= WINLINK_SILENCE; wl->flags |= WINLINK_SILENCE;
notify_winlink("alert-silence", wl); if (!alerts_action_applies(wl, "silence-action"))
} continue;
notify_winlink("alert-silence", wl);
if (s->flags & SESSION_ALERTED) if (s->flags & SESSION_ALERTED)
continue; continue;
s->flags |= SESSION_ALERTED; s->flags |= SESSION_ALERTED;
alerts_set_message(s, w, wl, "Silence", alerts_set_message(wl, "Silence", "visual-silence");
options_get_number(s->options, "silence-action"),
options_get_number(s->options, "visual-silence"));
} }
return (WINDOW_SILENCE); return (WINDOW_SILENCE);
} }
static void static void
alerts_set_message(struct session *s, struct window *w, struct winlink *wl, alerts_set_message(struct winlink *wl, const char *type, const char *option)
const char *type, int action, int visual)
{ {
struct client *c; struct client *c;
int flag; int visual;
/* /*
* We have found an alert (bell, activity or silence), so we need to * We have found an alert (bell, activity or silence), so we need to
* pass it on to the user. For each client attached to this session, * pass it on to the user. For each client attached to this session,
* decide whether a bell (or visual message) is needed. * decide whether a bell, message or both is needed.
*
* {bell,activity,silence}-action determines when we alert: none means
* nothing happens, current means we only do something for the current
* window and other means only for windows other than the current.
* *
* If visual-{bell,activity,silence} is on, then a message is * If visual-{bell,activity,silence} is on, then a message is
* substituted for a bell; if it is off, a bell is sent as normal; both * substituted for a bell; if it is off, a bell is sent as normal; both
* mean both a bell and visual message is sent. * mean both a bell and message is sent.
*/ */
if (action == ALERT_NONE) visual = options_get_number(wl->session->options, option);
return;
TAILQ_FOREACH(c, &clients, entry) { TAILQ_FOREACH(c, &clients, entry) {
if (c->session != s || c->flags & CLIENT_CONTROL) if (c->session != wl->session || c->flags & CLIENT_CONTROL)
continue;
flag = 0;
if (action == ALERT_ANY)
flag = 1;
else if (action == ALERT_CURRENT)
flag = (c->session->curw->window == w);
else if (action == ALERT_OTHER)
flag = (c->session->curw->window != w);
if (!flag)
continue; continue;
if (visual == VISUAL_OFF || visual == VISUAL_BOTH) if (visual == VISUAL_OFF || visual == VISUAL_BOTH)
tty_putcode(&c->tty, TTYC_BEL); tty_putcode(&c->tty, TTYC_BEL);
if (visual == VISUAL_OFF) if (visual == VISUAL_OFF)
continue; continue;
if (c->session->curw->window == w) if (c->session->curw == wl)
status_message_set(c, "%s in current window", type); status_message_set(c, "%s in current window", type);
else else
status_message_set(c, "%s in window %d", type, wl->idx); status_message_set(c, "%s in window %d", type, wl->idx);

View File

@ -190,7 +190,7 @@ args_print(struct args *args)
int int
args_has(struct args *args, u_char ch) args_has(struct args *args, u_char ch)
{ {
return (args_find(args, ch) == NULL ? 0 : 1); return (args_find(args, ch) != NULL);
} }
/* Set argument value in the arguments tree. */ /* Set argument value in the arguments tree. */

View File

@ -30,8 +30,8 @@ const struct cmd_entry cmd_choose_tree_entry = {
.name = "choose-tree", .name = "choose-tree",
.alias = NULL, .alias = NULL,
.args = { "F:f:O:st:w", 0, 1 }, .args = { "F:f:NO:st:w", 0, 1 },
.usage = "[-sw] [-F format] [-f filter] [-O sort-order] " .usage = "[-Nsw] [-F format] [-f filter] [-O sort-order] "
CMD_TARGET_PANE_USAGE, CMD_TARGET_PANE_USAGE,
.target = { 't', CMD_FIND_PANE, 0 }, .target = { 't', CMD_FIND_PANE, 0 },
@ -44,8 +44,8 @@ const struct cmd_entry cmd_choose_client_entry = {
.name = "choose-client", .name = "choose-client",
.alias = NULL, .alias = NULL,
.args = { "F:f:O:t:", 0, 1 }, .args = { "F:f:NO:t:", 0, 1 },
.usage = "[-F format] [-f filter] [-O sort-order] " .usage = "[-N] [-F format] [-f filter] [-O sort-order] "
CMD_TARGET_PANE_USAGE, CMD_TARGET_PANE_USAGE,
.target = { 't', CMD_FIND_PANE, 0 }, .target = { 't', CMD_FIND_PANE, 0 },
@ -58,8 +58,8 @@ const struct cmd_entry cmd_choose_buffer_entry = {
.name = "choose-buffer", .name = "choose-buffer",
.alias = NULL, .alias = NULL,
.args = { "F:f:O:t:", 0, 1 }, .args = { "F:f:NO:t:", 0, 1 },
.usage = "[-F format] [-f filter] [-O sort-order] " .usage = "[-N] [-F format] [-f filter] [-O sort-order] "
CMD_TARGET_PANE_USAGE, CMD_TARGET_PANE_USAGE,
.target = { 't', CMD_FIND_PANE, 0 }, .target = { 't', CMD_FIND_PANE, 0 },

View File

@ -60,6 +60,7 @@ struct mode_tree_data {
struct screen screen; struct screen screen;
int preview;
char *search; char *search;
char *filter; char *filter;
}; };
@ -295,6 +296,8 @@ mode_tree_start(struct window_pane *wp, struct args *args,
mtd->sort_size = sort_size; mtd->sort_size = sort_size;
mtd->sort_type = 0; mtd->sort_type = 0;
mtd->preview = !args_has(args, 'N');
sort = args_get(args, 'O'); sort = args_get(args, 'O');
if (sort != NULL) { if (sort != NULL) {
for (i = 0; i < sort_size; i++) { for (i = 0; i < sort_size; i++) {
@ -348,12 +351,15 @@ mode_tree_build(struct mode_tree_data *mtd)
mode_tree_set_current(mtd, tag); mode_tree_set_current(mtd, tag);
mtd->width = screen_size_x(s); mtd->width = screen_size_x(s);
mtd->height = (screen_size_y(s) / 3) * 2; if (mtd->preview) {
if (mtd->height > mtd->line_size) mtd->height = (screen_size_y(s) / 3) * 2;
mtd->height = screen_size_y(s) / 2; if (mtd->height > mtd->line_size)
if (mtd->height < 10) mtd->height = screen_size_y(s) / 2;
mtd->height = screen_size_y(s); if (mtd->height < 10)
if (screen_size_y(s) - mtd->height < 2) mtd->height = screen_size_y(s);
if (screen_size_y(s) - mtd->height < 2)
mtd->height = screen_size_y(s);
} else
mtd->height = screen_size_y(s); mtd->height = screen_size_y(s);
} }
@ -549,7 +555,7 @@ mode_tree_draw(struct mode_tree_data *mtd)
} }
sy = screen_size_y(s); sy = screen_size_y(s);
if (sy <= 4 || h <= 4 || sy - h <= 4 || w <= 4) { if (!mtd->preview || sy <= 4 || h <= 4 || sy - h <= 4 || w <= 4) {
screen_write_stop(&ctx); screen_write_stop(&ctx);
return; return;
} }
@ -861,6 +867,10 @@ mode_tree_key(struct mode_tree_data *mtd, struct client *c, key_code *key,
mode_tree_filter_callback, mode_tree_filter_free, mtd, mode_tree_filter_callback, mode_tree_filter_free, mtd,
PROMPT_NOFORMAT); PROMPT_NOFORMAT);
break; break;
case 'v':
mtd->preview = !mtd->preview;
mode_tree_build(mtd);
break;
} }
return (0); return (0);
} }

13
tmux.1
View File

@ -1358,6 +1358,7 @@ the end of the visible pane.
The default is to capture only the visible contents of the pane. The default is to capture only the visible contents of the pane.
.It Xo .It Xo
.Ic choose-client .Ic choose-client
.Op Fl N
.Op Fl F Ar format .Op Fl F Ar format
.Op Fl f Ar filter .Op Fl f Ar filter
.Op Fl O Ar sort-order .Op Fl O Ar sort-order
@ -1385,6 +1386,7 @@ The following keys may be used in client mode:
.It Li "Z" Ta "Suspend tagged clients" .It Li "Z" Ta "Suspend tagged clients"
.It Li "f" Ta "Enter a format to filter items" .It Li "f" Ta "Enter a format to filter items"
.It Li "O" Ta "Change sort order" .It Li "O" Ta "Change sort order"
.It Li "v" Ta "Toggle preview"
.It Li "q" Ta "Exit mode" .It Li "q" Ta "Exit mode"
.El .El
.Pp .Pp
@ -1408,10 +1410,12 @@ or
specifies an initial filter. specifies an initial filter.
.Fl F .Fl F
specifies the format for each item in the list. specifies the format for each item in the list.
.Fl N
starts without the preview.
This command works only if at least one client is attached. This command works only if at least one client is attached.
.It Xo .It Xo
.Ic choose-tree .Ic choose-tree
.Op Fl sw .Op Fl Nsw
.Op Fl F Ar format .Op Fl F Ar format
.Op Fl f Ar filter .Op Fl f Ar filter
.Op Fl O Ar sort-order .Op Fl O Ar sort-order
@ -1440,6 +1444,7 @@ The following keys may be used in tree mode:
.It Li "\&:" Ta "Run a command for each tagged item" .It Li "\&:" Ta "Run a command for each tagged item"
.It Li "f" Ta "Enter a format to filter items" .It Li "f" Ta "Enter a format to filter items"
.It Li "O" Ta "Change sort order" .It Li "O" Ta "Change sort order"
.It Li "v" Ta "Toggle preview"
.It Li "q" Ta "Exit mode" .It Li "q" Ta "Exit mode"
.El .El
.Pp .Pp
@ -1462,6 +1467,8 @@ or
specifies an initial filter. specifies an initial filter.
.Fl F .Fl F
specifies the format for each item in the tree. specifies the format for each item in the tree.
.Fl N
starts without the preview.
This command works only if at least one client is attached. This command works only if at least one client is attached.
.It Xo .It Xo
.Ic display-panes .Ic display-panes
@ -4060,6 +4067,7 @@ The buffer commands are as follows:
.Bl -tag -width Ds .Bl -tag -width Ds
.It Xo .It Xo
.Ic choose-buffer .Ic choose-buffer
.Op Fl N
.Op Fl F Ar format .Op Fl F Ar format
.Op Fl f Ar filter .Op Fl f Ar filter
.Op Fl O Ar sort-order .Op Fl O Ar sort-order
@ -4083,6 +4091,7 @@ The following keys may be used in buffer mode:
.It Li "D" Ta "Delete tagged buffers" .It Li "D" Ta "Delete tagged buffers"
.It Li "f" Ta "Enter a format to filter items" .It Li "f" Ta "Enter a format to filter items"
.It Li "O" Ta "Change sort order" .It Li "O" Ta "Change sort order"
.It Li "v" Ta "Toggle preview"
.It Li "q" Ta "Exit mode" .It Li "q" Ta "Exit mode"
.El .El
.Pp .Pp
@ -4105,6 +4114,8 @@ or
specifies an initial filter. specifies an initial filter.
.Fl F .Fl F
specifies the format for each item in the list. specifies the format for each item in the list.
.Fl N
starts without the preview.
This command works only if at least one client is attached. This command works only if at least one client is attached.
.It Ic clear-history Op Fl t Ar target-pane .It Ic clear-history Op Fl t Ar target-pane
.D1 (alias: Ic clearhist ) .D1 (alias: Ic clearhist )

View File

@ -1001,7 +1001,7 @@ window_copy_search_lr(struct grid *gd,
int matched; int matched;
for (ax = first; ax < last; ax++) { for (ax = first; ax < last; ax++) {
if (ax + sgd->sx >= gd->sx) if (ax + sgd->sx > gd->sx)
break; break;
for (bx = 0; bx < sgd->sx; bx++) { for (bx = 0; bx < sgd->sx; bx++) {
px = ax + bx; px = ax + bx;