mirror of
https://github.com/tmux/tmux.git
synced 2024-11-04 18:08:48 +00:00
Fix session choice so that preferring unattached sessions actually
works, reported by Drew Frank.
This commit is contained in:
parent
d762ced298
commit
991bfcf443
36
cmd.c
36
cmd.c
@ -116,6 +116,7 @@ const struct cmd_entry *cmd_table[] = {
|
|||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
|
int cmd_session_better(struct session *, struct session *, int);
|
||||||
struct session *cmd_choose_session_list(struct sessionslist *);
|
struct session *cmd_choose_session_list(struct sessionslist *);
|
||||||
struct session *cmd_choose_session(int);
|
struct session *cmd_choose_session(int);
|
||||||
struct client *cmd_choose_client(struct clients *);
|
struct client *cmd_choose_client(struct clients *);
|
||||||
@ -371,6 +372,24 @@ cmd_current_session(struct cmd_ctx *ctx, int prefer_unattached)
|
|||||||
return (cmd_choose_session(prefer_unattached));
|
return (cmd_choose_session(prefer_unattached));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Is this session better? */
|
||||||
|
int
|
||||||
|
cmd_session_better(struct session *s, struct session *best,
|
||||||
|
int prefer_unattached)
|
||||||
|
{
|
||||||
|
if (best == NULL)
|
||||||
|
return 1;
|
||||||
|
if (prefer_unattached) {
|
||||||
|
if (!(best->flags & SESSION_UNATTACHED) &&
|
||||||
|
(s->flags & SESSION_UNATTACHED))
|
||||||
|
return 1;
|
||||||
|
else if ((best->flags & SESSION_UNATTACHED) &&
|
||||||
|
!(s->flags & SESSION_UNATTACHED))
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return (timercmp(&s->activity_time, &best->activity_time, >));
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Find the most recently used session, preferring unattached if the flag is
|
* Find the most recently used session, preferring unattached if the flag is
|
||||||
* set.
|
* set.
|
||||||
@ -378,21 +397,14 @@ cmd_current_session(struct cmd_ctx *ctx, int prefer_unattached)
|
|||||||
struct session *
|
struct session *
|
||||||
cmd_choose_session(int prefer_unattached)
|
cmd_choose_session(int prefer_unattached)
|
||||||
{
|
{
|
||||||
struct session *s, *sbest;
|
struct session *s, *best;
|
||||||
struct timeval *tv = NULL;
|
|
||||||
|
|
||||||
sbest = NULL;
|
best = NULL;
|
||||||
RB_FOREACH(s, sessions, &sessions) {
|
RB_FOREACH(s, sessions, &sessions) {
|
||||||
if (tv == NULL || timercmp(&s->activity_time, tv, >) ||
|
if (cmd_session_better(s, best, prefer_unattached))
|
||||||
(prefer_unattached &&
|
best = s;
|
||||||
!(sbest->flags & SESSION_UNATTACHED) &&
|
|
||||||
(s->flags & SESSION_UNATTACHED))) {
|
|
||||||
sbest = s;
|
|
||||||
tv = &s->activity_time;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
return (best);
|
||||||
return (sbest);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Find the most recently used session from a list. */
|
/* Find the most recently used session from a list. */
|
||||||
|
2
names.c
2
names.c
@ -76,7 +76,7 @@ window_name_callback(unused int fd, unused short events, void *data)
|
|||||||
name != NULL && name[0] == '-' && name[1] != '\0')
|
name != NULL && name[0] == '-' && name[1] != '\0')
|
||||||
wname = parse_window_name(name + 1);
|
wname = parse_window_name(name + 1);
|
||||||
else
|
else
|
||||||
wname = parse_window_name(name);
|
wname = parse_window_name(name);
|
||||||
free(name);
|
free(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user