Add menu options to convert a popup into a pane.

pull/2824/head
nicm 2021-08-13 19:27:25 +00:00
parent 92615b534a
commit 2588c3e52e
3 changed files with 79 additions and 3 deletions

21
job.c
View File

@ -201,6 +201,27 @@ fail:
return (NULL);
}
/* Take job's file descriptor and free the job. */
int
job_transfer(struct job *job)
{
int fd = job->fd;
log_debug("transfer job %p: %s", job, job->cmd);
LIST_REMOVE(job, entry);
free(job->cmd);
if (job->freecb != NULL && job->data != NULL)
job->freecb(job->data);
if (job->event != NULL)
bufferevent_free(job->event);
free(job);
return (fd);
}
/* Kill and free an individual job. */
void
job_free(struct job *job)

59
popup.c
View File

@ -77,6 +77,18 @@ static const struct menu_item popup_menu_items[] = {
{ "", KEYC_NONE, NULL },
{ "Fill Space", 'F', NULL },
{ "Centre", 'C', NULL },
{ "", KEYC_NONE, NULL },
{ "Make Pane (H)", 'h', NULL },
{ "Make Pane (V)", 'v', NULL },
{ NULL, KEYC_NONE, NULL }
};
static const struct menu_item popup_internal_menu_items[] = {
{ "Close", 'q', NULL },
{ "", KEYC_NONE, NULL },
{ "Fill Space", 'F', NULL },
{ "Centre", 'C', NULL },
{ NULL, KEYC_NONE, NULL }
};
@ -278,6 +290,37 @@ popup_resize_cb(__unused struct client *c, void *data)
}
}
static void
popup_make_pane(struct popup_data *pd, enum layout_type type)
{
struct client *c = pd->c;
struct session *s = c->session;
struct window *w = s->curw->window;
struct layout_cell *lc;
struct window_pane *wp = w->active, *new_wp;
u_int hlimit;
window_unzoom(w);
lc = layout_split_pane(wp, type, -1, 0);
hlimit = options_get_number(s->options, "history-limit");
new_wp = window_add_pane(wp->window, NULL, hlimit, 0);
layout_assign_pane(lc, new_wp, 0);
new_wp->fd = job_transfer(pd->job);
pd->job = NULL;
screen_free(&new_wp->base);
memcpy(&new_wp->base, &pd->s, sizeof wp->base);
screen_resize(&new_wp->base, new_wp->sx, new_wp->sy, 1);
screen_init(&pd->s, 1, 1, 0);
window_pane_set_event(new_wp);
window_set_active_pane(w, new_wp, 1);
pd->close = 1;
}
static void
popup_menu_done(__unused struct menu *menu, __unused u_int choice,
key_code key, void *data)
@ -312,6 +355,12 @@ popup_menu_done(__unused struct menu *menu, __unused u_int choice,
pd->py = c->tty.sy / 2 - pd->sy / 2;
server_redraw_client(c);
break;
case 'h':
popup_make_pane(pd, LAYOUT_LEFTRIGHT);
break;
case 'v':
popup_make_pane(pd, LAYOUT_TOPBOTTOM);
break;
case 'q':
pd->close = 1;
break;
@ -460,7 +509,11 @@ popup_key_cb(struct client *c, void *data, struct key_event *event)
menu:
pd->menu = menu_create("");
menu_add_items(pd->menu, popup_menu_items, NULL, NULL, NULL);
if (pd->flags & POPUP_INTERNAL) {
menu_add_items(pd->menu, popup_internal_menu_items, NULL, NULL,
NULL);
} else
menu_add_items(pd->menu, popup_menu_items, NULL, NULL, NULL);
if (m->x >= (pd->menu->width + 4) / 2)
x = m->x - (pd->menu->width + 4) / 2;
else
@ -659,8 +712,8 @@ popup_editor(struct client *c, const char *buf, size_t len,
py = (c->tty.sy / 2) - (sy / 2);
xasprintf(&cmd, "%s %s", editor, path);
if (popup_display(POPUP_CLOSEEXIT, NULL, px, py, sx, sy, cmd, 0, NULL,
_PATH_TMP, c, NULL, popup_editor_close_cb, pe) != 0) {
if (popup_display(POPUP_INTERNAL|POPUP_CLOSEEXIT, NULL, px, py, sx, sy,
cmd, 0, NULL, _PATH_TMP, c, NULL, popup_editor_close_cb, pe) != 0) {
popup_editor_free(pe);
free(cmd);
return (-1);

2
tmux.h
View File

@ -2042,6 +2042,7 @@ struct job *job_run(const char *, int, char **, struct session *,
const char *, job_update_cb, job_complete_cb, job_free_cb,
void *, int, int, int);
void job_free(struct job *);
int job_transfer(struct job *);
void job_resize(struct job *, u_int, u_int);
void job_check_died(pid_t, int);
int job_get_status(struct job *);
@ -3038,6 +3039,7 @@ int menu_key_cb(struct client *, void *, struct key_event *);
#define POPUP_CLOSEEXIT 0x1
#define POPUP_CLOSEEXITZERO 0x2
#define POPUP_NOBORDER 0x4
#define POPUP_INTERNAL 0x8
typedef void (*popup_close_cb)(int, void *);
typedef void (*popup_finish_edit_cb)(char *, size_t, void *);
int popup_display(int, struct cmdq_item *, u_int, u_int, u_int,