mirror of
https://github.com/tmux/tmux.git
synced 2025-04-07 00:28:48 +00:00
Add menu options to convert a popup into a pane.
This commit is contained in:
parent
92615b534a
commit
2588c3e52e
21
job.c
21
job.c
@ -201,6 +201,27 @@ fail:
|
|||||||
return (NULL);
|
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. */
|
/* Kill and free an individual job. */
|
||||||
void
|
void
|
||||||
job_free(struct job *job)
|
job_free(struct job *job)
|
||||||
|
59
popup.c
59
popup.c
@ -77,6 +77,18 @@ static const struct menu_item popup_menu_items[] = {
|
|||||||
{ "", KEYC_NONE, NULL },
|
{ "", KEYC_NONE, NULL },
|
||||||
{ "Fill Space", 'F', NULL },
|
{ "Fill Space", 'F', NULL },
|
||||||
{ "Centre", 'C', 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 }
|
{ 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
|
static void
|
||||||
popup_menu_done(__unused struct menu *menu, __unused u_int choice,
|
popup_menu_done(__unused struct menu *menu, __unused u_int choice,
|
||||||
key_code key, void *data)
|
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;
|
pd->py = c->tty.sy / 2 - pd->sy / 2;
|
||||||
server_redraw_client(c);
|
server_redraw_client(c);
|
||||||
break;
|
break;
|
||||||
|
case 'h':
|
||||||
|
popup_make_pane(pd, LAYOUT_LEFTRIGHT);
|
||||||
|
break;
|
||||||
|
case 'v':
|
||||||
|
popup_make_pane(pd, LAYOUT_TOPBOTTOM);
|
||||||
|
break;
|
||||||
case 'q':
|
case 'q':
|
||||||
pd->close = 1;
|
pd->close = 1;
|
||||||
break;
|
break;
|
||||||
@ -460,7 +509,11 @@ popup_key_cb(struct client *c, void *data, struct key_event *event)
|
|||||||
|
|
||||||
menu:
|
menu:
|
||||||
pd->menu = menu_create("");
|
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)
|
if (m->x >= (pd->menu->width + 4) / 2)
|
||||||
x = m->x - (pd->menu->width + 4) / 2;
|
x = m->x - (pd->menu->width + 4) / 2;
|
||||||
else
|
else
|
||||||
@ -659,8 +712,8 @@ popup_editor(struct client *c, const char *buf, size_t len,
|
|||||||
py = (c->tty.sy / 2) - (sy / 2);
|
py = (c->tty.sy / 2) - (sy / 2);
|
||||||
|
|
||||||
xasprintf(&cmd, "%s %s", editor, path);
|
xasprintf(&cmd, "%s %s", editor, path);
|
||||||
if (popup_display(POPUP_CLOSEEXIT, NULL, px, py, sx, sy, cmd, 0, NULL,
|
if (popup_display(POPUP_INTERNAL|POPUP_CLOSEEXIT, NULL, px, py, sx, sy,
|
||||||
_PATH_TMP, c, NULL, popup_editor_close_cb, pe) != 0) {
|
cmd, 0, NULL, _PATH_TMP, c, NULL, popup_editor_close_cb, pe) != 0) {
|
||||||
popup_editor_free(pe);
|
popup_editor_free(pe);
|
||||||
free(cmd);
|
free(cmd);
|
||||||
return (-1);
|
return (-1);
|
||||||
|
2
tmux.h
2
tmux.h
@ -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,
|
const char *, job_update_cb, job_complete_cb, job_free_cb,
|
||||||
void *, int, int, int);
|
void *, int, int, int);
|
||||||
void job_free(struct job *);
|
void job_free(struct job *);
|
||||||
|
int job_transfer(struct job *);
|
||||||
void job_resize(struct job *, u_int, u_int);
|
void job_resize(struct job *, u_int, u_int);
|
||||||
void job_check_died(pid_t, int);
|
void job_check_died(pid_t, int);
|
||||||
int job_get_status(struct job *);
|
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_CLOSEEXIT 0x1
|
||||||
#define POPUP_CLOSEEXITZERO 0x2
|
#define POPUP_CLOSEEXITZERO 0x2
|
||||||
#define POPUP_NOBORDER 0x4
|
#define POPUP_NOBORDER 0x4
|
||||||
|
#define POPUP_INTERNAL 0x8
|
||||||
typedef void (*popup_close_cb)(int, void *);
|
typedef void (*popup_close_cb)(int, void *);
|
||||||
typedef void (*popup_finish_edit_cb)(char *, size_t, void *);
|
typedef void (*popup_finish_edit_cb)(char *, size_t, void *);
|
||||||
int popup_display(int, struct cmdq_item *, u_int, u_int, u_int,
|
int popup_display(int, struct cmdq_item *, u_int, u_int, u_int,
|
||||||
|
Loading…
Reference in New Issue
Block a user