summaryrefslogtreecommitdiff
path: root/src/window.c
diff options
context:
space:
mode:
authorsabetts <sabetts>2006-03-15 05:43:38 +0000
committersabetts <sabetts>2006-03-15 05:43:38 +0000
commit9c9e71d4e681112668240c6c0c9715b8f77ed673 (patch)
tree0d818469f129c7f7aecf933c93599f77df00e651 /src/window.c
parent0d47aa583ef5ce0178de264f46fcb028c8592e53 (diff)
downloadratpoison-9c9e71d4e681112668240c6c0c9715b8f77ed673.zip
(init_user_commands): add optional argument to "info"
(cmd_info): handle optional argument * src/format.c: new file * src/format.h: new file * Makefile.am (ratpoison_SOURCES): add format.c and format.h * src/actions.c (set_infofmt): new function (wingravity_to_string): char * instead of static char * because needed in format.c (cmd_info): use format_string * src/actions.h (wingravity_to_string): add prototype * src/data.h (info_fmt): new variable * src/main.c (init_defaults): set a value for defaults.info_fmt * src/ratpoison.h: include format.h * src/windows.c (get_window_list): use format_string (isdigit): remove function as the formatting is now done in format.c (concat_width): likewise (format_window_name): likewise
Diffstat (limited to 'src/window.c')
-rw-r--r--src/window.c147
1 files changed, 1 insertions, 146 deletions
diff --git a/src/window.c b/src/window.c
index ad926f4..3d021a4 100644
--- a/src/window.c
+++ b/src/window.c
@@ -705,151 +705,6 @@ print_window_information (rp_group *group, rp_window *win)
window_name(win), group->number);
}
-/* format options
- %n - Window number
- %s - Window status (current window, last window, etc)
- %t - Window Name
- %a - application name
- %c - resource class
- %i - X11 Window ID
- %l - last access number
- %f - print the frame number the window is in
-
- */
-static int
-isdigit (ch)
-{
- return ch >= '0' && ch <= '9';
-}
-
-/* if width >= 0 then limit the width of s to width chars. */
-static void
-concat_width (struct sbuf *buf, char *s, int width)
-{
- if (width >= 0)
- {
- char *s1 = xsprintf ("%%.%ds", width);
- char *s2 = xsprintf (s1, s);
- sbuf_concat (buf, s2);
- free (s1);
- free (s2);
- }
- else
- sbuf_concat (buf, s);
-}
-
-static void
-format_window_name (char *fmt, rp_window_elem *win_elem, rp_window *other_win,
- struct sbuf *buffer)
-{
-#define STATE_READ 0
-#define STATE_ESCAPE 1
-#define STATE_NUMBER 2
- int state = STATE_READ;
- char dbuf[10];
- int width = -1;
-
- for(; *fmt; fmt++)
- {
- if (*fmt == '%' && state == STATE_READ)
- {
- state = STATE_ESCAPE;
- continue;
- }
-
- if ((state == STATE_ESCAPE || state == STATE_NUMBER) && isdigit(*fmt))
- {
- /* Accumulate the width one digit at a time. */
- if (state == STATE_ESCAPE)
- width = 0;
- width *= 10;
- width += *fmt - '0';
- state = STATE_NUMBER;
- continue;
- }
-
- if (state == STATE_ESCAPE || state == STATE_NUMBER)
- {
- switch (*fmt)
- {
- case 'n':
- snprintf (dbuf, 10, "%d", win_elem->number);
- sbuf_concat (buffer, dbuf);
- break;
-
- case 's':
- if (win_elem->win == current_window())
- sbuf_concat (buffer, "*");
- else if (win_elem->win == other_win)
- sbuf_concat (buffer, "+");
- else
- sbuf_concat (buffer, "-");
- break;
-
- case 't':
- concat_width (buffer, window_name (win_elem->win), width);
- break;
-
- case 'a':
- if (win_elem->win->res_name)
- concat_width (buffer, win_elem->win->res_name, width);
- else
- concat_width (buffer, "None", width);
- break;
-
- case 'c':
- if (win_elem->win->res_class)
- concat_width (buffer, win_elem->win->res_class, width);
- else
- concat_width (buffer, "None", width);
- break;
-
- case 'i':
- snprintf (dbuf, 9, "%ld", (unsigned long)win_elem->win->w);
- sbuf_concat (buffer, dbuf);
- break;
-
- case 'l':
- snprintf (dbuf, 9, "%d", win_elem->win->last_access);
- sbuf_concat (buffer, dbuf);
- break;
-
- case 'f':
- if (win_elem->win->frame_number != EMPTY)
- {
- snprintf (dbuf, 9, "%d", win_elem->win->frame_number);
- sbuf_concat (buffer, dbuf);
- }
- else
- sbuf_concat (buffer, " ");
- break;
-
- case '%':
- sbuf_concat (buffer, "%");
- break;
-
- default:
- sbuf_printf_concat (buffer, "%%%c", *fmt);
- break;
- }
-
- /* Reset the 'escape' state. */
- state = STATE_READ;
- width = -1;
- }
- else
- {
- /* Insert the character. */
- dbuf[0] = *fmt;
- dbuf[1] = 0;
- sbuf_concat (buffer, dbuf);
- }
- }
-#undef STATE_READ
-#undef STATE_ESCAPE
-#undef STATE_NUMBER
-}
-
/* get the window list and store it in buffer delimiting each window
with delim. mark_start and mark_end will be filled with the text
positions for the start and end of the current window. */
@@ -878,7 +733,7 @@ get_window_list (char *fmt, char *delim, struct sbuf *buffer,
if (!delim)
sbuf_concat (buffer, " ");
- format_window_name (fmt, we, other_window, buffer);
+ format_string (fmt, we, buffer);
/* A hack, pad the window with a space at the beginning and end
if there is no delimiter. */