/* Set default format keys for a session. */ void format_session(struct format_tree *ft, struct session *s) { struct session_group *sg; char *tim; time_t t; format_add(ft, "session_name", "%s", s->name); format_add(ft, "session_windows", "%u", winlink_count(&s->windows)); format_add(ft, "session_width", "%u", s->sx); format_add(ft, "session_height", "%u", s->sy); format_add(ft, "session_id", "$%u", s->id); sg = session_group_find(s); format_add(ft, "session_grouped", "%d", sg != NULL); if (sg != NULL) format_add(ft, "session_group", "%u", session_group_index(sg)); t = s->creation_time.tv_sec; format_add(ft, "session_created", "%lld", (long long) t); tim = ctime(&t); *strchr(tim, '\n') = '\0'; format_add(ft, "session_created_string", "%s", tim); format_add(ft, "session_attached", "%u", s->attached); format_add(ft, "session_many_attached", "%u", s->attached > 1); }
int cmd_unlink_window_exec(struct cmd *self, struct cmd_ctx *ctx) { struct args *args = self->args; struct winlink *wl; struct window *w; struct session *s, *s2; struct session_group *sg; u_int references; if ((wl = cmd_find_window(ctx, args_get(args, 't'), &s)) == NULL) return (-1); w = wl->window; sg = session_group_find(s); if (sg != NULL) { references = 0; TAILQ_FOREACH(s2, &sg->sessions, gentry) references++; } else references = 1; if (!args_has(self->args, 'k') && w->references == references) { ctx->error(ctx, "window is only linked to one session"); return (-1); } server_unlink_window(s, wl); recalculate_sizes(); return (0); }
int cmd_list_sessions_exec(unused struct cmd *self, struct cmd_ctx *ctx) { struct session *s; struct session_group *sg; char *tim, tmp[64]; u_int i, idx; time_t t; for (i = 0; i < ARRAY_LENGTH(&sessions); i++) { s = ARRAY_ITEM(&sessions, i); if (s == NULL) continue; sg = session_group_find(s); if (sg == NULL) *tmp = '\0'; else { idx = session_group_index(sg); xsnprintf(tmp, sizeof tmp, " (group %u)", idx); } t = s->creation_time.tv_sec; tim = ctime(&t); *strchr(tim, '\n') = '\0'; ctx->print(ctx, "%s: %u windows (created %s) [%ux%u]%s%s", s->name, winlink_count(&s->windows), tim, s->sx, s->sy, tmp, s->flags & SESSION_UNATTACHED ? "" : " (attached)"); } return (0); }
int cmd_swap_window_exec(struct cmd *self, struct cmd_ctx *ctx) { struct args *args = self->args; const char *target_src, *target_dst; struct session *src, *dst; struct session_group *sg_src, *sg_dst; struct winlink *wl_src, *wl_dst; struct window *w; target_src = args_get(args, 's'); if ((wl_src = cmd_find_window(ctx, target_src, &src)) == NULL) return (-1); target_dst = args_get(args, 't'); if ((wl_dst = cmd_find_window(ctx, target_dst, &dst)) == NULL) return (-1); sg_src = session_group_find(src); sg_dst = session_group_find(dst); if (src != dst && sg_src != NULL && sg_dst != NULL && sg_src == sg_dst) { ctx->error(ctx, "can't move window, sessions are grouped"); return (-1); } if (wl_dst->window == wl_src->window) return (0); w = wl_dst->window; wl_dst->window = wl_src->window; wl_src->window = w; if (!args_has(self->args, 'd')) { session_select(dst, wl_dst->idx); if (src != dst) session_select(src, wl_src->idx); } session_group_synchronize_from(src); server_redraw_session_group(src); if (src != dst) { session_group_synchronize_from(dst); server_redraw_session_group(dst); } recalculate_sizes(); return (0); }
int cmd_swap_window_exec(struct cmd *self, struct cmd_ctx *ctx) { struct cmd_srcdst_data *data = self->data; struct session *src, *dst; struct session_group *sg_src, *sg_dst; struct winlink *wl_src, *wl_dst; struct window *w; if ((wl_src = cmd_find_window(ctx, data->src, &src)) == NULL) return (-1); if ((wl_dst = cmd_find_window(ctx, data->dst, &dst)) == NULL) return (-1); sg_src = session_group_find(src); sg_dst = session_group_find(dst); if (src != dst && sg_src != NULL && sg_dst != NULL && sg_src == sg_dst) { ctx->error(ctx, "can't move window, sessions are grouped"); return (-1); } if (wl_dst->window == wl_src->window) return (0); w = wl_dst->window; wl_dst->window = wl_src->window; wl_src->window = w; if (!cmd_check_flag(data->chflags, 'd')) { session_select(dst, wl_dst->idx); if (src != dst) session_select(src, wl_src->idx); } session_group_synchronize_from(src); server_redraw_session_group(src); if (src != dst) { session_group_synchronize_from(dst); server_redraw_session_group(dst); } recalculate_sizes(); return (0); }
enum cmd_retval cmd_swap_window_exec(struct cmd *self, struct cmd_q *cmdq) { struct session *src, *dst; struct session_group *sg_src, *sg_dst; struct winlink *wl_src, *wl_dst; struct window *w; wl_src = cmdq->state.sflag.wl; src = cmdq->state.sflag.s; sg_src = session_group_find(src); wl_dst = cmdq->state.tflag.wl; dst = cmdq->state.tflag.s; sg_dst = session_group_find(dst); if (src != dst && sg_src != NULL && sg_dst != NULL && sg_src == sg_dst) { cmdq_error(cmdq, "can't move window, sessions are grouped"); return (CMD_RETURN_ERROR); } if (wl_dst->window == wl_src->window) return (CMD_RETURN_NORMAL); w = wl_dst->window; wl_dst->window = wl_src->window; wl_src->window = w; if (!args_has(self->args, 'd')) { session_select(dst, wl_dst->idx); if (src != dst) session_select(src, wl_src->idx); } session_group_synchronize_from(src); server_redraw_session_group(src); if (src != dst) { session_group_synchronize_from(dst); server_redraw_session_group(dst); } recalculate_sizes(); return (CMD_RETURN_NORMAL); }