summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorsabetts <sabetts>2003-03-07 03:14:35 +0000
committersabetts <sabetts>2003-03-07 03:14:35 +0000
commitb5659f308a72902befb87c81e1e4a4f1d98d209d (patch)
tree6056d8cbfd4d89a1190952436e747a5d3ea54faf /src
parent293fca91a75f15c696c2f1d9dd4227f558cfc26f (diff)
downloadratpoison-b5659f308a72902befb87c81e1e4a4f1d98d209d.zip
* src/main.c (main): call init_window_stuff(). Remove call to init_numbers().
(clean_up): call free_window_stuff(). Remove call to free_numbers(). * src/list.h (free_window_stuff): new prototype (init_window_stuff): likewise * src/list.c (rp_window_numset): new global (init_window_stuff): new function (free_window_stuff): new function * src/data.h (rp_window_numset): new extern * src/number.c (numset_init): new function (number_is_taken): rename to numset_num_is_taken, callers updated. (find_empty_cell): rename to numset_find_empty_cell, callers updated. (add_window_number): rename to numset_add_num, callers updated. (return_window_number): rename to numset_release, callers updated. (init_numbers): remove function (free_numbers): rename to numset_free, callers updated. (numset_num_is_taken): take struct numset* as an argument. (numset_find_empty_cell): likewise (numset_add_num): likewise (numset_request): likewise (numset_release): likewise (numset_free): likewise (numset_new): new function
Diffstat (limited to 'src')
-rw-r--r--src/actions.c6
-rw-r--r--src/data.h3
-rw-r--r--src/list.c14
-rw-r--r--src/list.h2
-rw-r--r--src/main.c7
-rw-r--r--src/manage.c6
-rw-r--r--src/number.c77
-rw-r--r--src/number.h24
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);
}
diff --git a/src/data.h b/src/data.h
index 235517b..2164b5a 100644
--- a/src/data.h
+++ b/src/data.h
@@ -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 */
diff --git a/src/list.c b/src/list.c
index 12d51c8..87ad967 100644
--- a/src/list.c
+++ b/src/list.c
@@ -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);
+}
diff --git a/src/list.h b/src/list.h
index bc3314f..f15c26b 100644
--- a/src/list.h
+++ b/src/list.h
@@ -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 */
diff --git a/src/main.c b/src/main.c
index 4c31511..817b231 100644
--- a/src/main.c
+++ b/src/main.c
@@ -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 */