summaryrefslogtreecommitdiff
path: root/src/window.c
diff options
context:
space:
mode:
authorsabetts <sabetts>2005-06-11 17:23:27 +0000
committersabetts <sabetts>2005-06-11 17:23:27 +0000
commit6f21b38b010e1c1cb6866ca631adbbff4696c716 (patch)
treed7dd86fb61ecc75ad46d7442159656ef9b0f7317 /src/window.c
parentb9c8f7b7ee9930fa851392032ec3d36fe1ab2b61 (diff)
downloadratpoison-6f21b38b010e1c1cb6866ca631adbbff4696c716.zip
(isdigit): new function
(format_window_name): read a length argument and crop window names to that length. (get_window_list): length argument applies to %c and %a.
Diffstat (limited to 'src/window.c')
-rw-r--r--src/window.c45
1 files changed, 27 insertions, 18 deletions
diff --git a/src/window.c b/src/window.c
index 4d0fe08..cf625ab 100644
--- a/src/window.c
+++ b/src/window.c
@@ -622,13 +622,29 @@ 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
+#define STATE_READ 0
+#define STATE_ESCAPE 1
+#define STATE_NUMBER 2
int state = STATE_READ;
char dbuf[10];
int width = -1;
@@ -671,31 +687,21 @@ format_window_name (char *fmt, rp_window_elem *win_elem, rp_window *other_win,
break;
case 't':
- /* 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));
+ concat_width (buffer, window_name (win_elem->win), width);
break;
case 'a':
if (win_elem->win->res_name)
- sbuf_concat (buffer, win_elem->win->res_name);
+ concat_width (buffer, win_elem->win->res_name, width);
else
- sbuf_concat (buffer, "None");
+ concat_width (buffer, "None", width);
break;
case 'c':
if (win_elem->win->res_class)
- sbuf_concat (buffer, win_elem->win->res_class);
+ concat_width (buffer, win_elem->win->res_class, width);
else
- sbuf_concat (buffer, "None");
+ concat_width (buffer, "None", width);
break;
case 'i':
@@ -739,6 +745,9 @@ format_window_name (char *fmt, rp_window_elem *win_elem, rp_window *other_win,
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