summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsabetts <sabetts>2000-08-27 23:21:00 +0000
committersabetts <sabetts>2000-08-27 23:21:00 +0000
commit98a3dea008502975d0b4958a8dc2c4f37bfa6b80 (patch)
treeec6b94f9b93632859e314bb12f544ae01f413000
parent2f020a0d37e9bfb0b8ebc40062622ae4f200e4a1 (diff)
downloadratpoison-98a3dea008502975d0b4958a8dc2c4f37bfa6b80.zip
integrated the number sources. windows now keep the number they're
given.
-rw-r--r--bar.c16
-rw-r--r--data.h1
-rw-r--r--list.c11
-rw-r--r--main.c1
-rw-r--r--manage.c4
-rw-r--r--number.c18
-rw-r--r--ratpoison.h3
7 files changed, 37 insertions, 17 deletions
diff --git a/bar.c b/bar.c
index 6554f9a..e7107d8 100644
--- a/bar.c
+++ b/bar.c
@@ -70,17 +70,15 @@ static int
calc_bar_width (XFontStruct *font)
{
char str[100]; /* window names are capped at 99 chars */
- int i;
int size = 1;
rp_window *cur;
- for (i=0, cur = rp_window_head; cur; cur = cur->next)
+ for (cur = rp_window_head; cur; cur = cur->next)
{
if (cur->state == STATE_UNMAPPED) continue;
- sprintf (str, "%d-%s", i, cur->name);
+ sprintf (str, "%d-%s", cur->number, cur->name);
size += 10 + XTextWidth (font, str, strlen (str));
- i++;
}
return size;
@@ -104,7 +102,6 @@ void
update_window_names (screen_info *s)
{
char str[100]; /* window names are capped at 99 chars */
- int i;
int width = calc_bar_width (s->font);
rp_window *cur;
int cur_x = 5;
@@ -119,11 +116,15 @@ update_window_names (screen_info *s)
XRaiseWindow (dpy, s->bar_window);
if (rp_window_head == NULL) return;
- for (i=0, cur = rp_window_head; cur; cur = cur->next)
+
+ /* Draw them in reverse order they were added in, so the oldest
+ windows appear on the left and the newest on the right end of the
+ program bar. */
+ for (cur = rp_window_tail; cur; cur = cur->prev)
{
if (cur->state == STATE_UNMAPPED) continue;
- sprintf (str, "%d-%s", i, cur->name);
+ sprintf (str, "%d-%s", cur->number, cur->name);
if ( rp_current_window == cur)
{
XDrawString (dpy, s->bar_window, s->bold_gc, cur_x,
@@ -136,6 +137,5 @@ update_window_names (screen_info *s)
}
cur_x += 10 + XTextWidth (s->font, str, strlen (str));
- i++;
}
}
diff --git a/data.h b/data.h
index af88705..98da37d 100644
--- a/data.h
+++ b/data.h
@@ -36,6 +36,7 @@ struct rp_window
{
screen_info *scr;
Window w;
+ int number;
char *name;
int state;
int last_access;
diff --git a/list.c b/list.c
index 3398ae7..2f1a145 100644
--- a/list.c
+++ b/list.c
@@ -41,6 +41,7 @@ add_to_window_list (screen_info *s, Window w)
new_window->last_access = 0;
new_window->prev = NULL;
new_window->state = STATE_UNMAPPED;
+ new_window->number = -1;
if ((new_window->name = malloc (strlen ("Unnamed") + 1)) == NULL)
{
fprintf (stderr, "list.c:add_to_window_list():Out of memory.\n");
@@ -77,6 +78,7 @@ find_window (Window w)
return NULL;
}
+/* this function can rp_current_window a dangling pointer. */
void
remove_from_window_list (rp_window *w)
{
@@ -86,9 +88,6 @@ remove_from_window_list (rp_window *w)
if (w->prev != NULL) w->prev->next = w->next;
if (w->next != NULL) w->next->prev = w->prev;
- if (rp_current_window == w) rp_current_window = rp_window_head;
- if (rp_current_window && rp_current_window->state == STATE_UNMAPPED) next_window ();
-
free (w);
#ifdef DEBUG
printf ("Removed window from list.\n");
@@ -141,15 +140,13 @@ prev_window ()
rp_window *
find_window_by_number (int n)
{
- int i;
rp_window *cur;
- for (i=0, cur=rp_window_head; cur; cur=cur->next)
+ for (cur=rp_window_head; cur; cur=cur->next)
{
if (cur->state != STATE_MAPPED) continue;
- if (i == n) return cur;
- else i++;
+ if (n == cur->number) return cur;
}
return NULL;
diff --git a/main.c b/main.c
index 2a16c27..b7393fc 100644
--- a/main.c
+++ b/main.c
@@ -124,6 +124,7 @@ main (int argc, char *argv[])
signal (SIGHUP, SIG_IGN);
}
+ init_numbers ();
init_window_list ();
font = XLoadQueryFont (dpy, FONT_NAME);
diff --git a/manage.c b/manage.c
index 2ed6af9..04ce0ad 100644
--- a/manage.c
+++ b/manage.c
@@ -130,7 +130,9 @@ manage (rp_window *win, screen_info *s)
XSelectInput (dpy, win->w, PropertyChangeMask);
XAddToSaveSet(dpy, win->w);
grab_prefix_key (win->w);
+
win->state = STATE_MAPPED;
+ win->number = get_unique_window_number ();
#ifdef DEBUG
printf ("window '%s' managed.\n", win->name);
@@ -140,7 +142,9 @@ manage (rp_window *win, screen_info *s)
void
unmanage (rp_window *w)
{
+ return_window_number (w->number);
remove_from_window_list (w);
+ last_window ();
}
/* When starting up scan existing windows and start managing them. */
diff --git a/number.c b/number.c
index d1dfe3a..6bd11c6 100644
--- a/number.c
+++ b/number.c
@@ -91,7 +91,7 @@ get_unique_window_number ()
/* look for a unique number, and add it to the list of taken
numbers. */
i = 0;
- while (add_to_list (i)) i++;
+ while (!add_to_list (i)) i++;
return i;
}
@@ -112,3 +112,19 @@ return_window_number (int n)
}
}
}
+
+
+void
+init_numbers ()
+{
+ max_taken = 10;
+ num_taken = 0;
+
+ numbers_taken = malloc (max_taken * sizeof (int));
+ if (numbers_taken == NULL)
+ {
+ fprintf (stderr, "numbers.c: Cannot alloc numbers_taken.\n");
+ exit (EXIT_FAILURE);
+ }
+
+}
diff --git a/ratpoison.h b/ratpoison.h
index 02dab67..b683196 100644
--- a/ratpoison.h
+++ b/ratpoison.h
@@ -1,4 +1,4 @@
-/* Some standard datatypes for ratpoison
+/* Standard header for ratpoison.
*
* Copyright (C) 2000 Shawn Betts
*
@@ -27,6 +27,7 @@
#include "list.h"
#include "bar.h"
#include "events.h"
+#include "number.h"
void clean_up ();
screen_info *find_screen (Window w);