Rename cmdq_shared to cmdq_state which will better reflect what it is

(going to be) used for.
pull/2172/head
nicm 2020-04-13 14:04:25 +00:00
parent 77d5b0cc53
commit 9a65102bfc
24 changed files with 88 additions and 88 deletions

View File

@ -50,8 +50,8 @@ enum cmd_retval
cmd_attach_session(struct cmdq_item *item, const char *tflag, int dflag,
int xflag, int rflag, const char *cflag, int Eflag)
{
struct cmdq_shared *shared = cmdq_get_shared(item);
struct cmd_find_state *current = &shared->current;
struct cmdq_state *state = cmdq_get_state(item);
struct cmd_find_state *current = &state->current;
struct cmd_find_state target;
enum cmd_find_type type;
int flags;
@ -120,7 +120,7 @@ cmd_attach_session(struct cmdq_item *item, const char *tflag, int dflag,
environ_update(s->options, c->environ, s->environ);
c->session = s;
if (~shared->flags & CMDQ_SHARED_REPEAT)
if (~state->flags & CMDQ_STATE_REPEAT)
server_client_set_key_table(c, NULL);
tty_update_client_offset(c);
status_timer_start(c);

View File

@ -49,8 +49,8 @@ static enum cmd_retval
cmd_break_pane_exec(struct cmd *self, struct cmdq_item *item)
{
struct args *args = cmd_get_args(self);
struct cmdq_shared *shared = cmdq_get_shared(item);
struct cmd_find_state *current = &shared->current;
struct cmdq_state *state = cmdq_get_state(item);
struct cmd_find_state *current = &state->current;
struct cmd_find_state *target = cmdq_get_target(item);
struct cmd_find_state *source = cmdq_get_source(item);
struct client *c = cmd_find_client(item, NULL, 1);

View File

@ -57,7 +57,7 @@ static enum cmd_retval
cmd_copy_mode_exec(struct cmd *self, struct cmdq_item *item)
{
struct args *args = cmd_get_args(self);
struct cmdq_shared *shared = cmdq_get_shared(item);
struct cmdq_state *state = cmdq_get_state(item);
struct cmd_find_state *source = cmdq_get_source(item);
struct cmd_find_state *target = cmdq_get_target(item);
struct client *c = cmdq_get_client(item);
@ -70,7 +70,7 @@ cmd_copy_mode_exec(struct cmd *self, struct cmdq_item *item)
}
if (args_has(args, 'M')) {
if ((wp = cmd_mouse_pane(&shared->event.m, &s, NULL)) == NULL)
if ((wp = cmd_mouse_pane(&state->event.m, &s, NULL)) == NULL)
return (CMD_RETURN_NORMAL);
if (c == NULL || c->session != s)
return (CMD_RETURN_NORMAL);
@ -87,7 +87,7 @@ cmd_copy_mode_exec(struct cmd *self, struct cmdq_item *item)
swp = wp;
if (!window_pane_set_mode(wp, swp, &window_copy_mode, NULL, args)) {
if (args_has(args, 'M'))
window_copy_start_drag(c, &shared->event.m);
window_copy_start_drag(c, &state->event.m);
}
if (args_has(args, 'u'))
window_copy_pageup(wp, 0);

View File

@ -65,7 +65,7 @@ static void
cmd_display_menu_get_position(struct client *c, struct cmdq_item *item,
struct args *args, u_int *px, u_int *py, u_int w, u_int h)
{
struct cmdq_shared *shared = cmdq_get_shared(item);
struct cmdq_state *state = cmdq_get_state(item);
struct cmd_find_state *target = cmdq_get_target(item);
struct session *s = c->session;
struct winlink *wl = target->wl;
@ -100,8 +100,8 @@ cmd_display_menu_get_position(struct client *c, struct cmdq_item *item,
else
*px = 0;
} else if (strcmp(xp, "M") == 0) {
if (shared->event.m.valid && shared->event.m.x > w / 2)
*px = shared->event.m.x - w / 2;
if (state->event.m.valid && state->event.m.x > w / 2)
*px = state->event.m.x - w / 2;
else
*px = 0;
} else if (strcmp(xp, "W") == 0) {
@ -134,8 +134,8 @@ cmd_display_menu_get_position(struct client *c, struct cmdq_item *item,
else
*py = 0;
} else if (strcmp(yp, "M") == 0) {
if (shared->event.m.valid)
*py = shared->event.m.y + h;
if (state->event.m.valid)
*py = state->event.m.y + h;
else
*py = 0;
} else if (strcmp(yp, "S") == 0) {
@ -176,7 +176,7 @@ static enum cmd_retval
cmd_display_menu_exec(struct cmd *self, struct cmdq_item *item)
{
struct args *args = cmd_get_args(self);
struct cmdq_shared *shared = cmdq_get_shared(item);
struct cmdq_state *state = cmdq_get_state(item);
struct cmd_find_state *target = cmdq_get_target(item);
struct client *c;
struct menu *menu = NULL;
@ -230,7 +230,7 @@ cmd_display_menu_exec(struct cmd *self, struct cmdq_item *item)
cmd_display_menu_get_position(c, item, args, &px, &py, menu->width + 4,
menu->count + 2);
if (!shared->event.m.valid)
if (!state->event.m.valid)
flags |= MENU_NOMOUSE;
if (menu_display(menu, flags, item, px, py, c, target, NULL, NULL) != 0)
return (CMD_RETURN_NORMAL);

View File

@ -961,8 +961,8 @@ cmd_find_target(struct cmd_find_state *fs, struct cmdq_item *item,
if (server_check_marked() && (flags & CMD_FIND_DEFAULT_MARKED)) {
fs->current = &marked_pane;
log_debug("%s: current is marked pane", __func__);
} else if (cmd_find_valid_state(&cmdq_get_shared(item)->current)) {
fs->current = &cmdq_get_shared(item)->current;
} else if (cmd_find_valid_state(&cmdq_get_state(item)->current)) {
fs->current = &cmdq_get_state(item)->current;
log_debug("%s: current is from queue", __func__);
} else if (cmd_find_from_client(&current, cmdq_get_client(item),
flags) == 0) {
@ -982,7 +982,7 @@ cmd_find_target(struct cmd_find_state *fs, struct cmdq_item *item,
/* Mouse target is a plain = or {mouse}. */
if (strcmp(target, "=") == 0 || strcmp(target, "{mouse}") == 0) {
m = &cmdq_get_shared(item)->event.m;
m = &cmdq_get_state(item)->event.m;
switch (type) {
case CMD_FIND_PANE:
fs->wp = cmd_mouse_pane(m, &fs->s, &fs->wl);

View File

@ -63,9 +63,9 @@ static enum cmd_retval
cmd_if_shell_exec(struct cmd *self, struct cmdq_item *item)
{
struct args *args = cmd_get_args(self);
struct cmdq_shared *shared = cmdq_get_shared(item);
struct cmdq_state *state = cmdq_get_state(item);
struct cmd_find_state *target = cmdq_get_target(item);
struct mouse_event *m = &shared->event.m;
struct mouse_event *m = &state->event.m;
struct cmd_if_shell_data *cdata;
char *shellcmd, *cmd;
const char *file;

View File

@ -64,8 +64,8 @@ static enum cmd_retval
cmd_join_pane_exec(struct cmd *self, struct cmdq_item *item)
{
struct args *args = cmd_get_args(self);
struct cmdq_shared *shared = cmdq_get_shared(item);
struct cmd_find_state *current = &shared->current;
struct cmdq_state *state = cmdq_get_state(item);
struct cmd_find_state *current = &state->current;
struct cmd_find_state *target = cmdq_get_target(item);
struct cmd_find_state *source = cmdq_get_source(item);
struct session *dst_s;

View File

@ -67,8 +67,8 @@ static enum cmd_retval
cmd_new_session_exec(struct cmd *self, struct cmdq_item *item)
{
struct args *args = cmd_get_args(self);
struct cmdq_shared *shared = cmdq_get_shared(item);
struct cmd_find_state *current = &shared->current;
struct cmdq_state *state = cmdq_get_state(item);
struct cmd_find_state *current = &state->current;
struct cmd_find_state *target = cmdq_get_target(item);
struct client *c = cmdq_get_client(item);
struct session *s, *as, *groupwith;
@ -317,7 +317,7 @@ cmd_new_session_exec(struct cmd *self, struct cmdq_item *item)
} else if (c->session != NULL)
c->last_session = c->session;
c->session = s;
if (~shared->flags & CMDQ_SHARED_REPEAT)
if (~state->flags & CMDQ_STATE_REPEAT)
server_client_set_key_table(c, NULL);
tty_update_client_offset(c);
status_timer_start(c);

View File

@ -52,8 +52,8 @@ static enum cmd_retval
cmd_new_window_exec(struct cmd *self, struct cmdq_item *item)
{
struct args *args = cmd_get_args(self);
struct cmdq_shared *shared = cmdq_get_shared(item);
struct cmd_find_state *current = &shared->current;
struct cmdq_state *state = cmdq_get_state(item);
struct cmd_find_state *current = &state->current;
struct cmd_find_state *target = cmdq_get_target(item);
struct spawn_context sc;
struct client *c = cmd_find_client(item, NULL, 1);

View File

@ -51,7 +51,7 @@ struct cmdq_item {
int flags;
struct cmdq_shared *shared;
struct cmdq_state *state;
struct cmd_find_state source;
struct cmd_find_state target;
@ -142,11 +142,11 @@ cmdq_get_source(struct cmdq_item *item)
return (&item->source);
}
/* Get item shared. */
struct cmdq_shared *
cmdq_get_shared(struct cmdq_item *item)
/* Get item state. */
struct cmdq_state *
cmdq_get_state(struct cmdq_item *item)
{
return (item->shared);
return (item->state);
}
/* Merge formats from item. */
@ -159,8 +159,8 @@ cmdq_merge_formats(struct cmdq_item *item, struct format_tree *ft)
entry = cmd_get_entry (item->cmd);
format_add(ft, "command", "%s", entry->name);
}
if (item->shared->formats != NULL)
format_merge(ft, item->shared->formats);
if (item->state->formats != NULL)
format_merge(ft, item->state->formats);
}
/* Append an item. */
@ -228,7 +228,7 @@ cmdq_insert_hook(struct session *s, struct cmdq_item *item,
struct options_array_item *a;
struct cmd_list *cmdlist;
if (item->shared->flags & CMDQ_SHARED_NOHOOKS)
if (item->state->flags & CMDQ_STATE_NOHOOKS)
return;
if (s == NULL)
oo = global_s_options;
@ -255,7 +255,7 @@ cmdq_insert_hook(struct session *s, struct cmdq_item *item,
}
new_item = cmdq_get_command(cmdlist, fs, NULL,
CMDQ_SHARED_NOHOOKS);
CMDQ_STATE_NOHOOKS);
cmdq_format(new_item, "hook", "%s", name);
if (item != NULL)
item = cmdq_insert_after(item, new_item);
@ -279,10 +279,10 @@ cmdq_continue(struct cmdq_item *item)
static void
cmdq_remove(struct cmdq_item *item)
{
if (item->shared != NULL && --item->shared->references == 0) {
if (item->shared->formats != NULL)
format_free(item->shared->formats);
free(item->shared);
if (item->state != NULL && --item->state->references == 0) {
if (item->state->formats != NULL)
format_free(item->state->formats);
free(item->state);
}
if (item->client != NULL)
@ -322,23 +322,23 @@ cmdq_get_command(struct cmd_list *cmdlist, struct cmd_find_state *current,
struct cmdq_item *item, *first = NULL, *last = NULL;
struct cmd *cmd;
const struct cmd_entry *entry;
struct cmdq_shared *shared = NULL;
struct cmdq_state *state = NULL;
u_int group, last_group = 0;
cmd = cmd_list_first(cmdlist, &group);
while (cmd != NULL) {
if (group != last_group) {
shared = xcalloc(1, sizeof *shared);
state = xcalloc(1, sizeof *state);
if (current != NULL)
cmd_find_copy_state(&shared->current, current);
cmd_find_copy_state(&state->current, current);
else
cmd_find_clear_state(&shared->current, 0);
cmd_find_clear_state(&state->current, 0);
if (m != NULL) {
shared->event.key = KEYC_NONE;
memcpy(&shared->event.m, m,
sizeof shared->event.m);
state->event.key = KEYC_NONE;
memcpy(&state->event.m, m,
sizeof state->event.m);
}
shared->flags = flags;
state->flags = flags;
last_group = group;
}
entry = cmd_get_entry(cmd);
@ -348,13 +348,13 @@ cmdq_get_command(struct cmd_list *cmdlist, struct cmd_find_state *current,
item->type = CMDQ_COMMAND;
item->group = group;
item->shared = shared;
item->state = state;
item->cmdlist = cmdlist;
item->cmd = cmd;
log_debug("%s: %s group %u", __func__, item->name, item->group);
shared->references++;
state->references++;
cmdlist->references++;
if (first == NULL)
@ -394,7 +394,7 @@ cmdq_fire_command(struct cmdq_item *item)
{
struct client *c = item->client;
const char *name = cmdq_name(c);
struct cmdq_shared *shared = item->shared;
struct cmdq_state *state = item->state;
struct cmd *cmd = item->cmd;
const struct cmd_entry *entry = cmd_get_entry(cmd);
enum cmd_retval retval;
@ -408,7 +408,7 @@ cmdq_fire_command(struct cmdq_item *item)
free(tmp);
}
flags = !!(shared->flags & CMDQ_SHARED_CONTROL);
flags = !!(state->flags & CMDQ_STATE_CONTROL);
cmdq_guard(item, "begin", flags);
if (item->client == NULL)
@ -427,8 +427,8 @@ cmdq_fire_command(struct cmdq_item *item)
if (entry->flags & CMD_AFTERHOOK) {
if (cmd_find_valid_state(&item->target))
fsp = &item->target;
else if (cmd_find_valid_state(&item->shared->current))
fsp = &item->shared->current;
else if (cmd_find_valid_state(&item->state->current))
fsp = &item->state->current;
else if (cmd_find_from_client(&fs, item->client, 0) == 0)
fsp = &fs;
else
@ -492,7 +492,7 @@ cmdq_fire_callback(struct cmdq_item *item)
void
cmdq_format(struct cmdq_item *item, const char *key, const char *fmt, ...)
{
struct cmdq_shared *shared = item->shared;
struct cmdq_state *state = item->state;
va_list ap;
char *value;
@ -500,9 +500,9 @@ cmdq_format(struct cmdq_item *item, const char *key, const char *fmt, ...)
xvasprintf(&value, fmt, ap);
va_end(ap);
if (shared->formats == NULL)
shared->formats = format_create(NULL, NULL, FORMAT_NONE, 0);
format_add(shared->formats, key, "%s", value);
if (state->formats == NULL)
state->formats = format_create(NULL, NULL, FORMAT_NONE, 0);
format_add(state->formats, key, "%s", value);
free(value);
}

View File

@ -50,7 +50,7 @@ static enum cmd_retval
cmd_resize_pane_exec(struct cmd *self, struct cmdq_item *item)
{
struct args *args = cmd_get_args(self);
struct cmdq_shared *shared = cmdq_get_shared(item);
struct cmdq_state *state = cmdq_get_state(item);
struct cmd_find_state *target = cmdq_get_target(item);
struct window_pane *wp = target->wp;
struct winlink *wl = target->wl;
@ -76,12 +76,12 @@ cmd_resize_pane_exec(struct cmd *self, struct cmdq_item *item)
}
if (args_has(args, 'M')) {
if (cmd_mouse_window(&shared->event.m, &s) == NULL)
if (cmd_mouse_window(&state->event.m, &s) == NULL)
return (CMD_RETURN_NORMAL);
if (c == NULL || c->session != s)
return (CMD_RETURN_NORMAL);
c->tty.mouse_drag_update = cmd_resize_pane_mouse_update;
cmd_resize_pane_mouse_update(c, &shared->event.m);
cmd_resize_pane_mouse_update(c, &state->event.m);
return (CMD_RETURN_NORMAL);
}

View File

@ -44,8 +44,8 @@ static enum cmd_retval
cmd_rotate_window_exec(struct cmd *self, struct cmdq_item *item)
{
struct args *args = cmd_get_args(self);
struct cmdq_shared *shared = cmdq_get_shared(item);
struct cmd_find_state *current = &shared->current;
struct cmdq_state *state = cmdq_get_state(item);
struct cmd_find_state *current = &state->current;
struct cmd_find_state *target = cmdq_get_target(item);
struct winlink *wl = target->wl;
struct window *w = wl->window;

View File

@ -85,8 +85,8 @@ cmd_select_pane_exec(struct cmd *self, struct cmdq_item *item)
{
struct args *args = cmd_get_args(self);
const struct cmd_entry *entry = cmd_get_entry(self);
struct cmdq_shared *shared = cmdq_get_shared(item);
struct cmd_find_state *current = &shared->current;
struct cmdq_state *state = cmdq_get_state(item);
struct cmd_find_state *current = &state->current;
struct cmd_find_state *target = cmdq_get_target(item);
struct client *c = cmd_find_client(item, NULL, 1);
struct winlink *wl = target->wl;

View File

@ -85,8 +85,8 @@ static enum cmd_retval
cmd_select_window_exec(struct cmd *self, struct cmdq_item *item)
{
struct args *args = cmd_get_args(self);
struct cmdq_shared *shared = cmdq_get_shared(item);
struct cmd_find_state *current = &shared->current;
struct cmdq_state *state = cmdq_get_state(item);
struct cmd_find_state *current = &state->current;
struct cmd_find_state *target = cmdq_get_target(item);
struct winlink *wl = target->wl;
struct session *s = target->s;

View File

@ -134,13 +134,13 @@ static enum cmd_retval
cmd_send_keys_exec(struct cmd *self, struct cmdq_item *item)
{
struct args *args = cmd_get_args(self);
struct cmdq_shared *shared = cmdq_get_shared(item);
struct cmdq_state *state = cmdq_get_state(item);
struct cmd_find_state *target = cmdq_get_target(item);
struct client *c = cmd_find_client(item, NULL, 1);
struct window_pane *wp = target->wp;
struct session *s = target->s;
struct winlink *wl = target->wl;
struct mouse_event *m = &shared->event.m;
struct mouse_event *m = &state->event.m;
struct window_mode_entry *wme = TAILQ_FIRST(&wp->modes);
int i;
key_code key;

View File

@ -54,8 +54,8 @@ static enum cmd_retval
cmd_split_window_exec(struct cmd *self, struct cmdq_item *item)
{
struct args *args = cmd_get_args(self);
struct cmdq_shared *shared = cmdq_get_shared(item);
struct cmd_find_state *current = &shared->current;
struct cmdq_state *state = cmdq_get_state(item);
struct cmd_find_state *current = &state->current;
struct cmd_find_state *target = cmdq_get_target(item);
struct spawn_context sc;
struct client *c = cmd_find_client(item, NULL, 1);

View File

@ -48,8 +48,8 @@ static enum cmd_retval
cmd_switch_client_exec(struct cmd *self, struct cmdq_item *item)
{
struct args *args = cmd_get_args(self);
struct cmdq_shared *shared = cmdq_get_shared(item);
struct cmd_find_state *current = &shared->current;
struct cmdq_state *state = cmdq_get_state(item);
struct cmd_find_state *current = &state->current;
struct cmd_find_state target;
const char *tflag = args_get(args, 't');
enum cmd_find_type type;
@ -137,7 +137,7 @@ cmd_switch_client_exec(struct cmd *self, struct cmdq_item *item)
if (c->session != NULL && c->session != s)
c->last_session = c->session;
c->session = s;
if (~shared->flags & CMDQ_SHARED_REPEAT)
if (~state->flags & CMDQ_STATE_REPEAT)
server_client_set_key_table(c, NULL);
tty_update_client_offset(c);
status_timer_start(c);

View File

@ -86,7 +86,7 @@ control_callback(__unused struct client *c, __unused const char *path,
break;
case CMD_PARSE_SUCCESS:
item = cmdq_get_command(pr->cmdlist, NULL, NULL, 0);
cmdq_get_shared(item)->flags |= CMDQ_SHARED_CONTROL;
cmdq_get_state(item)->flags |= CMDQ_STATE_CONTROL;
cmdq_append(c, item);
cmd_list_free(pr->cmdlist);
break;

View File

@ -1124,16 +1124,16 @@ format_merge(struct format_tree *ft, struct format_tree *from)
static void
format_create_add_item(struct format_tree *ft, struct cmdq_item *item)
{
struct cmdq_shared *shared = cmdq_get_shared(item);
struct cmdq_state *state = cmdq_get_state(item);
struct mouse_event *m;
struct window_pane *wp;
u_int x, y;
cmdq_merge_formats(item, ft);
if (shared == NULL)
if (state == NULL)
return;
m = &shared->event.m;
m = &state->event.m;
if (m->valid && ((wp = cmd_mouse_pane(m, NULL, NULL)) != NULL)) {
format_add(ft, "mouse_pane", "%%%u", wp->id);
if (cmd_mouse_at(wp, m, &x, &y, 0) == 0) {

View File

@ -549,7 +549,7 @@ key_bindings_dispatch(struct key_binding *bd, struct cmdq_item *item,
else {
new_item = cmdq_get_command(bd->cmdlist, fs, m, 0);
if (bd->flags & KEY_BINDING_REPEAT)
cmdq_get_shared(new_item)->flags |= CMDQ_SHARED_REPEAT;
cmdq_get_state(new_item)->flags |= CMDQ_STATE_REPEAT;
}
if (item != NULL)
new_item = cmdq_insert_after(item, new_item);

2
menu.c
View File

@ -282,7 +282,7 @@ chosen:
break;
case CMD_PARSE_SUCCESS:
if (md->item != NULL)
m = &cmdq_get_shared(md->item)->event.m;
m = &cmdq_get_state(md->item)->event.m;
else
m = NULL;
new_item = cmdq_get_command(pr->cmdlist, &md->fs, m, 0);

View File

@ -96,7 +96,7 @@ notify_insert_hook(struct cmdq_item *item, struct notify_entry *ne)
}
new_item = cmdq_get_command(cmdlist, &fs, NULL,
CMDQ_SHARED_NOHOOKS);
CMDQ_STATE_NOHOOKS);
cmdq_format(new_item, "hook", "%s", ne->name);
notify_hook_formats(new_item, s, w, ne->pane);
item = cmdq_insert_after(item, new_item);

View File

@ -305,7 +305,7 @@ popup_key_cb(struct client *c, struct key_event *event)
break;
case CMD_PARSE_SUCCESS:
if (pd->item != NULL)
m = &cmdq_get_shared(pd->item)->event.m;
m = &cmdq_get_state(pd->item)->event.m;
else
m = NULL;
new_item = cmdq_get_command(pr->cmdlist, fs, m, 0);

12
tmux.h
View File

@ -1378,14 +1378,14 @@ struct cmd_parse_input {
struct cmd_find_state fs;
};
/* Command queue item shared state. */
struct cmdq_shared {
/* Command queue item state. */
struct cmdq_state {
int references;
int flags;
#define CMDQ_SHARED_REPEAT 0x1
#define CMDQ_SHARED_CONTROL 0x2
#define CMDQ_SHARED_NOHOOKS 0x4
#define CMDQ_STATE_REPEAT 0x1
#define CMDQ_STATE_CONTROL 0x2
#define CMDQ_STATE_NOHOOKS 0x4
struct format_tree *formats;
@ -2108,7 +2108,7 @@ const char *cmdq_get_name(struct cmdq_item *);
struct client *cmdq_get_client(struct cmdq_item *);
struct cmd_find_state *cmdq_get_target(struct cmdq_item *);
struct cmd_find_state *cmdq_get_source(struct cmdq_item *);
struct cmdq_shared *cmdq_get_shared(struct cmdq_item *);
struct cmdq_state *cmdq_get_state(struct cmdq_item *);
void cmdq_merge_formats(struct cmdq_item *, struct format_tree *);
struct cmdq_item *cmdq_get_command(struct cmd_list *, struct cmd_find_state *,
struct mouse_event *, int);