diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/actions.c | 6 | ||||
-rw-r--r-- | src/data.h | 3 | ||||
-rw-r--r-- | src/list.c | 14 | ||||
-rw-r--r-- | src/list.h | 2 | ||||
-rw-r--r-- | src/main.c | 7 | ||||
-rw-r--r-- | src/manage.c | 6 | ||||
-rw-r--r-- | src/number.c | 77 | ||||
-rw-r--r-- | src/number.h | 24 |
8 files changed, 88 insertions, 51 deletions
diff --git a/src/actions.c b/src/actions.c index 28a583e..e655341 100644 --- a/src/actions.c +++ b/src/actions.c @@ -1175,11 +1175,11 @@ cmd_number (int interactive, void *data) } else { - return_window_number (win->number); + numset_release (rp_window_numset, win->number); } win->number = new_number; - add_window_number (new_number); + numset_add_num (rp_window_numset, new_number); /* resort the the window in the list */ list_del (&win->node); @@ -2788,7 +2788,7 @@ cmd_tmpwm (int interactive, void *data) if (frame == win->scr->rp_current_frame) set_active_frame (frame); /* put the window in the unmapped list. */ - return_window_number (win->number); + numset_release (rp_window_numset, win->number); list_move_tail(&win->node, &rp_unmapped_window); } @@ -276,4 +276,7 @@ extern int rp_honour_normal_map; /* Keep track of X11 error messages. */ extern char *rp_error_msg; +/* Number sets for windows. */ +extern struct numset *rp_window_numset; + #endif /* _RATPOISON_DATA_H */ @@ -29,6 +29,8 @@ LIST_HEAD(rp_unmapped_window); LIST_HEAD(rp_mapped_window); +struct numset *rp_window_numset; + /* Get the mouse position relative to the root of the specified window */ static void get_mouse_root_position (rp_window *win, int *mouse_x, int *mouse_y) @@ -669,3 +671,15 @@ get_window_list (char *fmt, char *delim, struct sbuf *buffer, sbuf_copy (buffer, MESSAGE_NO_MANAGED_WINDOWS); } } + +void +init_window_stuff () +{ + rp_window_numset = numset_new (); +} + +void +free_window_stuff () +{ + numset_free (rp_window_numset); +} @@ -60,5 +60,7 @@ void insert_into_list (rp_window *win, struct list_head *list); void print_window_information (rp_window *win); void get_window_list (char *fmt, char *delim, struct sbuf *buffer, int *mark_start, int *mark_end); +void init_window_stuff (); +void free_window_stuff (); #endif /* ! _RATPOISON_LIST_H */ @@ -573,8 +573,8 @@ main (int argc, char *argv[]) set_sig_handler (SIGCHLD, chld_handler); /* Setup ratpoison's internal structures */ - init_defaults(); - init_numbers (); + init_defaults (); + init_window_stuff (); /* Initialize the screens */ num_screens = ScreenCount (dpy); @@ -730,8 +730,9 @@ clean_up () free_keybindings (); free_aliases (); free_bar (); - free_numbers (); free_history (); + + free_window_stuff (); for (i=0; i<num_screens; i++) { diff --git a/src/manage.c b/src/manage.c index 1cdb66a..7a19934 100644 --- a/src/manage.c +++ b/src/manage.c @@ -267,7 +267,7 @@ update_window_information (rp_window *win) void unmanage (rp_window *w) { - return_window_number (w->number); + numset_release (rp_window_numset, w->number); list_del (&w->node); free_window (w); @@ -635,7 +635,7 @@ map_window (rp_window *win) /* Fill in the necessary data about the window */ update_window_information (win); - win->number = get_unique_window_number (); + win->number = numset_request (rp_window_numset); grab_prefix_key (win->w); /* Put win in the mapped window list */ @@ -719,7 +719,7 @@ withdraw_window (rp_window *win) /* Give back the window number. the window will get another one, if it is remapped. */ - return_window_number (win->number); + numset_release (rp_window_numset, win->number); win->number = -1; list_move_tail(&win->node, &rp_unmapped_window); diff --git a/src/number.c b/src/number.c index 0dfd2cf..33dccab 100644 --- a/src/number.c +++ b/src/number.c @@ -24,71 +24,71 @@ #include "ratpoison.h" +/* Initialize a numset structure. */ +static void +numset_init (struct numset *ns) +{ + ns->max_taken = 10; + ns->num_taken = 0; -/* A list of the numbers taken. */ -static int *numbers_taken; - -/* the number of numbers currently stored in the numbers_taken - array. */ -static int num_taken; - -/* the size of the numbers_taken array. */ -static int max_taken; + ns->numbers_taken = xmalloc (ns->max_taken * sizeof (int)); +} static int -number_is_taken (int n) +numset_num_is_taken (struct numset *ns, int n) { int i; - for (i=0; i<num_taken; i++) + for (i=0; i<ns->num_taken; i++) { - if (numbers_taken[i] == n) return 1; + if (ns->numbers_taken[i] == n) return 1; } return 0; } /* returns index into numbers_taken that can be used. */ static int -find_empty_cell () +numset_find_empty_cell (struct numset *ns) { int i; - for (i=0; i<num_taken; i++) + for (i=0; i<ns->num_taken; i++) { - if (numbers_taken[i] == -1) return i; + if (ns->numbers_taken[i] == -1) return i; } /* no vacant ones, so grow the array. */ - if (num_taken >= max_taken) + if (ns->num_taken >= ns->max_taken) { - max_taken *= 2; - numbers_taken = xrealloc (numbers_taken, sizeof (int) * max_taken); + ns->max_taken *= 2; + ns->numbers_taken = xrealloc (ns->numbers_taken, sizeof (int) * ns->max_taken); } - num_taken++; + ns->num_taken++; - return num_taken-1; + return ns->num_taken-1; } int -add_window_number (int n) +numset_add_num (struct numset *ns, int n) { - if (number_is_taken (n)) return 0; /* failed. */ + if (numset_num_is_taken (ns, n)) + return 0; /* failed. */ - numbers_taken[find_empty_cell()] = n; + ns->numbers_taken[numset_find_empty_cell(ns)] = n; return 1; /* success! */ } /* returns a unique number that can be used as the window number in the program bar. */ int -get_unique_window_number () +numset_request (struct numset *ns) { int i; /* look for a unique number, and add it to the list of taken numbers. */ i = 0; - while (!add_window_number (i)) i++; + while (!numset_add_num (ns, i)) i++; return i; } @@ -96,32 +96,35 @@ get_unique_window_number () /* When a window is destroyed, it gives back its window number with this function. */ void -return_window_number (int n) +numset_release (struct numset *ns, int n) { int i; - for (i=0; i<num_taken; i++) + for (i=0; i<ns->num_taken; i++) { - if (numbers_taken[i] == n) + if (ns->numbers_taken[i] == n) { - numbers_taken[i] = -1; + ns->numbers_taken[i] = -1; return; } } } - -void -init_numbers () +/* Create a new numset and return a pointer to it. */ +struct numset * +numset_new () { - max_taken = 10; - num_taken = 0; + struct numset *ns; - numbers_taken = xmalloc (max_taken * sizeof (int)); + ns = (struct numset *)xmalloc (sizeof (struct numset)); + numset_init (ns); + return ns; } +/* Free a numset structure and it's internal data. */ void -free_numbers () +numset_free (struct numset *ns) { - free (numbers_taken); + free (ns->numbers_taken); + free (ns); } diff --git a/src/number.h b/src/number.h index caecff5..1fc6a09 100644 --- a/src/number.h +++ b/src/number.h @@ -22,10 +22,24 @@ #ifndef _RATPOISON_NUMBER_H #define _RATPOISON_NUMBER_H 1 -int get_unique_window_number (); -void return_window_number (int n); -int add_window_number (int n); -void init_numbers (); -void free_numbers (); +/* Keep track of a set of numbers. For frames and windows. */ +struct numset +{ + /* A list of the numbers taken. */ + int *numbers_taken; + +/* the number of numbers currently stored in the numbers_taken + array. */ + int num_taken; + +/* the size of the numbers_taken array. */ + int max_taken; +}; + +struct numset *numset_new (); +void numset_free (struct numset *ns); +void numset_release (struct numset *ns, int n); +int numset_request (struct numset *ns); +int numset_add_num (struct numset *ns, int n); #endif /* ! _RATPOISON_NUMBER_H */ |