diff options
author | sabetts <sabetts> | 2001-02-19 09:56:37 +0000 |
---|---|---|
committer | sabetts <sabetts> | 2001-02-19 09:56:37 +0000 |
commit | fe1b95fa672387232732507a65565bac8c470c26 (patch) | |
tree | fea1ebe54c235ec19eacebed1b7867bc17e086a2 /src/list.c | |
parent | 4f193c1f4d81f0f583d4db7a00c3cb54967b2058 (diff) | |
download | ratpoison-fe1b95fa672387232732507a65565bac8c470c26.zip |
* manage.c (manage): calls sort_window_list_by_number
* list.h (sort_window_list_by_number): Added prototype
* list.c (swap_list_elements): Added
(sort_window_list_by_number): Added
* input.c (update_input_window): Added
(get_input): calls update_input_window in place of xlib calls.
(get_input): exits if realloc fails
* conf.h: Added INPUT_WINDOW_SIZE
* bar.c (update_window_names): loops through window list from head
to tail.
Diffstat (limited to 'src/list.c')
-rw-r--r-- | src/list.c | 53 |
1 files changed, 53 insertions, 0 deletions
@@ -219,6 +219,59 @@ find_last_accessed_window () return most_recent; } +/* This somewhat CPU intensive (memcpy) swap function sorta defeats + the purpose of a linear linked list. */ +static void +swap_list_elements (rp_window *a, rp_window *b) +{ + rp_window tmp; + rp_window *tmp_a_next, *tmp_a_prev; + rp_window *tmp_b_next, *tmp_b_prev; + + if (a == NULL || b == NULL || a == b) return; + + tmp_a_next = a->next; + tmp_a_prev = a->prev; + + tmp_b_next = b->next; + tmp_b_prev = b->prev; + + memcpy (&tmp, a, sizeof (rp_window)); + memcpy (a, b, sizeof (rp_window)); + memcpy (b, &tmp, sizeof (rp_window)); + + a->next = tmp_a_next; + a->prev = tmp_a_prev; + + b->next = tmp_b_next; + b->prev = tmp_b_prev; +} + +/* Can you say b-b-b-b-bubble sort? */ +void +sort_window_list_by_number () +{ + rp_window *i, *j, *smallest; + + for (i=rp_window_head; i; i=i->next) + { + if (i->state == STATE_UNMAPPED) continue; + + smallest = i; + for (j=i->next; j; j=j->next) + { + if (j->state == STATE_UNMAPPED) continue; + + if (j->number < smallest->number) + { + smallest = j; + } + } + + swap_list_elements (i, smallest); + } +} + static void save_mouse_position (rp_window *win) { |