summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsabetts <sabetts>2005-06-11 17:11:27 +0000
committersabetts <sabetts>2005-06-11 17:11:27 +0000
commitb9c8f7b7ee9930fa851392032ec3d36fe1ab2b61 (patch)
treef38183fb9d3866e1a92ce90305ad1dc75fb89230
parentdad664031ac1a8122f919314095ef42fb1973366 (diff)
downloadratpoison-b9c8f7b7ee9930fa851392032ec3d36fe1ab2b61.zip
(isdigit): new function
(format_window_name): read a length argument and crop window names to that length.
-rw-r--r--ChangeLog3
-rw-r--r--src/window.c44
2 files changed, 41 insertions, 6 deletions
diff --git a/ChangeLog b/ChangeLog
index 4a47a77..3bd4c22 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
2005-06-11 Shawn Betts <sabetts@vcn.bc.ca>
+ * src/window.c (isdigit): new function
+ (format_window_name): read a length argument and crop window names to that length.
+
* src/actions.c (cmd_tmpwm): stop waiting for the child if waitpid
produced an error.
diff --git a/src/window.c b/src/window.c
index d5d191d..4d0fe08 100644
--- a/src/window.c
+++ b/src/window.c
@@ -616,22 +616,43 @@ print_window_information (rp_group *group, rp_window *win)
%f - print the frame number the window is in
*/
+static int
+isdigit (ch)
+{
+ return ch >= '0' && ch <= '9';
+}
+
static void
format_window_name (char *fmt, rp_window_elem *win_elem, rp_window *other_win,
struct sbuf *buffer)
{
- int esc = 0;
+ #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 == '%' && !esc)
+ if (*fmt == '%' && state == STATE_READ)
+ {
+ state = STATE_ESCAPE;
+ continue;
+ }
+
+ if ((state == STATE_ESCAPE || state == STATE_NUMBER) && isdigit(*fmt))
{
- esc = 1;
+ /* Accumulate the width one digit at a time. */
+ if (state == STATE_ESCAPE)
+ width = 0;
+ width *= 10;
+ width += *fmt - '0';
+ state = STATE_NUMBER;
continue;
}
- if (esc)
+ if (state == STATE_ESCAPE || state == STATE_NUMBER)
{
switch (*fmt)
{
@@ -650,7 +671,17 @@ format_window_name (char *fmt, rp_window_elem *win_elem, rp_window *other_win,
break;
case 't':
- sbuf_concat (buffer, window_name (win_elem->win));
+ /* If a width is given, honour it. */
+ if (width >= 0)
+ {
+ char *s1 = xsprintf ("%%.%ds", width);
+ char *s2 = xsprintf (s1, window_name (win_elem->win));
+ sbuf_concat (buffer, s2);
+ free (s1);
+ free (s2);
+ }
+ else
+ sbuf_concat (buffer, window_name (win_elem->win));
break;
case 'a':
@@ -697,7 +728,8 @@ format_window_name (char *fmt, rp_window_elem *win_elem, rp_window *other_win,
}
/* Reset the 'escape' state. */
- esc = 0;
+ state = STATE_READ;
+ width = -1;
}
else
{