Re: [dwm] [dvtm]: fix for status bar

2008-12-08 Thread Marc Andre Tanner
On Sat, Nov 29, 2008 at 09:12:20PM +0100, Claudio M. Alessi wrote:
 I tested your patch a bit and it seems to work properly.
 Does it will going in upstream?

I hope to push it sometime next weekend and then finally release
dvtm-0.5.

Regards,
Marc

-- 
 Marc Andre Tanner  http://www.brain-dump.org/  GPG key: CF7D56C0



Re: [dwm] [dvtm]: fix for status bar

2008-11-29 Thread Claudio M. Alessi
I tested your patch a bit and it seems to work properly.
Does it will going in upstream?

Thanks for your help and time.


Claudio M. Alessi

-- 
JID: [EMAIL PROTECTED]
WWW: http://dinotte.teroristi.org



Re: [dwm] [dvtm]: fix for status bar

2008-11-26 Thread Marc Andre Tanner
On Tue, Nov 25, 2008 at 12:21:53AM +0100, Claudio M. Alessi wrote:
 On Thu, Nov 20, 2008 at 10:48:30PM +0100, Marc Andre Tanner wrote:
  Problem is that strlen is used to calculate character width, which
  doesn't work for utf8 therefore the statusbar content is not properly
  aligned.
 I don't think i have the skills to fully solve the problem. I guess it
 would be useful a code like the following into the drawbar() function
 (replacing the strlen(3) call):
 
l = mbstowcs(trash, stext, sizeof trash);
 
 This works properly with the right alignment but not with the left one.
 
 I'll RTFM and try to solve the problem, however if anyone is able to do
 the work it would be faster (better?) than me.

I also had to RTFM and as I am very tired right now I wouldn't be
surprised if there is a simpler way to accomplish it. Anyway attached is
a patch which seems to work for my limited test case. Please test,
review and post possible simplifications.

Thanks,
Marc

-- 
 Marc Andre Tanner  http://www.brain-dump.org/  GPG key: CF7D56C0
diff --git a/config.h b/config.h
index dc0256b..1ba 100644
--- a/config.h
+++ b/config.h
@@ -27,9 +27,8 @@
 #define BAR_ATTRA_NORMAL
 #define BAR_FG  BLUE
 #define BAR_BG  -1
-/* true if the statusbar text should be right aligned,
- * set to false if you prefer it left aligned */
-#define BAR_ALIGN_RIGHT true
+/* determines whether the statusbar text should be right or left aligned */
+#define BAR_ALIGN	ALIGN_RIGHT
 /* separator between window title and window number */
 #define SEPARATOR  | 
 /* printf format string for the window title, first %s
diff --git a/dvtm.c b/dvtm.c
index afcb498..f18d573 100644
--- a/dvtm.c
+++ b/dvtm.c
@@ -126,6 +126,7 @@ static void zoom(const char *args[]);
 static void lock(const char *key[]);
 
 #ifdef CONFIG_STATUSBAR
+enum { ALIGN_LEFT, ALIGN_RIGHT };
 static void togglebar(const char *args[]);
 #endif
 
diff --git a/statusbar.c b/statusbar.c
index d918a5b..648514e 100644
--- a/statusbar.c
+++ b/statusbar.c
@@ -22,25 +22,28 @@ updatebarpos(void) {
 
 static void
 drawbar() {
-	int s, l, maxlen = width - 2;
-	char t = stext[maxlen];
+	wchar_t wbuf[sizeof stext];
+	int w, maxwidth = width - 2;
 	if (barpos == BarOff || !*stext)
 		return;
 	curs_set(0);
 	attrset(BAR_ATTR);
 	madtty_color_set(stdscr, BAR_FG, BAR_BG);
 	mvaddch(by, 0, '[');
-	stext[maxlen] = '\0';
-	l = strlen(stext);
-	if (BAR_ALIGN_RIGHT)
-		for (s = 0; s + l  maxlen; s++)
+	if (mbstowcs(wbuf, stext, sizeof stext) == -1)
+		return;
+	if ((w = wcswidth(wbuf, maxwidth)) == -1)
+		return;
+	if (BAR_ALIGN == ALIGN_RIGHT) {
+		for (int i = 0; i + w  maxwidth; i++)
 			addch(' ');
-	else
-		for (; l  maxlen; l++)
-			stext[l] = ' ';
+	}
 	addstr(stext);
-	stext[maxlen] = t;
-	addch(']');
+	if (BAR_ALIGN == ALIGN_LEFT) {
+		for (; w  maxwidth; w++)
+			addch(' ');
+	}
+	mvaddch(by, width - 1, ']');
 	attrset(NORMAL_ATTR);
 	if (sel)
 		curs_set(madtty_cursor(sel-term));


Re: [dwm] [dvtm]: fix for status bar

2008-11-24 Thread Claudio M. Alessi
On Thu, Nov 20, 2008 at 10:48:30PM +0100, Marc Andre Tanner wrote:
 Problem is that strlen is used to calculate character width, which
 doesn't work for utf8 therefore the statusbar content is not properly
 aligned.
I don't think i have the skills to fully solve the problem. I guess it
would be useful a code like the following into the drawbar() function
(replacing the strlen(3) call):

   l = mbstowcs(trash, stext, sizeof trash);

This works properly with the right alignment but not with the left one.

I'll RTFM and try to solve the problem, however if anyone is able to do
the work it would be faster (better?) than me.

Regards,
Claudio M. Alessi

-- 
JID: [EMAIL PROTECTED]
WWW: http://dinotte.teroristi.org



Re: [dwm] [dvtm]: fix for status bar

2008-11-20 Thread Marc Andre Tanner
On Thu, Nov 20, 2008 at 06:22:34PM +0100, Claudio M. Alessi wrote:
 On Wed, Nov 19, 2008 at 07:16:23PM +0100, Marc Andre Tanner wrote:
  Thanks, applied. Do you have a patch for the utf8 issue concerning
  the statusbar?
 You're welcome! I always use that script with dvtm without any problem.
 Can you tell me what's wrong (maybe attaching screenshot)? I have more
 time now to work on it.

Problem is that strlen is used to calculate character width, which
doesn't work for utf8 therefore the statusbar content is not properly
aligned.

 http://www.brain-dump.org/tmp/statusbar.png

Cheers,
Marc

-- 
 Marc Andre Tanner  http://www.brain-dump.org/  GPG key: CF7D56C0