Skip to content

Commit

Permalink
Merge branch 'master' into sixel
Browse files Browse the repository at this point in the history
  • Loading branch information
topcat001 committed Jul 23, 2023
2 parents 4baf764 + fda3937 commit 14b8b52
Show file tree
Hide file tree
Showing 28 changed files with 512 additions and 155 deletions.
2 changes: 1 addition & 1 deletion arguments.c
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ args_parse_flag_argument(struct args_value *values, u_int count, char **cause,
/* Parse flags argument. */
static int
args_parse_flags(const struct args_parse *parse, struct args_value *values,
u_int count, char **cause, struct args *args, int *i)
u_int count, char **cause, struct args *args, u_int *i)
{
struct args_value *value;
u_char flag;
Expand Down
20 changes: 14 additions & 6 deletions client.c
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,6 @@ client_main(struct event_base *base, int argc, char **argv, uint64_t flags,
u_int ncaps = 0;
struct args_value *values;

/* Ignore SIGCHLD now or daemon() in the server will leave a zombie. */
signal(SIGCHLD, SIG_IGN);

/* Set up the initial command. */
if (shell_command != NULL) {
msg = MSG_SHELL;
Expand Down Expand Up @@ -533,11 +530,22 @@ client_signal(int sig)
{
struct sigaction sigact;
int status;
pid_t pid;

log_debug("%s: %s", __func__, strsignal(sig));
if (sig == SIGCHLD)
waitpid(WAIT_ANY, &status, WNOHANG);
else if (!client_attached) {
if (sig == SIGCHLD) {
for (;;) {
pid = waitpid(WAIT_ANY, &status, WNOHANG);
if (pid == 0)
break;
if (pid == -1) {
if (errno == ECHILD)
break;
log_debug("waitpid failed: %s",
strerror(errno));
}
}
} else if (!client_attached) {
if (sig == SIGTERM || sig == SIGHUP)
proc_exit(client_proc);
} else {
Expand Down
2 changes: 1 addition & 1 deletion cmd-find.c
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,7 @@ cmd_find_get_pane_with_window(struct cmd_find_state *fs, const char *pane)

/* Try special characters. */
if (strcmp(pane, "!") == 0) {
fs->wp = fs->w->last;
fs->wp = TAILQ_FIRST(&fs->w->last_panes);
if (fs->wp == NULL)
return (-1);
return (0);
Expand Down
3 changes: 1 addition & 2 deletions cmd-resize-window.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ cmd_resize_window_exec(struct cmd *self, struct cmdq_item *item)
struct session *s = target->s;
const char *errstr;
char *cause;
u_int adjust, sx, sy;
int xpixel = -1, ypixel = -1;
u_int adjust, sx, sy, xpixel = 0, ypixel = 0;

if (args_count(args) == 0)
adjust = 1;
Expand Down
6 changes: 5 additions & 1 deletion cmd-select-pane.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,11 @@ cmd_select_pane_exec(struct cmd *self, struct cmdq_item *item)
struct options_entry *o;

if (entry == &cmd_last_pane_entry || args_has(args, 'l')) {
lastwp = w->last;
/*
* Check for no last pane found in case the other pane was
* spawned without being visited (for example split-window -d).
*/
lastwp = TAILQ_FIRST(&w->last_panes);
if (lastwp == NULL && window_count_panes(w) == 2) {
lastwp = TAILQ_PREV(w->active, window_panes, entry);
if (lastwp == NULL)
Expand Down
6 changes: 2 additions & 4 deletions cmd-swap-pane.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,8 @@ cmd_swap_pane_exec(struct cmd *self, struct cmdq_item *item)
window_set_active_pane(dst_w, src_wp, 1);
}
if (src_w != dst_w) {
if (src_w->last == src_wp)
src_w->last = NULL;
if (dst_w->last == dst_wp)
dst_w->last = NULL;
window_pane_stack_remove(&src_w->last_panes, src_wp);
window_pane_stack_remove(&dst_w->last_panes, dst_wp);
colour_palette_from_option(&src_wp->palette, src_wp->options);
colour_palette_from_option(&dst_wp->palette, dst_wp->options);
}
Expand Down
4 changes: 2 additions & 2 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ fi
if test "x$found_ncurses" = xno; then
AC_SEARCH_LIBS(
setupterm,
[tinfo ncurses ncursesw],
[tinfo terminfo ncurses ncursesw],
found_ncurses=yes,
found_ncurses=no
)
Expand Down Expand Up @@ -461,7 +461,7 @@ AM_CONDITIONAL(ENABLE_SIXEL, [test "x$enable_sixel" = xyes])

# Check for b64_ntop. If we have b64_ntop, we assume b64_pton as well.
AC_MSG_CHECKING(for b64_ntop)
AC_LINK_IFELSE([AC_LANG_PROGRAM(
AC_LINK_IFELSE([AC_LANG_PROGRAM(
[
#include <sys/types.h>
#include <netinet/in.h>
Expand Down
8 changes: 5 additions & 3 deletions format.c
Original file line number Diff line number Diff line change
Expand Up @@ -1902,7 +1902,7 @@ static void *
format_cb_pane_last(struct format_tree *ft)
{
if (ft->wp != NULL) {
if (ft->wp == ft->wp->window->last)
if (ft->wp == TAILQ_FIRST(&ft->wp->window->last_panes))
return (xstrdup("1"));
return (xstrdup("0"));
}
Expand Down Expand Up @@ -3664,7 +3664,9 @@ format_skip(const char *s, const char *end)
for (; *s != '\0'; s++) {
if (*s == '#' && s[1] == '{')
brackets++;
if (*s == '#' && strchr(",#{}:", s[1]) != NULL) {
if (*s == '#' &&
s[1] != '\0' &&
strchr(",#{}:", s[1]) != NULL) {
s++;
continue;
}
Expand Down Expand Up @@ -3813,7 +3815,7 @@ format_build_modifiers(struct format_expand_state *es, const char **s,
argc = 0;

/* Single argument with no wrapper character. */
if (!ispunct(cp[1]) || cp[1] == '-') {
if (!ispunct((u_char)cp[1]) || cp[1] == '-') {
end = format_skip(cp + 1, ":;");
if (end == NULL)
break;
Expand Down
13 changes: 7 additions & 6 deletions grid.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,20 @@

/* Default grid cell data. */
const struct grid_cell grid_default_cell = {
{ { ' ' }, 0, 1, 1 }, 0, 0, 8, 8, 0, 0
{ { ' ' }, 0, 1, 1 }, 0, 0, 8, 8, 8, 0
};

/*
* Padding grid cell data. Padding cells are the only zero width cell that
* appears in the grid - because of this, they are always extended cells.
*/
static const struct grid_cell grid_padding_cell = {
{ { '!' }, 0, 0, 0 }, 0, GRID_FLAG_PADDING, 8, 8, 0, 0
{ { '!' }, 0, 0, 0 }, 0, GRID_FLAG_PADDING, 8, 8, 8, 0
};

/* Cleared grid cell data. */
static const struct grid_cell grid_cleared_cell = {
{ { ' ' }, 0, 1, 1 }, 0, GRID_FLAG_CLEARED, 8, 8, 0, 0
{ { ' ' }, 0, 1, 1 }, 0, GRID_FLAG_CLEARED, 8, 8, 8, 0
};
static const struct grid_cell_entry grid_cleared_entry = {
{ .data = { 0, 8, 8, ' ' } }, GRID_FLAG_CLEARED
Expand Down Expand Up @@ -528,7 +528,7 @@ grid_get_cell1(struct grid_line *gl, u_int px, struct grid_cell *gc)
gc->bg = gce->data.bg;
if (gce->flags & GRID_FLAG_BG256)
gc->bg |= COLOUR_FLAG_256;
gc->us = 0;
gc->us = 8;
utf8_set(&gc->data, gce->data.data);
gc->link = 0;
}
Expand Down Expand Up @@ -956,7 +956,7 @@ grid_string_cells_code(const struct grid_cell *lastgc,
for (i = 0; i < nitems(attrs); i++) {
if (((~attr & attrs[i].mask) &&
(lastattr & attrs[i].mask)) ||
(lastgc->us != 0 && gc->us == 0)) {
(lastgc->us != 8 && gc->us == 8)) {
s[n++] = 0;
lastattr &= GRID_ATTR_CHARSET;
break;
Expand Down Expand Up @@ -1044,7 +1044,8 @@ grid_string_cells(struct grid *gd, u_int px, u_int py, u_int nx,
const char *data;
char *buf, code[8192];
size_t len, off, size, codelen;
u_int xx, has_link = 0, end;
u_int xx, end;
int has_link = 0;
const struct grid_line *gl;

if (lastgc != NULL && *lastgc == NULL) {
Expand Down
2 changes: 1 addition & 1 deletion hyperlinks.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@

#define MAX_HYPERLINKS 5000

static uint64_t hyperlinks_next_external_id = 1;
static long long hyperlinks_next_external_id = 1;
static u_int global_hyperlinks_count;

struct hyperlinks_uri {
Expand Down
32 changes: 29 additions & 3 deletions input.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ static void input_osc_104(struct input_ctx *, const char *);
static void input_osc_110(struct input_ctx *, const char *);
static void input_osc_111(struct input_ctx *, const char *);
static void input_osc_112(struct input_ctx *, const char *);
static void input_osc_133(struct input_ctx *, const char *);

/* Transition entry/exit handlers. */
static void input_clear(struct input_ctx *);
Expand Down Expand Up @@ -2069,7 +2070,7 @@ static void
input_csi_dispatch_sgr(struct input_ctx *ictx)
{
struct grid_cell *gc = &ictx->cell.cell;
u_int i;
u_int i, link;
int n;

if (ictx->param_list_len == 0) {
Expand Down Expand Up @@ -2101,7 +2102,9 @@ input_csi_dispatch_sgr(struct input_ctx *ictx)

switch (n) {
case 0:
link = gc->link;
memcpy(gc, &grid_default_cell, sizeof *gc);
gc->link = link;
break;
case 1:
gc->attr |= GRID_ATTR_BRIGHT;
Expand Down Expand Up @@ -2187,7 +2190,7 @@ input_csi_dispatch_sgr(struct input_ctx *ictx)
gc->attr &= ~GRID_ATTR_OVERLINE;
break;
case 59:
gc->us = 0;
gc->us = 8;
break;
case 90:
case 91:
Expand Down Expand Up @@ -2363,6 +2366,9 @@ input_exit_osc(struct input_ctx *ictx)
case 112:
input_osc_112(ictx, p);
break;
case 133:
input_osc_133(ictx, p);
break;
default:
log_debug("%s: unknown '%u'", __func__, option);
break;
Expand Down Expand Up @@ -2752,6 +2758,24 @@ input_osc_112(struct input_ctx *ictx, const char *p)
screen_set_cursor_colour(ictx->ctx.s, -1);
}

/* Handle the OSC 133 sequence. */
static void
input_osc_133(struct input_ctx *ictx, const char *p)
{
struct grid *gd = ictx->ctx.s->grid;
u_int line = ictx->ctx.s->cy + gd->hsize;
struct grid_line *gl;

if (line > gd->hsize + gd->sy - 1)
return;
gl = grid_get_line(gd, line);

switch (*p) {
case 'A':
gl->flags |= GRID_LINE_START_PROMPT;
break;
}
}

/* Handle the OSC 52 sequence for setting the clipboard. */
static void
Expand Down Expand Up @@ -2858,9 +2882,11 @@ input_reply_clipboard(struct bufferevent *bev, const char *buf, size_t len,
const char *end)
{
char *out = NULL;
size_t outlen = 0;
int outlen = 0;

if (buf != NULL && len != 0) {
if (len >= ((size_t)INT_MAX * 3 / 4) - 1)
return;
outlen = 4 * ((len + 2) / 3) + 1;
out = xmalloc(outlen);
if ((outlen = b64_ntop(buf, len, out, outlen)) == -1) {
Expand Down
4 changes: 2 additions & 2 deletions notify.c
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ notify_add(const char *name, struct cmd_find_state *fs, struct client *c,
ne->client = c;
ne->session = s;
ne->window = w;
ne->pane = (wp != NULL ? wp->id : -1);
ne->pane = (wp != NULL ? (int)wp->id : -1);
ne->pbname = (pbname != NULL ? xstrdup(pbname) : NULL);

ne->formats = format_create(NULL, NULL, 0, FORMAT_NOJOBS);
Expand Down Expand Up @@ -240,7 +240,7 @@ notify_hook(struct cmdq_item *item, const char *name)
ne.client = cmdq_get_client(item);
ne.session = target->s;
ne.window = target->w;
ne.pane = (target->wp != NULL ? target->wp->id : -1);
ne.pane = (target->wp != NULL ? (int)target->wp->id : -1);

ne.formats = format_create(NULL, NULL, 0, FORMAT_NOJOBS);
format_add(ne.formats, "hook", "%s", name);
Expand Down
2 changes: 2 additions & 0 deletions popup.c
Original file line number Diff line number Diff line change
Expand Up @@ -787,6 +787,8 @@ popup_editor(struct client *c, const char *buf, size_t len,
if (fd == -1)
return (-1);
f = fdopen(fd, "w");
if (f == NULL)
return (-1);
if (fwrite(buf, len, 1, f) != 1) {
fclose(f);
return (-1);
Expand Down
4 changes: 2 additions & 2 deletions regsub.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include "tmux.h"

static void
regsub_copy(char **buf, size_t *len, const char *text, size_t start, size_t end)
regsub_copy(char **buf, ssize_t *len, const char *text, size_t start, size_t end)
{
size_t add = end - start;

Expand All @@ -34,7 +34,7 @@ regsub_copy(char **buf, size_t *len, const char *text, size_t start, size_t end)
}

static void
regsub_expand(char **buf, size_t *len, const char *with, const char *text,
regsub_expand(char **buf, ssize_t *len, const char *with, const char *text,
regmatch_t *m, u_int n)
{
const char *cp;
Expand Down
4 changes: 3 additions & 1 deletion screen-write.c
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,9 @@ screen_write_reset(struct screen_write_ctx *ctx)
screen_reset_tabs(s);
screen_write_scrollregion(ctx, 0, screen_size_y(s) - 1);

s->mode = MODE_CURSOR | MODE_WRAP;
s->mode = MODE_CURSOR|MODE_WRAP;
if (options_get_number(global_options, "extended-keys") == 2)
s->mode |= MODE_KEXTENDED;

screen_write_clearscreen(ctx, 8);
screen_write_set_cursor(ctx, 0, 0);
Expand Down
2 changes: 1 addition & 1 deletion screen.c
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,7 @@ screen_alternate_off(struct screen *s, struct grid_cell *gc, int cursor)
* before copying back.
*/
if (s->saved_grid != NULL)
screen_resize(s, s->saved_grid->sx, s->saved_grid->sy, 1);
screen_resize(s, s->saved_grid->sx, s->saved_grid->sy, 0);

/*
* Restore the cursor position and cell. This happens even if not
Expand Down
5 changes: 4 additions & 1 deletion session.c
Original file line number Diff line number Diff line change
Expand Up @@ -737,9 +737,12 @@ session_renumber_windows(struct session *s)
memcpy(&old_lastw, &s->lastw, sizeof old_lastw);
TAILQ_INIT(&s->lastw);
TAILQ_FOREACH(wl, &old_lastw, sentry) {
wl->flags &= ~WINLINK_VISITED;
wl_new = winlink_find_by_window(&s->windows, wl->window);
if (wl_new != NULL)
if (wl_new != NULL) {
TAILQ_INSERT_TAIL(&s->lastw, wl_new, sentry);
wl_new->flags |= WINLINK_VISITED;
}
}

/* Set the current window. */
Expand Down
3 changes: 2 additions & 1 deletion spawn.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ spawn_window(struct spawn_context *sc, char **cause)
window_pane_resize(sc->wp0, w->sx, w->sy);

layout_init(w, sc->wp0);
w->active = NULL;
window_set_active_pane(w, sc->wp0, 0);
}

Expand Down Expand Up @@ -428,8 +429,8 @@ spawn_pane(struct spawn_context *sc, char **cause)
_exit(1);

/* Clean up file descriptors and signals and update the environment. */
closefrom(STDERR_FILENO + 1);
proc_clear_signals(server_proc, 1);
closefrom(STDERR_FILENO + 1);
sigprocmask(SIG_SETMASK, &oldset, NULL);
log_close();
environ_push(child);
Expand Down
Loading

0 comments on commit 14b8b52

Please sign in to comment.