diff options
author | sabetts <sabetts> | 2000-08-27 23:21:00 +0000 |
---|---|---|
committer | sabetts <sabetts> | 2000-08-27 23:21:00 +0000 |
commit | 98a3dea008502975d0b4958a8dc2c4f37bfa6b80 (patch) | |
tree | ec6b94f9b93632859e314bb12f544ae01f413000 | |
parent | 2f020a0d37e9bfb0b8ebc40062622ae4f200e4a1 (diff) | |
download | ratpoison-98a3dea008502975d0b4958a8dc2c4f37bfa6b80.zip |
integrated the number sources. windows now keep the number they're
given.
-rw-r--r-- | bar.c | 16 | ||||
-rw-r--r-- | data.h | 1 | ||||
-rw-r--r-- | list.c | 11 | ||||
-rw-r--r-- | main.c | 1 | ||||
-rw-r--r-- | manage.c | 4 | ||||
-rw-r--r-- | number.c | 18 | ||||
-rw-r--r-- | ratpoison.h | 3 |
7 files changed, 37 insertions, 17 deletions
@@ -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++; } } @@ -36,6 +36,7 @@ struct rp_window { screen_info *scr; Window w; + int number; char *name; int state; int last_access; @@ -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; @@ -124,6 +124,7 @@ main (int argc, char *argv[]) signal (SIGHUP, SIG_IGN); } + init_numbers (); init_window_list (); font = XLoadQueryFont (dpy, FONT_NAME); @@ -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. */ @@ -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); |