summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/ChangeLog18
-rw-r--r--src/actions.c10
-rw-r--r--src/bar.c2
-rw-r--r--src/conf.h5
-rw-r--r--src/input.c84
-rw-r--r--src/list.c53
-rw-r--r--src/list.h1
-rw-r--r--src/manage.c2
8 files changed, 136 insertions, 39 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index a8a7128..f1995a8 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,21 @@
+2001-02-19 shawn <sabetts@diggin.lamenet.tmp>
+
+ * 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.
+
2001-02-18 shawn <sabetts@diggin.lamenet.tmp>
* conf.h: restructured comments. Added #define for AUTO_CLOSE.
diff --git a/src/actions.c b/src/actions.c
index b7f00ff..1240c3a 100644
--- a/src/actions.c
+++ b/src/actions.c
@@ -557,10 +557,11 @@ void
goto_window_number (void *data)
{
int n = (int)data;
-
rp_window *win;
- if ((win = find_window_by_number (n)) == NULL)
+ win = find_window_by_number (n);
+
+ if (win == NULL)
{
/* Display window list to indicate failure. */
/* FIXME: We can always assume there is 1 screen, but which one
@@ -569,6 +570,11 @@ goto_window_number (void *data)
return;
}
+ if (win == rp_current_window)
+ {
+ /* TODO: Add message "This IS window # (xxx) */
+ }
+
set_active_window (win);
}
diff --git a/src/bar.c b/src/bar.c
index 15f0090..24380e8 100644
--- a/src/bar.c
+++ b/src/bar.c
@@ -104,7 +104,7 @@ update_window_names (screen_info *s)
sbuf_clear (bar_buffer);
- for (w = rp_window_tail; w; w = w->prev)
+ for (w = rp_window_head; w; w = w->next)
{
PRINT_DEBUG ("%d-%s\n", w->number, w->name);
diff --git a/src/conf.h b/src/conf.h
index 1f5e860..6a9629f 100644
--- a/src/conf.h
+++ b/src/conf.h
@@ -29,12 +29,15 @@
#define MODIFIER_PREFIX ControlMask
/* Pressing a key sends the mouse to the bottom right corner. This
- doesn't work ver well yet. */
+ doesn't work very well yet. */
//#define HIDE_MOUSE
/* Quit ratpoison when there are no more managed windows. */
//#define AUTO_CLOSE
+/* The minimum size of the input window */
+#define INPUT_WINDOW_SIZE 200
+
#define BAR_FG_COLOR "black"
#define BAR_BG_COLOR "white"
#define FONT_NAME "9x15bold"
diff --git a/src/input.c b/src/input.c
index 835d233..ffba346 100644
--- a/src/input.c
+++ b/src/input.c
@@ -127,50 +127,70 @@ read_key (KeySym *keysym, unsigned int *modifiers)
} while (IsModifierKey (*keysym));
}
+static void
+update_input_window (screen_info *s, char *prompt, char *input, int input_len)
+{
+ int prompt_width = XTextWidth (s->font, prompt, strlen (prompt));
+ int input_width = XTextWidth (s->font, input, input_len);
+ int width;
+
+ width = BAR_X_PADDING * 2 + prompt_width + input_width;
+
+ if (width < INPUT_WINDOW_SIZE + prompt_width)
+ {
+ width = INPUT_WINDOW_SIZE + prompt_width;
+ }
+
+ XMoveResizeWindow (dpy, s->input_window,
+ bar_x (s, width), bar_y (s), width,
+ (FONT_HEIGHT (s->font) + BAR_Y_PADDING * 2));
+
+ XClearWindow (dpy, s->input_window);
+
+ XDrawString (dpy, s->input_window, s->normal_gc,
+ BAR_X_PADDING,
+ BAR_Y_PADDING + s->font->max_bounds.ascent, prompt,
+ strlen (prompt));
+
+ XDrawString (dpy, s->input_window, s->normal_gc,
+ BAR_X_PADDING + prompt_width,
+ BAR_Y_PADDING + s->font->max_bounds.ascent, input,
+ input_len);
+}
+
char *
get_input (char *prompt)
{
screen_info *s = current_screen ();
- int cur_len; /* Current length of the string. */
- int allocated_len=100; /* The ammount of memory we allocated for str */
+ int cur_len = 0; /* Current length of the string. */
+ int allocated_len=100; /* The amount of memory we allocated for str */
KeySym ch;
unsigned int modifier;
int revert;
Window fwin;
- int prompt_width = XTextWidth (s->font, prompt, strlen (prompt));
- int width = 200 + prompt_width;
char *str;
+ /* Allocate some memory to start with */
+ str = (char *) malloc ( allocated_len );
+ if ( str == NULL )
+ {
+ PRINT_ERROR ("Out of memory\n");
+ exit (EXIT_FAILURE);
+ }
/* We don't want to draw overtop of the program bar. */
hide_bar (s);
XMapWindow (dpy, s->input_window);
- XMoveResizeWindow (dpy, s->input_window,
- bar_x (s, width), bar_y (s), width,
- (FONT_HEIGHT (s->font) + BAR_Y_PADDING * 2));
XClearWindow (dpy, s->input_window);
XRaiseWindow (dpy, s->input_window);
- /* draw the window prompt. */
- XDrawString (dpy, s->input_window, s->normal_gc, BAR_X_PADDING,
- BAR_Y_PADDING + s->font->max_bounds.ascent, prompt,
- strlen (prompt));
+ update_input_window (s, prompt, str, cur_len);
XGetInputFocus (dpy, &fwin, &revert);
XSetInputFocus (dpy, s->input_window, RevertToPointerRoot, CurrentTime);
/* XSync (dpy, False); */
- cur_len = 0;
-
- /* Allocate some memory */
- str = (char *) malloc ( 100 ); /* Most of the time people
- won't type more than 100 chars, will they ?*/
- if ( str == NULL )
- {
- PRINT_ERROR ("Out of memory\n");
- exit (EXIT_FAILURE);
- }
read_key (&ch, &modifier);
while (ch != XK_Return)
@@ -179,30 +199,24 @@ get_input (char *prompt)
if (ch == XK_BackSpace)
{
if (cur_len > 0) cur_len--;
- XClearWindow (dpy, s->input_window);
- XDrawString (dpy, s->input_window, s->normal_gc, BAR_X_PADDING,
- BAR_Y_PADDING + s->font->max_bounds.ascent, prompt,
- strlen (prompt));
- XDrawString (dpy, s->input_window, s->normal_gc,
- BAR_X_PADDING + prompt_width,
- BAR_Y_PADDING + s->font->max_bounds.ascent, str,
- cur_len);
+ update_input_window(s, prompt, str, cur_len);
}
else
{
if (cur_len > allocated_len - 1)
{
- str = realloc ( str, allocated_len + 100 );
- /** FIXME: realloc(3) is unlcear to me, how should I check for
- its success ? - algernon **/
allocated_len += 100;
+ str = realloc ( str, allocated_len );
+ if (str == NULL)
+ {
+ PRINT_ERROR ("Out of memory\n");
+ exit (EXIT_FAILURE);
+ }
}
str[cur_len] = ch;
cur_len++;
- XDrawString (dpy, s->input_window, s->normal_gc,
- BAR_X_PADDING + prompt_width,
- BAR_Y_PADDING + s->font->max_bounds.ascent, str, cur_len);
+ update_input_window(s, prompt, str, cur_len);
}
read_key (&ch, &modifier);
diff --git a/src/list.c b/src/list.c
index 83b4e03..83241b3 100644
--- a/src/list.c
+++ b/src/list.c
@@ -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)
{
diff --git a/src/list.h b/src/list.h
index d292bbf..04100f6 100644
--- a/src/list.h
+++ b/src/list.h
@@ -35,5 +35,6 @@ void set_current_window (rp_window *win);
int goto_window_name (char *name);
rp_window *find_last_accessed_window ();
rp_window *find_window_by_number (int n);
+void sort_window_list_by_number ();
#endif /* ! _RATPOISON_LIST_H */
diff --git a/src/manage.c b/src/manage.c
index cda4dde..6d15e05 100644
--- a/src/manage.c
+++ b/src/manage.c
@@ -196,6 +196,8 @@ manage (rp_window *win, screen_info *s)
win->state = STATE_MAPPED;
win->number = get_unique_window_number ();
+ sort_window_list_by_number();
+
PRINT_DEBUG ("window '%s' managed.\n", win->name);
}