mirror of
https://github.com/profanity-im/profanity.git
synced 2024-12-04 14:46:46 -05:00
Copy list when sorting windows for /wins
This commit is contained in:
parent
e565812d09
commit
6ab937c3e3
14
src/common.c
14
src/common.c
@ -488,25 +488,34 @@ cmp_win_num(gconstpointer a, gconstpointer b)
|
|||||||
int
|
int
|
||||||
get_next_available_win_num(GList *used)
|
get_next_available_win_num(GList *used)
|
||||||
{
|
{
|
||||||
used = g_list_sort(used, cmp_win_num);
|
|
||||||
// only console used
|
// only console used
|
||||||
if (g_list_length(used) == 1) {
|
if (g_list_length(used) == 1) {
|
||||||
return 2;
|
return 2;
|
||||||
} else {
|
} else {
|
||||||
|
GList *sorted = NULL;
|
||||||
|
GList *curr = used;
|
||||||
|
while (curr) {
|
||||||
|
sorted = g_list_insert_sorted(sorted, curr->data, cmp_win_num);
|
||||||
|
curr = g_list_next(curr);
|
||||||
|
}
|
||||||
|
|
||||||
int result = 0;
|
int result = 0;
|
||||||
int last_num = 1;
|
int last_num = 1;
|
||||||
GList *curr = used;
|
curr = sorted;
|
||||||
// skip console
|
// skip console
|
||||||
curr = g_list_next(curr);
|
curr = g_list_next(curr);
|
||||||
while (curr != NULL) {
|
while (curr != NULL) {
|
||||||
int curr_num = GPOINTER_TO_INT(curr->data);
|
int curr_num = GPOINTER_TO_INT(curr->data);
|
||||||
|
|
||||||
if (((last_num != 9) && ((last_num + 1) != curr_num)) ||
|
if (((last_num != 9) && ((last_num + 1) != curr_num)) ||
|
||||||
((last_num == 9) && (curr_num != 0))) {
|
((last_num == 9) && (curr_num != 0))) {
|
||||||
result = last_num + 1;
|
result = last_num + 1;
|
||||||
if (result == 10) {
|
if (result == 10) {
|
||||||
result = 0;
|
result = 0;
|
||||||
}
|
}
|
||||||
|
g_list_free(sorted);
|
||||||
return (result);
|
return (result);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
last_num = curr_num;
|
last_num = curr_num;
|
||||||
if (last_num == 0) {
|
if (last_num == 0) {
|
||||||
@ -520,6 +529,7 @@ get_next_available_win_num(GList *used)
|
|||||||
result = 0;
|
result = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
g_list_free(sorted);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user